@@ -28,14 +28,9 @@ inline LoRaWANStack& stk_obj()
28
28
return LoRaWANStack::get_lorawan_stack ();
29
29
}
30
30
31
- LoRaWANInterface::LoRaWANInterface (LoRaRadio& radio) : _link_check_requested( false )
31
+ LoRaWANInterface::LoRaWANInterface (LoRaRadio& radio)
32
32
{
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);
39
34
}
40
35
41
36
LoRaWANInterface::~LoRaWANInterface ()
@@ -44,71 +39,17 @@ LoRaWANInterface::~LoRaWANInterface()
44
39
45
40
lorawan_status_t LoRaWANInterface::initialize (EventQueue *queue)
46
41
{
47
- if (!queue) {
48
- return LORAWAN_STATUS_PARAMETER_INVALID;
49
- }
50
-
51
42
return stk_obj ().initialize_mac_layer (queue);
52
43
}
53
44
54
45
lorawan_status_t LoRaWANInterface::connect ()
55
46
{
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 ();
97
48
}
98
49
99
50
lorawan_status_t LoRaWANInterface::connect (const lorawan_connect_t &connect)
100
51
{
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);
112
53
}
113
54
114
55
lorawan_status_t LoRaWANInterface::disconnect ()
@@ -118,13 +59,12 @@ lorawan_status_t LoRaWANInterface::disconnect()
118
59
119
60
lorawan_status_t LoRaWANInterface::add_link_check_request ()
120
61
{
121
- _link_check_requested = true ;
122
62
return stk_obj ().set_link_check_request ();
123
63
}
124
64
125
65
void LoRaWANInterface::remove_link_check_request ()
126
66
{
127
- _link_check_requested = false ;
67
+ stk_obj (). remove_link_check_request () ;
128
68
}
129
69
130
70
lorawan_status_t LoRaWANInterface::set_datarate (uint8_t data_rate)
@@ -170,37 +110,22 @@ lorawan_status_t LoRaWANInterface::remove_channel_plan()
170
110
int16_t LoRaWANInterface::send (uint8_t port, const uint8_t * data,
171
111
uint16_t length, int flags)
172
112
{
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);
178
114
179
- if (data) {
180
- return stk_obj ().handle_tx (port, data, length, flags);
181
- } else {
182
- return LORAWAN_STATUS_PARAMETER_INVALID;
183
- }
184
115
}
185
116
186
117
int16_t LoRaWANInterface::receive (uint8_t port, uint8_t * data, uint16_t length,
187
118
int flags)
188
119
{
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);
194
121
}
195
122
196
123
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
+ }
203
127
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
+ }
0 commit comments