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.

Fork of kpn_senml by KPN IoT

Committer:
kpniot
Date:
Sat May 19 17:35:20 2018 +0000
Revision:
0:a9259748d982
first commit

Who changed what in which revision?

UserRevisionLine numberNew 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 float sensors header
kpniot 0:a9259748d982 12 */
kpniot 0:a9259748d982 13
kpniot 0:a9259748d982 14 #ifndef SENMLFLOATRECORD
kpniot 0:a9259748d982 15 #define SENMLFLOATRECORD
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 float data.
kpniot 0:a9259748d982 21 * This type of object can only be used for sensor data. If actuation is needed, use SenMLFloatActuator
kpniot 0:a9259748d982 22 * instead.
kpniot 0:a9259748d982 23 */
kpniot 0:a9259748d982 24 class SenMLFloatRecord: public SenMLRecordTemplate<float>
kpniot 0:a9259748d982 25 {
kpniot 0:a9259748d982 26 public:
kpniot 0:a9259748d982 27 SenMLFloatRecord(const char* name);
kpniot 0:a9259748d982 28 SenMLFloatRecord(const char* name, SenMLUnit unit);
kpniot 0:a9259748d982 29 SenMLFloatRecord(const char* name, SenMLUnit unit, float value): SenMLRecordTemplate(name, unit, value){};
kpniot 0:a9259748d982 30 ~SenMLFloatRecord(){};
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 float getAdjustedValue();
kpniot 0:a9259748d982 55 };
kpniot 0:a9259748d982 56
kpniot 0:a9259748d982 57 #endif // SENMLFLOATRECORD
kpniot 0:a9259748d982 58
kpniot 0:a9259748d982 59
kpniot 0:a9259748d982 60
kpniot 0:a9259748d982 61
kpniot 0:a9259748d982 62
kpniot 0:a9259748d982 63
kpniot 0:a9259748d982 64