@@ -129,7 +129,7 @@ lora_mac_status_t LoRaWANStack::set_application_port(uint8_t port)
129
129
****************************************************************************/
130
130
LoRaWANStack::LoRaWANStack ()
131
131
: _device_current_state(DEVICE_STATE_NOT_INITIALIZED), _mac_handlers(NULL ),
132
- _num_retry(1 ), _queue(NULL ), _duty_cycle_on(LORAWAN_DUTYCYCLE_ON)
132
+ _num_retry(1 ), _queue(NULL ), _duty_cycle_on(LORAWAN_DUTYCYCLE_ON)
133
133
{
134
134
#ifdef MBED_CONF_LORA_APP_PORT
135
135
// is_port_valid() is not virtual, so we can call it in constructor
@@ -168,7 +168,7 @@ LoRaWANStack& LoRaWANStack::get_lorawan_stack()
168
168
radio_events_t *LoRaWANStack::bind_radio_driver (LoRaRadio& radio)
169
169
{
170
170
// Store pointer to callback routines inside MAC layer (non-IRQ safe)
171
- _mac_handlers = GetPhyEventHandlers ();
171
+ _mac_handlers = _loramac. GetPhyEventHandlers ();
172
172
// passes the reference to radio driver down to PHY layer
173
173
lora_phy.get ()->set_radio_instance (radio);
174
174
return _mac_handlers;
@@ -204,7 +204,8 @@ lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
204
204
LoRaMacPrimitives.MacMcpsConfirm = callback (this , &LoRaWANStack::mcps_confirm);
205
205
LoRaMacPrimitives.MacMcpsIndication = callback (this , &LoRaWANStack::mcps_indication);
206
206
LoRaMacPrimitives.MacMlmeConfirm = callback (this , &LoRaWANStack::mlme_confirm);
207
- LoRaMacInitialization (&LoRaMacPrimitives, &LoRaMacCallbacks, lora_phy.get (), queue);
207
+ LoRaMacPrimitives.MacMlmeIndication = callback (this , &LoRaWANStack::mlme_indication);
208
+ _loramac.LoRaMacInitialization (&LoRaMacPrimitives, &LoRaMacCallbacks, lora_phy.get (), queue);
208
209
209
210
mib_req.type = LORA_MIB_ADR;
210
211
mib_req.param .adr_enable = LORAWAN_ADR_ON;
@@ -315,7 +316,7 @@ lora_mac_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
315
316
uint16_t LoRaWANStack::check_possible_tx_size (uint16_t size)
316
317
{
317
318
LoRaMacTxInfo_t txInfo;
318
- if (LoRaMacQueryTxPossible (size, &txInfo) == LORAMAC_STATUS_LENGTH_ERROR) {
319
+ if (_loramac. LoRaMacQueryTxPossible (size, &txInfo) == LORAMAC_STATUS_LENGTH_ERROR) {
319
320
// Cannot transmit this much. Return how much data can be sent
320
321
// at the moment
321
322
return txInfo.MaxPossiblePayload ;
@@ -461,9 +462,30 @@ void LoRaWANStack::mlme_confirm(MlmeConfirm_t *mlme_confirm)
461
462
mlme_confirm_handler (&lora_mlme_confirm);
462
463
}
463
464
464
- void LoRaWANStack::set_lora_callbacks (lorawan_app_callbacks_t *cbs)
465
+ /* !
466
+ * \brief MLME-Indication event function
467
+ *
468
+ * \param [IN] mlmeIndication - Pointer to the indication structure.
469
+ */
470
+ void LoRaWANStack::mlme_indication ( MlmeIndication_t *mlmeIndication )
465
471
{
472
+ switch ( mlmeIndication->MlmeIndication )
473
+ {
474
+ case MLME_SCHEDULE_UPLINK:
475
+ {// The MAC signals that we shall provide an uplink as soon as possible
476
+ // TODO: Sending implementation missing and will be implemented using
477
+ // another task.
478
+ // OnTxNextPacketTimerEvent( );
479
+ break ;
480
+ }
481
+ default :
482
+ break ;
483
+ }
484
+ }
485
+
466
486
487
+ void LoRaWANStack::set_lora_callbacks (lorawan_app_callbacks_t *cbs)
488
+ {
467
489
if (cbs) {
468
490
if (cbs->events ) {
469
491
_callbacks.events = cbs->events ;
@@ -508,7 +530,7 @@ lora_mac_status_t LoRaWANStack::add_channels(const lora_channelplan_t &channel_p
508
530
mac_layer_ch_params.Frequency = channel_plan.channels [i].ch_param .frequency ;
509
531
mac_layer_ch_params.Rx1Frequency =channel_plan.channels [i].ch_param .rx1_frequency ;
510
532
511
- status = LoRaMacChannelAdd (channel_plan.channels [i].id , mac_layer_ch_params);
533
+ status = _loramac. LoRaMacChannelAdd (channel_plan.channels [i].id , mac_layer_ch_params);
512
534
513
535
if (status != LORAMAC_STATUS_OK) {
514
536
return error_type_converter (status);
@@ -560,7 +582,7 @@ lora_mac_status_t LoRaWANStack::drop_channel_list()
560
582
continue ;
561
583
}
562
584
563
- status = error_type_converter (LoRaMacChannelRemove (i));
585
+ status = error_type_converter (_loramac. LoRaMacChannelRemove (i));
564
586
565
587
if (status != LORA_MAC_STATUS_OK) {
566
588
return status;
@@ -609,7 +631,7 @@ lora_mac_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
609
631
return LORA_MAC_STATUS_PARAMETER_INVALID;
610
632
}
611
633
612
- return error_type_converter (LoRaMacChannelRemove (channel_id));
634
+ return error_type_converter (_loramac. LoRaMacChannelRemove (channel_id));
613
635
}
614
636
615
637
lora_mac_status_t LoRaWANStack::get_enabled_channels (lora_channelplan_t & channel_plan)
@@ -872,7 +894,9 @@ int16_t LoRaWANStack::handle_tx(uint8_t port, const uint8_t* data,
872
894
_tx_msg.f_buffer_size = length;
873
895
_tx_msg.pending_size = 0 ;
874
896
// copy user buffer upto the max_possible_size
875
- memcpy (_tx_msg.f_buffer , data, length);
897
+ if (data && length > 0 ) {
898
+ memcpy (_tx_msg.f_buffer , data, length);
899
+ }
876
900
}
877
901
878
902
// Handles all unconfirmed messages, including proprietary and multicast
@@ -1018,7 +1042,7 @@ lora_mac_status_t LoRaWANStack::mlme_request_handler(lora_mac_mlme_req_t *mlme_r
1018
1042
break ;
1019
1043
}
1020
1044
1021
- return error_type_converter (LoRaMacMlmeRequest (&request));
1045
+ return error_type_converter (_loramac. LoRaMacMlmeRequest (&request));
1022
1046
}
1023
1047
1024
1048
/* * MLME-Confirm event function
@@ -1057,8 +1081,15 @@ void LoRaWANStack::mlme_confirm_handler(lora_mac_mlme_confirm_t *mlme_confirm)
1057
1081
_compliance_test.link_check = true ;
1058
1082
_compliance_test.demod_margin = mlme_confirm->demod_margin ;
1059
1083
_compliance_test.nb_gateways = mlme_confirm->nb_gateways ;
1060
- }
1084
+ } else
1061
1085
#endif
1086
+ {
1087
+ // normal operation as oppose to compliance testing
1088
+ if (_callbacks.link_check_resp ) {
1089
+ _queue->call (_callbacks.link_check_resp , mlme_confirm->demod_margin ,
1090
+ mlme_confirm->nb_gateways );
1091
+ }
1092
+ }
1062
1093
}
1063
1094
break ;
1064
1095
default :
@@ -1101,7 +1132,7 @@ lora_mac_status_t LoRaWANStack::mcps_request_handler(lora_mac_mcps_req_t *mcps_r
1101
1132
break ;
1102
1133
}
1103
1134
1104
- return error_type_converter (LoRaMacMcpsRequest (&request));
1135
+ return error_type_converter (_loramac. LoRaMacMcpsRequest (&request));
1105
1136
}
1106
1137
1107
1138
/* * MCPS-Confirm event function
@@ -1253,6 +1284,14 @@ void LoRaWANStack::mcps_indication_handler(lora_mac_mcps_indication_t *mcps_indi
1253
1284
if (_callbacks.events ) {
1254
1285
_queue->call (_callbacks.events , RX_DONE);
1255
1286
}
1287
+
1288
+ // If fPending bit is set we try to generate an empty packet
1289
+ // with CONFIRMED flag set. We always set a CONFIRMED flag so
1290
+ // that we could retry a certain number of times if the uplink
1291
+ // failed for some reason
1292
+ if (mcps_indication->frame_pending ) {
1293
+ handle_tx (mcps_indication->port , NULL , 0 , MSG_CONFIRMED_FLAG);
1294
+ }
1256
1295
} else {
1257
1296
// Invalid port, ports 0, 224 and 225-255 are reserved.
1258
1297
}
@@ -1292,10 +1331,10 @@ void LoRaWANStack::compliance_test_handler(lora_mac_mcps_indication_t *mcps_indi
1292
1331
mib_set_request (&mib_req);
1293
1332
1294
1333
#if MBED_CONF_LORA_PHY == 0
1295
- LoRaMacTestSetDutyCycleOn (false );
1334
+ _loramac. LoRaMacTestSetDutyCycleOn (false );
1296
1335
#endif
1297
1336
// 5000ms
1298
- LoRaMacSetTxTimer (5000 );
1337
+ _loramac. LoRaMacSetTxTimer (5000 );
1299
1338
set_device_state (DEVICE_STATE_COMPLIANCE_TEST);
1300
1339
tr_debug (" Compliance test activated." );
1301
1340
}
@@ -1314,11 +1353,11 @@ void LoRaWANStack::compliance_test_handler(lora_mac_mcps_indication_t *mcps_indi
1314
1353
mib_req.param .adr_enable = LORAWAN_ADR_ON;
1315
1354
mib_set_request (&mib_req);
1316
1355
#if MBED_CONF_LORA_PHY == 0
1317
- LoRaMacTestSetDutyCycleOn (LORAWAN_DUTYCYCLE_ON);
1356
+ _loramac. LoRaMacTestSetDutyCycleOn (LORAWAN_DUTYCYCLE_ON);
1318
1357
#endif
1319
1358
// Go to idle state after compliance test mode.
1320
1359
tr_debug (" Compliance test disabled." );
1321
- LoRaMacStopTxTimer ();
1360
+ _loramac. LoRaMacStopTxTimer ();
1322
1361
1323
1362
// Clear any compliance test message stuff before going back to normal operation.
1324
1363
memset (&_tx_msg, 0 , sizeof (_tx_msg));
@@ -1366,7 +1405,7 @@ void LoRaWANStack::compliance_test_handler(lora_mac_mcps_indication_t *mcps_indi
1366
1405
mib_request.param .adr_enable = LORAWAN_ADR_ON;
1367
1406
mib_set_request (&mib_request);
1368
1407
#if MBED_CONF_LORA_PHY == 0
1369
- LoRaMacTestSetDutyCycleOn (LORAWAN_DUTYCYCLE_ON);
1408
+ _loramac. LoRaMacTestSetDutyCycleOn (LORAWAN_DUTYCYCLE_ON);
1370
1409
#endif
1371
1410
mlme_request.type = LORA_MLME_JOIN;
1372
1411
mlme_request.req .join .dev_eui = _lw_session.connection .connection_u .otaa .dev_eui ;
@@ -1569,7 +1608,7 @@ lora_mac_status_t LoRaWANStack::mib_set_request(lora_mac_mib_request_confirm_t *
1569
1608
/*
1570
1609
* Set MIB data to LoRa stack
1571
1610
*/
1572
- status = error_type_converter (LoRaMacMibSetRequestConfirm (&stack_mib_set));
1611
+ status = error_type_converter (_loramac. LoRaMacMibSetRequestConfirm (&stack_mib_set));
1573
1612
/*
1574
1613
* Release memory if reserved by multicast list
1575
1614
*/
@@ -1598,7 +1637,7 @@ lora_mac_status_t LoRaWANStack::mib_get_request(lora_mac_mib_request_confirm_t *
1598
1637
1599
1638
// Interprets from lora_mac_mib_t to Mib_t
1600
1639
stack_mib_get.Type = interpret_mib_req_confirm_type (mib_get_params->type );
1601
- mac_status = error_type_converter (LoRaMacMibGetRequestConfirm (&stack_mib_get));
1640
+ mac_status = error_type_converter (_loramac. LoRaMacMibGetRequestConfirm (&stack_mib_get));
1602
1641
1603
1642
if (LORA_MAC_STATUS_OK != mac_status) {
1604
1643
return LORA_MAC_STATUS_SERVICE_UNKNOWN;
@@ -1782,6 +1821,19 @@ lora_mac_status_t LoRaWANStack::error_type_converter(LoRaMacStatus_t type)
1782
1821
}
1783
1822
}
1784
1823
1824
+ lora_mac_status_t LoRaWANStack::set_link_check_request ()
1825
+ {
1826
+ if (!_callbacks.link_check_resp ) {
1827
+ tr_error (" Must assign a callback function for link check request. " );
1828
+ return LORA_MAC_STATUS_PARAMETER_INVALID;
1829
+ }
1830
+
1831
+ lora_mac_mlme_req_t mlme_req;
1832
+
1833
+ mlme_req.type = LORA_MLME_LINK_CHECK;
1834
+ return mlme_request_handler (&mlme_req);
1835
+ }
1836
+
1785
1837
void LoRaWANStack::shutdown ()
1786
1838
{
1787
1839
set_device_state (DEVICE_STATE_SHUTDOWN);
@@ -1944,7 +1996,7 @@ lora_mac_status_t LoRaWANStack::lora_state_machine()
1944
1996
tr_debug (" Device is in compliance test mode." );
1945
1997
1946
1998
// 5000ms
1947
- LoRaMacSetTxTimer (5000 );
1999
+ _loramac. LoRaMacSetTxTimer (5000 );
1948
2000
if (_compliance_test.running == true ) {
1949
2001
send_compliance_test_frame_to_mac ();
1950
2002
}
0 commit comments