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_binary_record.cpp
00001 /* _ __ ____ _ _ 00002 * | |/ / | _ \ | \ | | 00003 * | ' / | |_) | | \| | 00004 * | . \ | __/ | |\ | 00005 * |_|\_\ |_| |_| \_| 00006 * 00007 * (c) 2018 KPN 00008 * License: MIT License. 00009 * Author: Jan Bogaerts 00010 * 00011 * support for binary sensors 00012 */ 00013 00014 #include <senml_binary_record.h> 00015 #include <senml_helpers.h> 00016 #include <cbor.h> 00017 00018 SenMLBinaryRecord::SenMLBinaryRecord(const char* name): SenMLRecord(name) 00019 { 00020 } 00021 00022 SenMLBinaryRecord::SenMLBinaryRecord(const char* name, SenMLUnit unit): SenMLRecord(name, unit) 00023 { 00024 } 00025 00026 bool SenMLBinaryRecord::set(unsigned char* value, unsigned int length, double time) 00027 { 00028 this->_value = (unsigned char*)malloc(length); 00029 memcpy(this->_value, value, length); 00030 this->_length = length; 00031 return this->setTime(time); 00032 } 00033 00034 00035 void SenMLBinaryRecord::fieldsToJson() 00036 { 00037 SenMLRecord::fieldsToJson(); 00038 printText(",\"vd\":\"", 7); 00039 printBinaryAsBase64(this->_value, this->_length); 00040 printText("\"", 1); 00041 } 00042 00043 int SenMLBinaryRecord::fieldsToCbor() 00044 { 00045 int res = SenMLRecord::fieldsToCbor(); 00046 res += cbor_serialize_int(SENML_CBOR_VD_LABEL); 00047 res += cbor_serialize_byte_string((const char*)this->_value, this->_length); 00048 return res; 00049 } 00050 00051 00052 00053 00054 00055 00056
Generated on Tue Jul 12 2022 23:07:21 by
