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) base class for packs that have base values
kpniot 0:a9259748d982 12 */
kpniot 0:a9259748d982 13
kpniot 0:a9259748d982 14 #ifndef SENMLPACKTEMPLATE
kpniot 0:a9259748d982 15 #define SENMLPACKTEMPLATE
kpniot 0:a9259748d982 16
kpniot 0:a9259748d982 17 #include <senml_pack.h>
kpniot 0:a9259748d982 18
kpniot 0:a9259748d982 19 /**
kpniot 0:a9259748d982 20 * A template class that can be used to create new SenMLPack types that store a base-value and/or base-sum
kpniot 0:a9259748d982 21 * with a basic data type (no structs or classes).
kpniot 0:a9259748d982 22 * When you create a new class, you should always implement the following functions in order
kpniot 0:a9259748d982 23 * for the new class to operate correctly: fieldsToJson() and fieldsToCbor(). These functions are responsible
kpniot 0:a9259748d982 24 * for rendering both base-value and base-sum. This class does not implement any rendering.
kpniot 0:a9259748d982 25 * See previous implementations such as SenMLIntPack for inspiration.
kpniot 0:a9259748d982 26 */
kpniot 0:a9259748d982 27 template <class T>
kpniot 0:a9259748d982 28 class SenMLPackTemplate: public SenMLPack
kpniot 0:a9259748d982 29 {
kpniot 0:a9259748d982 30 public:
kpniot 0:a9259748d982 31
kpniot 0:a9259748d982 32 SenMLPackTemplate(const char* baseName): SenMLPack(baseName, SENML_UNIT_NONE, NAN) {};
kpniot 0:a9259748d982 33 SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit): SenMLPack(baseName, baseUnit, NAN) {};
kpniot 0:a9259748d982 34 SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit, double baseTime): SenMLPack(baseName, baseUnit, baseTime) {};
kpniot 0:a9259748d982 35
kpniot 0:a9259748d982 36 SenMLPackTemplate(PACK_ACTUATOR_SIGNATURE): SenMLPack("", SENML_UNIT_NONE, NAN, callback) {};
kpniot 0:a9259748d982 37 SenMLPackTemplate(const char* baseName, PACK_ACTUATOR_SIGNATURE): SenMLPack(baseName, SENML_UNIT_NONE, NAN, callback) {};
kpniot 0:a9259748d982 38 SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit, PACK_ACTUATOR_SIGNATURE): SenMLPack(baseName, baseUnit, NAN, callback) {};
kpniot 0:a9259748d982 39 SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit, double baseTime, PACK_ACTUATOR_SIGNATURE): SenMLPack(baseName, baseUnit, baseTime, callback){};
kpniot 0:a9259748d982 40
kpniot 0:a9259748d982 41
kpniot 0:a9259748d982 42
kpniot 0:a9259748d982 43 ~SenMLPackTemplate(){};
kpniot 0:a9259748d982 44
kpniot 0:a9259748d982 45 /**
kpniot 0:a9259748d982 46 * Get the base-sum assigned to this pack object.
kpniot 0:a9259748d982 47 * @returns: the base-sum.
kpniot 0:a9259748d982 48 */
kpniot 0:a9259748d982 49 T getBaseSum() {return _sum; } ;
kpniot 0:a9259748d982 50
kpniot 0:a9259748d982 51 /**
kpniot 0:a9259748d982 52 * Store the base-sum in the pack object.
kpniot 0:a9259748d982 53 * @returns: true (returns a value to support possible future extentions)
kpniot 0:a9259748d982 54 */
kpniot 0:a9259748d982 55 bool setBaseSum(T value) {_sum = value; return true;};
kpniot 0:a9259748d982 56
kpniot 0:a9259748d982 57 /**
kpniot 0:a9259748d982 58 * Get the base-value assigned to this pack object.
kpniot 0:a9259748d982 59 * @returns: the base-value.
kpniot 0:a9259748d982 60 */
kpniot 0:a9259748d982 61 T getBaseValue() {return _value; } ;
kpniot 0:a9259748d982 62
kpniot 0:a9259748d982 63 /**
kpniot 0:a9259748d982 64 * Store the base-value in the pack object.
kpniot 0:a9259748d982 65 * @returns: true (returns a value to support possible future extentions)
kpniot 0:a9259748d982 66 */
kpniot 0:a9259748d982 67 bool setBaseValue(T value) {_value = value; return true;};
kpniot 0:a9259748d982 68
kpniot 0:a9259748d982 69 protected:
kpniot 0:a9259748d982 70
kpniot 0:a9259748d982 71
kpniot 0:a9259748d982 72 private:
kpniot 0:a9259748d982 73 T _sum;
kpniot 0:a9259748d982 74 T _value;
kpniot 0:a9259748d982 75 };
kpniot 0:a9259748d982 76
kpniot 0:a9259748d982 77 #endif // SENMLPACKTEMPLATE
kpniot 0:a9259748d982 78
kpniot 0:a9259748d982 79
kpniot 0:a9259748d982 80
kpniot 0:a9259748d982 81
kpniot 0:a9259748d982 82
kpniot 0:a9259748d982 83
kpniot 0:a9259748d982 84