Skip to content

Commit a0a265a

Browse files
author
Cruz Monrreal
authored
Merge pull request #10196 from hasnainvirk/premature_rx2_fix
LoRaWAN: Fixing premature RX2 closure
2 parents 365cf11 + 4c1b8a8 commit a0a265a

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

UNITTESTS/stubs/LoRaPHY_stub.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ uint8_t LoRaPHY::verify_link_ADR_req(verify_adr_params_t *verify_params,
173173

174174
void LoRaPHY::get_rx_window_params(float t_symbol, uint8_t min_rx_symbols,
175175
float rx_error, float wakeup_time,
176-
uint32_t *window_length, int32_t *window_offset,
176+
uint32_t *window_length, uint32_t *window_length_ms,
177+
int32_t *window_offset,
177178
uint8_t phy_dr)
178179
{
179180
}

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,14 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
664664
if (get_device_class() == CLASS_C) {
665665
_lora_time.start(_rx2_closure_timer_for_class_c,
666666
(_params.rx_window2_delay - time_diff) +
667-
_params.rx_window2_config.window_timeout);
667+
_params.rx_window2_config.window_timeout_ms);
668668
}
669669

670670
// start timer after which ack wait will timeout (for Confirmed messages)
671671
if (_params.is_node_ack_requested) {
672672
_lora_time.start(_params.timers.ack_timeout_timer,
673673
(_params.rx_window2_delay - time_diff) +
674+
_params.rx_window2_config.window_timeout_ms +
674675
_lora_phy->get_ack_timeout());
675676
}
676677
} else {
@@ -1094,6 +1095,8 @@ lorawan_status_t LoRaMac::schedule_tx()
10941095
{
10951096
channel_selection_params_t next_channel;
10961097
lorawan_time_t backoff_time = 0;
1098+
lorawan_time_t aggregated_timeoff = 0;
1099+
uint8_t channel = 0;
10971100
uint8_t fopts_len = 0;
10981101

10991102
if (_params.sys_params.max_duty_cycle == 255) {
@@ -1119,9 +1122,12 @@ lorawan_status_t LoRaMac::schedule_tx()
11191122
next_channel.last_aggregate_tx_time = _params.timers.aggregated_last_tx_time;
11201123

11211124
lorawan_status_t status = _lora_phy->set_next_channel(&next_channel,
1122-
&_params.channel,
1125+
&channel,
11231126
&backoff_time,
1124-
&_params.timers.aggregated_timeoff);
1127+
&aggregated_timeoff);
1128+
1129+
_params.channel = channel;
1130+
_params.timers.aggregated_timeoff = aggregated_timeoff;
11251131

11261132
switch (status) {
11271133
case LORAWAN_STATUS_NO_CHANNEL_FOUND:

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ float LoRaPHY::compute_symb_timeout_fsk(uint8_t phy_dr)
406406

407407
void LoRaPHY::get_rx_window_params(float t_symb, uint8_t min_rx_symb,
408408
float error_fudge, float wakeup_time,
409-
uint32_t *window_length, int32_t *window_offset,
409+
uint32_t *window_length, uint32_t *window_length_ms,
410+
int32_t *window_offset,
410411
uint8_t phy_dr)
411412
{
412413
float target_rx_window_offset;
@@ -442,6 +443,7 @@ void LoRaPHY::get_rx_window_params(float t_symb, uint8_t min_rx_symb,
442443
// Setting the window_length in terms of 'symbols' for LoRa modulation or
443444
// in terms of 'bytes' for FSK
444445
*window_length = (uint32_t) ceil(window_len_in_ms / t_symb);
446+
*window_length_ms = window_len_in_ms;
445447
}
446448

447449
int8_t LoRaPHY::compute_tx_power(int8_t tx_power_idx, float max_eirp,
@@ -628,8 +630,7 @@ uint16_t LoRaPHY::get_maximum_frame_counter_gap()
628630
uint32_t LoRaPHY::get_ack_timeout()
629631
{
630632
uint16_t ack_timeout_rnd = phy_params.ack_timeout_rnd;
631-
return (phy_params.ack_timeout
632-
+ get_random(-ack_timeout_rnd, ack_timeout_rnd));
633+
return (phy_params.ack_timeout + get_random(0, ack_timeout_rnd));
633634
}
634635

635636
uint32_t LoRaPHY::get_default_rx2_frequency()
@@ -849,7 +850,8 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
849850
}
850851

851852
get_rx_window_params(t_symbol, min_rx_symbols, (float) rx_error, MBED_CONF_LORA_WAKEUP_TIME,
852-
&rx_conf_params->window_timeout, &rx_conf_params->window_offset,
853+
&rx_conf_params->window_timeout, &rx_conf_params->window_timeout_ms,
854+
&rx_conf_params->window_offset,
853855
rx_conf_params->datarate);
854856
}
855857

features/lorawan/lorastack/phy/LoRaPHY.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
626626
*/
627627
void get_rx_window_params(float t_symbol, uint8_t min_rx_symbols,
628628
float rx_error, float wakeup_time,
629-
uint32_t *window_length, int32_t *window_offset,
629+
uint32_t *window_length, uint32_t *window_length_ms,
630+
int32_t *window_offset,
630631
uint8_t phy_dr);
631632

632633
/**

features/lorawan/system/lorawan_data_structures.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,13 @@ typedef struct {
10071007
*/
10081008
uint32_t frequency;
10091009
/*!
1010-
* The RX window timeout
1010+
* The RX window timeout - Symbols
10111011
*/
10121012
uint32_t window_timeout;
1013+
/*!
1014+
* The RX window timeout - Milliseconds
1015+
*/
1016+
uint32_t window_timeout_ms;
10131017
/*!
10141018
* The RX window offset
10151019
*/

0 commit comments

Comments
 (0)