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 * base class for all parsers
kpniot 0:a9259748d982 12 */
kpniot 0:a9259748d982 13
kpniot 0:a9259748d982 14
kpniot 0:a9259748d982 15 #include <senml_base_parser.h>
kpniot 0:a9259748d982 16 #include <senml_logging.h>
kpniot 0:a9259748d982 17
kpniot 0:a9259748d982 18 void SenMLBaseParser::setCurrentPack(String& name)
kpniot 0:a9259748d982 19 {
kpniot 0:a9259748d982 20 this->curPack = NULL; //reset before we start so we indicate that nothing was ound
kpniot 0:a9259748d982 21 this->curPackName = name; //need a ref to the name in case we can't find the pack object
kpniot 0:a9259748d982 22
kpniot 0:a9259748d982 23 if(name == this->root->getBaseName()){ //check the root first, most common probably
kpniot 0:a9259748d982 24 this->curPack = this->root;
kpniot 0:a9259748d982 25 return;
kpniot 0:a9259748d982 26 }
kpniot 0:a9259748d982 27 SenMLBase* found = this->root->getFirst();
kpniot 0:a9259748d982 28 while(found){
kpniot 0:a9259748d982 29 if(found->isPack() && name == ((SenMLPack*)found)->getBaseName()){
kpniot 0:a9259748d982 30 this->curPack = (SenMLPack*)found;
kpniot 0:a9259748d982 31 return;
kpniot 0:a9259748d982 32 }
kpniot 0:a9259748d982 33 found = found->getNext();
kpniot 0:a9259748d982 34 }
kpniot 0:a9259748d982 35 }
kpniot 0:a9259748d982 36
kpniot 0:a9259748d982 37 void SenMLBaseParser::checkBaseUnit(String& name)
kpniot 0:a9259748d982 38 {
kpniot 0:a9259748d982 39 if(!(this->curPack && name == senml_units_names[this->curPack->getBaseUnit()]))
kpniot 0:a9259748d982 40 log_debug("bu different");
kpniot 0:a9259748d982 41 }
kpniot 0:a9259748d982 42
kpniot 0:a9259748d982 43 void SenMLBaseParser::setCurrentRecord(String& name)
kpniot 0:a9259748d982 44 {
kpniot 0:a9259748d982 45 this->curRec = NULL;
kpniot 0:a9259748d982 46 this->curRecName = name;
kpniot 0:a9259748d982 47 if(this->curPack){
kpniot 0:a9259748d982 48 SenMLBase* rec = this->curPack->getFirst();
kpniot 0:a9259748d982 49 while(rec){
kpniot 0:a9259748d982 50 if(rec->isPack() == false && name == ((SenMLRecord*)rec)->getName()){
kpniot 0:a9259748d982 51 this->curRec = (SenMLRecord*)rec;
kpniot 0:a9259748d982 52 return;
kpniot 0:a9259748d982 53 }
kpniot 0:a9259748d982 54 rec = rec->getNext();
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
kpniot 0:a9259748d982 62
kpniot 0:a9259748d982 63
kpniot 0:a9259748d982 64