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
Diff: senml_base_parser.cpp
- Revision:
- 0:a9259748d982
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/senml_base_parser.cpp Sat May 19 17:35:20 2018 +0000 @@ -0,0 +1,64 @@ +/* _ __ ____ _ _ + * | |/ / | _ \ | \ | | + * | ' / | |_) | | \| | + * | . \ | __/ | |\ | + * |_|\_\ |_| |_| \_| + * + * (c) 2018 KPN + * License: MIT License. + * Author: Jan Bogaerts + * + * base class for all parsers + */ + + +#include <senml_base_parser.h> +#include <senml_logging.h> + +void SenMLBaseParser::setCurrentPack(String& name) +{ + this->curPack = NULL; //reset before we start so we indicate that nothing was ound + this->curPackName = name; //need a ref to the name in case we can't find the pack object + + if(name == this->root->getBaseName()){ //check the root first, most common probably + this->curPack = this->root; + return; + } + SenMLBase* found = this->root->getFirst(); + while(found){ + if(found->isPack() && name == ((SenMLPack*)found)->getBaseName()){ + this->curPack = (SenMLPack*)found; + return; + } + found = found->getNext(); + } +} + +void SenMLBaseParser::checkBaseUnit(String& name) +{ + if(!(this->curPack && name == senml_units_names[this->curPack->getBaseUnit()])) + log_debug("bu different"); +} + +void SenMLBaseParser::setCurrentRecord(String& name) +{ + this->curRec = NULL; + this->curRecName = name; + if(this->curPack){ + SenMLBase* rec = this->curPack->getFirst(); + while(rec){ + if(rec->isPack() == false && name == ((SenMLRecord*)rec)->getName()){ + this->curRec = (SenMLRecord*)rec; + return; + } + rec = rec->getNext(); + } + } +} + + + + + + +