forked from Eba-M/E3DC-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RscpProtocol.h
executable file
·555 lines (551 loc) · 27.7 KB
/
RscpProtocol.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
/*
* RscpProtocol.h
*
* Created on: 19.05.2014
* Author: dikirile
*/
#ifndef RSCPPROTOCOL_H_
#define RSCPPROTOCOL_H_
#include <vector>
#include <string>
#include <string.h>
#include "RscpTypes.h"
class RscpProtocol {
public:
/*
* Constructor
*/
RscpProtocol();
/*
* Destructor
*/
virtual ~RscpProtocol();
/*
* \brief Function to get the total expected length that the frame buffer inside \var data should have (not has).
* This function also validates the MAGIC and VERSION of the frame. The frame inside the \var data buffer
* does not have to be complete but should at least have the size of an SRscpFrameHeader in bytes.
* @param data - Pointer to the raw data frame buffer
* @param length - Length of data buffer in bytes. Must be at least sizeof(SRscpFrameHeader) bytes.
* @return - RSCP error code if the function fails or the amount of bytes the frame should have to be full.
*/
int32_t getFrameLength(const uint8_t * data, const uint32_t & length);
/*
* \brief Create a RSCP frame from one single RscpValue struct into the pre-allocated \var frameBuffer.
* The data is aligned in line inside the frameBuffer structure to allow direct send of the complete frame.
* The user is responsible to free the memory of \var frameBuffer with RscpProtocol::destroyFrameBuffer().
* @param frame - Pointer to an rscp frame struct (should be != NULL)
* @param data - Pointer to the first RSCP value struct in line.
* @param dataLength - Data length of the data buffer in bytes.
* @param calcCRC - If set TRUE the CRC for the frame is calculated and appended to the frame.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createFrameAsBuffer(SRscpFrameBuffer* frameBuffer, const uint8_t * data, uint16_t dataLength, bool calcCRC);
/*
* \brief Create a RSCP frame from one single RscpValue struct into the pre-allocated \var frameBuffer.
* The data is aligned in line inside the frameBuffer structure to allow direct send of the complete frame.
* The user is responsible to free the memory of \var frameBuffer with RscpProtocol::destroyFrameBuffer().
* @param frame - Pointer to an rscp frame struct (should be != NULL)
* @param data - RSCP value struct
* @param calcCRC - If set TRUE the CRC for the frame is calculated and appended to the frame.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createFrameAsBuffer(SRscpFrameBuffer* frameBuffer, const SRscpValue & data, bool calcCRC);
/*
* \brief Create a RSCP frame from more than one RscpValue struct into the pre-allocated \var frameBuffer.
* The data is aligned in line inside the frameBuffer structure to allow direct send of the complete frame.
* The user is responsible to free the memory of \var frameBuffer with RscpProtocol::destroyFrameBuffer().
* @param frame - Pointer to an rscp frame struct (should be != NULL)
* @param data - Reference RSCP value struct
* @param calcCRC - If set TRUE the CRC for the frame is calculated and appended to the frame.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createFrameAsBuffer(SRscpFrameBuffer *frameBuffer, const std::vector<SRscpValue> & data, bool calcCRC);
/*
* \brief Create a RSCP frame from SRscpFrame struct into the pre-allocated \var frameBuffer.
* The data is aligned in line inside the frameBuffer structure to allow direct send of the complete frame.
* The user is responsible to free the memory of \var frameBuffer with RscpProtocol::destroyFrameBuffer().
* @param frame - Pointer to an rscp frame struct (should be != NULL)
* @param data - vector with RSCP value structs
* @param calcCRC - If set TRUE the CRC for the frame is calculated and appended to the frame.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createFrameAsBuffer(SRscpFrameBuffer *frameBuffer, const SRscpFrame & frame, bool calcCRC);
/*
* \brief Create a RSCP frame from one single RscpValue struct into the pre-allocated \var frame.
* The user is responsible to free the memory of \var frame with RscpProtocol::destroyFrameData().
* @param frame - Pointer to an rscp frame struct (should be != NULL)
* @param data - RSCP value struct
* @param calcCRC - If set TRUE the CRC for the frame is calculated and appended to the frame.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createFrame(SRscpFrame* frame, const SRscpValue & data, bool calcCRC);
/*
* \brief Create a RSCP frame from more than one RscpValue struct into the pre-allocated \var frame.
* The user is responsible to free the memory of \var frame with RscpProtocol::destroyFrameData().
* @param frame - Pointer to an rscp frame struct (should be != NULL)
* @param data - vector with RSCP value structs
* @param calcCRC - If set TRUE the CRC for the frame is calculated and appended to the frame.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createFrame(SRscpFrame* frame, const std::vector<SRscpValue> & data, bool calcCRC);
/*
* \brief Function to parse raw frame data from \var data of length \var length
* into the preallocated struct \var frame.
* The user is responsible to free the memory of \var frame with RscpProtocol::destroyFrameData().
* @param data - Pointer to the raw data frame buffer
* @param length - Length of data in bytes
* @param frame - Frame buffer into which the data is parsed (should be != NULL)
* @return - RSCP error code if the function fails or processed amount of bytes on success
*/
int32_t parseFrame(const uint8_t* data, const uint32_t & length, SRscpFrame* frame);
/*
* \brief Function to parse raw tag data from \var data of length \var length
* and return a vector of tags.
* The user is responsible to free the memory of \var frameData with RscpProtocol::destroyValueData().
* @param data - Pointer to the raw data frame buffer
* @param length - Length of data in bytes
* @param frameData - Reference to a data vector of SRscpValues
* @return - RSCP error code if the function fails or processed amount of bytes on success
*/
int32_t parseData(const uint8_t* data, const uint32_t & length, std::vector<SRscpValue> & frameData);
/*
* \biref This function allocates memory of size \var size. If data is already allocated it will reallocate the requested size.
* @param value - Pointer to the RSCP value struct.
* @param size - The buffer size that is required
* @return TRUE if data was allocated otherwise false.
*/
bool allocateMemory(SRscpValue* value, size_t size);
/*
* \brief Create value as a new RSCP tag inside an RSCP value struct \var response.
* The struct length is set 0 and the data type to RSCP::eTypeNone. The data pointer
* is set to NULL pointer.
* @param response - RSCP value struct into which the value should be added as a new RSCP tag.
* @param tag - TAG number that should be used for this tag.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag) {
return createValue(response, tag, NULL, 0, RSCP::eTypeNone);
}
/*
* \brief Create value as a new RSCP tag inside an RSCP value struct \var response.
* The struct length is incremented further and the necessary data is allocated.
* The allocated data in the \var response.data has to be freed by the user when
* unused anymore.
* The user is responsible to free the memory of \var response with RscpProtocol::destroyValueData().
* @param response - RSCP value struct into which the value should be added as a new RSCP tag.
* @param tag - TAG number that should be used for this tag.
* @param value - The value with the datatype that should be added to the tag.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const bool & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeBool);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const char & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const char & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeChar8);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const int8_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeChar8);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUChar8);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const int16_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const int16_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeInt16);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint16_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const uint16_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUInt16);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const int32_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const int32_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeInt32);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUInt32);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const int64_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const int64_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeInt64);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint64_t & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const uint64_t & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUInt64);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const float & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const float & value) {
return createValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeFloat32);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const double & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const double & value) {
return createValue(response, tag, (uint8_t *)&value, sizeof(value), RSCP::eTypeDouble64);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const SRscpTimestamp & timestamp)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const SRscpTimestamp & timestamp) {
return createValue(response, tag, (uint8_t *)×tamp, sizeof(timestamp), RSCP::eTypeTimestamp);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const char * value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const char * value) {
return createValue(response, tag, (uint8_t*)value, strlen(value), RSCP::eTypeString);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const std::string & value)
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const std::string & value) {
return createValue(response, tag, (uint8_t*)value.c_str(), value.size(), RSCP::eTypeString);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const bool & value);
*
* This function copies the \var value.data and adds it to the \var response.data buffer. The \var value.data buffer
* is not freed and has to be freed by the user. The datatype is therefore set as RSCP::eTypeContainer.
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const SRscpValue & value) {
return createValue(response, tag, std::vector<SRscpValue>(1, value));
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const SRscpValue & value)
*
* Copy a vector of SRscpValue into a new container with the tag \var tag.
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const std::vector<SRscpValue> & value);
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const bool & value);
*
* This function copies the \var value buffer and adds it to the \var response.data buffer. The \var value.data buffer
* is not freed and has to be freed by the user. The datatype is therefore set as RSCP::eTypeByteArray.
* @param value - Pointer to the value buffer
* @param dataLength - Length of the value buffer
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* value, const uint16_t & dataLength) {
return createValue(response, tag, value, dataLength, RSCP::eTypeByteArray);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* value, const uint16_t & dataLength);
*
* Same as RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* value, const uint16_t & dataLength)
* but the data type can be user defined.
*/
int32_t createValue(SRscpValue* response, const SRscpTag & tag, const uint8_t * data, const uint16_t & dataLength, const uint8_t &dataType);
/*
* @copydoc RscpProtocol::createErrorValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & error)
*/
int32_t createErrorValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & error) {
return createValue(response, tag, (uint8_t *)&error, sizeof(error), RSCP::eTypeError);
}
/*
* @copydoc RscpProtocol::createValue(SRscpValue* response, const SRscpTag & tag, const bool & value);
*
* This function just sets the tag and the datatype inside the response variable.
* It does not allocate any memory or modify the length of the response.
*/
int32_t createValueType(SRscpValue* response, const SRscpTag & tag, const uint8_t & dataType) {
return createValue(response, tag, NULL, 0, dataType);
}
/*
* @copydoc RscpProtocol::createContainerValue(SRscpValue* response, const SRscpTag & tag)
*/
int32_t createContainerValue(SRscpValue* response, const SRscpTag & tag) {
return createValueType(response, tag, RSCP::eTypeContainer);
}
/*
* \brief The appendValue functions are equivalent to the createValue function but they create a new SRscpValue inside an existing SRscpValue
* The user is responsible to free the memory of \var response with RscpProtocol::destroyValueData().
*/
int32_t appendValue(SRscpValue* response, const SRscpTag & tag) {
return appendValue(response, tag, NULL, 0, RSCP::eTypeNone);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const bool & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeBool);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const char & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeChar8);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const int8_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeChar8);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const uint8_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUChar8);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const int16_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeInt16);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const uint16_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUInt16);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const int32_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeInt32);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUInt32);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const int64_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeInt64);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const uint64_t & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeUInt64);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const float & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeFloat32);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const double & value) {
return appendValue(response, tag, (uint8_t *) &value, sizeof(value), RSCP::eTypeDouble64);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const char * value) {
return appendValue(response, tag, (uint8_t*)value, strlen(value), RSCP::eTypeString);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const std::string & value) {
return appendValue(response, tag, (uint8_t *) value.c_str(), value.size(), RSCP::eTypeString);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const SRscpTimestamp & timestamp) {
return appendValue(response, tag, (uint8_t *) ×tamp, sizeof(timestamp), RSCP::eTypeTimestamp);
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const SRscpValue & value) {
return appendValue(response, tag, std::vector<SRscpValue>(1, value));
}
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const std::vector<SRscpValue> & value);
/*
* These functions append the value struct(s) into the data field of response without changing the tag variable of the response.
* The length variable of the response and the data variable are increased.
*/
int32_t appendValue(SRscpValue* response, const SRscpValue & value) {
return appendValue(response, std::vector<SRscpValue>(1, value));
}
/*
* @copydoc RscpProtocol::appendValue(SRscpValue* response, const SRscpValue & value);
*
* These functions append the value struct(s) into the data field of response without changing the tag variable of the response.
* The length variable of the response and the data variable are increased.
*/
int32_t appendValue(SRscpValue* response, const std::vector<SRscpValue> & value);
/*
* @copydoc RscpProtocol::appendValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* value, const uint16_t & dataLength);
*
* This function adds a new TAG value with \var value as the data of \var dataLength bytes.
*/
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* value, const uint16_t & dataLength) {
return appendValue(response, tag, value, dataLength, RSCP::eTypeByteArray);
}
/*
* @copydoc RscpProtocol::appendValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* value, const uint16_t & dataLength, const uint8_t &dataType);
*
* This function adds a new TAG value with \var value as the data of \var dataLength bytes and \var dataType as type.
*/
int32_t appendValue(SRscpValue* response, const SRscpTag & tag, const uint8_t* data, const uint16_t & dataLength, const uint8_t &dataType);
/*
* @copydoc RscpProtocol::appendValueType(SRscpValue* response, const SRscpTag & tag, const bool & value);
*
* This function just adds a tag and sets the datatype inside the response variable. The length is set 0.
*/
int32_t appendValueType(SRscpValue* response, const SRscpTag & tag, const uint8_t & dataType) {
return appendValue(response, tag, NULL, 0, dataType);
}
/*
* @copydoc RscpProtocol::appendErrorValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & error)
*/
int32_t appendErrorValue(SRscpValue* response, const SRscpTag & tag, const uint32_t & error) {
return appendValue(response, tag, (uint8_t *)&error, sizeof(error), RSCP::eTypeError);
}
/*!
* \brief This templates is called by the get functions to unify the getting process of all datatypes.
*/
template <class cType>
cType getValue(const SRscpValue* value) {
if((value == NULL) || (value->data == NULL)) {
return cType();
}
// if the size is smaller than needed copy only the smaller part
if(sizeof(cType) <= value->length) {
cType tTmp;
memcpy(&tTmp, value->data, sizeof(cType));
return tTmp;
}
// if the size needed is bigger then zero out the rest
else {
cType tTmp;
memset(&tTmp, 0, sizeof(cType));
memcpy(&tTmp, value->data, value->length);
return tTmp;
}
}
/*
* \brief Get a value from the RSCP struct \var value as a define return data type.
* @param value - The pointer to a struct RSCP.
* @return - The value in the requested data type.
*/
bool getValueAsBool(const SRscpValue* value) {
return getValue<bool>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
int8_t getValueAsChar8(const SRscpValue* value) {
return getValue<int8_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
uint8_t getValueAsUChar8(const SRscpValue* value) {
return getValue<uint8_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
int16_t getValueAsInt16(const SRscpValue* value) {
return getValue<int16_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
uint16_t getValueAsUInt16(const SRscpValue* value) {
return getValue<uint16_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
int32_t getValueAsInt32(const SRscpValue* value) {
return getValue<int32_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
uint32_t getValueAsUInt32(const SRscpValue* value) {
return getValue<uint32_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
int64_t getValueAsInt64(const SRscpValue* value) {
return getValue<int64_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
uint64_t getValueAsUInt64(const SRscpValue* value) {
return getValue<uint64_t>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
float getValueAsFloat32(const SRscpValue* value) {
return getValue<float>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsDouble64(const SRscpValue* value)
*/
double getValueAsDouble64(const SRscpValue* value) {
return getValue<double>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
SRscpTimestamp getValueAsTimestamp(const SRscpValue* value) {
return getValue<SRscpTimestamp>(value);
}
/*!
* \copydoc RscpProtocol::getValueAsBool(const SRscpValue* value)
*/
std::string getValueAsString(const SRscpValue* value);
/*
* \brief Function get \var value as a container type. It returns all the SRscpValue structs from the container.
* The user is responsible to free the memory of the vector<SRscpValue> with RscpProtocol::destroyValueData().
* @param data - RSCP value struct
* @return - Vector with all rscp value structs found in the container. Empty on failure and no or invalid data.
*/
std::vector<SRscpValue> getValueAsContainer(const SRscpValue* value) {
std::vector<SRscpValue> dataValues;
parseData(value->data, value->length, dataValues);
return dataValues;
}
/*
* \brief This function destroys all allocated data inside a RSCP value.
* @param - Pointer to the RSCP value.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t destroyValueData(SRscpValue * value);
/*
* \copydoc RscpProtocol::destroyValueData(SRscpValue & value)
* Overload with reference to SRscpValue.
*/
int32_t destroyValueData(SRscpValue & value) {
return destroyValueData(&value);
}
/*
* \brief This function destroys all allocated data inside a vector of RSCP values.
* @param - Reference to the vector of the RSCP values.
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t destroyValueData(std::vector<SRscpValue> & value);
/*
* \brief This function destroys all allocated data inside a RSCP frame.
* @param - Pointer to a RSCP frame
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t destroyFrameData(SRscpFrame * frame);
/*
* \copydoc RscpProtocol::destroyFrameData(SRscpFrame * frame)
* Overload with reference to SRscpFrame.
*/
int32_t destroyFrameData(SRscpFrame & frame) {
return destroyValueData(frame.data);
}
/*
* \brief This function destroys all allocated data inside a RSCP frame buffer.
* @param - Pointer to a RSCP frame buffer struct
* @return - RSCP error code if the function fails else RSCP::OK
*/
int32_t destroyFrameData(SRscpFrameBuffer * frameBuffer);
/*!
* \copydoc RscpProtocol::destroyFrameBuffer(SRscpFrameBuffer & frameBuffer)
* Overload with reference to SRscpFrameBuffer.
*/
int32_t destroyFrameData(SRscpFrameBuffer & frameBuffer) {
return destroyFrameData(&frameBuffer);
}
private:
/*
* \brief This function calculates the ethernet protocol CRC32 hash from \var data over \var length bytes.
* @param - Pointer to a data buffer
* @param - Length of the buffer data
* @return The calculated CRC32 value is returned.
*/
uint32_t calculateCRC32(const uint8_t *data, uint16_t length);
/*
* \brief This function sets the current time in seconds and nanoseconds to the frame.
* @param - Pointer to an rscp frame object.
* @return True on success else false.
*/
bool setHeaderTimestamp(SRscpFrame *frame);
};
#endif /* RSCPPROTOCOL_H_ */