Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 1 | /* |
| 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 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 10 | #ifndef __KNOT_THING_MAIN_H__ |
| 11 | #define __KNOT_THING_MAIN_H__ |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 12 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 16 | |
Rodrigo Alves | 925ba53 | 2016-11-03 10:54:05 -0300 | [diff] [blame] | 17 | #include "knot_thing_protocol.h" |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 18 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 19 | typedef int (*intDataFunction) (int32_t *val, int32_t *multiplier); |
| 20 | typedef int (*floatDataFunction) (int32_t *val_int, uint32_t *val_dec, int32_t *multiplier); |
| 21 | typedef int (*boolDataFunction) (uint8_t *val); |
| 22 | typedef int (*rawDataFunction) (uint8_t *val, uint8_t *len); |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 23 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 24 | typedef struct __attribute__ ((packed)) { |
| 25 | intDataFunction read; |
| 26 | intDataFunction write; |
| 27 | } knot_int_functions; |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 28 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 29 | typedef struct __attribute__ ((packed)) { |
| 30 | floatDataFunction read; |
| 31 | floatDataFunction write; |
| 32 | } knot_float_functions; |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 33 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 34 | typedef struct __attribute__ ((packed)) { |
| 35 | boolDataFunction read; |
| 36 | boolDataFunction write; |
| 37 | } knot_bool_functions; |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 38 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 39 | typedef struct __attribute__ ((packed)) { |
| 40 | rawDataFunction read; |
| 41 | rawDataFunction write; |
| 42 | } knot_raw_functions; |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 43 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 44 | typedef union __attribute__ ((packed)) { |
| 45 | knot_int_functions int_f; |
| 46 | knot_float_functions float_f; |
| 47 | knot_bool_functions bool_f; |
| 48 | knot_raw_functions raw_f; |
| 49 | } knot_data_functions; |
Claudio Takahasi | 6b7aad5 | 2016-08-08 22:32:08 -0300 | [diff] [blame] | 50 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 51 | /* KNOT Thing main initialization functions and polling */ |
Rodrigo Alves | 4d633dc | 2016-11-09 11:03:04 -0300 | [diff] [blame] | 52 | int8_t knot_thing_init(const char *thing_name); |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 53 | void knot_thing_exit(void); |
| 54 | int8_t knot_thing_run(void); |
Claudio Takahasi | fa33d71 | 2016-08-10 10:09:39 -0300 | [diff] [blame] | 55 | |
Claudio Takahasi | 05c7190 | 2016-08-10 09:41:51 -0300 | [diff] [blame] | 56 | /* |
Rodrigo Alves | c2653c4 | 2016-11-21 16:12:42 -0300 | [diff] [blame] | 57 | * Data item (source/sink) registration functions |
Claudio Takahasi | 05c7190 | 2016-08-10 09:41:51 -0300 | [diff] [blame] | 58 | */ |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 59 | int8_t knot_thing_register_raw_data_item(uint8_t sensor_id, const char *name, |
| 60 | uint8_t *raw_buffer, uint8_t raw_buffer_len, uint16_t type_id, |
| 61 | uint8_t value_type, uint8_t unit, knot_data_functions *func); |
Claudio Takahasi | 05c7190 | 2016-08-10 09:41:51 -0300 | [diff] [blame] | 62 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 63 | int8_t knot_thing_register_data_item(uint8_t sensor_id, const char *name, uint16_t type_id, |
| 64 | uint8_t value_type, uint8_t unit, knot_data_functions *func); |
| 65 | |
Tiago Barros | c468b9e | 2017-07-07 10:29:02 -0300 | [diff] [blame] | 66 | int knot_thing_create_schema(uint8_t id, knot_msg_schema *msg); |
| 67 | int knot_thing_data_item_read(uint8_t id, knot_msg_data *data); |
| 68 | int knot_thing_data_item_write(uint8_t id, knot_msg_data *data); |
| 69 | int knot_thing_verify_events(knot_msg_data *data); |
| 70 | int knot_thing_config_data_item(uint8_t id, uint8_t evflags, uint16_t time_sec, |
| 71 | knot_value_types *lower, |
| 72 | knot_value_types *upper); |
| 73 | |
Tiago Barros | 9ca6b3d | 2016-09-05 14:27:05 -0300 | [diff] [blame] | 74 | #ifdef __cplusplus |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | #endif /* __KNOT_THING_MAIN_H__ */ |