Skip to content

Commit 5170daa

Browse files
author
Hasnain Virk
committed
RX window calculation algorithm version 2
In this version we try to mitigate a situation when we start listening right in the middle of a preamble sequence (e.g., in high SF case).
1 parent ca08367 commit 5170daa

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,32 +406,39 @@ void LoRaPHY::get_rx_window_params(float t_symb, uint8_t min_rx_symb,
406406
uint32_t *window_length, int32_t *window_offset,
407407
uint8_t phy_dr)
408408
{
409-
float min_rx_symbol_overlap_required = float (min_rx_symb);
410409
float target_rx_window_offset;
411410
float window_len_in_ms;
412411

413412
if (phy_params.fsk_supported && phy_dr == phy_params.max_rx_datarate) {
414-
min_rx_symbol_overlap_required = MAX_PREAMBLE_LENGTH;
413+
min_rx_symb = MAX_PREAMBLE_LENGTH;
415414
}
416415

417416
// We wish to be as close as possible to the actual start of data, i.e.,
418417
// we are interested in the preamble symbols which are at the tail of the
419418
// preamble sequence.
420-
target_rx_window_offset = (MAX_PREAMBLE_LENGTH - min_rx_symbol_overlap_required) * t_symb; //in ms
419+
target_rx_window_offset = (MAX_PREAMBLE_LENGTH - min_rx_symb) * t_symb; //in ms
421420

422421
// Actual window offset in ms in response to timing error fudge factor and
423422
// radio wakeup/turned around time.
424-
*window_offset = floor(target_rx_window_offset - error_fudge - wakeup_time);
423+
*window_offset = floor(target_rx_window_offset - error_fudge - MBED_CONF_LORA_WAKEUP_TIME);
424+
425+
// possible wait for next symbol start if we start inside the preamble
426+
float possible_wait_for_symb_start = MIN(t_symb,
427+
((2 * error_fudge) + MBED_CONF_LORA_WAKEUP_TIME + TICK_GRANULARITY_JITTER));
428+
429+
// how early we might start reception relative to transmit start (so negative if before transmit starts)
430+
float earliest_possible_start_time = *window_offset - error_fudge - TICK_GRANULARITY_JITTER;
431+
432+
// time in (ms) we may have to wait for the other side to start transmission
433+
float possible_wait_for_transmit = -earliest_possible_start_time;
425434

426435
// Minimum reception time plus extra time (in ms) we may have turned on before the
427436
// other side started transmission
428-
window_len_in_ms = (min_rx_symbol_overlap_required * t_symb) - MIN(0, (*window_offset - error_fudge - TICK_GRANULARITY_JITTER));
437+
window_len_in_ms = (min_rx_symb * t_symb) + MAX(possible_wait_for_transmit, possible_wait_for_symb_start);
429438

430439
// Setting the window_length in terms of 'symbols' for LoRa modulation or
431440
// in terms of 'bytes' for FSK
432441
*window_length = (uint32_t) ceil(window_len_in_ms / t_symb);
433-
434-
435442
}
436443

437444
int8_t LoRaPHY::compute_tx_power(int8_t tx_power_idx, float max_eirp,
@@ -874,13 +881,13 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
874881
// Radio configuration
875882
if (dr == DR_7 && phy_params.fsk_supported) {
876883
modem = MODEM_FSK;
877-
_radio->set_rx_config(modem, 50000, phy_dr * 1000, 0, 83333, 5,
884+
_radio->set_rx_config(modem, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
878885
rx_conf->window_timeout, false, 0, true, 0, 0,
879886
false, rx_conf->is_rx_continuous);
880887
} else {
881888
modem = MODEM_LORA;
882889
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0,
883-
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
890+
MAX_PREAMBLE_LENGTH,
884891
rx_conf->window_timeout, false, 0, false, 0, 0,
885892
true, rx_conf->is_rx_continuous);
886893
}
@@ -926,8 +933,8 @@ bool LoRaPHY::tx_config(tx_config_params_t *tx_conf, int8_t *tx_power,
926933
// High Speed FSK channel
927934
modem = MODEM_FSK;
928935
_radio->set_tx_config(modem, phy_tx_power, 25000, bandwidth,
929-
phy_dr * 1000, 0, 5, false, true, 0, 0, false,
930-
3000);
936+
phy_dr * 1000, 0, MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH,
937+
false, true, 0, 0, false, 3000);
931938
} else {
932939
modem = MODEM_LORA;
933940
_radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1,

features/lorawan/mbed_lib.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,16 @@
7070
"value": true
7171
},
7272
"max-sys-rx-error": {
73-
"help": "Maximum timing error of the receiver in ms. The receiver will turn on in [-RxError : + RxError]",
74-
"value": 1
73+
"help": "Max. timing error fudge. The receiver will turn on in [-RxError : + RxError]",
74+
"value": 5
75+
},
76+
"wakeup-time": {
77+
"help": "Time in (ms) the platform takes to wakeup from sleep/deep sleep state. This number is platform dependent",
78+
"value": 5
7579
},
7680
"downlink-preamble-length": {
7781
"help": "Number of whole preamble symbols needed to have a firm lock on the signal. Default: 5 + 1",
78-
"value": 6
82+
"value": 5
7983
},
8084
"uplink-preamble-length": {
8185
"help": "Number of preamble symbols to transmit. Default: 8",

0 commit comments

Comments
 (0)