KPN IoT / senml

Fork of kpn_senml by KPN IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers senml_base_parser.cpp Source File

senml_base_parser.cpp

00001 /*  _  __  ____    _   _ 
00002  * | |/ / |  _ \  | \ | |
00003  * | ' /  | |_) | |  \| |
00004  * | . \  |  __/  | |\  |
00005  * |_|\_\ |_|     |_| \_|
00006  * 
00007  * (c) 2018 KPN
00008  * License: MIT License.
00009  * Author: Jan Bogaerts
00010  * 
00011  * base class for all parsers
00012  */
00013 
00014 
00015 #include <senml_base_parser.h>
00016 #include <senml_logging.h>
00017 
00018 void SenMLBaseParser::setCurrentPack(String& name)
00019 {
00020     this->curPack = NULL;                                                   //reset before we start so we indicate that nothing was ound
00021     this->curPackName = name;                                               //need a ref to the name in case we can't find the pack object
00022 
00023     if(name == this->root->getBaseName()){                                  //check the root first, most common probably
00024         this->curPack = this->root;
00025         return;
00026     }
00027     SenMLBase* found = this->root->getFirst();
00028     while(found){
00029         if(found->isPack() && name == ((SenMLPack*)found)->getBaseName()){
00030             this->curPack = (SenMLPack*)found;
00031             return;
00032         }
00033         found = found->getNext();
00034     }
00035 }
00036 
00037 void SenMLBaseParser::checkBaseUnit(String& name)
00038 {
00039     if(!(this->curPack && name == senml_units_names[this->curPack->getBaseUnit()]))
00040         log_debug("bu different");
00041 }
00042 
00043 void SenMLBaseParser::setCurrentRecord(String& name)
00044 {
00045     this->curRec = NULL;
00046     this->curRecName = name;
00047     if(this->curPack){
00048         SenMLBase* rec = this->curPack->getFirst();
00049         while(rec){
00050             if(rec->isPack() == false &&  name == ((SenMLRecord*)rec)->getName()){
00051                 this->curRec = (SenMLRecord*)rec;
00052                 return;
00053             }
00054             rec = rec->getNext();
00055         }
00056     }
00057 }
00058 
00059 
00060 
00061 
00062 
00063 
00064