@@ -189,41 +189,14 @@ void LoRaMac::post_process_mlme_ind()
189
189
_mlme_indication.pending = false ;
190
190
}
191
191
192
- void LoRaMac::on_radio_tx_done (void )
192
+ lorawan_time_t LoRaMac::get_current_time (void )
193
193
{
194
- lorawan_time_t cur_time = _lora_time.get_current_time ();
195
-
196
- if (_device_class != CLASS_C) {
197
- _lora_phy.put_radio_to_sleep ();
198
- } else {
199
- // this will open a continuous RX2 window until time==RECV_DELAY1
200
- if (!_continuous_rx2_window_open) {
201
- open_rx2_window ();
202
- }
203
- }
204
-
205
- if (_params.is_rx_window_enabled == true ) {
206
- // start timer after which rx1_window will get opened
207
- _lora_time.start (_params.timers .rx_window1_timer , _params.rx_window1_delay );
208
-
209
- if (_device_class != CLASS_C) {
210
- _lora_time.start (_params.timers .rx_window2_timer , _params.rx_window2_delay );
211
- }
212
-
213
- if (_params.is_node_ack_requested ) {
214
- _lora_time.start (_params.timers .ack_timeout_timer ,
215
- _params.rx_window2_delay + _lora_phy.get_ack_timeout ());
216
- }
217
- } else {
218
- _mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_OK;
219
- _mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT;
220
- }
221
-
222
- _params.last_channel_idx = _params.channel ;
223
-
224
- _lora_phy.set_last_tx_done (_params.channel , _is_nwk_joined, cur_time);
194
+ return _lora_time.get_current_time ();
195
+ }
225
196
226
- _params.timers .aggregated_last_tx_time = cur_time;
197
+ rx_slot_t LoRaMac::get_current_slot (void )
198
+ {
199
+ return _params.rx_slot ;
227
200
}
228
201
229
202
/* *
@@ -656,7 +629,44 @@ void LoRaMac::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_le
656
629
_mac_commands.set_batterylevel_callback (battery_level);
657
630
}
658
631
659
- void LoRaMac::on_radio_rx_done (const uint8_t *const payload, uint16_t size,
632
+ void LoRaMac::on_radio_tx_done (lorawan_time_t timestamp)
633
+ {
634
+ if (_device_class == CLASS_C) {
635
+ // this will open a continuous RX2 window until time==RECV_DELAY1
636
+ open_rx2_window ();
637
+ } else {
638
+ _lora_phy.put_radio_to_sleep ();
639
+ }
640
+
641
+ if (_params.is_rx_window_enabled == true ) {
642
+ lorawan_time_t time_diff = _lora_time.get_current_time () - timestamp;
643
+ // start timer after which rx1_window will get opened
644
+ _lora_time.start (_params.timers .rx_window1_timer ,
645
+ _params.rx_window1_delay - time_diff);
646
+
647
+ if (_device_class != CLASS_C) {
648
+ _lora_time.start (_params.timers .rx_window2_timer ,
649
+ _params.rx_window2_delay - time_diff);
650
+ }
651
+
652
+ if (_params.is_node_ack_requested ) {
653
+ _lora_time.start (_params.timers .ack_timeout_timer ,
654
+ (_params.rx_window2_delay - time_diff) +
655
+ _lora_phy.get_ack_timeout ());
656
+ }
657
+ } else {
658
+ _mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_OK;
659
+ _mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT;
660
+ }
661
+
662
+ _params.last_channel_idx = _params.channel ;
663
+
664
+ _lora_phy.set_last_tx_done (_params.channel , _is_nwk_joined, timestamp);
665
+
666
+ _params.timers .aggregated_last_tx_time = timestamp;
667
+ }
668
+
669
+ void LoRaMac::on_radio_rx_done (const uint8_t * const payload, uint16_t size,
660
670
int16_t rssi, int8_t snr)
661
671
{
662
672
// stop the RX1 timer here if its the first RX slot.
@@ -731,9 +741,11 @@ void LoRaMac::on_radio_tx_timeout(void)
731
741
post_process_mcps_req ();
732
742
}
733
743
734
- rx_slot_t LoRaMac::on_radio_rx_timeout (bool is_timeout)
744
+ void LoRaMac::on_radio_rx_timeout (bool is_timeout)
735
745
{
736
- if (_device_class != CLASS_C) {
746
+ if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
747
+ open_rx2_window ();
748
+ } else {
737
749
_lora_phy.put_radio_to_sleep ();
738
750
}
739
751
@@ -763,12 +775,6 @@ rx_slot_t LoRaMac::on_radio_rx_timeout(bool is_timeout)
763
775
LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
764
776
LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
765
777
}
766
-
767
- if (_device_class == CLASS_C) {
768
- open_rx2_window ();
769
- }
770
-
771
- return _params.rx_slot ;
772
778
}
773
779
774
780
bool LoRaMac::continue_joining_process ()
@@ -857,7 +863,6 @@ void LoRaMac::on_backoff_timer_expiry(void)
857
863
void LoRaMac::open_rx1_window (void )
858
864
{
859
865
Lock lock (*this );
860
- tr_debug (" Opening RX1 Window" );
861
866
_continuous_rx2_window_open = false ;
862
867
_lora_time.stop (_params.timers .rx_window1_timer );
863
868
_params.rx_slot = RX_SLOT_WIN_1;
@@ -878,25 +883,26 @@ void LoRaMac::open_rx1_window(void)
878
883
879
884
_lora_phy.setup_rx_window (_params.rx_window1_config .is_rx_continuous ,
880
885
_params.sys_params .max_rx_win_time );
886
+
887
+ tr_debug (" Opening RX1 Window" );
881
888
}
882
889
883
890
void LoRaMac::open_rx2_window ()
884
891
{
885
892
Lock lock (*this );
886
- tr_debug ( " Opening RX2 Window " ) ;
893
+ _continuous_rx2_window_open = true ;
887
894
_lora_time.stop (_params.timers .rx_window2_timer );
888
895
889
896
_params.rx_window2_config .channel = _params.channel ;
890
897
_params.rx_window2_config .frequency = _params.sys_params .rx2_channel .frequency ;
891
898
_params.rx_window2_config .dl_dwell_time = _params.sys_params .downlink_dwell_time ;
892
899
_params.rx_window2_config .is_repeater_supported = _params.is_repeater_supported ;
893
- _params.rx_window2_config .rx_slot = RX_SLOT_WIN_2;
900
+ _params.rx_window2_config .rx_slot = _params.rx_window2_config .is_rx_continuous ?
901
+ RX_SLOT_WIN_CLASS_C : RX_SLOT_WIN_2;
894
902
895
903
if (get_device_class () == CLASS_C) {
896
- _continuous_rx2_window_open = true ;
897
904
_params.rx_window2_config .is_rx_continuous = true ;
898
905
} else {
899
- _continuous_rx2_window_open = false ;
900
906
_params.rx_window2_config .is_rx_continuous = false ;
901
907
}
902
908
@@ -907,9 +913,10 @@ void LoRaMac::open_rx2_window()
907
913
_lora_phy.setup_rx_window (_params.rx_window2_config .is_rx_continuous ,
908
914
_params.sys_params .max_rx_win_time );
909
915
910
- _params.rx_slot = _params.rx_window2_config .is_rx_continuous ?
911
- RX_SLOT_WIN_CLASS_C : RX_SLOT_WIN_2;
916
+ _params.rx_slot = _params.rx_window2_config .rx_slot ;
912
917
}
918
+
919
+ tr_debug (" Opening RX2 Window, Frequency = %u" , _params.rx_window2_config .frequency );
913
920
}
914
921
915
922
void LoRaMac::on_ack_timeout_timer_event (void )
@@ -1346,8 +1353,6 @@ void LoRaMac::set_device_class(const device_class_t &device_class,
1346
1353
tr_debug (" Changing device class to -> CLASS_C" );
1347
1354
open_rx2_window ();
1348
1355
}
1349
-
1350
-
1351
1356
}
1352
1357
1353
1358
void LoRaMac::setup_link_check_request ()
0 commit comments