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 * base class for all parsers header
kpniot 0:a9259748d982 12 */
kpniot 0:a9259748d982 13
kpniot 0:a9259748d982 14
kpniot 0:a9259748d982 15
kpniot 0:a9259748d982 16 #ifndef SENMLBASEPARSER
kpniot 0:a9259748d982 17 #define SENMLBASEPARSER
kpniot 0:a9259748d982 18
kpniot 0:a9259748d982 19 #include <senml_pack.h>
kpniot 0:a9259748d982 20 #include <senml_record.h>
kpniot 0:a9259748d982 21
kpniot 0:a9259748d982 22 /**
kpniot 0:a9259748d982 23 * base class for json and cbor parsers. Provides functionality to connect to
kpniot 0:a9259748d982 24 * and search in senml packs and recrods.
kpniot 0:a9259748d982 25 */
kpniot 0:a9259748d982 26 class SenMLBaseParser {
kpniot 0:a9259748d982 27
kpniot 0:a9259748d982 28 public:
kpniot 0:a9259748d982 29 SenMLBaseParser(SenMLPack* root): root(root), curPack(root) {};
kpniot 0:a9259748d982 30
kpniot 0:a9259748d982 31
kpniot 0:a9259748d982 32 private:
kpniot 0:a9259748d982 33
kpniot 0:a9259748d982 34
kpniot 0:a9259748d982 35 protected:
kpniot 0:a9259748d982 36 SenMLPack* root; //the root document for which we are parsing. Used to search the up all the actuators.
kpniot 0:a9259748d982 37 SenMLRecord* curRec;
kpniot 0:a9259748d982 38 SenMLPack* curPack; //used while searching, to store the current pack to use. init to root pack by default. Make it protected, so child parsers can easily access it without too much fuzz
kpniot 0:a9259748d982 39 String curRecName; //keeps a ref of the record name, for raising events for unknown records
kpniot 0:a9259748d982 40 String curPackName; //name of hte current pack to send the actuator to.
kpniot 0:a9259748d982 41
kpniot 0:a9259748d982 42 //looks up the pack object that has to contain the next field. This is in order
kpniot 0:a9259748d982 43 //to support multiple packs (gateway functionality)
kpniot 0:a9259748d982 44 void setCurrentPack(String& name);
kpniot 0:a9259748d982 45
kpniot 0:a9259748d982 46
kpniot 0:a9259748d982 47 //check if base units match, if not, show error message
kpniot 0:a9259748d982 48 void checkBaseUnit(String& name);
kpniot 0:a9259748d982 49
kpniot 0:a9259748d982 50 //look up a record with the spedified name in the current pack
kpniot 0:a9259748d982 51 void setCurrentRecord(String& name);
kpniot 0:a9259748d982 52 };
kpniot 0:a9259748d982 53
kpniot 0:a9259748d982 54 #endif // SENMLBASEPARSER
kpniot 0:a9259748d982 55
kpniot 0:a9259748d982 56
kpniot 0:a9259748d982 57
kpniot 0:a9259748d982 58
kpniot 0:a9259748d982 59
kpniot 0:a9259748d982 60
kpniot 0:a9259748d982 61