This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
senml_binary_record.h
95 lines (73 loc) · 2.79 KB
/
senml_binary_record.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
/* _ __ ____ _ _
* | |/ / | _ \ | \ | |
* | ' / | |_) | | \| |
* | . \ | __/ | |\ |
* |_|\_\ |_| |_| \_|
*
* (c) 2018 KPN
* License: MIT License.
* Author: Jan Bogaerts
*
* support for binary sensors header
*/
#ifndef SENMLBINARYRECORD
#define SENMLBINARYRECORD
#include <senml_record.h>
/**
* A SenMLRecord that stores binary data.
* This type of object can only be used for sensor data. If actuation is needed, use SenMLBinaryActuator
* instead.
*/
class SenMLBinaryRecord: public SenMLRecord
{
public:
SenMLBinaryRecord(const char* name);
SenMLBinaryRecord(const char* name, SenMLUnit unit);
~SenMLBinaryRecord(){ if(this->_value) free(this->_value); };
#ifdef __MBED__
/**
* set the value and length.
* warning: value is not copied over. a direct reference to the buffer is stored, so if this
* memory is changed/freed, then the data stored in the object will also be changed.
*/
bool set(unsigned char* value, unsigned int length)
{
return this->set(value, length, NAN);
}
/**
* set the value and length.
* warning: value is not copied over. a direct reference to the buffer is stored, so if this
* memory is changed/freed, then the data stored in the object will also be changed.
*/
bool set(unsigned char* value, unsigned int length, double time);
#else
/**
* set the value and length.
* warning: value is not copied over. a direct reference to the buffer is stored, so if this
* memory is changed/freed, then the data stored in the object will also be changed.
*/
bool set(unsigned char* value, unsigned int length, double time = NAN);
#endif
/**
* renders all the fields to json, without the starting and ending brackets.
* Inheriters can extend this function if they want to add extra fields to the json output
* note: this is public so that custom implementations for the record object can use other objects
* internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for lat, lon & alt.
* @returns: None
*/
void fieldsToJson();
/**
* renders all the fields to cbor format. renders all the fields of the object without the length info
* at the beginning
* note: this is public so that custom implementations for the record object can use other objects
* internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for
* lat, lon & alt.
* @returns: The number of bytes that were written.
*/
virtual int fieldsToCbor();
protected:
private:
unsigned char* _value; //raw data buffer (not null terminated)
unsigned int _length; //size of the _data packet
};
#endif // SENMLBINARYRECORD