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_int_actuator.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 | * (c) 2018 KPN |
kpniot | 0:a9259748d982 | 8 | * License: MIT License. |
kpniot | 0:a9259748d982 | 9 | * Author: Jan Bogaerts |
kpniot | 0:a9259748d982 | 10 | * |
kpniot | 0:a9259748d982 | 11 | * support for int actuators |
kpniot | 0:a9259748d982 | 12 | */ |
kpniot | 0:a9259748d982 | 13 | |
kpniot | 0:a9259748d982 | 14 | #include <senml_int_actuator.h> |
kpniot | 0:a9259748d982 | 15 | #include <senml_logging.h> |
kpniot | 0:a9259748d982 | 16 | |
kpniot | 0:a9259748d982 | 17 | void SenMLIntActuator::actuate(const void* value, int dataLength, SenMLDataType dataType) |
kpniot | 0:a9259748d982 | 18 | { |
kpniot | 0:a9259748d982 | 19 | if(dataType == SENML_TYPE_NR){ |
kpniot | 0:a9259748d982 | 20 | this->set((int)*((double*)value)); |
kpniot | 0:a9259748d982 | 21 | if(this->callback) |
kpniot | 0:a9259748d982 | 22 | this->callback((int)*((double*)value)); |
kpniot | 0:a9259748d982 | 23 | } |
kpniot | 0:a9259748d982 | 24 | else if(dataType == CBOR_TYPE_INT){ |
kpniot | 0:a9259748d982 | 25 | int64_t val = *((int64_t*)value); |
kpniot | 0:a9259748d982 | 26 | this->set((int)val); |
kpniot | 0:a9259748d982 | 27 | if(this->callback) |
kpniot | 0:a9259748d982 | 28 | this->callback((int)val); |
kpniot | 0:a9259748d982 | 29 | } |
kpniot | 0:a9259748d982 | 30 | else if(dataType == CBOR_TYPE_UINT){ |
kpniot | 0:a9259748d982 | 31 | uint64_t val = *((uint64_t*)value); |
kpniot | 0:a9259748d982 | 32 | this->set((int)val); |
kpniot | 0:a9259748d982 | 33 | if(this->callback) |
kpniot | 0:a9259748d982 | 34 | this->callback((int)val); |
kpniot | 0:a9259748d982 | 35 | } |
kpniot | 0:a9259748d982 | 36 | else |
kpniot | 0:a9259748d982 | 37 | log_debug("invalid type"); |
kpniot | 0:a9259748d982 | 38 | } |
kpniot | 0:a9259748d982 | 39 | |
kpniot | 0:a9259748d982 | 40 | |
kpniot | 0:a9259748d982 | 41 | |
kpniot | 0:a9259748d982 | 42 | |
kpniot | 0:a9259748d982 | 43 | |
kpniot | 0:a9259748d982 | 44 | |
kpniot | 0:a9259748d982 | 45 |