Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_radio.h
1 #ifndef _BC_RADIO_H
2 #define _BC_RADIO_H
3 
4 #include <bc_common.h>
5 #include <bc_button.h>
6 #include <bc_led.h>
7 #include <bc_spirit1.h>
8 
12 
13 #ifndef BC_RADIO_MAX_DEVICES
14 #define BC_RADIO_MAX_DEVICES 4
15 #endif
16 
17 #ifndef BC_RADIO_PUB_QUEUE_BUFFER_SIZE
18 #define BC_RADIO_PUB_QUEUE_BUFFER_SIZE 512
19 #endif
20 
21 #ifndef BC_RADIO_RX_QUEUE_BUFFER_SIZE
22 #define BC_RADIO_RX_QUEUE_BUFFER_SIZE 128
23 #endif
24 
25 #define BC_RADIO_ID_SIZE 6
26 #define BC_RADIO_HEAD_SIZE (BC_RADIO_ID_SIZE + 2)
27 #define BC_RADIO_MAX_BUFFER_SIZE (BC_SPIRIT1_MAX_PACKET_SIZE - BC_RADIO_HEAD_SIZE)
28 #define BC_RADIO_MAX_TOPIC_LEN (BC_RADIO_MAX_BUFFER_SIZE - 1 - 4 - 1)
29 #define BC_RADIO_NULL_BOOL 0xff
30 #define BC_RADIO_NULL_INT INT32_MIN
31 #define BC_RADIO_NULL_FLOAT NAN
32 #define BC_RADIO_NULL_UINT32 UINT32_MAX
33 #define BC_RADIO_NULL_UINT16 UINT16_MAX
34 
36 
37 typedef enum
38 {
41 
44 
47 
50 
52 
53 typedef enum
54 {
55  BC_RADIO_EVENT_INIT_FAILURE = 0,
56  BC_RADIO_EVENT_INIT_DONE = 1,
57  BC_RADIO_EVENT_ATTACH = 2,
58  BC_RADIO_EVENT_ATTACH_FAILURE = 3,
59  BC_RADIO_EVENT_DETACH = 4,
60  BC_RADIO_EVENT_SCAN_FIND_DEVICE = 5,
61  BC_RADIO_EVENT_PAIRED = 6,
62  BC_RADIO_EVENT_UNPAIRED = 7,
63  BC_RADIO_EVENT_TX_DONE = 8,
64  BC_RADIO_EVENT_TX_ERROR = 9
65 
66 } bc_radio_event_t;
67 
68 typedef enum
69 {
70  BC_RADIO_HEADER_PAIRING = 0x00,
71  BC_RADIO_HEADER_PUB_PUSH_BUTTON = 0x01,
72  BC_RADIO_HEADER_PUB_TEMPERATURE = 0x02,
73  BC_RADIO_HEADER_PUB_HUMIDITY = 0x03,
74  BC_RADIO_HEADER_PUB_LUX_METER = 0x04,
75  BC_RADIO_HEADER_PUB_BAROMETER = 0x05,
76  BC_RADIO_HEADER_PUB_CO2 = 0x06,
77  BC_RADIO_HEADER_PUB_BUFFER = 0x07,
78  BC_RADIO_HEADER_NODE_ATTACH = 0x08,
79  BC_RADIO_HEADER_NODE_DETACH = 0x09,
80  BC_RADIO_HEADER_PUB_BATTERY = 0x0a,
81  BC_RADIO_HEADER_PUB_INFO = 0x0b, // deprecated
82 
83  BC_RADIO_HEADER_PUB_ACCELERATION = 0x0d,
84  BC_RADIO_HEADER_PUB_TOPIC_STRING = 0x0e,
85  BC_RADIO_HEADER_PUB_TOPIC_UINT32 = 0x0f,
86  BC_RADIO_HEADER_PUB_TOPIC_BOOL = 0x10,
87  BC_RADIO_HEADER_PUB_TOPIC_INT = 0x11,
88  BC_RADIO_HEADER_PUB_TOPIC_FLOAT = 0x12,
89  BC_RADIO_HEADER_PUB_EVENT_COUNT = 0x13,
90  BC_RADIO_HEADER_PUB_STATE = 0x14,
91  BC_RADIO_HEADER_NODE_STATE_SET = 0x15,
92  BC_RADIO_HEADER_NODE_STATE_GET = 0x16,
93  BC_RADIO_HEADER_NODE_BUFFER = 0x17,
94  BC_RADIO_HEADER_NODE_LED_STRIP_COLOR_SET = 0x18,
95  BC_RADIO_HEADER_NODE_LED_STRIP_BRIGHTNESS_SET = 0x19,
96  BC_RADIO_HEADER_NODE_LED_STRIP_COMPOUND_SET = 0x1a,
97  BC_RADIO_HEADER_NODE_LED_STRIP_EFFECT_SET = 0x1b,
98  BC_RADIO_HEADER_NODE_LED_STRIP_THERMOMETER_SET = 0x1c,
99  BC_RADIO_HEADER_SUB_DATA = 0x1d,
100  BC_RADIO_HEADER_PUB_VALUE_INT = 0x1e,
101 
102  BC_RADIO_HEADER_SUB_REG = 0x20,
103 
104  BC_RADIO_HEADER_ACK = 0xaa,
105 
106 
107 } bc_radio_header_t;
108 
110 
111 typedef enum
112 {
113  BC_RADIO_SUB_PT_BOOL = 0,
114  BC_RADIO_SUB_PT_INT = 1,
115  BC_RADIO_SUB_PT_FLOAT = 2,
116  BC_RADIO_SUB_PT_STRING = 3,
117  BC_RADIO_SUB_PT_NULL = 4,
118 
120 
121 typedef struct bc_radio_sub_t bc_radio_sub_t;
122 
124  const char *topic;
125  bc_radio_sub_pt_t type;
126  void (*callback)(uint64_t *id, const char *, void *, void *);
127  void *param;
128 };
129 
130 typedef struct
131 {
132  uint64_t id;
133  uint16_t message_id;
134  bool message_id_synced;
135  bc_radio_mode_t mode;
136  int rssi;
137 
139 
142 
143 void bc_radio_init(bc_radio_mode_t mode);
144 
145 void bc_radio_set_event_handler(void (*event_handler)(bc_radio_event_t, void *), void *event_param);
146 
147 void bc_radio_listen(bc_tick_t timeout);
148 
149 void bc_radio_pairing_request(const char *firmware, const char *version);
150 
151 void bc_radio_pairing_mode_start(void);
152 
153 void bc_radio_pairing_mode_stop(void);
154 
155 bool bc_radio_peer_device_add(uint64_t id);
156 
157 bool bc_radio_peer_device_remove(uint64_t id);
158 
159 bool bc_radio_peer_device_purge_all(void);
160 
161 void bc_radio_get_peer_id(uint64_t *id, int length);
162 
163 void bc_radio_scan_start(void);
164 
165 void bc_radio_scan_stop(void);
166 
167 void bc_radio_automatic_pairing_start(void);
168 
169 void bc_radio_automatic_pairing_stop(void);
170 
171 uint64_t bc_radio_get_my_id(void);
172 
173 uint64_t bc_radio_get_event_id(void);
174 
175 bool bc_radio_is_peer_device(uint64_t id);
176 
177 bool bc_radio_pub_queue_put(const void *buffer, size_t length);
178 
179 void bc_radio_set_subs(bc_radio_sub_t *subs, int length);
180 
181 bool bc_radio_send_sub_data(uint64_t *id, uint8_t order, void *payload, size_t size);
182 
183 void bc_radio_set_rx_timeout_for_sleeping_node(bc_tick_t timeout);
184 
185 bc_radio_peer_t *bc_radio_get_peer_device(uint64_t id);
186 
187 uint8_t *bc_radio_id_to_buffer(uint64_t *id, uint8_t *buffer);
188 uint8_t *bc_radio_bool_to_buffer(bool *value, uint8_t *buffer);
189 uint8_t *bc_radio_int_to_buffer(int *value, uint8_t *buffer);
190 uint8_t *bc_radio_uint16_to_buffer(uint16_t *value, uint8_t *buffer);
191 uint8_t *bc_radio_uint32_to_buffer(uint32_t *value, uint8_t *buffer);
192 uint8_t *bc_radio_float_to_buffer(float *value, uint8_t *buffer);
193 uint8_t *bc_radio_data_to_buffer(void *data, size_t length, uint8_t *buffer);
194 uint8_t *bc_radio_id_from_buffer(uint8_t *buffer, uint64_t *id);
195 uint8_t *bc_radio_bool_from_buffer(uint8_t *buffer, bool *value, bool **pointer);
196 uint8_t *bc_radio_int_from_buffer(uint8_t *buffer, int *value, int **pointer);
197 uint8_t *bc_radio_uint16_from_buffer(uint8_t *buffer, uint16_t *value, uint16_t **pointer);
198 uint8_t *bc_radio_uint32_from_buffer(uint8_t *buffer, uint32_t *value, uint32_t **pointer);
199 uint8_t *bc_radio_float_from_buffer(uint8_t *buffer, float *value, float **pointer);
200 uint8_t *bc_radio_data_from_buffer(uint8_t *buffer, void *data, size_t length);
201 
202 void bc_radio_init_pairing_button();
203 
205 
206 #endif // _BC_RADIO_H
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
Unknown mode.
Definition: bc_radio.h:40
void bc_radio_init(bc_radio_mode_t mode)
Initialize radio.
Definition: bc_radio.c:89
bc_radio_mode_t
Radio mode.
Definition: bc_radio.h:37
Node listening mode.
Definition: bc_radio.h:46
Gateway mode.
Definition: bc_radio.h:43
bc_radio_sub_pt_t
Subscribe payload type.
Definition: bc_radio.h:111
Node sleeping mode, suitable for battery.
Definition: bc_radio.h:49