@@ -68,20 +68,20 @@ using namespace events;
68
68
* Constructor *
69
69
****************************************************************************/
70
70
LoRaWANStack::LoRaWANStack ()
71
- : _loramac(),
72
- _device_current_state(DEVICE_STATE_NOT_INITIALIZED),
73
- _lw_session(),
74
- _tx_msg(),
75
- _rx_msg(),
76
- _tx_metadata(),
77
- _rx_metadata(),
78
- _num_retry(1 ),
79
- _ctrl_flags(IDLE_FLAG),
80
- _app_port(INVALID_PORT),
81
- _link_check_requested(false ),
82
- _automatic_uplink_ongoing(false ),
83
- _ready_for_rx(true ),
84
- _queue(NULL )
71
+ : _loramac(),
72
+ _device_current_state(DEVICE_STATE_NOT_INITIALIZED),
73
+ _lw_session(),
74
+ _tx_msg(),
75
+ _rx_msg(),
76
+ _tx_metadata(),
77
+ _rx_metadata(),
78
+ _num_retry(1 ),
79
+ _ctrl_flags(IDLE_FLAG),
80
+ _app_port(INVALID_PORT),
81
+ _link_check_requested(false ),
82
+ _automatic_uplink_ongoing(false ),
83
+ _ready_for_rx(true ),
84
+ _queue(NULL )
85
85
{
86
86
_tx_metadata.stale = true ;
87
87
_rx_metadata.stale = true ;
@@ -481,7 +481,7 @@ lorawan_status_t LoRaWANStack::acquire_rx_metadata(lorawan_rx_metadata &metadata
481
481
return LORAWAN_STATUS_METADATA_NOT_AVAILABLE;
482
482
}
483
483
484
- lorawan_status_t LoRaWANStack::acquire_backoff_metadata (int & backoff)
484
+ lorawan_status_t LoRaWANStack::acquire_backoff_metadata (int & backoff)
485
485
{
486
486
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
487
487
return LORAWAN_STATUS_NOT_INITIALIZED;
@@ -503,6 +503,7 @@ lorawan_status_t LoRaWANStack::acquire_backoff_metadata(int& backoff)
503
503
****************************************************************************/
504
504
void LoRaWANStack::tx_interrupt_handler (void )
505
505
{
506
+ _tx_timestamp = _loramac.get_current_time ();
506
507
const int ret = _queue->call (this , &LoRaWANStack::process_transmission);
507
508
MBED_ASSERT (ret != 0 );
508
509
(void )ret;
@@ -565,7 +566,7 @@ void LoRaWANStack::process_transmission_timeout()
565
566
void LoRaWANStack::process_transmission (void )
566
567
{
567
568
tr_debug (" Transmission completed" );
568
- _loramac.on_radio_tx_done ();
569
+ _loramac.on_radio_tx_done (_tx_timestamp );
569
570
570
571
make_tx_metadata_available ();
571
572
@@ -680,10 +681,12 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size
680
681
681
682
void LoRaWANStack::process_reception_timeout (bool is_timeout)
682
683
{
684
+ rx_slot_t slot = _loramac.get_current_slot ();
685
+
683
686
// when is_timeout == false, a CRC error took place in the received frame
684
687
// we treat that erroneous frame as no frame received at all, hence handle
685
688
// it exactly as we would handle timeout
686
- rx_slot_t slot = _loramac.on_radio_rx_timeout (is_timeout);
689
+ _loramac.on_radio_rx_timeout (is_timeout);
687
690
688
691
if (slot == RX_SLOT_WIN_2 && !_loramac.nwk_joined ()) {
689
692
state_controller (DEVICE_STATE_JOINING);
@@ -851,9 +854,11 @@ void LoRaWANStack::mlme_indication_handler()
851
854
#if MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE
852
855
_automatic_uplink_ongoing = true ;
853
856
tr_debug (" mlme indication: sending empty uplink to port 0 to acknowledge MAC commands..." );
854
- send_automatic_uplink_message (0 );
857
+ const uint8_t port = 0 ;
858
+ const int ret = _queue->call (this , &LoRaWANStack::send_automatic_uplink_message, port);
859
+ MBED_ASSERT (ret != 0 );
860
+ (void )ret;
855
861
#else
856
-
857
862
send_event_to_application (UPLINK_REQUIRED);
858
863
#endif
859
864
return ;
@@ -957,8 +962,9 @@ void LoRaWANStack::mcps_indication_handler()
957
962
_rx_msg.msg .mcps_indication .type = mcps_indication->type ;
958
963
959
964
// Notify application about received frame..
960
- tr_debug (" Packet Received %d bytes" ,
961
- _rx_msg.msg .mcps_indication .buffer_size );
965
+ tr_debug (" Packet Received %d bytes, Port=%d" ,
966
+ _rx_msg.msg .mcps_indication .buffer_size ,
967
+ mcps_indication->port );
962
968
_rx_msg.receive_ready = true ;
963
969
send_event_to_application (RX_DONE);
964
970
}
@@ -981,7 +987,9 @@ void LoRaWANStack::mcps_indication_handler()
981
987
#if (MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE)
982
988
tr_debug (" Sending empty uplink message..." );
983
989
_automatic_uplink_ongoing = true ;
984
- send_automatic_uplink_message (mcps_indication->port );
990
+ const int ret = _queue->call (this , &LoRaWANStack::send_automatic_uplink_message, mcps_indication->port );
991
+ MBED_ASSERT (ret != 0 );
992
+ (void )ret;
985
993
#else
986
994
send_event_to_application (UPLINK_REQUIRED);
987
995
#endif
@@ -1354,9 +1362,11 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
1354
1362
} else if (mcps_indication->buffer_size == 7 ) {
1355
1363
loramac_mlme_req_t mlme_req;
1356
1364
mlme_req.type = MLME_TXCW_1;
1357
- mlme_req.cw_tx_mode .timeout = (uint16_t )((mcps_indication->buffer [1 ] << 8 ) | mcps_indication->buffer [2 ]);
1358
- mlme_req.cw_tx_mode .frequency = (uint32_t )((mcps_indication->buffer [3 ] << 16 ) | (mcps_indication->buffer [4 ] << 8 )
1359
- | mcps_indication->buffer [5 ]) * 100 ;
1365
+ mlme_req.cw_tx_mode .timeout = (uint16_t )((mcps_indication->buffer [1 ] << 8 )
1366
+ | mcps_indication->buffer [2 ]);
1367
+ mlme_req.cw_tx_mode .frequency = (uint32_t )((mcps_indication->buffer [3 ] << 16 )
1368
+ | (mcps_indication->buffer [4 ] << 8 )
1369
+ | mcps_indication->buffer [5 ]) * 100 ;
1360
1370
mlme_req.cw_tx_mode .power = mcps_indication->buffer [6 ];
1361
1371
_loramac.mlme_request (&mlme_req);
1362
1372
}
0 commit comments