@@ -83,6 +83,7 @@ LoRaMac::LoRaMac()
83
83
_mlme_indication(),
84
84
_mlme_confirmation(),
85
85
_is_nwk_joined(false ),
86
+ _continuous_rx2_window_open(false ),
86
87
_device_class(CLASS_A)
87
88
{
88
89
_params.keys .dev_eui = NULL ;
@@ -196,7 +197,9 @@ void LoRaMac::on_radio_tx_done(void)
196
197
_lora_phy.put_radio_to_sleep ();
197
198
} else {
198
199
// this will open a continuous RX2 window until time==RECV_DELAY1
199
- open_rx2_window ();
200
+ if (!_continuous_rx2_window_open) {
201
+ open_rx2_window ();
202
+ }
200
203
}
201
204
202
205
if (_params.is_rx_window_enabled == true ) {
@@ -226,8 +229,7 @@ void LoRaMac::on_radio_tx_done(void)
226
229
/* *
227
230
* This part handles incoming frames in response to Radio RX Interrupt
228
231
*/
229
- void LoRaMac::handle_join_accept_frame (const uint8_t *payload,
230
- uint16_t size)
232
+ void LoRaMac::handle_join_accept_frame (const uint8_t *payload, uint16_t size)
231
233
{
232
234
uint32_t mic = 0 ;
233
235
uint32_t mic_rx = 0 ;
@@ -258,7 +260,7 @@ void LoRaMac::handle_join_accept_frame(const uint8_t *payload,
258
260
mic_rx |= ((uint32_t ) _params.rx_buffer [size - LORAMAC_MFR_LEN + 3 ] << 24 );
259
261
260
262
if (mic_rx == mic) {
261
-
263
+ _lora_time. stop (_params. timers . rx_window2_timer );
262
264
if (_lora_crypto.compute_skeys_for_join_frame (_params.keys .app_key ,
263
265
APPKEY_KEY_LENGTH,
264
266
_params.rx_buffer + 1 ,
@@ -517,6 +519,7 @@ void LoRaMac::handle_data_frame(const uint8_t* const payload,
517
519
if (!is_multicast) {
518
520
// We are not the destination of this frame.
519
521
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL;
522
+ _mcps_indication.pending = false ;
520
523
return ;
521
524
}
522
525
} else {
@@ -533,14 +536,14 @@ void LoRaMac::handle_data_frame(const uint8_t* const payload,
533
536
if (!message_integrity_check (payload, size, &ptr_pos, address,
534
537
&downlink_counter, nwk_skey)) {
535
538
tr_error (" MIC failed" );
539
+ _mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_MIC_FAIL;
540
+ _mcps_indication.pending = false ;
536
541
return ;
537
542
}
538
543
539
544
// message is intended for us and MIC have passed, stop RX2 Window
540
545
// Spec: 3.3.4 Receiver Activity during the receive windows
541
- if (_params.rx_slot == RX_SLOT_WIN_2) {
542
- _lora_time.stop (_params.timers .rx_window2_timer );
543
- }
546
+ _lora_time.stop (_params.timers .rx_window2_timer );
544
547
545
548
_mcps_confirmation.ack_received = false ;
546
549
_mcps_indication.is_ack_recvd = false ;
@@ -612,7 +615,7 @@ void LoRaMac::handle_data_frame(const uint8_t* const payload,
612
615
// to take retransmissions and repetitions into account. Error cases
613
616
// will be handled in function OnMacStateCheckTimerEvent.
614
617
if (_params.is_node_ack_requested ) {
615
- if (fctrl.bits .ack == 1 ) {
618
+ if (fctrl.bits .ack ) {
616
619
_mac_commands.clear_command_buffer ();
617
620
_mcps_confirmation.ack_received = fctrl.bits .ack ;
618
621
_mcps_indication.is_ack_recvd = fctrl.bits .ack ;
@@ -641,7 +644,7 @@ void LoRaMac::handle_data_frame(const uint8_t* const payload,
641
644
_mcps_indication.buffer_size = size - ptr_pos;
642
645
}
643
646
644
- // only stop act timer, if the ack is actuall recieved
647
+ // only stop act timer, if the ack is actually recieved
645
648
if (_mcps_confirmation.ack_received ) {
646
649
_lora_time.stop (_params.timers .ack_timeout_timer );
647
650
}
@@ -665,7 +668,9 @@ void LoRaMac::on_radio_rx_done(const uint8_t* const payload, uint16_t size,
665
668
}
666
669
667
670
if (_device_class == CLASS_C) {
668
- open_rx2_window ();
671
+ if (!_continuous_rx2_window_open) {
672
+ open_rx2_window ();
673
+ }
669
674
} else {
670
675
_lora_phy.put_radio_to_sleep ();
671
676
}
@@ -841,12 +846,14 @@ void LoRaMac::on_backoff_timer_expiry(void)
841
846
Lock lock (*this );
842
847
lorawan_status_t status = schedule_tx ();
843
848
MBED_ASSERT (status==LORAWAN_STATUS_OK);
849
+ (void ) status;
844
850
}
845
851
846
852
void LoRaMac::open_rx1_window (void )
847
853
{
848
854
Lock lock (*this );
849
855
tr_debug (" Opening RX1 Window" );
856
+ _continuous_rx2_window_open = false ;
850
857
_lora_time.stop (_params.timers .rx_window1_timer );
851
858
_params.rx_slot = RX_SLOT_WIN_1;
852
859
@@ -880,7 +887,13 @@ void LoRaMac::open_rx2_window()
880
887
_params.rx_window2_config .is_repeater_supported = _params.is_repeater_supported ;
881
888
_params.rx_window2_config .rx_slot = RX_SLOT_WIN_2;
882
889
883
- _params.rx_window2_config .is_rx_continuous = get_device_class ()==CLASS_C ? true : false ;
890
+ if (get_device_class () == CLASS_C) {
891
+ _continuous_rx2_window_open = true ;
892
+ _params.rx_window2_config .is_rx_continuous = true ;
893
+ } else {
894
+ _continuous_rx2_window_open = false ;
895
+ _params.rx_window2_config .is_rx_continuous = false ;
896
+ }
884
897
885
898
_mcps_indication.rx_datarate = _params.rx_window2_config .datarate ;
886
899
@@ -911,8 +924,11 @@ void LoRaMac::on_ack_timeout_timer_event(void)
911
924
tr_debug (" ACK_TIMEOUT Elapses, Retrying ..." );
912
925
_lora_time.stop (_params.timers .ack_timeout_timer );
913
926
914
- // reduce data rate
915
- if ((_params.ack_timeout_retry_counter % 2 )) {
927
+ // reduce data rate on every 2nd attempt if and only if the
928
+ // ADR is on
929
+ if ((_params.ack_timeout_retry_counter % 2 )
930
+ && (_params.sys_params .adr_on )) {
931
+ tr_debug (" Trading datarate for range" );
916
932
_params.sys_params .channel_data_rate = _lora_phy.get_next_lower_tx_datarate (
917
933
_params.sys_params .channel_data_rate );
918
934
}
@@ -933,6 +949,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
933
949
// now that is a critical failure
934
950
lorawan_status_t status = handle_retransmission ();
935
951
MBED_ASSERT (status==LORAWAN_STATUS_OK);
952
+ (void ) status;
936
953
}
937
954
938
955
_params.ack_timeout_retry_counter ++;
@@ -1501,6 +1518,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
1501
1518
}
1502
1519
1503
1520
if (_params.is_srv_ack_requested == true ) {
1521
+ tr_debug (" Acking to NS" );
1504
1522
fctrl->bits .ack = 1 ;
1505
1523
}
1506
1524
0 commit comments