blob: 317320806b535ad26ed3d9036e33a63efc8781a6 [file] [log] [blame]
Tiago Barros7428dfd2016-09-06 17:56:00 -03001/*
2 * Copyright (c) 2016, CESAR.
3 * All rights reserved.
4 *
5 * This software may be modified and distributed under the terms
6 * of the BSD license. See the LICENSE file for details.
7 *
8 */
9
10#include <stdint.h>
11
12#include "KNoTThing.h"
13
14KNoTThing::KNoTThing()
15{
Rodrigo Alves3740c832016-11-04 13:08:12 -030016
Tiago Barros7428dfd2016-09-06 17:56:00 -030017}
18
19KNoTThing::~KNoTThing()
20{
21 knot_thing_exit();
22}
23
Rodrigo Alves4d633dc2016-11-09 11:03:04 -030024int KNoTThing::init(const char *thing_name)
Tiago Barros7428dfd2016-09-06 17:56:00 -030025{
Rodrigo Alves4d633dc2016-11-09 11:03:04 -030026 return knot_thing_init(thing_name);
Tiago Barros7428dfd2016-09-06 17:56:00 -030027}
28
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030029int KNoTThing::registerIntData(const char *name, uint8_t sensor_id,
30 uint16_t type_id, uint8_t unit,
31 intDataFunction read, intDataFunction write)
Tiago Barros7428dfd2016-09-06 17:56:00 -030032{
33 knot_data_functions func;
34 func.int_f.read = read;
35 func.int_f.write = write;
36
Rodrigo Alves3740c832016-11-04 13:08:12 -030037 return knot_thing_register_data_item(sensor_id, name, type_id,
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030038 KNOT_VALUE_TYPE_INT, unit, &func);
Tiago Barros7428dfd2016-09-06 17:56:00 -030039}
40
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030041int KNoTThing::registerFloatData(const char *name, uint8_t sensor_id,
42 uint16_t type_id, uint8_t unit,
43 floatDataFunction read, floatDataFunction write)
Tiago Barros7428dfd2016-09-06 17:56:00 -030044{
45 knot_data_functions func;
46 func.float_f.read = read;
47 func.float_f.write = write;
48
Rodrigo Alves3740c832016-11-04 13:08:12 -030049 return knot_thing_register_data_item(sensor_id, name, type_id,
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030050 KNOT_VALUE_TYPE_FLOAT, unit, &func);
Tiago Barros7428dfd2016-09-06 17:56:00 -030051
52}
53
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030054int KNoTThing::registerBoolData(const char *name, uint8_t sensor_id,
55 uint16_t type_id, uint8_t unit,
56 boolDataFunction read, boolDataFunction write)
Tiago Barros7428dfd2016-09-06 17:56:00 -030057{
58 knot_data_functions func;
59 func.bool_f.read = read;
60 func.bool_f.write = write;
61
Rodrigo Alves3740c832016-11-04 13:08:12 -030062 return knot_thing_register_data_item(sensor_id, name, type_id,
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030063 KNOT_VALUE_TYPE_BOOL, unit, &func);
Tiago Barros7428dfd2016-09-06 17:56:00 -030064
65}
66
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030067int KNoTThing::registerRawData(const char *name, uint8_t *raw_buffer,
68 uint8_t raw_buffer_len, uint8_t sensor_id, uint16_t type_id,
Claudio Takahasid4df10f2018-07-26 13:58:56 -030069 uint8_t unit, rawReadFunction read, rawWriteFunction write)
Tiago Barros7428dfd2016-09-06 17:56:00 -030070{
71 knot_data_functions func;
72 func.raw_f.read = read;
73 func.raw_f.write = write;
74
Rodrigo Alves2d4e99d2016-11-23 11:19:11 -030075 return knot_thing_register_raw_data_item(sensor_id, name, raw_buffer,
76 raw_buffer_len, type_id, KNOT_VALUE_TYPE_RAW, unit, &func);
Tiago Barros7428dfd2016-09-06 17:56:00 -030077}
78
Tiago Barros7428dfd2016-09-06 17:56:00 -030079void KNoTThing::run()
80{
81 knot_thing_run();
82}
83
Larissa Lages6fd84f22017-05-08 08:07:12 -030084int KNoTThing::registerDefaultConfig(uint8_t sensor_id, uint8_t event_flags,
85 uint16_t time_sec, int32_t upper_int, uint32_t upper_dec,
86 int32_t lower_int, uint32_t lower_dec)
87{
Claudio Takahasia04a2d42018-07-24 14:24:28 -030088 knot_value_type lower;
89 knot_value_type upper;
Larissa Lages56f067b2017-07-19 15:08:06 -030090
91 lower.val_f.value_int = lower_int;
92 lower.val_f.value_dec = lower_dec;
93 upper.val_f.value_int = upper_int;
94 upper.val_f.value_dec = upper_dec;
95
96 return knot_thing_config_data_item(sensor_id, event_flags, time_sec,
97 &lower, &upper);
Larissa Lages6fd84f22017-05-08 08:07:12 -030098}