KPN Things Device SDK
senml_bool_record.h
Go to the documentation of this file.
1/* _ __ ____ _ _
2 * | |/ / | _ \ | \ | |
3 * | ' / | |_) | | \| |
4 * | . \ | __/ | |\ |
5 * |_|\_\ |_| |_| \_|
6 *
7 * (c) 2020 KPN
8 * License: MIT License.
9 * Author: Joseph Verburg, Jan Bogaerts
10 *
11 * support for bool sensor header
12 */
13
14#ifndef SENMLBOOLRECORD
15#define SENMLBOOLRECORD
16
17#include "senml_record_t.h"
18
25 public:
26 SenMLBoolRecord(const char *name) : SenMLRecord(name){};
27 SenMLBoolRecord(const char *name, SenMLUnit unit) : SenMLRecord(name, unit){};
28 SenMLBoolRecord(const char *name, SenMLUnit unit, bool value) : SenMLRecord(name, unit), _value(value){};
30 SenMLBoolRecord(ThingsMLMeasurementIndex index, bool value) : SenMLRecord(index), _value(value){};
32
41 virtual int fieldsToJson();
42
50 virtual int fieldsToCbor();
51
58 bool get() {
59 return _value;
60 };
61
62#ifdef __MBED__
63
71 bool set(T value) {
72 return this->set(value, (double)NAN);
73 };
74
85 bool set(T value, double time)
86#else
87
98 bool set(bool value, double time = (double)NAN)
99#endif
100 {
101 this->_value = value;
102 return this->setTime(time);
103 };
104
105 protected:
106 private:
107 bool _value = false; // Initialize else we get undefined behaviour
108};
109
110#endif // SENMLBOOLRECORD
Definition: senml_bool_record.h:24
bool set(bool value, double time=(double) NAN)
Definition: senml_bool_record.h:98
virtual int fieldsToJson()
Definition: senml_bool_record.cpp:18
~SenMLBoolRecord()
Definition: senml_bool_record.h:31
SenMLBoolRecord(const char *name, SenMLUnit unit)
Definition: senml_bool_record.h:27
SenMLBoolRecord(const char *name, SenMLUnit unit, bool value)
Definition: senml_bool_record.h:28
SenMLBoolRecord(const char *name)
Definition: senml_bool_record.h:26
SenMLBoolRecord(ThingsMLMeasurementIndex index)
Definition: senml_bool_record.h:29
virtual int fieldsToCbor()
Definition: senml_bool_record.cpp:29
bool get()
Definition: senml_bool_record.h:58
SenMLBoolRecord(ThingsMLMeasurementIndex index, bool value)
Definition: senml_bool_record.h:30
Definition: senml_record.h:33
bool setTime(double value, bool absolute=true)
Definition: senml_record.cpp:25
SenMLUnit
Definition: senml_enums.h:97
ThingsMLMeasurementIndex
Definition: senml_enums.h:51