KPN IoT / senml

Fork of kpn_senml by KPN IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers senml_binary_actuator.h Source File

senml_binary_actuator.h

00001 /*  _  __  ____    _   _ 
00002  * | |/ / |  _ \  | \ | |
00003  * | ' /  | |_) | |  \| |
00004  * | . \  |  __/  | |\  |
00005  * |_|\_\ |_|     |_| \_|
00006  * 
00007  * (c) 2018 KPN
00008  * License: MIT License.
00009  * Author: Jan Bogaerts
00010  * 
00011  * support for binary actuators header
00012  */
00013 
00014 #ifndef SENMLBINARYACTUATOR
00015 #define SENMLBINARYACTUATOR
00016 
00017 #include <senml_binary_record.h>
00018 
00019 #define BINARY_ACTUATOR_SIGNATURE void (*callback)(const unsigned char*, int)
00020 
00021 /**
00022  * A SenMLRecord that stores binary data and supports actuation.
00023  */ 
00024 class SenMLBinaryActuator: public SenMLBinaryRecord
00025 {
00026     friend class SenMLCborParser;
00027 public:
00028     SenMLBinaryActuator(const char* name, BINARY_ACTUATOR_SIGNATURE): SenMLBinaryRecord(name, SENML_UNIT_NONE), callback(callback) {};
00029     SenMLBinaryActuator(const char* name, SenMLUnit unit, BINARY_ACTUATOR_SIGNATURE): SenMLBinaryRecord(name, unit), callback(callback) {};
00030     ~SenMLBinaryActuator(){};
00031 
00032 protected:
00033 
00034     //called while parsing a senml message, when the parser found the value for an SenMLJsonListener
00035     virtual void actuate(const void* value, int dataLength, SenMLDataType dataType);
00036 
00037     //called while parsing a senml message, when the parser found the value for an SenMLJsonListener
00038     //the actual value has already been converted to it's appropriate type
00039     inline void actuate(const char* value, int length)
00040     {
00041         this->set((unsigned char*)value, length);
00042         if(this->callback)
00043             this->callback((unsigned char*)value, length);
00044     };
00045 
00046 private:
00047     BINARY_ACTUATOR_SIGNATURE;
00048 };
00049 
00050 #endif // SENMLBINARYACTUATOR
00051 
00052 
00053 
00054 
00055 
00056 
00057