Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of kpn_senml by
senml_double_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 double base values 00012 */ 00013 00014 00015 #include <senml_double_pack.h> 00016 #include <senml_helpers.h> 00017 #include <cbor.h> 00018 00019 00020 void SenMLDoublePack::setupStreamCtx(Stream *dest, SenMLStreamMethod format) 00021 { 00022 SenMLPack::setupStreamCtx(dest, format); 00023 _streamCtx->baseValue.baseDouble = this->getBaseValue(); 00024 _streamCtx->baseSum.baseDouble = this->getBaseValue(); 00025 _streamCtx->baseDataType = CBOR_TYPE_DOUBLE; 00026 } 00027 00028 void SenMLDoublePack::setupStreamCtx(char *dest, int length, SenMLStreamMethod format) 00029 { 00030 SenMLPack::setupStreamCtx(dest, length, format); 00031 _streamCtx->baseValue.baseDouble = this->getBaseValue(); 00032 _streamCtx->baseSum.baseDouble = this->getBaseValue(); 00033 _streamCtx->baseDataType = CBOR_TYPE_DOUBLE; 00034 } 00035 00036 void SenMLDoublePack::fieldsToJson() 00037 { 00038 double val; 00039 SenMLPack::fieldsToJson(); 00040 val = this->getBaseValue(); 00041 if(val != 0){ 00042 printText(",\"bv\":", 6); 00043 printDouble(val, SENML_MAX_DOUBLE_PRECISION); 00044 } 00045 00046 val = this->getBaseSum(); 00047 if(val != 0){ 00048 printText(",\"bs\":", 6); 00049 printDouble(val, SENML_MAX_DOUBLE_PRECISION); 00050 } 00051 00052 } 00053 00054 int SenMLDoublePack::fieldsToCbor() 00055 { 00056 int val; 00057 int res = SenMLPack::fieldsToCbor(); 00058 00059 val = this->getBaseValue(); 00060 if(val){ 00061 res += cbor_serialize_int(SENML_CBOR_VB_LABEL); 00062 res += cbor_serialize_double(val); 00063 } 00064 00065 val = this->getBaseSum(); 00066 if(val){ 00067 res += cbor_serialize_int(SENML_CBOR_BS_LABEL); 00068 res += cbor_serialize_double(val); 00069 } 00070 return res; 00071 } 00072 00073 00074 00075 00076 00077 00078
Generated on Tue Jul 12 2022 23:07:21 by
1.7.2
