Firmware SDK
twr_module_sigfox.c
1 #include <twr_module_sigfox.h>
2 
3 static void _twr_module_sigfox_event_handler_td1207r(twr_td1207r_t *child, twr_td1207r_event_t event, void *event_param);
4 
5 static void _twr_module_sigfox_event_handler_wssfm10r1at(twr_wssfm10r1at_t *child, twr_wssfm10r1at_event_t event, void *event_param);
6 
7 void twr_module_sigfox_init(twr_module_sigfox_t *self, twr_module_sigfox_revision_t revision)
8 {
9  memset(self, 0, sizeof(*self));
10 
11  self->_revision = revision;
12 
13  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
14  {
15  twr_td1207r_init(&self->_modem.td1207r, TWR_GPIO_P6, TWR_UART_UART1);
16 
17  twr_td1207r_set_event_handler(&self->_modem.td1207r, _twr_module_sigfox_event_handler_td1207r, self);
18  }
19  else
20  {
21  twr_wssfm10r1at_init(&self->_modem.wssfm10r1at, TWR_GPIO_P6, TWR_UART_UART1);
22 
23  twr_wssfm10r1at_set_event_handler(&self->_modem.wssfm10r1at, _twr_module_sigfox_event_handler_wssfm10r1at, self);
24  }
25 }
26 
27 void twr_module_sigfox_set_event_handler(twr_module_sigfox_t *self, void (*event_handler)(twr_module_sigfox_t *, twr_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 twr_module_sigfox_is_ready(twr_module_sigfox_t *self)
35 {
36  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
37  {
38  return twr_td1207r_is_ready(&self->_modem.td1207r);
39  }
40 
41  return twr_wssfm10r1at_is_ready(&self->_modem.wssfm10r1at);
42 }
43 
44 bool twr_module_sigfox_send_rf_frame(twr_module_sigfox_t *self, const void *buffer, size_t length)
45 {
46  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
47  {
48  return twr_td1207r_send_rf_frame(&self->_modem.td1207r, buffer, length);
49  }
50 
51  return twr_wssfm10r1at_send_rf_frame(&self->_modem.wssfm10r1at, buffer, length);
52 }
53 
54 bool twr_module_sigfox_read_device_id(twr_module_sigfox_t *self)
55 {
56  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
57  {
58  return false;
59  }
60 
61  return twr_wssfm10r1at_read_device_id(&self->_modem.wssfm10r1at);
62 }
63 
64 bool twr_module_sigfox_get_device_id(twr_module_sigfox_t *self, char *buffer, size_t buffer_size)
65 {
66  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
67  {
68  return false;
69  }
70 
71  return twr_wssfm10r1at_get_device_id(&self->_modem.wssfm10r1at, buffer, buffer_size);
72 }
73 
74 bool twr_module_sigfox_read_device_pac(twr_module_sigfox_t *self)
75 {
76  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
77  {
78  return false;
79  }
80 
81  return twr_wssfm10r1at_read_device_pac(&self->_modem.wssfm10r1at);
82 }
83 
84 bool twr_module_sigfox_get_device_pac(twr_module_sigfox_t *self, char *buffer, size_t buffer_size)
85 {
86  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
87  {
88  return false;
89  }
90 
91  return twr_wssfm10r1at_get_device_pac(&self->_modem.wssfm10r1at, buffer, buffer_size);
92 }
93 
94 bool twr_module_sigfox_continuous_wave(twr_module_sigfox_t *self)
95 {
96  if (self->_revision == TWR_MODULE_SIGFOX_REVISION_R1)
97  {
98  return false;
99  }
100 
101  return twr_wssfm10r1at_continuous_wave(&self->_modem.wssfm10r1at);
102 }
103 
104 static void _twr_module_sigfox_event_handler_td1207r(twr_td1207r_t *child, twr_td1207r_event_t event, void *event_param)
105 {
106  (void) child;
107 
108  twr_module_sigfox_t *self = event_param;
109 
110  if (self->_event_handler != NULL)
111  {
112  if (event == TWR_TD1207R_EVENT_READY)
113  {
114  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_READY, self->_event_param);
115  }
116  else if (event == TWR_TD1207R_EVENT_ERROR)
117  {
118  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_ERROR, self->_event_param);
119  }
120  else if (event == TWR_TD1207R_EVENT_SEND_RF_FRAME_START)
121  {
122  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START, self->_event_param);
123  }
124  else if (event == TWR_TD1207R_EVENT_SEND_RF_FRAME_DONE)
125  {
126  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_DONE, self->_event_param);
127  }
128  }
129 }
130 
131 static void _twr_module_sigfox_event_handler_wssfm10r1at(twr_wssfm10r1at_t *child, twr_wssfm10r1at_event_t event, void *event_param)
132 {
133  (void) child;
134 
135  twr_module_sigfox_t *self = event_param;
136 
137  if (self->_event_handler != NULL)
138  {
139  if (event == TWR_WSSFM10R1AT_EVENT_READY)
140  {
141  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_READY, self->_event_param);
142  }
143  else if (event == TWR_WSSFM10R1AT_EVENT_ERROR)
144  {
145  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_ERROR, self->_event_param);
146  }
148  {
149  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START, self->_event_param);
150  }
152  {
153  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_DONE, self->_event_param);
154  }
155  else if (event == TWR_WSSFM10R1AT_EVENT_READ_DEVICE_ID)
156  {
157  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_READ_DEVICE_ID, self->_event_param);
158  }
159  else if (event == TWR_WSSFM10R1AT_EVENT_READ_DEVICE_PAC)
160  {
161  self->_event_handler(self, TWR_MODULE_SIGFOX_EVENT_READ_DEVICE_PAC, self->_event_param);
162  }
163  }
164 }
@ TWR_GPIO_P6
GPIO channel P6.
Definition: twr_gpio.h:33
void twr_module_sigfox_set_event_handler(twr_module_sigfox_t *self, void(*event_handler)(twr_module_sigfox_t *, twr_module_sigfox_event_t, void *), void *event_param)
Set callback function.
bool twr_module_sigfox_get_device_pac(twr_module_sigfox_t *self, char *buffer, size_t buffer_size)
Get device PAC (can be called only in TWR_WSSFM10R1AT_EVENT_READ_DEVICE_ID event)
bool twr_module_sigfox_read_device_pac(twr_module_sigfox_t *self)
Read device PAC command.
bool twr_module_sigfox_read_device_id(twr_module_sigfox_t *self)
Read device ID command.
twr_module_sigfox_revision_t
SigFox Module hardware revision.
bool twr_module_sigfox_is_ready(twr_module_sigfox_t *self)
Check if modem is ready for commands.
bool twr_module_sigfox_send_rf_frame(twr_module_sigfox_t *self, const void *buffer, size_t length)
Send RF frame command.
twr_module_sigfox_event_t
Callback events.
void twr_module_sigfox_init(twr_module_sigfox_t *self, twr_module_sigfox_revision_t revision)
Initialize HARDWARIO SigFox Module.
bool twr_module_sigfox_continuous_wave(twr_module_sigfox_t *self)
Generate continuous wave command.
bool twr_module_sigfox_get_device_id(twr_module_sigfox_t *self, char *buffer, size_t buffer_size)
Get device ID (can be called only in TWR_WSSFM10R1AT_EVENT_READ_DEVICE_ID event)
@ TWR_MODULE_SIGFOX_REVISION_R1
Hardware revision R1.
@ TWR_MODULE_SIGFOX_EVENT_READ_DEVICE_PAC
Device PAC has been read event.
@ TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_DONE
RF frame transmission finished event.
@ TWR_MODULE_SIGFOX_EVENT_ERROR
Error event.
@ TWR_MODULE_SIGFOX_EVENT_READY
Ready event.
@ TWR_MODULE_SIGFOX_EVENT_READ_DEVICE_ID
Device ID has been read event.
@ TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START
RF frame transmission started event.
bool twr_td1207r_send_rf_frame(twr_td1207r_t *self, const void *buffer, size_t length)
Send RF frame command.
Definition: twr_td1207r.c:47
bool twr_td1207r_is_ready(twr_td1207r_t *self)
Check if modem is ready for commands.
Definition: twr_td1207r.c:42
void twr_td1207r_init(twr_td1207r_t *self, twr_gpio_channel_t reset_signal, twr_uart_channel_t uart_channel)
Initialize TD1207R.
Definition: twr_td1207r.c:13
void twr_td1207r_set_event_handler(twr_td1207r_t *self, void(*event_handler)(twr_td1207r_t *, twr_td1207r_event_t, void *), void *event_param)
Set callback function.
Definition: twr_td1207r.c:36
twr_td1207r_event_t
Callback events.
Definition: twr_td1207r.h:22
struct twr_td1207r_t twr_td1207r_t
TD1207R instance.
Definition: twr_td1207r.h:39
@ TWR_TD1207R_EVENT_SEND_RF_FRAME_DONE
RF frame transmission finished event.
Definition: twr_td1207r.h:33
@ TWR_TD1207R_EVENT_READY
Ready event.
Definition: twr_td1207r.h:24
@ TWR_TD1207R_EVENT_SEND_RF_FRAME_START
RF frame transmission started event.
Definition: twr_td1207r.h:30
@ TWR_TD1207R_EVENT_ERROR
Error event.
Definition: twr_td1207r.h:27
@ TWR_UART_UART1
UART channel UART1.
Definition: twr_uart.h:19
bool twr_wssfm10r1at_get_device_id(twr_wssfm10r1at_t *self, char *buffer, size_t buffer_size)
Get device ID (can be called only in TWR_WSSFM10R1AT_EVENT_READ_DEVICE_ID event)
void twr_wssfm10r1at_set_event_handler(twr_wssfm10r1at_t *self, void(*event_handler)(twr_wssfm10r1at_t *, twr_wssfm10r1at_event_t, void *), void *event_param)
Set callback function.
twr_wssfm10r1at_event_t
Callback events.
bool twr_wssfm10r1at_is_ready(twr_wssfm10r1at_t *self)
Check if modem is ready for commands.
bool twr_wssfm10r1at_send_rf_frame(twr_wssfm10r1at_t *self, const void *buffer, size_t length)
Send RF frame command.
bool twr_wssfm10r1at_read_device_id(twr_wssfm10r1at_t *self)
Read device ID command.
void twr_wssfm10r1at_init(twr_wssfm10r1at_t *self, twr_gpio_channel_t reset_signal, twr_uart_channel_t uart_channel)
Initialize WSSFM10R1AT.
struct twr_wssfm10r1at_t twr_wssfm10r1at_t
WSSFM10R1AT instance.
bool twr_wssfm10r1at_read_device_pac(twr_wssfm10r1at_t *self)
Read device PAC command.
bool twr_wssfm10r1at_get_device_pac(twr_wssfm10r1at_t *self, char *buffer, size_t buffer_size)
Get device PAC (can be called only in TWR_WSSFM10R1AT_EVENT_READ_DEVICE_PAC event)
bool twr_wssfm10r1at_continuous_wave(twr_wssfm10r1at_t *self)
Generate continuous wave command.
@ TWR_WSSFM10R1AT_EVENT_SEND_RF_FRAME_DONE
RF frame transmission finished event.
@ TWR_WSSFM10R1AT_EVENT_ERROR
Error event.
@ TWR_WSSFM10R1AT_EVENT_SEND_RF_FRAME_START
RF frame transmission started event.
@ TWR_WSSFM10R1AT_EVENT_READY
Ready event.
@ TWR_WSSFM10R1AT_EVENT_READ_DEVICE_PAC
Device PAC has been read event.
@ TWR_WSSFM10R1AT_EVENT_READ_DEVICE_ID
Device ID has been read event.