Make RXPS preamble adaptive for fast radio settings
This commit is contained in:
1 parent
444df2969d
commit
e7433abb80
31 files changed
+1393
-242
No files matched your search
@@ -116,10 +116,6 @@ void Dispatcher::restoreOutboundTxOverrides() {
|
||||
_radio->setCodingRate(outbound_restore_cr);
|
||||
outbound_restore_cr = 0;
|
||||
}
|
||||
if (outbound_restore_preamble_len != 0) {
|
||||
_radio->setPreambleLength(outbound_restore_preamble_len);
|
||||
outbound_restore_preamble_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool Dispatcher::startOutboundTransmit() {
|
||||
@@ -146,9 +142,7 @@ bool Dispatcher::startOutboundTransmit() {
|
||||
|
||||
uint32_t max_airtime = _radio->getEstAirtimeFor(len) * 3 / 2;
|
||||
outbound_restore_cr = 0;
|
||||
outbound_restore_preamble_len = 0;
|
||||
uint8_t default_cr = getDefaultTxCodingRate();
|
||||
bool is_retry = outbound->tx_cr >= 4 && outbound->tx_cr <= 8;
|
||||
if (outbound->tx_cr >= 4 && outbound->tx_cr <= 8
|
||||
&& default_cr >= 4 && default_cr <= 8
|
||||
&& outbound->tx_cr != default_cr) {
|
||||
@@ -160,14 +154,6 @@ bool Dispatcher::startOutboundTransmit() {
|
||||
getLogDateTime(), (uint32_t)outbound->tx_cr);
|
||||
}
|
||||
}
|
||||
if (is_retry) {
|
||||
uint16_t default_preamble_len = _radio->getDefaultPreambleLength();
|
||||
if (default_preamble_len != 32 && _radio->setPreambleLength(32)) {
|
||||
outbound_restore_preamble_len = default_preamble_len;
|
||||
max_airtime = _radio->getEstAirtimeFor(len) * 3 / 2;
|
||||
}
|
||||
}
|
||||
|
||||
outbound_start = _ms->getMillis();
|
||||
if (!_radio->startSendRaw(raw, len)) {
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::startOutboundTransmit(): ERROR: send start failed!",
|
||||
|
||||
@@ -63,8 +63,6 @@ public:
|
||||
* \returns true if the radio accepted the coding rate.
|
||||
*/
|
||||
virtual bool setCodingRate(uint8_t cr) { return false; }
|
||||
virtual uint16_t getDefaultPreambleLength() const { return 0; }
|
||||
virtual bool setPreambleLength(uint16_t len) { return false; }
|
||||
|
||||
/**
|
||||
* \returns true if the previous 'startSendRaw()' completed successfully.
|
||||
@@ -239,7 +237,6 @@ class Dispatcher {
|
||||
#else
|
||||
RadioLivenessTracker radio_liveness;
|
||||
#endif
|
||||
uint16_t outbound_restore_preamble_len;
|
||||
uint8_t outbound_restore_cr;
|
||||
unsigned long next_tx_time;
|
||||
unsigned long cad_busy_start;
|
||||
@@ -280,7 +277,6 @@ protected:
|
||||
outbound_radio_retry_at = 0;
|
||||
outbound_radio_retry_pending = false;
|
||||
outbound_radio_retry_used = false;
|
||||
outbound_restore_preamble_len = 0;
|
||||
outbound_restore_cr = 0;
|
||||
total_air_time = rx_air_time = 0;
|
||||
next_tx_time = ms.getMillis();
|
||||
|
||||
@@ -450,7 +450,8 @@ static const char* retryPresetName(uint8_t preset) {
|
||||
|
||||
bool CommonCLI::calculateRxPowerSavingLevel(uint32_t level, uint8_t sf, float bw, uint32_t preamble,
|
||||
uint32_t* rx_us, uint32_t* sleep_us) {
|
||||
if (level < 1 || level > 10 || (preamble != 16 && preamble != 32)) {
|
||||
if (level < 1 || level > 10 || preamble > 0xFF
|
||||
|| !isRxPowerSavingPreamble((uint8_t)preamble)) {
|
||||
return false;
|
||||
}
|
||||
return calcRxPowerSavingLevelAtOrAbove(
|
||||
@@ -482,7 +483,7 @@ static void appendRxPowerSavingAdjustmentNote(char* reply, const NodePrefs* pref
|
||||
(unsigned)prefs->rx_ps_level);
|
||||
} else {
|
||||
const uint8_t requested_preamble = prefs->rx_ps_preamble == 0
|
||||
? rxPowerSavingPreambleForSF(sf) : prefs->rx_ps_preamble;
|
||||
? rxPowerSavingPreambleForParams(sf, bw) : prefs->rx_ps_preamble;
|
||||
if (effective_level == prefs->rx_ps_level
|
||||
&& effective_preamble == requested_preamble) {
|
||||
return;
|
||||
@@ -3419,9 +3420,10 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
uint32_t rx_us = _prefs->rx_ps_rx_us;
|
||||
uint32_t sleep_us = _prefs->rx_ps_sleep_us;
|
||||
uint8_t level = 0;
|
||||
uint8_t preamble = rxPowerSavingPreambleForSF(_prefs->sf);
|
||||
uint8_t preamble = rxPowerSavingPreambleForParams(_prefs->sf, _prefs->bw);
|
||||
bool level_requested = false;
|
||||
bool preamble_overridden = false;
|
||||
bool manual_timings_requested = false;
|
||||
|
||||
ensureRxPowerSavingDefaults(&_prefs->rx_ps_rx_us, &_prefs->rx_ps_sleep_us);
|
||||
rx_us = _prefs->rx_ps_rx_us;
|
||||
@@ -3464,20 +3466,36 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
rx_us = _atoi(parts[0]);
|
||||
sleep_us = _atoi(parts[1]);
|
||||
enable = 1;
|
||||
manual_timings_requested = true;
|
||||
} else {
|
||||
strcpy(reply, "ERROR: use off|on|conservative|balanced|level <1-10>|<rx_us> <sleep_us>");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (level_requested && preamble_overridden
|
||||
&& preamble != 16 && preamble != 32) {
|
||||
strcpy(reply, "ERROR: level range is 1-10; preamble is 16 or 32");
|
||||
return;
|
||||
}
|
||||
|
||||
if (level_requested && !calculateRxPowerSavingLevel(level, _prefs->sf, _prefs->bw, preamble, &rx_us, &sleep_us)) {
|
||||
strcpy(reply, "ERROR: level range is 1-10; preamble is 16 or 32");
|
||||
return;
|
||||
}
|
||||
|
||||
if (manual_timings_requested
|
||||
&& (rx_us < RX_POWERSAVING_MIN_MANUAL_PERIOD_US
|
||||
|| sleep_us < RX_POWERSAVING_MIN_MANUAL_PERIOD_US)) {
|
||||
sprintf(reply, "ERROR: range is %lu-%lu us",
|
||||
(unsigned long)RX_POWERSAVING_MIN_MANUAL_PERIOD_US,
|
||||
(unsigned long)RX_POWERSAVING_MAX_PERIOD_US);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidRxPowerSavingPeriod(rx_us) || !isValidRxPowerSavingPeriod(sleep_us)) {
|
||||
sprintf(reply, "ERROR: range is %lu-%lu us",
|
||||
(unsigned long)RX_POWERSAVING_MIN_PERIOD_US,
|
||||
(unsigned long)RX_POWERSAVING_MIN_MANUAL_PERIOD_US,
|
||||
(unsigned long)RX_POWERSAVING_MAX_PERIOD_US);
|
||||
return;
|
||||
}
|
||||
@@ -4248,6 +4266,14 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
} else {
|
||||
sprintf(reply, "> %s", _callbacks->isRxPowerSavingRfRxDisabled() ? "on" : "off");
|
||||
}
|
||||
} else if (strcmp(config, "radio.rxps.config") == 0) {
|
||||
ensureRxPowerSavingDefaults(&_prefs->rx_ps_rx_us, &_prefs->rx_ps_sleep_us);
|
||||
sprintf(reply, "> %s,level=%u,preamble=%u,rx=%lu,sleep=%lu",
|
||||
_prefs->rx_powersaving_enabled ? "on" : "off",
|
||||
(unsigned)_prefs->rx_ps_level,
|
||||
(unsigned)_prefs->rx_ps_preamble,
|
||||
(unsigned long)_prefs->rx_ps_rx_us,
|
||||
(unsigned long)_prefs->rx_ps_sleep_us);
|
||||
} else if (memcmp(config, "radio.rxps", 10) == 0) { // RX PowerSaving
|
||||
ensureRxPowerSavingDefaults(&_prefs->rx_ps_rx_us, &_prefs->rx_ps_sleep_us);
|
||||
sprintf(reply, "> %s,%lu,%lu", _prefs->rx_powersaving_enabled ? "on" : "off",
|
||||
|
||||
@@ -16,10 +16,10 @@ protected:
|
||||
&& ((CustomLLCC68 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomLLCC68 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomLLCC68 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf);
|
||||
&& updatePreamble(sf, bw);
|
||||
if (!success) return false;
|
||||
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForParams(sf, bw));
|
||||
((CustomLLCC68 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
||||
((CustomLLCC68 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
||||
return true;
|
||||
|
||||
@@ -26,10 +26,10 @@ protected:
|
||||
&& ((CustomLR1110 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomLR1110 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomLR1110 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf);
|
||||
&& updatePreamble(sf, bw);
|
||||
if (!success) return false;
|
||||
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForParams(sf, bw));
|
||||
((CustomLR1110 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
||||
((CustomLR1110 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
||||
return true;
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
void onSendFinished() override {
|
||||
RadioLibWrapper::onSendFinished();
|
||||
_radio->setPreambleLength(preambleLengthForSF(getSpreadingFactor())); // overcomes weird issues with small and big pkts
|
||||
_radio->setPreambleLength(currentPreambleLength()); // overcomes weird issues with small and big pkts
|
||||
}
|
||||
|
||||
bool supportsRxPowerSaving() const override { return true; }
|
||||
|
||||
@@ -24,11 +24,11 @@ protected:
|
||||
&& ((CustomLR2021 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomLR2021 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomLR2021 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf)
|
||||
&& updatePreamble(sf, bw)
|
||||
&& applySideDetectorConfig(sf, bw);
|
||||
if (!success) return false;
|
||||
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForParams(sf, bw));
|
||||
((CustomLR2021 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
||||
((CustomLR2021 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
||||
return true;
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
|
||||
void onSendFinished() override {
|
||||
RadioLibWrapper::onSendFinished();
|
||||
_radio->setPreambleLength(preambleLengthForSF(getSpreadingFactor())); // overcomes weird issues with small and big pkts
|
||||
_radio->setPreambleLength(currentPreambleLength()); // overcomes weird issues with small and big pkts
|
||||
}
|
||||
|
||||
uint8_t getSpreadingFactor() const override { return ((CustomLR2021 *)_radio)->getSpreadingFactor(); }
|
||||
|
||||
@@ -15,7 +15,7 @@ protected:
|
||||
&& ((CustomSTM32WLx *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSTM32WLx *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSTM32WLx *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf);
|
||||
&& updatePreamble(sf, bw);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -18,10 +18,10 @@ protected:
|
||||
&& ((CustomSX1262 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSX1262 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSX1262 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf);
|
||||
&& updatePreamble(sf, bw);
|
||||
if (!success) return false;
|
||||
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForParams(sf, bw));
|
||||
((CustomSX1262 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
||||
((CustomSX1262 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
||||
return true;
|
||||
|
||||
@@ -20,10 +20,10 @@ protected:
|
||||
&& ((CustomSX1268 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSX1268 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSX1268 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf);
|
||||
&& updatePreamble(sf, bw);
|
||||
if (!success) return false;
|
||||
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
||||
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForParams(sf, bw));
|
||||
((CustomSX1268 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
||||
((CustomSX1268 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
||||
return true;
|
||||
|
||||
@@ -19,7 +19,7 @@ protected:
|
||||
&& ((CustomSX1276 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSX1276 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
|
||||
&& ((CustomSX1276 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
|
||||
&& updatePreamble(sf);
|
||||
&& updatePreamble(sf, bw);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -3,30 +3,26 @@
|
||||
|
||||
#define RX_POWERSAVING_DEFAULT_RX_US 65625UL
|
||||
#define RX_POWERSAVING_DEFAULT_SLEEP_US 60000UL
|
||||
#define RX_POWERSAVING_MIN_PERIOD_US 1000UL
|
||||
#define RX_POWERSAVING_MIN_PERIOD_US 32UL
|
||||
#define RX_POWERSAVING_MIN_MANUAL_PERIOD_US 1000UL
|
||||
#define RX_POWERSAVING_MAX_PERIOD_US 30000000UL
|
||||
|
||||
// Actual transmit preamble used by MeshCore at SF5-SF8. Keep 32 as the wire
|
||||
// compatible default; controlled qualification builds can select 64 to test
|
||||
// faster RX duty-cycle profiles without pretending the sender transmits a
|
||||
// longer preamble than it really does.
|
||||
#ifndef LORA_FAST_PREAMBLE
|
||||
#define LORA_FAST_PREAMBLE 32
|
||||
#endif
|
||||
#if LORA_FAST_PREAMBLE != 32 && LORA_FAST_PREAMBLE != 64
|
||||
#error "LORA_FAST_PREAMBLE must be 32 or 64"
|
||||
#endif
|
||||
// Every sender must make the same wire-preamble choice for a given SF/BW,
|
||||
// regardless of whether that sender enables RXPS locally. Qualify the choice
|
||||
// against the worst supported SX1262+TCXO transition so a receiver never bases
|
||||
// its sleep window on a longer preamble than another current sender transmits.
|
||||
#define RX_POWERSAVING_WIRE_TRANSITION_US 6000UL
|
||||
|
||||
// A level-derived timing pair equal to this value means the requested LoRa
|
||||
// tuple is too fast for a safe duty cycle. Keep the operator's RXPS preference
|
||||
// enabled, but receive continuously until a later SF/BW change produces usable
|
||||
// timings. Using an in-range pair lets the existing radio-parameter API carry
|
||||
// the fallback without persisting invalid sub-millisecond periods.
|
||||
#define RX_POWERSAVING_CONTINUOUS_FALLBACK_US RX_POWERSAVING_MIN_PERIOD_US
|
||||
#define RX_POWERSAVING_CONTINUOUS_FALLBACK_US 1000UL
|
||||
|
||||
// The named profiles are level presets pinned to a 16-symbol preamble: most
|
||||
// deployed senders still transmit 16-symbol preambles regardless of the newer
|
||||
// SF-based rule (32 for SF <= 8). Revisit once the field has largely migrated.
|
||||
// Named profiles keep a conservative 16-symbol timing assumption. The adaptive
|
||||
// calculation may use the longer physical preamble only when the configured
|
||||
// assumption cannot safely cover the current tuple.
|
||||
#define RX_POWERSAVING_CONSERVATIVE_LEVEL 1
|
||||
#define RX_POWERSAVING_BALANCED_LEVEL 5
|
||||
#define RX_POWERSAVING_PROFILE_PREAMBLE 16
|
||||
@@ -102,15 +98,8 @@ inline bool canStartRxPowerSavingDutyCycle(uint32_t rx_us, uint32_t sleep_us,
|
||||
&& (((sleep_us - transition_us) * 8UL) / 125UL) != 0;
|
||||
}
|
||||
|
||||
// MeshCore preamble convention used for the RX powersaving timing calculation.
|
||||
// Must stay in sync with RadioLibWrapper::preambleLengthForSF() (the value the
|
||||
// radio actually transmits); kept local here because CommonCLI is radio-agnostic.
|
||||
inline uint8_t rxPowerSavingPreambleForSF(uint8_t sf) {
|
||||
return sf <= 8 ? LORA_FAST_PREAMBLE : 16;
|
||||
}
|
||||
|
||||
inline bool isRxPowerSavingPreamble(uint8_t preamble) {
|
||||
return preamble == 16 || preamble == 32 || preamble == 64;
|
||||
return preamble == 16 || preamble == 32 || preamble == 64 || preamble == 128;
|
||||
}
|
||||
|
||||
inline bool isNumeric(const char *sp) {
|
||||
@@ -147,11 +136,9 @@ inline bool calcRxPowerSavingLevel(uint8_t level, uint8_t sf, float bw, uint8_t
|
||||
uint32_t calculated_rx_us = ceilPositiveFloat(rx_symbols * symbol_us);
|
||||
uint32_t calculated_sleep_us = (uint32_t)(sleep_symbols * symbol_us);
|
||||
|
||||
// At high-rate settings (notably SF5/BW500), the entire preamble can be
|
||||
// shorter than the radio's sleep/wake transition. Scaling either period up
|
||||
// would break the preamble-overlap guarantee and silently lose packets.
|
||||
// Canonicalize that case to continuous RX instead; the wrapper will resume
|
||||
// a real duty cycle automatically when slower parameters are restored.
|
||||
// Do not scale an undersized period up: that would break the preamble-overlap
|
||||
// guarantee. The 32 us floor is the first whole-microsecond value that
|
||||
// produces a non-zero timer tick on every supported duty-cycle radio.
|
||||
if (calculated_rx_us < RX_POWERSAVING_MIN_PERIOD_US
|
||||
|| calculated_sleep_us < RX_POWERSAVING_MIN_PERIOD_US) {
|
||||
calculated_rx_us = RX_POWERSAVING_CONTINUOUS_FALLBACK_US;
|
||||
@@ -163,6 +150,23 @@ inline bool calcRxPowerSavingLevel(uint8_t level, uint8_t sf, float bw, uint8_t
|
||||
return true;
|
||||
}
|
||||
|
||||
// MeshCore wire-preamble convention. SF5-SF8 normally use 32 symbols. Try 64
|
||||
// and then 128 only when every shorter choice fails to support RXPS at any
|
||||
// level. If none works, retain 32 and fall back to continuous receive. This
|
||||
// must stay in sync with RadioLibWrapper::preambleLengthForParams().
|
||||
inline uint8_t rxPowerSavingPreambleForParams(uint8_t sf, float bw) {
|
||||
if (sf > 8) return 16;
|
||||
if (sf < 5 || bw <= 0.0f) return 32;
|
||||
|
||||
// The validated LoRa bandwidth grid tops out at 500 kHz and contains 125,
|
||||
// 250, and 500 kHz at the fast end. Checking the resulting safe boundaries
|
||||
// directly is equivalent to searching all ten levels, but keeps this common
|
||||
// sender-side decision small enough for the 256 KiB STM32WL targets.
|
||||
if (sf >= 7 || bw <= 125.0f || (sf == 6 && bw <= 250.0f)) return 32;
|
||||
if (sf == 6 || bw <= 250.0f) return 64;
|
||||
return 128;
|
||||
}
|
||||
|
||||
// Treat requested_level as the operator's minimum. Faster tuples shorten each
|
||||
// LoRa symbol, so progressively more aggressive levels are tried until the
|
||||
// sleep window is long enough to cover the radio/TCXO transition. The
|
||||
@@ -181,15 +185,17 @@ inline bool calcRxPowerSavingLevelAtOrAbove(
|
||||
return false;
|
||||
}
|
||||
|
||||
// Keep the configured/legacy preamble assumption if any level can satisfy
|
||||
// it. A second pass may use the radio's real, longer transmit preamble when
|
||||
// the configured assumption cannot cover the transition at a faster tuple.
|
||||
const uint8_t transmitted_preamble = rxPowerSavingPreambleForSF(sf);
|
||||
const bool can_try_transmitted = transmitted_preamble > preamble;
|
||||
// Never derive a receive window from more symbols than are actually sent.
|
||||
// Keep the configured/conservative assumption when possible, then use the
|
||||
// tuple's real, longer wire preamble only when that is required.
|
||||
const uint8_t transmitted_preamble = rxPowerSavingPreambleForParams(sf, bw);
|
||||
const uint8_t configured_preamble = preamble < transmitted_preamble
|
||||
? preamble : transmitted_preamble;
|
||||
const bool can_try_transmitted = transmitted_preamble > configured_preamble;
|
||||
const uint8_t pass_count = can_try_transmitted ? 2 : 1;
|
||||
for (uint8_t pass = 0; pass < pass_count; pass++) {
|
||||
const uint8_t candidate_preamble = pass == 0
|
||||
? preamble : transmitted_preamble;
|
||||
? configured_preamble : transmitted_preamble;
|
||||
for (uint8_t level = requested_level; level <= 10; level++) {
|
||||
const float symbol_us = (1000.0f * (float)(1UL << sf)) / bw;
|
||||
const float amount = (float)(level - 1) / 9.0f;
|
||||
@@ -247,7 +253,7 @@ inline bool recalcRxPowerSavingFromLevel(uint8_t level, uint8_t sf, float bw, ui
|
||||
}
|
||||
|
||||
if (preamble == 0) {
|
||||
preamble = rxPowerSavingPreambleForSF(sf);
|
||||
preamble = rxPowerSavingPreambleForParams(sf, bw);
|
||||
}
|
||||
|
||||
uint32_t rx_us, sleep_us;
|
||||
|
||||
@@ -38,8 +38,7 @@ void RadioLibWrapper::begin() {
|
||||
(void) mesh::initializeCC310Crypto();
|
||||
#endif
|
||||
_radio->setPacketReceivedAction(setFlag); // this is also SentComplete interrupt
|
||||
_preamble_sf = getSpreadingFactor();
|
||||
_radio->setPreambleLength(preambleLengthForSF(_preamble_sf)); // longer preamble for lower SF improves reliability
|
||||
_radio->setPreambleLength(currentPreambleLength()); // longer preamble for lower SF improves reliability
|
||||
state = STATE_IDLE;
|
||||
|
||||
if (_board->getStartupReason() == BD_STARTUP_RX_PACKET) { // received a LoRa packet (while in deep sleep)
|
||||
@@ -114,8 +113,7 @@ bool RadioLibWrapper::restoreAfterDeepInit() {
|
||||
if (_params_valid) {
|
||||
restored = applyParams(_cur_freq, _cur_bw, _cur_sf, _cur_cr);
|
||||
} else {
|
||||
_preamble_sf = getSpreadingFactor();
|
||||
restored = _radio->setPreambleLength(preambleLengthForSF(_preamble_sf))
|
||||
restored = _radio->setPreambleLength(currentPreambleLength())
|
||||
== RADIOLIB_ERR_NONE;
|
||||
}
|
||||
if (_dbm_valid) {
|
||||
|
||||
@@ -38,7 +38,6 @@ protected:
|
||||
int32_t _floor_sample_sum;
|
||||
unsigned long last_recv_millis;
|
||||
unsigned long last_radio_interrupt_millis; // updated on any ISR event, even CRC errors
|
||||
uint8_t _preamble_sf;
|
||||
bool _rx_ps_enabled;
|
||||
bool _rx_ps_armed; // radio is currently in RX duty-cycle mode
|
||||
bool _rx_ps_continuous_fallback; // requested RXPS is receiving continuously for this tuple
|
||||
@@ -120,7 +119,7 @@ protected:
|
||||
public:
|
||||
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board)
|
||||
: _radio(&radio), _board(&board), _noise_floor_valid(false), _nf_refresh_requested(true),
|
||||
_preamble_sf(0), _rx_ps_enabled(false), _rx_ps_armed(false),
|
||||
_rx_ps_enabled(false), _rx_ps_armed(false),
|
||||
_rx_ps_continuous_fallback(false), _rx_hold_continuous(false),
|
||||
_rx_ps_rx_us(RX_PS_FALLBACK_RX_US), _rx_ps_sleep_us(RX_PS_FALLBACK_SLEEP_US),
|
||||
_wd_last_busy(false), _wd_stage(0), _wd_strikes(0), _startrx_fails(0), _wd_last_transition(0),
|
||||
@@ -165,20 +164,21 @@ public:
|
||||
const uint32_t* rx_ps_timings = NULL) override;
|
||||
bool setParams(float freq, float bw, uint8_t sf, uint8_t cr,
|
||||
const uint32_t* rx_ps_timings = NULL);
|
||||
uint16_t getDefaultPreambleLength() const override { return preambleLengthForSF(_preamble_sf); }
|
||||
bool setPreambleLength(uint16_t len) override { return _radio->setPreambleLength(len) == RADIOLIB_ERR_NONE; }
|
||||
uint32_t getRngSeed();
|
||||
void setTxPower(int8_t dbm);
|
||||
|
||||
virtual float getCurrentRSSI() =0;
|
||||
virtual uint8_t getSpreadingFactor() const { return LORA_SF; }
|
||||
static uint16_t preambleLengthForSF(uint8_t sf) {
|
||||
return rxPowerSavingPreambleForSF(sf);
|
||||
static uint16_t preambleLengthForParams(uint8_t sf, float bw) {
|
||||
return rxPowerSavingPreambleForParams(sf, bw);
|
||||
}
|
||||
bool updatePreamble(uint8_t sf) {
|
||||
if (_radio->setPreambleLength(preambleLengthForSF(sf)) != RADIOLIB_ERR_NONE) return false;
|
||||
_preamble_sf = sf;
|
||||
return true;
|
||||
uint16_t currentPreambleLength() const {
|
||||
return _params_valid
|
||||
? preambleLengthForParams(_cur_sf, _cur_bw)
|
||||
: preambleLengthForParams(getSpreadingFactor(), static_cast<float>(LORA_BW));
|
||||
}
|
||||
bool updatePreamble(uint8_t sf, float bw) {
|
||||
return _radio->setPreambleLength(preambleLengthForParams(sf, bw)) == RADIOLIB_ERR_NONE;
|
||||
}
|
||||
PacketMillis calcMaxPacketMillis(uint8_t sf, float bw, uint8_t cr, uint8_t preambleSymbols);
|
||||
virtual int16_t performChannelScan();
|
||||
|
||||
Reference in new issue
Block a user