The KPN SenML library helps you create and parse senml documents in both json and cbor format. The library can be used for sending sensor data and receiving actuator commands.
senml_string_record.h@0:a9259748d982, 2018-05-19 (annotated)
- Committer:
- kpniot
- Date:
- Sat May 19 17:35:20 2018 +0000
- Revision:
- 0:a9259748d982
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kpniot | 0:a9259748d982 | 1 | /* _ __ ____ _ _ |
kpniot | 0:a9259748d982 | 2 | * | |/ / | _ \ | \ | | |
kpniot | 0:a9259748d982 | 3 | * | ' / | |_) | | \| | |
kpniot | 0:a9259748d982 | 4 | * | . \ | __/ | |\ | |
kpniot | 0:a9259748d982 | 5 | * |_|\_\ |_| |_| \_| |
kpniot | 0:a9259748d982 | 6 | * |
kpniot | 0:a9259748d982 | 7 | * (c) 2018 KPN |
kpniot | 0:a9259748d982 | 8 | * License: MIT License. |
kpniot | 0:a9259748d982 | 9 | * Author: Jan Bogaerts |
kpniot | 0:a9259748d982 | 10 | * |
kpniot | 0:a9259748d982 | 11 | * support for string sensors |
kpniot | 0:a9259748d982 | 12 | */ |
kpniot | 0:a9259748d982 | 13 | |
kpniot | 0:a9259748d982 | 14 | #ifndef SENMLSTRINGRECORD |
kpniot | 0:a9259748d982 | 15 | #define SENMLSTRINGRECORD |
kpniot | 0:a9259748d982 | 16 | |
kpniot | 0:a9259748d982 | 17 | #include <senml_record_t.h> |
kpniot | 0:a9259748d982 | 18 | |
kpniot | 0:a9259748d982 | 19 | /** |
kpniot | 0:a9259748d982 | 20 | * A SenMLRecord that stores text data. |
kpniot | 0:a9259748d982 | 21 | * This type of object can only be used for sensor data. If actuation is needed, use SenMLStringActuator |
kpniot | 0:a9259748d982 | 22 | * instead. |
kpniot | 0:a9259748d982 | 23 | */ |
kpniot | 0:a9259748d982 | 24 | class SenMLStringRecord: public SenMLRecordTemplate<String> |
kpniot | 0:a9259748d982 | 25 | { |
kpniot | 0:a9259748d982 | 26 | public: |
kpniot | 0:a9259748d982 | 27 | SenMLStringRecord(const char* name): SenMLRecordTemplate(name){}; |
kpniot | 0:a9259748d982 | 28 | SenMLStringRecord(const char* name, SenMLUnit unit): SenMLRecordTemplate(name, unit){}; |
kpniot | 0:a9259748d982 | 29 | SenMLStringRecord(const char* name, SenMLUnit unit, const char* value): SenMLRecordTemplate(name, unit, value){}; |
kpniot | 0:a9259748d982 | 30 | //~SenMLStringRecord(){}; |
kpniot | 0:a9259748d982 | 31 | |
kpniot | 0:a9259748d982 | 32 | /** |
kpniot | 0:a9259748d982 | 33 | * renders all the fields to json, without the starting and ending brackets. |
kpniot | 0:a9259748d982 | 34 | * Inheriters can extend this function if they want to add extra fields to the json output |
kpniot | 0:a9259748d982 | 35 | * note: this is public so that custom implementations for the record object can use other objects |
kpniot | 0:a9259748d982 | 36 | * internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for lat, lon & alt. |
kpniot | 0:a9259748d982 | 37 | * @returns: None |
kpniot | 0:a9259748d982 | 38 | */ |
kpniot | 0:a9259748d982 | 39 | virtual void fieldsToJson(); |
kpniot | 0:a9259748d982 | 40 | |
kpniot | 0:a9259748d982 | 41 | /** |
kpniot | 0:a9259748d982 | 42 | * renders all the fields to cbor format. renders all the fields of the object without the length info |
kpniot | 0:a9259748d982 | 43 | * at the beginning |
kpniot | 0:a9259748d982 | 44 | * note: this is public so that custom implementations for the record object can use other objects |
kpniot | 0:a9259748d982 | 45 | * internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for |
kpniot | 0:a9259748d982 | 46 | * lat, lon & alt. |
kpniot | 0:a9259748d982 | 47 | * @returns: The number of bytes that were written. |
kpniot | 0:a9259748d982 | 48 | */ |
kpniot | 0:a9259748d982 | 49 | virtual int fieldsToCbor(); |
kpniot | 0:a9259748d982 | 50 | protected: |
kpniot | 0:a9259748d982 | 51 | |
kpniot | 0:a9259748d982 | 52 | |
kpniot | 0:a9259748d982 | 53 | private: |
kpniot | 0:a9259748d982 | 54 | }; |
kpniot | 0:a9259748d982 | 55 | |
kpniot | 0:a9259748d982 | 56 | #endif // SENMLSTRINGRECORD |
kpniot | 0:a9259748d982 | 57 | |
kpniot | 0:a9259748d982 | 58 | |
kpniot | 0:a9259748d982 | 59 | |
kpniot | 0:a9259748d982 | 60 | |
kpniot | 0:a9259748d982 | 61 | |
kpniot | 0:a9259748d982 | 62 | |
kpniot | 0:a9259748d982 | 63 |