-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathICollectionScheme.h
565 lines (484 loc) · 17.2 KB
/
ICollectionScheme.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "CollectionInspectionAPITypes.h"
#include "SignalTypes.h"
#include "collection_schemes.pb.h"
#include <climits>
#include <cstdint>
#include <memory>
#include <vector>
namespace Aws
{
namespace IoTFleetWise
{
struct FetchInformation
{
/**
* @brief ID of signal to be fetched.
*/
SignalID signalID{ 0U };
/**
* @brief AST root node to specify condition to fetch data (nullptr for time-based fetching).
*/
ExpressionNode *condition{ nullptr };
/**
* @brief Specify if data fetching should occur only on rising edge of condition (false to true).
*/
bool triggerOnlyOnRisingEdge{ false };
/**
* @brief Max number of action executions (per action?) can occur per interval (refer executionIntervalMs).
*/
uint64_t maxExecutionPerInterval{ 0U };
/**
* @brief Action execution period - between consecutive action executions (per action?).
*/
uint64_t executionPeriodMs{ 0U };
/**
* @brief Action execution interval (per action?) (refer maxExecutionPerInterval).
*/
uint64_t executionIntervalMs{ 0U };
/**
* @brief Actions to be executed on fetching.
*/
std::vector<ExpressionNode *> actions;
};
struct SignalCollectionInfo
{
/**
* @brief Unique Signal ID provided by Cloud or Partial Signal Id generated internally see
* INTERNAL_SIGNAL_ID_BITMASK
*/
SignalID signalID{ 0 };
/**
* @brief The size of the ring buffer that will contain the data points for this signal
*/
uint32_t sampleBufferSize{ 0 };
/**
* @brief Minimum time period in milliseconds that must elapse between collecting samples. Samples
* arriving faster than this period will be dropped. A value of 0 will collect samples as fast
* as they arrive.
*/
uint32_t minimumSampleIntervalMs{ 0 };
/**
* @brief The size of a fixed window in milliseconds which will be used by aggregate condition
* functions to calculate min/max/avg etc.
*/
uint32_t fixedWindowPeriod{ 0 };
/**
* @brief When true, this signal will not be collected and sent to cloud. It will only be used in the
* condition logic with its associated fixed_window_period_ms. Default is false.
*/
bool isConditionOnlySignal{ false };
#ifdef FWE_FEATURE_STORE_AND_FORWARD
/**
* @brief The Id of the partition where this signal should be stored.
* This Id will be used to index into the partition configuration array.
*/
uint32_t dataPartitionId{ 0 };
#endif
};
struct CanFrameCollectionInfo
{
/**
* @brief CAN Message ID to collect. This Raw CAN message will be collected. Whatever number of bytes
* present on the bus for this message ID will be collected.
*/
CANRawFrameID frameID{ 0 };
/**
* @brief The Interface Id specified by the Decoder Manifest. This will contain the physical channel
* id of the hardware CAN Bus the frame is present on.
*/
InterfaceID interfaceID{ INVALID_INTERFACE_ID };
/**
* @brief Ring buffer size used to store these sampled CAN frames. One CAN Frame is a sample.
*/
uint32_t sampleBufferSize{ 0 };
/**
* @brief Minimum time period in milliseconds that must elapse between collecting samples. Samples
* arriving faster than this period will be dropped. A value of 0 will collect samples as fast
* as they arrive.
*/
uint32_t minimumSampleIntervalMs{ 0 };
};
enum class ExpressionNodeType
{
FLOAT = 0,
SIGNAL, // Node_Signal_ID
BOOLEAN,
STRING,
OPERATOR_SMALLER, // NodeOperator
OPERATOR_BIGGER,
OPERATOR_SMALLER_EQUAL,
OPERATOR_BIGGER_EQUAL,
OPERATOR_EQUAL,
OPERATOR_NOT_EQUAL,
OPERATOR_LOGICAL_AND,
OPERATOR_LOGICAL_OR,
OPERATOR_LOGICAL_NOT,
OPERATOR_ARITHMETIC_PLUS,
OPERATOR_ARITHMETIC_MINUS,
OPERATOR_ARITHMETIC_MULTIPLY,
OPERATOR_ARITHMETIC_DIVIDE,
WINDOW_FUNCTION, // NodeFunction
CUSTOM_FUNCTION,
IS_NULL_FUNCTION,
NONE
};
enum class WindowFunction
{
LAST_FIXED_WINDOW_AVG = 0,
PREV_LAST_FIXED_WINDOW_AVG,
LAST_FIXED_WINDOW_MIN,
PREV_LAST_FIXED_WINDOW_MIN,
LAST_FIXED_WINDOW_MAX,
PREV_LAST_FIXED_WINDOW_MAX,
NONE
};
struct ExpressionFunction
{
/**
* @brief Specify which window function to be used (in case ExpressionNodeType is WINDOW_FUNCTION).
*/
WindowFunction windowFunction{ WindowFunction::NONE };
/**
* @brief Specify custom function name and params (in case ExpressionNodeType is CUSTOM_FUNCTION).
*/
std::string customFunctionName;
std::vector<ExpressionNode *> customFunctionParams;
CustomFunctionInvocationID customFunctionInvocationId{};
};
// Instead of c style struct an object oriented interface could be implemented with different
// Implementations like LeafNodes like Signal or Float all inheriting from expressionNode.
struct ExpressionNode
{
/**
* @brief Indicated the action of the node if its an operator or a variable
*/
ExpressionNodeType nodeType{ ExpressionNodeType::FLOAT };
/**
* @brief AST Construction Left Side
*/
ExpressionNode *left{ nullptr };
/**
* @brief AST Construction Right Side
*/
ExpressionNode *right{ nullptr };
/**
* @brief Node Value is a floating point
*/
double floatingValue{ 0 };
/**
* @brief Node Value is boolean
*/
bool booleanValue{ false };
/**
* @brief Node Value is string
*/
std::string stringValue;
/**
* @brief Unique Signal ID provided by Cloud
*/
SignalID signalID{ 0 };
/**
* @brief Function operation on the nodes
*/
ExpressionFunction function;
};
#ifdef FWE_FEATURE_VISION_SYSTEM_DATA
struct S3UploadMetadata
{
/**
* @brief Bucket name for S3 upload
*/
std::string bucketName;
/**
* @brief Prefix to add to every upload object
*/
std::string prefix;
/**
* @brief Region of the S3 bucket for upload
*/
std::string region;
/**
* @brief Account ID of bucket owner
*/
std::string bucketOwner;
public:
/**
* @brief Overload of the == operator for S3UploadMetadata
* @param other Other S3UploadMetadata object to compare
* @return true if ==, false otherwise
*/
bool
operator==( const S3UploadMetadata &other ) const
{
return ( bucketName == other.bucketName ) && ( prefix == other.prefix ) && ( region == other.region ) &&
( bucketOwner == other.bucketOwner );
}
/**
* @brief Overloaded != operator for S3UploadMetadata.
* @param other Other S3UploadMetadata to compare to.
* @return True if !=, false otherwise.
*/
bool
operator!=( const S3UploadMetadata &other ) const
{
return !( *this == other );
}
};
#endif
#ifdef FWE_FEATURE_STORE_AND_FORWARD
struct StorageOptions
{
/**
* @brief The total amount of space allocated to this campaign including all overhead. uint64 can support up to 8GB.
*/
uint64_t maximumSizeInBytes{ 0 };
/**
* @brief Specifies where the data should be stored withing the device.
* Implementation is defined by the user who integrates FWE with their filesystem library.
*/
std::string storageLocation;
/**
* @brief The minimum amount of time to keep data on disk after it is collected.
* When this TTL expires, data may be deleted, but it is not guaranteed to be deleted immediately after expiry.
* Can hold TTL more than 132 years.
*/
uint32_t minimumTimeToLiveInSeconds{ 0 };
};
struct UploadOptions
{
/**
* @brief Root condition node for the Abstract Syntax Tree.
*/
ExpressionNode *conditionTree{ nullptr };
};
struct PartitionConfiguration
{
/**
* @brief Optional Store and Forward storage options.
* If not specified, data in this partition will be uploaded in realtime.
*/
StorageOptions storageOptions;
/**
* @brief Store and Forward upload options defines when the stored data may be uploaded.
* It is only used when spoolingMode=TO_DISK. May be non-null only when spoolingMode=TO_DISK.
*/
UploadOptions uploadOptions;
};
#endif
/**
* @brief ICollectionScheme is used to exchange CollectionScheme between components
*
* This interface exist to abstract from the underlying data format which means no protobuf
* or jsoncpp headers etc. are exposed through this API.
* For example if protobuf is used this interface header abstract from this and presents another
* view to the data. This means in most scenarios the underlying type is changed (i.e protobuf schemas)
* also this interface needs to be changed.
* This abstraction increases overhead compared passing the raw low level format but increases
* decoupling. If this is identified to be a bottleneck it will be replaced by the low level data
* view.
*
*/
class ICollectionScheme
{
public:
/**
* @brief Signals_t is vector of IDs provided by Cloud that is unique across all signals found in the vehicle
* regardless of the network bus.
*/
using Signals_t = std::vector<SignalCollectionInfo>;
const Signals_t INVALID_COLLECTED_SIGNALS = std::vector<SignalCollectionInfo>();
/**
* @brief RawCanFrames_t is vector representing metadata for CAN collected DATA.
*/
using RawCanFrames_t = std::vector<CanFrameCollectionInfo>;
const RawCanFrames_t INVALID_RAW_CAN_COLLECTED_SIGNALS = std::vector<CanFrameCollectionInfo>();
#ifdef FWE_FEATURE_VISION_SYSTEM_DATA
/**
* @brief Complex signals can have multiple PartialSignalID. As complex signals are represented as a tree
* the SignalPath give the path inside the SignalID that contains the PartialSignalID.
*/
using PartialSignalIDLookup = std::unordered_map<PartialSignalID, std::pair<SignalID, SignalPath>>;
const PartialSignalIDLookup INVALID_PARTIAL_SIGNAL_ID_LOOKUP = PartialSignalIDLookup();
const S3UploadMetadata INVALID_S3_UPLOAD_METADATA = S3UploadMetadata();
#endif
#ifdef FWE_FEATURE_STORE_AND_FORWARD
/**
* @brief Configuration of store and forward campaign.
*/
using StoreAndForwardConfig = std::vector<PartitionConfiguration>;
const StoreAndForwardConfig INVALID_STORE_AND_FORWARD_CONFIG = std::vector<PartitionConfiguration>();
#endif
/**
* @brief ExpressionNode_t is a vector that represents the AST Expression Tree per collectionScheme provided.
*/
using ExpressionNode_t = std::vector<ExpressionNode>;
const ExpressionNode_t INVALID_EXPRESSION_NODES = std::vector<ExpressionNode>();
/**
* @brief FetchInformation_t is a vector that represents all fetch informations in the CollectionScheme.
*/
using FetchInformation_t = std::vector<FetchInformation>;
const FetchInformation_t INVALID_FETCH_INFORMATIONS = std::vector<FetchInformation>();
const uint64_t INVALID_COLLECTION_SCHEME_START_TIME = std::numeric_limits<uint64_t>::max();
const uint64_t INVALID_COLLECTION_SCHEME_EXPIRY_TIME = std::numeric_limits<uint64_t>::max();
const uint32_t INVALID_MINIMUM_PUBLISH_TIME = std::numeric_limits<uint32_t>::max();
const uint32_t INVALID_AFTER_TRIGGER_DURATION = std::numeric_limits<uint32_t>::max();
const uint32_t INVALID_PRIORITY_LEVEL = std::numeric_limits<uint32_t>::max();
const SyncID INVALID_COLLECTION_SCHEME_ID = SyncID();
const SyncID INVALID_DECODER_MANIFEST_ID = SyncID();
#ifdef FWE_FEATURE_STORE_AND_FORWARD
const std::string INVALID_CAMPAIGN_ARN = std::string();
#endif
virtual bool operator==( const ICollectionScheme &other ) const = 0;
virtual bool operator!=( const ICollectionScheme &other ) const = 0;
/**
* @brief indicates if the decoder manifest is prepared to be used for example by calling getters
*
* @return true if ready and false if not ready then build function must be called first
* */
virtual bool isReady() const = 0;
/**
* @brief Build internal structures from raw input so lazy initialization is possible
*
* @return true if build succeeded false if the collectionScheme is corrupted and can not be used
* */
virtual bool build() = 0;
/**
* @brief Get the unique collectionScheme ID in the form of an Amazon Resource Name
*
* @return A string containing the unique ID of this collectionScheme.
*/
virtual const SyncID &getCollectionSchemeID() const = 0;
#ifdef FWE_FEATURE_STORE_AND_FORWARD
/**
* @brief Get the Amazon Resource Name of the campaign this collectionScheme is part of
*
* @return A string containing the Campaign Arn of this collectionScheme
*/
virtual const std::string &getCampaignArn() const = 0;
#endif
/**
* @brief Get the associated Decoder Manifest ID of this collectionScheme
*
* @return A string containing the unique Decoder Manifest of this collectionScheme.
*/
virtual const SyncID &getDecoderManifestID() const = 0;
/**
* @brief Get Activation timestamp of the collectionScheme
*
* @return time since epoch in milliseconds
*/
virtual uint64_t getStartTime() const = 0;
/**
* @brief Get Deactivation timestamp of the collectionScheme
*
* @return time since epoch in milliseconds
*/
virtual uint64_t getExpiryTime() const = 0;
/**
* @brief Limit the rate at which a collection scheme triggers
*
* If a collection scheme condition is true but the last time the condition was triggered
* is less than this interval ago the trigger will be ignored
*
* @return interval in milliseconds
*/
virtual uint32_t getMinimumPublishIntervalMs() const = 0;
/**
* @brief Limit the rate at which a collection scheme triggers
*
* If a collection scheme condition is true but the last time the condition was triggered
* is less than this interval ago the trigger will be ignored
*
* @return interval in milliseconds
*/
virtual uint32_t getAfterDurationMs() const = 0;
/**
* @brief Should all active DTCs be included when sending out the collectionScheme
*/
virtual bool isActiveDTCsIncluded() const = 0;
/**
* @brief Should the collectionScheme trigger only once when the collectionScheme condition changes from false to
* true
*
* @return true: trigger on change from false to true, false: trigger as long condition is true
*/
virtual bool isTriggerOnlyOnRisingEdge() const = 0;
/**
* @brief get priority which is used by the offboard offboardconnectivity module
* A smaller value collectionScheme has more priority (takes precedence) over larger values
*/
virtual uint32_t getPriority() const = 0;
/**
* @brief Is it needed to persist the data
*/
virtual bool isPersistNeeded() const = 0;
/**
* @brief Is it needed to compress data before it is sent
*/
virtual bool isCompressionNeeded() const = 0;
/**
* @brief Returns the condition to trigger the collectionScheme
*
* @return the returned pointer is either nullptr or valid as long as ICollectionScheme is alive
*/
virtual const ExpressionNode *getCondition() const = 0;
/**
* @brief Returns all signals that this collectionScheme wants to collect
*
* @return if not ready an empty vector
*/
virtual const Signals_t &getCollectSignals() const = 0;
/**
* @brief Returns all raw can frames that this collectionScheme wants to collect
*
* @return if not ready an empty vector
*/
virtual const RawCanFrames_t &getCollectRawCanFrames() const = 0;
/**
* @brief Returns all of the Expression Nodes
*
* @return if not ready an empty vector
*/
virtual const ExpressionNode_t &getAllExpressionNodes() const = 0;
#ifdef FWE_FEATURE_VISION_SYSTEM_DATA
/**
* @brief Returns a lookup table to translate internal PartialSignalId to the signal id and path
* provided by cloud
*
* @return if not ready an empty unordered_map
*/
virtual const PartialSignalIDLookup &getPartialSignalIdToSignalPathLookupTable() const = 0;
/**
* @brief Returns S3 Upload Metadata
*
* @return if not ready empty struct
*/
virtual S3UploadMetadata getS3UploadMetadata() const = 0;
#endif
#ifdef FWE_FEATURE_STORE_AND_FORWARD
/**
* @brief Returns store and forward campaign configuration
*
* @return if not ready an empty vector
*/
virtual const StoreAndForwardConfig &getStoreAndForwardConfiguration() const = 0;
#endif
/**
* @brief Get all expression nodes used for fetching conditions. Return empty vector if it is not ready.
*/
virtual const ExpressionNode_t &getAllExpressionNodesForFetchCondition() const = 0;
/**
* @brief Get all expression nodes used for fetching actions. Return empty vector if it is not ready.
*/
virtual const ExpressionNode_t &getAllExpressionNodesForFetchAction() const = 0;
/**
* @brief Get all fetch informations. Return empty vector if it is not ready.
*/
virtual const FetchInformation_t &getAllFetchInformations() const = 0;
virtual ~ICollectionScheme() = default;
};
} // namespace IoTFleetWise
} // namespace Aws