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
senml_base.cpp@2:9b44be6e79ac, 2018-05-27 (annotated)
- Committer:
- kpniot
- Date:
- Sun May 27 14:31:44 2018 +0000
- Revision:
- 2:9b44be6e79ac
- Parent:
- 0:a9259748d982
try to fix repo
Who changed what in which revision?
User | Revision | Line number | New 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 | * |
kpniot | 0:a9259748d982 | 8 | * (c) 2018 KPN |
kpniot | 0:a9259748d982 | 9 | * License: MIT License. |
kpniot | 0:a9259748d982 | 10 | * Author: Jan Bogaerts |
kpniot | 0:a9259748d982 | 11 | * |
kpniot | 0:a9259748d982 | 12 | * base class for all senml objects |
kpniot | 0:a9259748d982 | 13 | */ |
kpniot | 0:a9259748d982 | 14 | |
kpniot | 0:a9259748d982 | 15 | |
kpniot | 0:a9259748d982 | 16 | #include <senml_base.h> |
kpniot | 0:a9259748d982 | 17 | #include <senml_pack.h> |
kpniot | 0:a9259748d982 | 18 | |
kpniot | 0:a9259748d982 | 19 | |
kpniot | 0:a9259748d982 | 20 | SenMLBase::SenMLBase(): _prev(NULL), _next(NULL) |
kpniot | 0:a9259748d982 | 21 | { |
kpniot | 0:a9259748d982 | 22 | } |
kpniot | 0:a9259748d982 | 23 | |
kpniot | 0:a9259748d982 | 24 | SenMLBase::~SenMLBase() |
kpniot | 0:a9259748d982 | 25 | { |
kpniot | 0:a9259748d982 | 26 | if(this->_prev) |
kpniot | 0:a9259748d982 | 27 | this->_prev->setNext(this->_next); |
kpniot | 0:a9259748d982 | 28 | if(this->_next) |
kpniot | 0:a9259748d982 | 29 | this->_next->setPrev(this->_prev); |
kpniot | 0:a9259748d982 | 30 | |
kpniot | 0:a9259748d982 | 31 | } |
kpniot | 0:a9259748d982 | 32 | |
kpniot | 0:a9259748d982 | 33 | void SenMLBase::setNext(SenMLBase* value) |
kpniot | 0:a9259748d982 | 34 | { |
kpniot | 0:a9259748d982 | 35 | if(value == NULL){ //if next becomes null and there is a root, then this object became the last in the list, so let the root know. |
kpniot | 0:a9259748d982 | 36 | SenMLPack* root = (SenMLPack*)this->getRoot(); |
kpniot | 0:a9259748d982 | 37 | if(root) |
kpniot | 0:a9259748d982 | 38 | root->setLast(this); |
kpniot | 0:a9259748d982 | 39 | } |
kpniot | 0:a9259748d982 | 40 | this->_next = value; |
kpniot | 0:a9259748d982 | 41 | } |
kpniot | 0:a9259748d982 | 42 | |
kpniot | 0:a9259748d982 | 43 | void SenMLBase::setPrev(SenMLBase* value) |
kpniot | 0:a9259748d982 | 44 | { |
kpniot | 0:a9259748d982 | 45 | this->_prev = value; |
kpniot | 0:a9259748d982 | 46 | } |
kpniot | 0:a9259748d982 | 47 | |
kpniot | 0:a9259748d982 | 48 | SenMLBase* SenMLBase::getPrev() |
kpniot | 0:a9259748d982 | 49 | { |
kpniot | 0:a9259748d982 | 50 | return this->_prev; |
kpniot | 0:a9259748d982 | 51 | } |
kpniot | 0:a9259748d982 | 52 | |
kpniot | 0:a9259748d982 | 53 | SenMLBase* SenMLBase::getRoot() |
kpniot | 0:a9259748d982 | 54 | { |
kpniot | 0:a9259748d982 | 55 | SenMLBase* prev = this->_prev; |
kpniot | 0:a9259748d982 | 56 | while(prev){ |
kpniot | 0:a9259748d982 | 57 | SenMLBase* newPrev = prev->getPrev(); |
kpniot | 0:a9259748d982 | 58 | if(newPrev == NULL) |
kpniot | 0:a9259748d982 | 59 | return prev; |
kpniot | 0:a9259748d982 | 60 | else |
kpniot | 0:a9259748d982 | 61 | prev = newPrev; |
kpniot | 0:a9259748d982 | 62 | } |
kpniot | 0:a9259748d982 | 63 | return this; //if there was no first prev, it means we are root. |
kpniot | 0:a9259748d982 | 64 | } |
kpniot | 0:a9259748d982 | 65 | |
kpniot | 0:a9259748d982 | 66 | |
kpniot | 0:a9259748d982 | 67 | |
kpniot | 0:a9259748d982 | 68 | |
kpniot | 0:a9259748d982 | 69 | |
kpniot | 0:a9259748d982 | 70 | |
kpniot | 0:a9259748d982 | 71 | |
kpniot | 0:a9259748d982 | 72 |