Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_cmwx1zzabz.h
1 #ifndef _BC_CMWX1ZZABZ_H
2 #define _BC_CMWX1ZZABZ_H
3 
4 #include <bc_scheduler.h>
5 #include <bc_gpio.h>
6 #include <bc_uart.h>
7 
11 
13 
14 #define BC_CMWX1ZZABZ_TX_MAX_PACKET_SIZE 230
15 
16 #define BC_CMWX1ZZABZ_TX_FIFO_BUFFER_SIZE (BC_CMWX1ZZABZ_TX_MAX_PACKET_SIZE + 25)
17 #define BC_CMWX1ZZABZ_RX_FIFO_BUFFER_SIZE 64
18 
20 
22 
23 typedef enum
24 {
27 
30 
33 
36 
39 
42 
45 
48 
51 
54 
57 
59 
61 
63 
65 
66 typedef enum
67 {
68  BC_CMWX1ZZABZ_CONFIG_MODE_ABP = 0,
69  BC_CMWX1ZZABZ_CONFIG_MODE_OTAA = 1
70 
72 
74 
75 typedef enum
76 {
77  BC_CMWX1ZZABZ_CONFIG_BAND_AS923 = 0,
78  BC_CMWX1ZZABZ_CONFIG_BAND_AU915 = 1,
79  BC_CMWX1ZZABZ_CONFIG_BAND_EU868 = 5,
80  BC_CMWX1ZZABZ_CONFIG_BAND_KR920 = 6,
81  BC_CMWX1ZZABZ_CONFIG_BAND_IN865 = 7,
82  BC_CMWX1ZZABZ_CONFIG_BAND_US915 = 8
83 
85 
87 
88 typedef enum
89 {
90  BC_CMWX1ZZABZ_CONFIG_CLASS_A = 0,
91  BC_CMWX1ZZABZ_CONFIG_CLASS_C = 2
92 
94 
96 
97 typedef enum
98 {
99  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF12_125KHZ = 0,
100  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF11_125KHZ = 1,
101  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF10_125KHZ = 2,
102  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF9_125KHZ = 3,
103  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF8_125KHZ = 4,
104  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF7_125KHZ = 5,
105  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_SF7_250KHZ = 6,
106  BC_CMWX1ZZABZ_CONFIG_DATARATE_AS923_FSK_50KBPS = 7,
107 
109 
111 
112 typedef enum
113 {
114  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF12_125KHZ = 0,
115  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF11_125KHZ = 1,
116  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF10_125KHZ = 2,
117  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF9_125KHZ = 3,
118  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF8_125KHZ = 4,
119  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF7_125KHZ = 5,
120  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF8_500KHZ = 6,
121  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF12_500KHZ = 8,
122  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF11_500KHZ = 9,
123  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF10_500KHZ = 10,
124  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF9_500KHZ = 11,
125  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF8_500KHZ_2 = 12,
126  BC_CMWX1ZZABZ_CONFIG_DATARATE_AU915_SF7_500KHZ = 13
127 
129 
130 
132 
133 typedef enum
134 {
135  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF12_125KHZ = 0,
136  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF11_125KHZ = 1,
137  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF10_125KHZ = 2,
138  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF9_125KHZ = 3,
139  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF8_125KHZ = 4,
140  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF7_125KHZ = 5,
141  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_SF7_250KHZ = 6,
142  BC_CMWX1ZZABZ_CONFIG_DATARATE_EU868_FSK_50KBPS = 7
143 
145 
147 
148 typedef enum
149 {
150  BC_CMWX1ZZABZ_CONFIG_DATARATE_KR920_SF12_125KHZ = 0,
151  BC_CMWX1ZZABZ_CONFIG_DATARATE_KR920_SF11_125KHZ = 1,
152  BC_CMWX1ZZABZ_CONFIG_DATARATE_KR920_SF10_125KHZ = 2,
153  BC_CMWX1ZZABZ_CONFIG_DATARATE_KR920_SF9_125KHZ = 3,
154  BC_CMWX1ZZABZ_CONFIG_DATARATE_KR920_SF8_125KHZ = 4,
155  BC_CMWX1ZZABZ_CONFIG_DATARATE_KR920_SF7_125KHZ = 5
156 
158 
160 
161 typedef enum
162 {
163  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF10_125KHZ = 0,
164  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF9_125KHZ = 1,
165  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF8_125KHZ = 2,
166  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF7_125KHZ = 3,
167  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF8_500KHZ = 4,
168  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF12_500KHZ = 8,
169  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF11_500KHZ = 9,
170  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF10_500KHZ = 10,
171  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF9_500KHZ = 11,
172  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF8_500KHZ_2 = 12,
173  BC_CMWX1ZZABZ_CONFIG_DATARATE_US915_SF7_500KHZ = 13
174 
176 
178 
179 typedef enum
180 {
181  BC_CMWX1ZZABZ_CONFIG_INDEX_DEVADDR = 0,
182  BC_CMWX1ZZABZ_CONFIG_INDEX_DEVEUI = 1,
183  BC_CMWX1ZZABZ_CONFIG_INDEX_APPEUI = 2,
184  BC_CMWX1ZZABZ_CONFIG_INDEX_NWKSKEY = 3,
185  BC_CMWX1ZZABZ_CONFIG_INDEX_APPSKEY = 4,
186  BC_CMWX1ZZABZ_CONFIG_INDEX_APPKEY = 5,
187  BC_CMWX1ZZABZ_CONFIG_INDEX_BAND = 6,
188  BC_CMWX1ZZABZ_CONFIG_INDEX_MODE = 7,
189  BC_CMWX1ZZABZ_CONFIG_INDEX_CLASS = 8,
190  BC_CMWX1ZZABZ_CONFIG_INDEX_RX2 = 9,
191  BC_CMWX1ZZABZ_CONFIG_INDEX_NWK = 10,
192  BC_CMWX1ZZABZ_CONFIG_INDEX_DATARATE = 11,
193  BC_CMWX1ZZABZ_CONFIG_INDEX_LAST_ITEM
194 
195 } bc_cmwx1zzabz_config_index_t;
196 
197 typedef enum
198 {
199  BC_CMWX1ZZABZ_STATE_READY = 0,
200  BC_CMWX1ZZABZ_STATE_ERROR = 1,
201  BC_CMWX1ZZABZ_STATE_INITIALIZE = 2,
202  BC_CMWX1ZZABZ_STATE_IDLE = 3,
203  BC_CMWX1ZZABZ_STATE_INITIALIZE_COMMAND_SEND = 5,
204  BC_CMWX1ZZABZ_STATE_INITIALIZE_COMMAND_RESPONSE = 6,
205 
206  BC_CMWX1ZZABZ_STATE_CONFIG_SAVE_SEND = 7,
207  BC_CMWX1ZZABZ_STATE_CONFIG_SAVE_RESPONSE = 8,
208 
209  BC_CMWX1ZZABZ_STATE_SEND_MESSAGE_COMMAND = 9,
210  BC_CMWX1ZZABZ_STATE_SEND_MESSAGE_CONFIRMED_COMMAND = 10,
211  BC_CMWX1ZZABZ_STATE_SEND_MESSAGE_RESPONSE = 11,
212 
213  BC_CMWX1ZZABZ_STATE_JOIN_SEND = 12,
214  BC_CMWX1ZZABZ_STATE_JOIN_RESPONSE = 13,
215 
216  BC_CMWX1ZZABZ_STATE_RECEIVE = 14
217 
218 } bc_cmwx1zzabz_state_t;
219 
220 typedef struct
221 {
225  char devaddr[8 + 1];
226  char deveui[16 + 1];
227  char appeui[16 + 1];
228  char nwkskey[32 + 1];
229  char appskey[32 + 1];
230  char appkey[32 + 1];
231  uint32_t rx2_frequency;
232  uint8_t rx2_datarate;
233  uint8_t nwk_public;
234  uint8_t datarate;
235 
236 } bc_cmwx1zzabz_config;
237 
238 struct bc_cmwx1zzabz_t
239 {
240  bc_scheduler_task_id_t _task_id;
241  bc_uart_channel_t _uart_channel;
242  bc_cmwx1zzabz_state_t _state;
243  bc_cmwx1zzabz_state_t _state_after_sleep;
244  bc_fifo_t _tx_fifo;
245  bc_fifo_t _rx_fifo;
246  uint8_t _tx_fifo_buffer[BC_CMWX1ZZABZ_TX_FIFO_BUFFER_SIZE];
247  uint8_t _rx_fifo_buffer[BC_CMWX1ZZABZ_RX_FIFO_BUFFER_SIZE];
248  void (*_event_handler)(bc_cmwx1zzabz_t *, bc_cmwx1zzabz_event_t, void *);
249  void *_event_param;
250  char _command[BC_CMWX1ZZABZ_TX_FIFO_BUFFER_SIZE];
251  char _response[BC_CMWX1ZZABZ_RX_FIFO_BUFFER_SIZE];
252  uint8_t _message_buffer[BC_CMWX1ZZABZ_TX_MAX_PACKET_SIZE];
253  size_t _message_length;
254  uint8_t _message_port;
255  uint8_t _init_command_index;
256  uint8_t _save_command_index;
257  bool _save_flag;
258  uint32_t _save_config_mask;
259  bc_cmwx1zzabz_config _config;
260  bool _join_command;
261  uint8_t _tx_port;
262 };
263 
265 
269 
270 void bc_cmwx1zzabz_init(bc_cmwx1zzabz_t *self, bc_uart_channel_t uart_channel);
271 
276 
277 void bc_cmwx1zzabz_set_event_handler(bc_cmwx1zzabz_t *self, void (*event_handler)(bc_cmwx1zzabz_t *, bc_cmwx1zzabz_event_t, void *), void *event_param);
278 
283 
285 
292 
293 bool bc_cmwx1zzabz_send_message(bc_cmwx1zzabz_t *self, const void *buffer, size_t length);
294 
301 
302 bool bc_cmwx1zzabz_send_message_confirmed(bc_cmwx1zzabz_t *self, const void *buffer, size_t length);
303 
307 
308 void bc_cmwx1zzabz_set_devaddr(bc_cmwx1zzabz_t *self, char *devaddr);
309 
313 
314 void bc_cmwx1zzabz_get_devaddr(bc_cmwx1zzabz_t *self, char *devaddr);
315 
319 
320 void bc_cmwx1zzabz_set_deveui(bc_cmwx1zzabz_t *self, char *deveui);
321 
325 
326 void bc_cmwx1zzabz_get_deveui(bc_cmwx1zzabz_t *self, char *deveui);
327 
331 
332 void bc_cmwx1zzabz_set_appeui(bc_cmwx1zzabz_t *self, char *appeui);
333 
337 
338 void bc_cmwx1zzabz_get_appeui(bc_cmwx1zzabz_t *self, char *appeui);
339 
343 
344 void bc_cmwx1zzabz_set_nwkskey(bc_cmwx1zzabz_t *self, char *nwkskey);
345 
349 
350 void bc_cmwx1zzabz_get_nwkskey(bc_cmwx1zzabz_t *self, char *nwkskey);
351 
355 
356 void bc_cmwx1zzabz_set_appskey(bc_cmwx1zzabz_t *self, char *appskey);
357 
361 
362 void bc_cmwx1zzabz_get_appskey(bc_cmwx1zzabz_t *self, char *appskey);
363 
367 
368 void bc_cmwx1zzabz_set_appkey(bc_cmwx1zzabz_t *self, char *appkey);
369 
373 
374 void bc_cmwx1zzabz_get_appkey(bc_cmwx1zzabz_t *self, char *appkey);
375 
379 
381 
385 
387 
391 
393 
397 
399 
403 
405 
409 
411 
416 
418 
422 
424 
428 
430 
436 
437 uint32_t bc_cmwx1zzabz_get_received_message_data(bc_cmwx1zzabz_t *self, uint8_t *buffer, uint32_t buffer_size);
438 
442 
443 void bc_cmwx1zzabz_set_port(bc_cmwx1zzabz_t *self, uint8_t port);
444 
448 
450 
455 
456 void bc_cmwx1zzabz_set_rx2(bc_cmwx1zzabz_t *self, uint32_t frequency, uint8_t datarate);
457 
462 
463 void bc_cmwx1zzabz_get_rx2(bc_cmwx1zzabz_t *self, uint32_t *frequency, uint8_t *datarate);
464 
468 
469 void bc_cmwx1zzabz_set_nwk_public(bc_cmwx1zzabz_t *self, uint8_t public);
470 
474 
476 
480 
481 void bc_cmwx1zzabz_set_datarate(bc_cmwx1zzabz_t *self, uint8_t datarate);
482 
486 
488 
490 
491 #endif // _BC_CMWX1ZZABZ_H
void bc_cmwx1zzabz_set_deveui(bc_cmwx1zzabz_t *self, char *deveui)
Set DEVEUI.
void bc_cmwx1zzabz_set_datarate(bc_cmwx1zzabz_t *self, uint8_t datarate)
Set the configuration of datarate.
bc_uart_channel_t
UART channels.
Definition: bc_uart.h:13
void bc_cmwx1zzabz_get_appeui(bc_cmwx1zzabz_t *self, char *appeui)
Get APPEUI.
Configuration save done.
Definition: bc_cmwx1zzabz.h:38
void bc_cmwx1zzabz_get_devaddr(bc_cmwx1zzabz_t *self, char *devaddr)
Get DEVADDR.
void bc_cmwx1zzabz_set_event_handler(bc_cmwx1zzabz_t *self, void(*event_handler)(bc_cmwx1zzabz_t *, bc_cmwx1zzabz_event_t, void *), void *event_param)
Set callback function.
Definition: bc_cmwx1zzabz.c:69
Structure of FIFO instance.
Definition: bc_fifo.h:12
void bc_cmwx1zzabz_set_mode(bc_cmwx1zzabz_t *self, bc_cmwx1zzabz_config_mode_t mode)
Set ABP/OTAA mode.
bc_cmwx1zzabz_config_mode_t
LoRa mode ABP/OTAA.
Definition: bc_cmwx1zzabz.h:66
void bc_cmwx1zzabz_set_devaddr(bc_cmwx1zzabz_t *self, char *devaddr)
Set DEVADDR.
void bc_cmwx1zzabz_set_band(bc_cmwx1zzabz_t *self, bc_cmwx1zzabz_config_band_t band)
Set BAND.
void bc_cmwx1zzabz_init(bc_cmwx1zzabz_t *self, bc_uart_channel_t uart_channel)
Initialize CMWX1ZZABZ.
Definition: bc_cmwx1zzabz.c:38
void bc_cmwx1zzabz_get_deveui(bc_cmwx1zzabz_t *self, char *deveui)
Get DEVEUI.
struct bc_cmwx1zzabz_t bc_cmwx1zzabz_t
CMWX1ZZABZ instance.
Definition: bc_cmwx1zzabz.h:62
Retransmission of the confirmed message.
Definition: bc_cmwx1zzabz.h:50
bool bc_cmwx1zzabz_send_message(bc_cmwx1zzabz_t *self, const void *buffer, size_t length)
Send LoRa message.
Definition: bc_cmwx1zzabz.c:85
void bc_cmwx1zzabz_get_nwkskey(bc_cmwx1zzabz_t *self, char *nwkskey)
Set NWKSKEY.
Sent message not confirmed.
Definition: bc_cmwx1zzabz.h:56
void bc_cmwx1zzabz_set_appkey(bc_cmwx1zzabz_t *self, char *appkey)
Set APPKEY.
uint32_t bc_cmwx1zzabz_get_received_message_length(bc_cmwx1zzabz_t *self)
Get length of the received message.
uint8_t bc_cmwx1zzabz_get_nwk_public(bc_cmwx1zzabz_t *self)
Get the configuration if public networks are enabled.
uint32_t bc_cmwx1zzabz_get_received_message_data(bc_cmwx1zzabz_t *self, uint8_t *buffer, uint32_t buffer_size)
Get received message data.
bool bc_cmwx1zzabz_is_ready(bc_cmwx1zzabz_t *self)
Check if modem is ready for commands.
Definition: bc_cmwx1zzabz.c:75
bc_cmwx1zzabz_config_datarate_eu868_t
Datarate for EU868.
void bc_cmwx1zzabz_join(bc_cmwx1zzabz_t *self)
Start LoRa OTAA join procedure.
bc_cmwx1zzabz_config_datarate_au915_t
Datarate for AU915.
bc_cmwx1zzabz_config_datarate_kr920_t
Datarate for KR920.
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bc_cmwx1zzabz_config_mode_t bc_cmwx1zzabz_get_mode(bc_cmwx1zzabz_t *self)
Get ABP/OTAA mode.
bc_cmwx1zzabz_config_datarate_as923_t
Datarate for AS923.
Definition: bc_cmwx1zzabz.h:97
void bc_cmwx1zzabz_get_appkey(bc_cmwx1zzabz_t *self, char *appkey)
Get APPKEY.
void bc_cmwx1zzabz_set_appskey(bc_cmwx1zzabz_t *self, char *appskey)
Set APPSKEY.
bc_cmwx1zzabz_config_class_t bc_cmwx1zzabz_get_class(bc_cmwx1zzabz_t *self)
Get device class.
void bc_cmwx1zzabz_set_nwk_public(bc_cmwx1zzabz_t *self, uint8_t public)
Set the configuration enabling public networks.
bool bc_cmwx1zzabz_send_message_confirmed(bc_cmwx1zzabz_t *self, const void *buffer, size_t length)
Send LoRa confirmed message.
uint8_t bc_cmwx1zzabz_get_datarate(bc_cmwx1zzabz_t *self)
Get the configuration of datarate.
void bc_cmwx1zzabz_set_nwkskey(bc_cmwx1zzabz_t *self, char *nwkskey)
Set NWKSKEY.
bc_cmwx1zzabz_config_datarate_us915_t
Datarate for US915.
bc_cmwx1zzabz_event_t
Callback events.
Definition: bc_cmwx1zzabz.h:23
void bc_cmwx1zzabz_get_rx2(bc_cmwx1zzabz_t *self, uint32_t *frequency, uint8_t *datarate)
Get the frequency and datarate for RX2 receive window.
void bc_cmwx1zzabz_set_rx2(bc_cmwx1zzabz_t *self, uint32_t frequency, uint8_t datarate)
Set the frequency and datarate for RX2 receive window.
void bc_cmwx1zzabz_set_class(bc_cmwx1zzabz_t *self, bc_cmwx1zzabz_config_class_t class)
Set device class.
uint8_t bc_cmwx1zzabz_get_port(bc_cmwx1zzabz_t *self)
Get the port for the transmission of the messages.
void bc_cmwx1zzabz_set_appeui(bc_cmwx1zzabz_t *self, char *appeui)
Set APPEUI.
void bc_cmwx1zzabz_get_appskey(bc_cmwx1zzabz_t *self, char *appskey)
Get APPSKEY.
bc_cmwx1zzabz_config_class_t
LoRa device class A or C.
Definition: bc_cmwx1zzabz.h:88
uint8_t bc_cmwx1zzabz_get_received_message_port(bc_cmwx1zzabz_t *self)
Get port of the received message.
bc_cmwx1zzabz_config_band_t bc_cmwx1zzabz_get_band(bc_cmwx1zzabz_t *self)
Get BAND.
void bc_cmwx1zzabz_set_port(bc_cmwx1zzabz_t *self, uint8_t port)
Set the port for the transmission of the messages.
RF frame transmission started event.
Definition: bc_cmwx1zzabz.h:32
RF frame transmission finished event.
Definition: bc_cmwx1zzabz.h:35
bc_cmwx1zzabz_config_band_t
Frequency modes and standards.
Definition: bc_cmwx1zzabz.h:75