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.

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 * pack (document) with double base values headers
kpniot 0:a9259748d982 12 */
kpniot 0:a9259748d982 13
kpniot 0:a9259748d982 14 #ifndef SENMLDOUBLEPACK
kpniot 0:a9259748d982 15 #define SENMLDOUBLEPACK
kpniot 0:a9259748d982 16
kpniot 0:a9259748d982 17 #include <senml_pack_t.h>
kpniot 0:a9259748d982 18
kpniot 0:a9259748d982 19 /**
kpniot 0:a9259748d982 20 * An implimentation of the SenMLPack template that stores double base value and base-sum.
kpniot 0:a9259748d982 21 */
kpniot 0:a9259748d982 22 class SenMLDoublePack: public SenMLPackTemplate<double>
kpniot 0:a9259748d982 23 {
kpniot 0:a9259748d982 24 public:
kpniot 0:a9259748d982 25
kpniot 0:a9259748d982 26 SenMLDoublePack(const char* baseName): SenMLPackTemplate(baseName, SENML_UNIT_NONE, NAN) {};
kpniot 0:a9259748d982 27 SenMLDoublePack(const char* baseName, SenMLUnit baseUnit): SenMLPackTemplate(baseName, baseUnit, NAN) {};
kpniot 0:a9259748d982 28 SenMLDoublePack(const char* baseName, SenMLUnit baseUnit, double baseTime): SenMLPackTemplate(baseName, baseUnit, baseTime) {};
kpniot 0:a9259748d982 29
kpniot 0:a9259748d982 30 SenMLDoublePack(PACK_ACTUATOR_SIGNATURE): SenMLPackTemplate("", SENML_UNIT_NONE, NAN, callback) {};
kpniot 0:a9259748d982 31 SenMLDoublePack(const char* baseName, PACK_ACTUATOR_SIGNATURE): SenMLPackTemplate(baseName, SENML_UNIT_NONE, NAN, callback) {};
kpniot 0:a9259748d982 32 SenMLDoublePack(const char* baseName, SenMLUnit baseUnit, PACK_ACTUATOR_SIGNATURE): SenMLPackTemplate(baseName, baseUnit, NAN, callback) {};
kpniot 0:a9259748d982 33 SenMLDoublePack(const char* baseName, SenMLUnit baseUnit, double baseTime, PACK_ACTUATOR_SIGNATURE): SenMLPackTemplate(baseName, baseUnit, baseTime, callback){};
kpniot 0:a9259748d982 34
kpniot 0:a9259748d982 35
kpniot 0:a9259748d982 36
kpniot 0:a9259748d982 37 ~SenMLDoublePack(){};
kpniot 0:a9259748d982 38
kpniot 0:a9259748d982 39 /**
kpniot 0:a9259748d982 40 * renders all the fields to json, without the starting and ending brackets.
kpniot 0:a9259748d982 41 * Inheriters can extend this function if they want to add extra fields to the json output
kpniot 0:a9259748d982 42 * note: this is public so that custom implementations for the record object can use other objects
kpniot 0:a9259748d982 43 * internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for lat, lon & alt.
kpniot 0:a9259748d982 44 * @returns: None
kpniot 0:a9259748d982 45 */
kpniot 0:a9259748d982 46 virtual void fieldsToJson();
kpniot 0:a9259748d982 47
kpniot 0:a9259748d982 48 /**
kpniot 0:a9259748d982 49 * renders all the fields to cbor format. renders all the fields of the object without the length info
kpniot 0:a9259748d982 50 * at the beginning
kpniot 0:a9259748d982 51 * note: this is public so that custom implementations for the record object can use other objects
kpniot 0:a9259748d982 52 * internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for
kpniot 0:a9259748d982 53 * lat, lon & alt.
kpniot 0:a9259748d982 54 * @returns: The number of bytes that were written.
kpniot 0:a9259748d982 55 */
kpniot 0:a9259748d982 56 virtual int fieldsToCbor();
kpniot 0:a9259748d982 57
kpniot 0:a9259748d982 58 protected:
kpniot 0:a9259748d982 59
kpniot 0:a9259748d982 60 virtual void setupStreamCtx(Stream *dest, SenMLStreamMethod format);
kpniot 0:a9259748d982 61 virtual void setupStreamCtx(char *dest, int length, SenMLStreamMethod format);
kpniot 0:a9259748d982 62
kpniot 0:a9259748d982 63
kpniot 0:a9259748d982 64
kpniot 0:a9259748d982 65 private:
kpniot 0:a9259748d982 66 };
kpniot 0:a9259748d982 67
kpniot 0:a9259748d982 68 #endif // SENMLDOUBLEPACK
kpniot 0:a9259748d982 69
kpniot 0:a9259748d982 70
kpniot 0:a9259748d982 71
kpniot 0:a9259748d982 72
kpniot 0:a9259748d982 73
kpniot 0:a9259748d982 74
kpniot 0:a9259748d982 75