Skip to content

Commit c027743

Browse files
author
Hasnain Virk
committed
[IOTCELL-282] Code cleanup/simplification and rules
Baseline is changed to use a single set of data structures that simplifies the code in the LoRaWANStack and Mac layer. We are now following certian rules for naming data structures. - All structures visible outside their domain are prefixed as 'lorawan_' - All mac structures are prefixed as 'loramac_' - All subsystem or module strucutures carry their name in prefix, like 'mcps_' PHY layer still have legacy camel case data structures which will be entertained later while we will be simplifying PHY layer. Test cases are also updated with the new data structure naming conventions. One major difference from the previous baseline is the removal of static buffer from mcps indication. And we do not copy data from stack buffer to rx_msg buffer. This saves at least 512 bytes. It may look like now that if we have received something but the user have not read from the buffer, then the buffer will be overwritten and we will lose previous frame. Yes, we will. But the same will happen even if we would have copied the buffer into rx_msg because then the rx_msg gets overwritten. So we decide to abandon copying the buffer at multiple locations. We inform the user about reception, if the user doesn't read and the data gets overwritten, then so be it.
1 parent 6ea541c commit c027743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2618
-4051
lines changed

features/lorawan/LoRaWANInterface.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ LoRaWANInterface::~LoRaWANInterface()
4242
{
4343
}
4444

45-
lora_mac_status_t LoRaWANInterface::initialize(EventQueue *queue)
45+
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
4646
{
4747
if(!queue) {
48-
return LORA_MAC_STATUS_PARAMETER_INVALID;
48+
return LORAWAN_STATUS_PARAMETER_INVALID;
4949
}
5050

5151
return stk_obj().initialize_mac_layer(queue);
5252
}
5353

54-
lora_mac_status_t LoRaWANInterface::connect()
54+
lorawan_status_t LoRaWANInterface::connect()
5555
{
5656
// connection attempt without parameters.
5757
// System tries to look for configuration in mbed_lib.json that can be
@@ -96,28 +96,28 @@ lora_mac_status_t LoRaWANInterface::connect()
9696
}
9797
}
9898

99-
lora_mac_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
99+
lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
100100
{
101-
lora_mac_status_t mac_status;
101+
lorawan_status_t mac_status;
102102

103103
if (connect.connect_type == LORAWAN_CONNECTION_OTAA) {
104104
mac_status = stk_obj().join_request_by_otaa(connect);
105105
} else if (connect.connect_type == LORAWAN_CONNECTION_ABP) {
106106
mac_status = stk_obj().activation_by_personalization(connect);
107107
} else {
108-
return LORA_MAC_STATUS_PARAMETER_INVALID;
108+
return LORAWAN_STATUS_PARAMETER_INVALID;
109109
}
110110

111111
return mac_status;
112112
}
113113

114-
lora_mac_status_t LoRaWANInterface::disconnect()
114+
lorawan_status_t LoRaWANInterface::disconnect()
115115
{
116116
stk_obj().shutdown();
117-
return LORA_MAC_STATUS_OK;
117+
return LORAWAN_STATUS_OK;
118118
}
119119

120-
lora_mac_status_t LoRaWANInterface::add_link_check_request()
120+
lorawan_status_t LoRaWANInterface::add_link_check_request()
121121
{
122122
_link_check_requested = true;
123123
return stk_obj().set_link_check_request();
@@ -128,42 +128,42 @@ void LoRaWANInterface::remove_link_check_request()
128128
_link_check_requested = false;
129129
}
130130

131-
lora_mac_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
131+
lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
132132
{
133133
return stk_obj().set_channel_data_rate(data_rate);
134134
}
135135

136-
lora_mac_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count)
136+
lorawan_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count)
137137
{
138138
return stk_obj().set_confirmed_msg_retry(count);
139139
}
140140

141-
lora_mac_status_t LoRaWANInterface::enable_adaptive_datarate()
141+
lorawan_status_t LoRaWANInterface::enable_adaptive_datarate()
142142
{
143143
return stk_obj().enable_adaptive_datarate(true);
144144
}
145145

146-
lora_mac_status_t LoRaWANInterface::disable_adaptive_datarate()
146+
lorawan_status_t LoRaWANInterface::disable_adaptive_datarate()
147147
{
148148
return stk_obj().enable_adaptive_datarate(false);
149149
}
150150

151-
lora_mac_status_t LoRaWANInterface::set_channel_plan(const lora_channelplan_t &channel_plan)
151+
lorawan_status_t LoRaWANInterface::set_channel_plan(const lorawan_channelplan_t &channel_plan)
152152
{
153153
return stk_obj().add_channels(channel_plan);
154154
}
155155

156-
lora_mac_status_t LoRaWANInterface::get_channel_plan(lora_channelplan_t &channel_plan)
156+
lorawan_status_t LoRaWANInterface::get_channel_plan(lorawan_channelplan_t &channel_plan)
157157
{
158158
return stk_obj().get_enabled_channels(channel_plan);
159159
}
160160

161-
lora_mac_status_t LoRaWANInterface::remove_channel(uint8_t id)
161+
lorawan_status_t LoRaWANInterface::remove_channel(uint8_t id)
162162
{
163163
return stk_obj().remove_a_channel(id);
164164
}
165165

166-
lora_mac_status_t LoRaWANInterface::remove_channel_plan()
166+
lorawan_status_t LoRaWANInterface::remove_channel_plan()
167167
{
168168
return stk_obj().drop_channel_list();
169169
}
@@ -180,7 +180,7 @@ int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data,
180180
if (data) {
181181
return stk_obj().handle_tx(port, data, length, flags);
182182
} else {
183-
return LORA_MAC_STATUS_PARAMETER_INVALID;
183+
return LORAWAN_STATUS_PARAMETER_INVALID;
184184
}
185185
}
186186

@@ -190,19 +190,18 @@ int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length,
190190
if (data && length > 0) {
191191
return stk_obj().handle_rx(port, data, length, flags);
192192
} else {
193-
return LORA_MAC_STATUS_PARAMETER_INVALID;
193+
return LORAWAN_STATUS_PARAMETER_INVALID;
194194
}
195195
}
196196

197-
lora_mac_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
197+
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
198198
{
199199

200200
if (!callbacks || !callbacks->events) {
201201
// Event Callback is mandatory
202-
return LORA_MAC_STATUS_PARAMETER_INVALID;
202+
return LORAWAN_STATUS_PARAMETER_INVALID;
203203
}
204204

205205
stk_obj().set_lora_callbacks(callbacks);
206-
207-
return LORA_MAC_STATUS_OK;
206+
return LORAWAN_STATUS_OK;
208207
}

features/lorawan/LoRaWANInterface.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ class LoRaWANInterface: public LoRaWANBase {
4444
*
4545
* @return 0 on success, a negative error code on failure.
4646
*/
47-
virtual lora_mac_status_t initialize(events::EventQueue *ev_queue) ;
47+
virtual lorawan_status_t initialize(events::EventQueue *ev_queue) ;
4848

4949
/** Connect OTAA or ABP using Mbed-OS config system
5050
*
5151
* Connect by Over The Air Activation or Activation By Personalization.
5252
* You need to configure the connection properly via the Mbed OS configuration
5353
* system.
5454
*
55-
* When connecting via OTAA, the return code for success (LORA_MAC_STATUS_CONNECT_IN_PROGRESS) is negative.
55+
* When connecting via OTAA, the return code for success (LORAWAN_STATUS_CONNECT_IN_PROGRESS) is negative.
5656
* However, this is not a real error. It tells you that the connection is in progress and you will
5757
* be notified of the completion via an event. By default, after the Join Accept message
5858
* is received, base stations may provide the node with a CF-List that replaces
@@ -78,17 +78,17 @@ class LoRaWANInterface: public LoRaWANBase {
7878
* is important, at least for ABP. That's why we try to restore frame counters from
7979
* session information after a disconnection.
8080
*
81-
* @return LORA_MAC_STATUS_OK or LORA_MAC_STATUS_CONNECT_IN_PROGRESS
81+
* @return LORAWAN_STATUS_OK or LORAWAN_STATUS_CONNECT_IN_PROGRESS
8282
* on success, or a negative error code on failure.
8383
*/
84-
virtual lora_mac_status_t connect();
84+
virtual lorawan_status_t connect();
8585

8686
/** Connect OTAA or ABP with parameters
8787
*
8888
* All connection parameters are chosen by the user and provided in the
8989
* data structure passed down.
9090
*
91-
* When connecting via OTAA, the return code for success (LORA_MAC_STATUS_CONNECT_IN_PROGRESS) is negative.
91+
* When connecting via OTAA, the return code for success (LORAWAN_STATUS_CONNECT_IN_PROGRESS) is negative.
9292
* However, this is not a real error. It tells you that connection is in progress and you will
9393
* be notified of completion via an event. By default, after Join Accept message
9494
* is received, base stations may provide the node with a CF-List which replaces
@@ -118,17 +118,17 @@ class LoRaWANInterface: public LoRaWANBase {
118118
*
119119
* @param connect Options for an end device connection to the gateway.
120120
*
121-
* @return LORA_MAC_STATUS_OK or LORA_MAC_STATUS_CONNECT_IN_PROGRESS,
121+
* @return LORAWAN_STATUS_OK or LORAWAN_STATUS_CONNECT_IN_PROGRESS,
122122
* a negative error code on failure.
123123
*/
124-
virtual lora_mac_status_t connect(const lorawan_connect_t &connect);
124+
virtual lorawan_status_t connect(const lorawan_connect_t &connect);
125125

126126
/** Disconnect the current session.
127127
*
128-
* @return LORA_MAC_STATUS_OK on success, a negative error code on
128+
* @return LORAWAN_STATUS_OK on success, a negative error code on
129129
* failure.
130130
*/
131-
virtual lora_mac_status_t disconnect();
131+
virtual lorawan_status_t disconnect();
132132

133133
/** Validate the connectivity with the network.
134134
*
@@ -145,7 +145,7 @@ class LoRaWANInterface: public LoRaWANBase {
145145
*
146146
* This API is usable only when the 'link_check_resp' callback is set by
147147
* the application. See add_lora_app_callbacks API. If the above mentioned
148-
* callback is not set, a LORA_MAC_STATUS_PARAMETER_INVALID error is thrown.
148+
* callback is not set, a LORAWAN_STATUS_PARAMETER_INVALID error is thrown.
149149
*
150150
* First parameter to callback function is the demodulation margin and
151151
* the second parameter is the number of gateways that successfully received
@@ -155,11 +155,11 @@ class LoRaWANInterface: public LoRaWANBase {
155155
* transmission, until/unless application explicitly turns it off using
156156
* remove_link_check_request() API.
157157
*
158-
* @return LORA_MAC_STATUS_OK on successfully queuing a request, or
158+
* @return LORAWAN_STATUS_OK on successfully queuing a request, or
159159
* a negative error code on failure.
160160
*
161161
*/
162-
virtual lora_mac_status_t add_link_check_request();
162+
virtual lorawan_status_t add_link_check_request();
163163

164164
/** Removes link check request sticky MAC command.
165165
*
@@ -176,28 +176,28 @@ class LoRaWANInterface: public LoRaWANBase {
176176
* @param data_rate The intended data rate, for example DR_0 or DR_1.
177177
* Please note, that the macro DR_* can mean different
178178
* things in different regions.
179-
* @return LORA_MAC_STATUS_OK if everything goes well, otherwise
179+
* @return LORAWAN_STATUS_OK if everything goes well, otherwise
180180
* a negative error code.
181181
*/
182-
virtual lora_mac_status_t set_datarate(uint8_t data_rate);
182+
virtual lorawan_status_t set_datarate(uint8_t data_rate);
183183

184184
/** Enables adaptive data rate (ADR).
185185
*
186186
* The underlying LoRaPHY and LoRaMac layers handle the data rate automatically
187187
* for the user, based upon the radio conditions (network congestion).
188188
*
189-
* @return LORA_MAC_STATUS_OK or negative error code otherwise.
189+
* @return LORAWAN_STATUS_OK or negative error code otherwise.
190190
*/
191-
virtual lora_mac_status_t enable_adaptive_datarate();
191+
virtual lorawan_status_t enable_adaptive_datarate();
192192

193193
/** Disables adaptive data rate.
194194
*
195195
* When adaptive data rate (ADR) is disabled, you can either set a certain
196196
* data rate or the MAC layer selects a default value.
197197
*
198-
* @return LORA_MAC_STATUS_OK or negative error code otherwise.
198+
* @return LORAWAN_STATUS_OK or negative error code otherwise.
199199
*/
200-
virtual lora_mac_status_t disable_adaptive_datarate();
200+
virtual lorawan_status_t disable_adaptive_datarate();
201201

202202
/** Sets up the retry counter for confirmed messages.
203203
*
@@ -212,9 +212,9 @@ class LoRaWANInterface: public LoRaWANBase {
212212
*
213213
* @param count The number of retries for confirmed messages.
214214
*
215-
* @return LORA_MAC_STATUS_OK or a negative error code.
215+
* @return LORAWAN_STATUS_OK or a negative error code.
216216
*/
217-
virtual lora_mac_status_t set_confirmed_msg_retries(uint8_t count);
217+
virtual lorawan_status_t set_confirmed_msg_retries(uint8_t count);
218218

219219
/** Sets the channel plan.
220220
*
@@ -240,10 +240,10 @@ class LoRaWANInterface: public LoRaWANBase {
240240
*
241241
* @param channel_plan The channel plan to set.
242242
*
243-
* @return LORA_MAC_STATUS_OK on success, a negative error
243+
* @return LORAWAN_STATUS_OK on success, a negative error
244244
* code on failure.
245245
*/
246-
virtual lora_mac_status_t set_channel_plan(const lora_channelplan_t &channel_plan);
246+
virtual lorawan_status_t set_channel_plan(const lorawan_channelplan_t &channel_plan);
247247

248248
/** Gets the channel plans from the LoRa stack.
249249
*
@@ -254,31 +254,31 @@ class LoRaWANInterface: public LoRaWANBase {
254254
*
255255
* @param channel_plan The current channel plan information.
256256
*
257-
* @return LORA_MAC_STATUS_OK on success, a negative error
257+
* @return LORAWAN_STATUS_OK on success, a negative error
258258
* code on failure.
259259
*/
260-
virtual lora_mac_status_t get_channel_plan(lora_channelplan_t &channel_plan);
260+
virtual lorawan_status_t get_channel_plan(lorawan_channelplan_t &channel_plan);
261261

262262
/** Removes an active channel plan.
263263
*
264264
* You cannot remove default channels (the channels the base stations are listening to).
265265
* When a plan is abolished, only the non-default channels are removed.
266266
*
267-
* @return LORA_MAC_STATUS_OK on success, a negative error
267+
* @return LORAWAN_STATUS_OK on success, a negative error
268268
* code on failure.
269269
*/
270-
virtual lora_mac_status_t remove_channel_plan();
270+
virtual lorawan_status_t remove_channel_plan();
271271

272272
/** Removes a single channel.
273273
*
274274
* You cannot remove default channels (the channels the base stations are listening to).
275275
*
276276
* @param index The channel index.
277277
*
278-
* @return LORA_MAC_STATUS_OK on success, a negative error
278+
* @return LORAWAN_STATUS_OK on success, a negative error
279279
* code on failure.
280280
*/
281-
virtual lora_mac_status_t remove_channel(uint8_t index);
281+
virtual lorawan_status_t remove_channel(uint8_t index);
282282

283283
/** Send message to gateway
284284
*
@@ -311,7 +311,7 @@ class LoRaWANInterface: public LoRaWANBase {
311311
*
312312
*
313313
* @return The number of bytes sent, or
314-
* LORA_MAC_STATUS_WOULD_BLOCK if another TX is
314+
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
315315
* ongoing, or a negative error code on failure.
316316
*/
317317
virtual int16_t send(uint8_t port, const uint8_t* data, uint16_t length,
@@ -352,7 +352,7 @@ class LoRaWANInterface: public LoRaWANBase {
352352
* @return It could be one of these:
353353
* i) 0 if there is nothing else to read.
354354
* ii) Number of bytes written to user buffer.
355-
* iii) LORA_MAC_STATUS_WOULD_BLOCK if there is
355+
* iii) LORAWAN_STATUS_WOULD_BLOCK if there is
356356
* nothing available to read at the moment.
357357
* iv) A negative error code on failure.
358358
*/
@@ -427,7 +427,7 @@ class LoRaWANInterface: public LoRaWANBase {
427427
* @param callbacks A pointer to the structure containing application
428428
* callbacks.
429429
*/
430-
virtual lora_mac_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks);
430+
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks);
431431

432432
private:
433433
bool _link_check_requested;

0 commit comments

Comments
 (0)