KPN IoT / senml

Fork of kpn_senml by KPN IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers senml_int_pack.cpp Source File

senml_int_pack.cpp

00001 /*  _  __  ____    _   _ 
00002  * | |/ / |  _ \  | \ | |
00003  * | ' /  | |_) | |  \| |
00004  * | . \  |  __/  | |\  |
00005  * |_|\_\ |_|     |_| \_|
00006  * 
00007  * (c) 2018 KPN
00008  * License: MIT License.
00009  * Author: Jan Bogaerts
00010  * 
00011  * pack (document) with int base values
00012  */
00013 
00014 
00015 #include <senml_int_pack.h> 
00016 #include <senml_helpers.h>
00017 #include <cbor.h>
00018  
00019 
00020 void SenMLIntPack::setupStreamCtx(Stream *dest, SenMLStreamMethod format)
00021 {
00022     SenMLPack::setupStreamCtx(dest, format);
00023     _streamCtx->baseValue.baseInt = this->getBaseValue();
00024     _streamCtx->baseSum.baseInt = this->getBaseValue();
00025     _streamCtx->baseDataType = CBOR_TYPE_INT;
00026 }
00027 
00028 void SenMLIntPack::setupStreamCtx(char *dest, int length, SenMLStreamMethod format)
00029 {
00030     SenMLPack::setupStreamCtx(dest, length, format);
00031     _streamCtx->baseValue.baseInt = this->getBaseValue();
00032     _streamCtx->baseSum.baseInt = this->getBaseValue();
00033     _streamCtx->baseDataType = CBOR_TYPE_INT;
00034 }
00035 
00036 void SenMLIntPack::fieldsToJson() 
00037 {
00038     int val;
00039     String strVal;
00040     SenMLPack::fieldsToJson();
00041     val = this->getBaseValue();
00042     if(val != 0){
00043         printText(",\"bv\":", 6);
00044         strVal = val;
00045         printText(strVal.c_str(), strVal.length());
00046     }
00047 
00048     val = this->getBaseSum();
00049     if(val != 0){
00050         printText(",\"bs\":", 6);
00051         strVal = val;
00052         printText(strVal.c_str(), strVal.length());
00053     }
00054 
00055 }
00056 
00057 int SenMLIntPack::fieldsToCbor() 
00058 {
00059     int val;
00060     int res = SenMLPack::fieldsToCbor();
00061     
00062     val = this->getBaseValue();
00063     if(val){
00064         res += cbor_serialize_int(SENML_CBOR_VB_LABEL);
00065         res += cbor_serialize_int(val);
00066     }
00067 
00068     val = this->getBaseSum();
00069     if(val){
00070         res += cbor_serialize_int(SENML_CBOR_BS_LABEL);
00071         res += cbor_serialize_int(val);
00072     }
00073     return res;
00074 }
00075 
00076 
00077 
00078 
00079 
00080 
00081