Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_module_sigfox.c
1 #include <bc_module_sigfox.h>
2 
3 static void _bc_module_sigfox_event_handler_td1207r(bc_td1207r_t *child, bc_td1207r_event_t event, void *event_param);
4 
5 static void _bc_module_sigfox_event_handler_wssfm10r1at(bc_wssfm10r1at_t *child, bc_wssfm10r1at_event_t event, void *event_param);
6 
7 void bc_module_sigfox_init(bc_module_sigfox_t *self, bc_module_sigfox_revision_t revision)
8 {
9  memset(self, 0, sizeof(*self));
10 
11  self->_revision = revision;
12 
13  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
14  {
15  bc_td1207r_init(&self->_modem.td1207r, BC_GPIO_P6, BC_UART_UART1);
16 
17  bc_td1207r_set_event_handler(&self->_modem.td1207r, _bc_module_sigfox_event_handler_td1207r, self);
18  }
19  else
20  {
21  bc_wssfm10r1at_init(&self->_modem.wssfm10r1at, BC_GPIO_P6, BC_UART_UART1);
22 
23  bc_wssfm10r1at_set_event_handler(&self->_modem.wssfm10r1at, _bc_module_sigfox_event_handler_wssfm10r1at, self);
24  }
25 }
26 
27 void bc_module_sigfox_set_event_handler(bc_module_sigfox_t *self, void (*event_handler)(bc_module_sigfox_t *, bc_module_sigfox_event_t, void *), void *event_param)
28 {
29  self->_event_handler = event_handler;
30 
31  self->_event_param = event_param;
32 }
33 
34 bool bc_module_sigfox_is_ready(bc_module_sigfox_t *self)
35 {
36  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
37  {
38  return bc_td1207r_is_ready(&self->_modem.td1207r);
39  }
40 
41  return bc_wssfm10r1at_is_ready(&self->_modem.wssfm10r1at);
42 }
43 
44 bool bc_module_sigfox_send_rf_frame(bc_module_sigfox_t *self, const void *buffer, size_t length)
45 {
46  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
47  {
48  return bc_td1207r_send_rf_frame(&self->_modem.td1207r, buffer, length);
49  }
50 
51  return bc_wssfm10r1at_send_rf_frame(&self->_modem.wssfm10r1at, buffer, length);
52 }
53 
54 bool bc_module_sigfox_read_device_id(bc_module_sigfox_t *self)
55 {
56  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
57  {
58  return false;
59  }
60 
61  return bc_wssfm10r1at_read_device_id(&self->_modem.wssfm10r1at);
62 }
63 
64 bool bc_module_sigfox_get_device_id(bc_module_sigfox_t *self, char *buffer, size_t buffer_size)
65 {
66  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
67  {
68  return false;
69  }
70 
71  return bc_wssfm10r1at_get_device_id(&self->_modem.wssfm10r1at, buffer, buffer_size);
72 }
73 
74 bool bc_module_sigfox_read_device_pac(bc_module_sigfox_t *self)
75 {
76  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
77  {
78  return false;
79  }
80 
81  return bc_wssfm10r1at_read_device_pac(&self->_modem.wssfm10r1at);
82 }
83 
84 bool bc_module_sigfox_get_device_pac(bc_module_sigfox_t *self, char *buffer, size_t buffer_size)
85 {
86  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
87  {
88  return false;
89  }
90 
91  return bc_wssfm10r1at_get_device_pac(&self->_modem.wssfm10r1at, buffer, buffer_size);
92 }
93 
94 bool bc_module_sigfox_continuous_wave(bc_module_sigfox_t *self)
95 {
96  if (self->_revision == BC_MODULE_SIGFOX_REVISION_R1)
97  {
98  return false;
99  }
100 
101  return bc_wssfm10r1at_continuous_wave(&self->_modem.wssfm10r1at);
102 }
103 
104 static void _bc_module_sigfox_event_handler_td1207r(bc_td1207r_t *child, bc_td1207r_event_t event, void *event_param)
105 {
106  (void) child;
107 
108  bc_module_sigfox_t *self = event_param;
109 
110  if (self->_event_handler != NULL)
111  {
112  if (event == BC_TD1207R_EVENT_READY)
113  {
114  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_READY, self->_event_param);
115  }
116  else if (event == BC_TD1207R_EVENT_ERROR)
117  {
118  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_ERROR, self->_event_param);
119  }
120  else if (event == BC_TD1207R_EVENT_SEND_RF_FRAME_START)
121  {
122  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START, self->_event_param);
123  }
124  else if (event == BC_TD1207R_EVENT_SEND_RF_FRAME_DONE)
125  {
126  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_DONE, self->_event_param);
127  }
128  }
129 }
130 
131 static void _bc_module_sigfox_event_handler_wssfm10r1at(bc_wssfm10r1at_t *child, bc_wssfm10r1at_event_t event, void *event_param)
132 {
133  (void) child;
134 
135  bc_module_sigfox_t *self = event_param;
136 
137  if (self->_event_handler != NULL)
138  {
139  if (event == BC_WSSFM10R1AT_EVENT_READY)
140  {
141  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_READY, self->_event_param);
142  }
143  else if (event == BC_WSSFM10R1AT_EVENT_ERROR)
144  {
145  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_ERROR, self->_event_param);
146  }
148  {
149  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START, self->_event_param);
150  }
151  else if (event == BC_WSSFM10R1AT_EVENT_SEND_RF_FRAME_DONE)
152  {
153  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_DONE, self->_event_param);
154  }
155  else if (event == BC_WSSFM10R1AT_EVENT_READ_DEVICE_ID)
156  {
157  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_READ_DEVICE_ID, self->_event_param);
158  }
159  else if (event == BC_WSSFM10R1AT_EVENT_READ_DEVICE_PAC)
160  {
161  self->_event_handler(self, BC_MODULE_SIGFOX_EVENT_READ_DEVICE_PAC, self->_event_param);
162  }
163  }
164 }
RF frame transmission started event.
bool bc_td1207r_send_rf_frame(bc_td1207r_t *self, const void *buffer, size_t length)
Send RF frame command.
Definition: bc_td1207r.c:47
Device ID has been read event.
bc_module_sigfox_revision_t
SigFox Module hardware revision.
Device PAC has been read event.
bool bc_module_sigfox_read_device_id(bc_module_sigfox_t *self)
Read device ID command.
struct bc_wssfm10r1at_t bc_wssfm10r1at_t
WSSFM10R1AT instance.
bc_wssfm10r1at_event_t
Callback events.
bc_module_sigfox_event_t
Callback events.
void bc_wssfm10r1at_init(bc_wssfm10r1at_t *self, bc_gpio_channel_t reset_signal, bc_uart_channel_t uart_channel)
Initialize WSSFM10R1AT.
bool bc_wssfm10r1at_read_device_pac(bc_wssfm10r1at_t *self)
Read device PAC command.
RF frame transmission started event.
Definition: bc_td1207r.h:30
bool bc_module_sigfox_get_device_pac(bc_module_sigfox_t *self, char *buffer, size_t buffer_size)
Get device PAC (can be called only in BC_WSSFM10R1AT_EVENT_READ_DEVICE_ID event)
bool bc_wssfm10r1at_is_ready(bc_wssfm10r1at_t *self)
Check if modem is ready for commands.
RF frame transmission finished event.
RF frame transmission finished event.
UART channel UART1.
Definition: bc_uart.h:19
bool bc_module_sigfox_get_device_id(bc_module_sigfox_t *self, char *buffer, size_t buffer_size)
Get device ID (can be called only in BC_WSSFM10R1AT_EVENT_READ_DEVICE_ID event)
struct bc_td1207r_t bc_td1207r_t
TD1207R instance.
Definition: bc_td1207r.h:39
void bc_module_sigfox_init(bc_module_sigfox_t *self, bc_module_sigfox_revision_t revision)
Initialize BigClown SigFox Module.
GPIO channel P6.
Definition: bc_gpio.h:33
void bc_td1207r_set_event_handler(bc_td1207r_t *self, void(*event_handler)(bc_td1207r_t *, bc_td1207r_event_t, void *), void *event_param)
Set callback function.
Definition: bc_td1207r.c:36
bc_td1207r_event_t
Callback events.
Definition: bc_td1207r.h:21
Hardware revision R1.
bool bc_wssfm10r1at_get_device_pac(bc_wssfm10r1at_t *self, char *buffer, size_t buffer_size)
Get device PAC (can be called only in BC_WSSFM10R1AT_EVENT_READ_DEVICE_PAC event) ...
bool bc_wssfm10r1at_continuous_wave(bc_wssfm10r1at_t *self)
Generate continuous wave command.
bool bc_module_sigfox_read_device_pac(bc_module_sigfox_t *self)
Read device PAC command.
bool bc_wssfm10r1at_read_device_id(bc_wssfm10r1at_t *self)
Read device ID command.
RF frame transmission started event.
RF frame transmission finished event.
Definition: bc_td1207r.h:33
void bc_td1207r_init(bc_td1207r_t *self, bc_gpio_channel_t reset_signal, bc_uart_channel_t uart_channel)
Initialize TD1207R.
Definition: bc_td1207r.c:13
bool bc_module_sigfox_is_ready(bc_module_sigfox_t *self)
Check if modem is ready for commands.
Error event.
Definition: bc_td1207r.h:27
void bc_wssfm10r1at_set_event_handler(bc_wssfm10r1at_t *self, void(*event_handler)(bc_wssfm10r1at_t *, bc_wssfm10r1at_event_t, void *), void *event_param)
Set callback function.
Ready event.
Definition: bc_td1207r.h:24
bool bc_wssfm10r1at_get_device_id(bc_wssfm10r1at_t *self, char *buffer, size_t buffer_size)
Get device ID (can be called only in BC_WSSFM10R1AT_EVENT_READ_DEVICE_ID event)
void bc_module_sigfox_set_event_handler(bc_module_sigfox_t *self, void(*event_handler)(bc_module_sigfox_t *, bc_module_sigfox_event_t, void *), void *event_param)
Set callback function.
Device PAC has been read event.
bool bc_module_sigfox_continuous_wave(bc_module_sigfox_t *self)
Generate continuous wave command.
Device ID has been read event.
bool bc_module_sigfox_send_rf_frame(bc_module_sigfox_t *self, const void *buffer, size_t length)
Send RF frame command.
bool bc_wssfm10r1at_send_rf_frame(bc_wssfm10r1at_t *self, const void *buffer, size_t length)
Send RF frame command.
bool bc_td1207r_is_ready(bc_td1207r_t *self)
Check if modem is ready for commands.
Definition: bc_td1207r.c:42