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_bool_record.cpp@0:a9259748d982, 2018-05-19 (annotated)
- Committer:
- kpniot
- Date:
- Sat May 19 17:35:20 2018 +0000
- Revision:
- 0:a9259748d982
first commit
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 bool sensor |
kpniot | 0:a9259748d982 | 12 | */ |
kpniot | 0:a9259748d982 | 13 | |
kpniot | 0:a9259748d982 | 14 | |
kpniot | 0:a9259748d982 | 15 | #include <senml_bool_record.h> |
kpniot | 0:a9259748d982 | 16 | #include <cbor.h> |
kpniot | 0:a9259748d982 | 17 | #include <senml_helpers.h> |
kpniot | 0:a9259748d982 | 18 | |
kpniot | 0:a9259748d982 | 19 | SenMLBoolRecord::SenMLBoolRecord(const char* name): SenMLRecordTemplate(name) |
kpniot | 0:a9259748d982 | 20 | { |
kpniot | 0:a9259748d982 | 21 | } |
kpniot | 0:a9259748d982 | 22 | |
kpniot | 0:a9259748d982 | 23 | SenMLBoolRecord::SenMLBoolRecord(const char* name, SenMLUnit unit): SenMLRecordTemplate(name, unit) |
kpniot | 0:a9259748d982 | 24 | { |
kpniot | 0:a9259748d982 | 25 | } |
kpniot | 0:a9259748d982 | 26 | |
kpniot | 0:a9259748d982 | 27 | void SenMLBoolRecord::fieldsToJson() |
kpniot | 0:a9259748d982 | 28 | { |
kpniot | 0:a9259748d982 | 29 | SenMLRecord::fieldsToJson(); |
kpniot | 0:a9259748d982 | 30 | printText(",\"vb\":", 6); |
kpniot | 0:a9259748d982 | 31 | if(this->get()) |
kpniot | 0:a9259748d982 | 32 | printText("true", 4); |
kpniot | 0:a9259748d982 | 33 | else |
kpniot | 0:a9259748d982 | 34 | printText("false", 5); |
kpniot | 0:a9259748d982 | 35 | } |
kpniot | 0:a9259748d982 | 36 | |
kpniot | 0:a9259748d982 | 37 | int SenMLBoolRecord::fieldsToCbor() |
kpniot | 0:a9259748d982 | 38 | { |
kpniot | 0:a9259748d982 | 39 | int res = SenMLRecord::fieldsToCbor(); |
kpniot | 0:a9259748d982 | 40 | res += cbor_serialize_int(SENML_CBOR_VB_LABEL); |
kpniot | 0:a9259748d982 | 41 | res += cbor_serialize_bool(this->get()); |
kpniot | 0:a9259748d982 | 42 | return res; |
kpniot | 0:a9259748d982 | 43 | } |
kpniot | 0:a9259748d982 | 44 | |
kpniot | 0:a9259748d982 | 45 | |
kpniot | 0:a9259748d982 | 46 | |
kpniot | 0:a9259748d982 | 47 | |
kpniot | 0:a9259748d982 | 48 | |
kpniot | 0:a9259748d982 | 49 | |
kpniot | 0:a9259748d982 | 50 |