Skip to content

Commit 75cb4d7

Browse files
author
Cruz Monrreal
authored
Merge pull request #6411 from AnttiKauppila/stack_refactoring
Stack refactoring
2 parents 1529ad6 + 10ad173 commit 75cb4d7

32 files changed

+1736
-3391
lines changed

features/lorawan/LoRaWANBase.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ class LoRaWANBase {
331331
* callbacks.
332332
*/
333333
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks) = 0;
334+
335+
/** Change device class
336+
*
337+
* Change current device class.
338+
*
339+
* @param device_class The device class
340+
*
341+
* @return LORAWAN_STATUS_OK on success,
342+
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
343+
* or other negative error code if request failed.
344+
*/
345+
virtual lorawan_status_t set_device_class(device_class_t device_class) = 0;
334346
};
335347

336348
#endif /* LORAWAN_BASE_H_ */

features/lorawan/LoRaWANInterface.cpp

Lines changed: 14 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,9 @@ inline LoRaWANStack& stk_obj()
2828
return LoRaWANStack::get_lorawan_stack();
2929
}
3030

31-
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio) : _link_check_requested(false)
31+
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
3232
{
33-
// Pass mac_handlers to radio to the radio driver after
34-
// binding radio driver to PHY layer
35-
radio_events_t *events = stk_obj().bind_radio_driver(radio);
36-
radio.lock();
37-
radio.init_radio(events);
38-
radio.unlock();
33+
stk_obj().bind_radio_driver(radio);
3934
}
4035

4136
LoRaWANInterface::~LoRaWANInterface()
@@ -44,71 +39,17 @@ LoRaWANInterface::~LoRaWANInterface()
4439

4540
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
4641
{
47-
if(!queue) {
48-
return LORAWAN_STATUS_PARAMETER_INVALID;
49-
}
50-
5142
return stk_obj().initialize_mac_layer(queue);
5243
}
5344

5445
lorawan_status_t LoRaWANInterface::connect()
5546
{
56-
// connection attempt without parameters.
57-
// System tries to look for configuration in mbed_lib.json that can be
58-
// overridden by mbed_app.json. However, if none of the json files are
59-
// available (highly unlikely), we still fallback to some default parameters.
60-
// Check lorawan_data_structure for fallback defaults.
61-
62-
lorawan_connect_t connection_params;
63-
64-
if (MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION) {
65-
static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
66-
static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
67-
static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
68-
/**
69-
*
70-
* OTAA join
71-
*/
72-
connection_params.connect_type = LORAWAN_CONNECTION_OTAA;
73-
connection_params.connection_u.otaa.app_eui = app_eui;
74-
connection_params.connection_u.otaa.dev_eui = dev_eui;
75-
connection_params.connection_u.otaa.app_key = app_key;
76-
connection_params.connection_u.otaa.nb_trials = MBED_CONF_LORA_NB_TRIALS;
77-
78-
return connect(connection_params);
79-
} else {
80-
static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY;
81-
static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY;
82-
static uint32_t dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS;
83-
static uint32_t nwk_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);
84-
85-
/**
86-
*
87-
* ABP connection
88-
*/
89-
connection_params.connect_type = LORAWAN_CONNECTION_ABP;
90-
connection_params.connection_u.abp.nwk_id = nwk_id;
91-
connection_params.connection_u.abp.dev_addr = dev_addr;
92-
connection_params.connection_u.abp.nwk_skey = nwk_skey;
93-
connection_params.connection_u.abp.app_skey = app_skey;
94-
95-
return connect(connection_params);
96-
}
47+
return stk_obj().connect();
9748
}
9849

9950
lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
10051
{
101-
lorawan_status_t mac_status;
102-
103-
if (connect.connect_type == LORAWAN_CONNECTION_OTAA) {
104-
mac_status = stk_obj().join_request_by_otaa(connect);
105-
} else if (connect.connect_type == LORAWAN_CONNECTION_ABP) {
106-
mac_status = stk_obj().activation_by_personalization(connect);
107-
} else {
108-
return LORAWAN_STATUS_PARAMETER_INVALID;
109-
}
110-
111-
return mac_status;
52+
return stk_obj().connect(connect);
11253
}
11354

11455
lorawan_status_t LoRaWANInterface::disconnect()
@@ -118,13 +59,12 @@ lorawan_status_t LoRaWANInterface::disconnect()
11859

11960
lorawan_status_t LoRaWANInterface::add_link_check_request()
12061
{
121-
_link_check_requested = true;
12262
return stk_obj().set_link_check_request();
12363
}
12464

12565
void LoRaWANInterface::remove_link_check_request()
12666
{
127-
_link_check_requested = false;
67+
stk_obj().remove_link_check_request();
12868
}
12969

13070
lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
@@ -170,37 +110,22 @@ lorawan_status_t LoRaWANInterface::remove_channel_plan()
170110
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data,
171111
uint16_t length, int flags)
172112
{
173-
if (_link_check_requested) {
174-
// add a link check request with normal data, until the application
175-
// explicitly removes it.
176-
add_link_check_request();
177-
}
113+
return stk_obj().handle_tx(port, data, length, flags);
178114

179-
if (data) {
180-
return stk_obj().handle_tx(port, data, length, flags);
181-
} else {
182-
return LORAWAN_STATUS_PARAMETER_INVALID;
183-
}
184115
}
185116

186117
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length,
187118
int flags)
188119
{
189-
if (data && length > 0) {
190-
return stk_obj().handle_rx(port, data, length, flags);
191-
} else {
192-
return LORAWAN_STATUS_PARAMETER_INVALID;
193-
}
120+
return stk_obj().handle_rx(port, data, length, flags);
194121
}
195122

196123
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
197-
{
198-
199-
if (!callbacks || !callbacks->events) {
200-
// Event Callback is mandatory
201-
return LORAWAN_STATUS_PARAMETER_INVALID;
202-
}
124+
{
125+
return stk_obj().set_lora_callbacks(callbacks);
126+
}
203127

204-
stk_obj().set_lora_callbacks(callbacks);
205-
return LORAWAN_STATUS_OK;
206-
}
128+
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
129+
{
130+
return stk_obj().set_device_class(device_class);
131+
}

features/lorawan/LoRaWANInterface.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,17 @@ class LoRaWANInterface: public LoRaWANBase {
429429
*/
430430
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks);
431431

432-
private:
433-
bool _link_check_requested;
432+
/** Change device class
433+
*
434+
* Change current device class.
435+
*
436+
* @param device_class The device class
437+
*
438+
* @return LORAWAN_STATUS_OK on success,
439+
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
440+
* or other negative error code if request failed.
441+
*/
442+
virtual lorawan_status_t set_device_class(const device_class_t device_class);
434443
};
435444

436445
#endif /* LORAWANINTERFACE_H_ */

0 commit comments

Comments
 (0)