feat(radio): enable fast profile switching across direct SX1262 boards

Add acknowledged SetFs and packet-cache shortcuts for SX1262, extend the LR1110 FS-mode fast path with buffered SPI, and keep the expander-backed Indicator on its previous path. Include HIL fixtures, validation notes, and regression tests.
This commit is contained in:
mikecarper committed 2026-09-21 22:57:22 -07:00
1 parent 082466f71b
commit 8c7f4df1cd
28 files changed
+1954 -33

No files matched your search

+223 -1
View File
@@ -4,6 +4,13 @@
#include "MeshCore.h"
#include "RXPowerSaving.h"
#include "LR1110RxRecovery.h"
#include "LR1110ProfileSwitchState.h"
#ifndef MC_LR1110_FAST_PROFILE_SWITCH
// All MeshCore LR1110 targets use the checked FS-mode continuous-RX retune.
// Boards can opt out if hardware validation finds an incompatibility.
#define MC_LR1110_FAST_PROFILE_SWITCH 1
#endif
#ifndef LR11X0_TX_BUSY_TIMEOUT_MS
#define LR11X0_TX_BUSY_TIMEOUT_MS 1000UL
@@ -15,14 +22,173 @@ class CustomLR1110 : public LR1110 {
uint32_t _activityAt = 0;
bool _headerSeen = false;
bool _rx_boosted = false;
LR1110ProfileSwitchState _profileSwitch{MC_LR1110_FAST_PROFILE_SWITCH != 0};
bool _profileStandbyWarm = false;
bool _profilePacketDirty = false;
uint32_t _profileFastResumes = 0;
public:
CustomLR1110(Module *mod) : LR1110(mod) { }
void setProfileSwitchOptimization(bool enabled) {
_profileSwitch.enabled = enabled;
_profileSwitch.invalidate();
_profilePacketDirty = false;
}
void setProfileStandbyWarm(bool enabled) {
_profileStandbyWarm = enabled;
if (!enabled) _profileSwitch.invalidate();
}
void beginProfileSwitch(bool continuousRx) {
_profileSwitch.begin(continuousRx, _profileStandbyWarm);
}
void endProfileSwitch(bool success) { _profileSwitch.end(success); }
bool profileSwitchFailed() const { return _profileSwitch.failed(); }
uint32_t getOptimizedProfileSwitches() const { return _profileFastResumes; }
#ifdef MC_LR1110_HIL
uint64_t fastClearCycles = 0, fastPacketCycles = 0, fastSetRxCycles = 0;
uint8_t hilFastClearMode = 2; // 0=always, 1=never, 2=checked (production)
bool hilInjectRxTimeout = false;
bool hilUseFsOnRetune = true;
uint32_t hilPendingIrqSnapshots = 0;
#endif
// Outside RX, no new packet IRQ can arise. Check the pending bits after
// leaving RX and clear them only when present. RadioLib's plain
// getIrqStatus() discards SPI errors, so use a checked transfer here.
int16_t snapshotIrqAfterRxExit(uint32_t* irq) {
uint8_t reply[6] = {};
auto& statusWidth = mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS];
const auto savedWidth = statusWidth;
statusWidth = Module::BITS_0;
const int16_t rc = mod->SPItransferStream(nullptr, 0, false, nullptr,
reply, sizeof(reply), true);
statusWidth = savedWidth;
if (rc == RADIOLIB_ERR_NONE) {
*irq = (uint32_t(reply[2]) << 24) | (uint32_t(reply[3]) << 16)
| (uint32_t(reply[4]) << 8) | uint32_t(reply[5]);
}
return rc;
}
int16_t standby() override {
const bool warm = _profileSwitch.active && _profileSwitch.rxValid;
if (!warm) _profileSwitch.invalidate();
// RadioLib 7.7.1 defines STANDBY_XOSC as 0, the same as STANDBY_RC.
// The LR1110 command's XOSC selector is 1 (Semtech UM §2.1.1).
bool useFs = warm;
#ifdef MC_LR1110_HIL
useFs = useFs && hilUseFsOnRetune;
#endif
int16_t rc;
if (useFs) {
mod->setRfSwitchState(Module::MODE_IDLE);
rc = setFs();
} else if (warm) {
rc = LR1110::standby(0x01, false);
} else {
rc = LR1110::standby();
}
_profileSwitch.standbyResult(rc);
return rc;
}
int16_t standby(uint8_t mode) override {
_profileSwitch.invalidate();
return LR1110::standby(mode);
}
int16_t sleep() override {
_profileSwitch.invalidate();
return LR1110::sleep();
}
int16_t reset() {
_profileSwitch.invalidate();
return LR1110::reset();
}
int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t* cfg) override {
_profileSwitch.invalidate();
return LR1110::stageMode(mode, cfg);
}
int16_t setPreambleLength(size_t symbols) override {
if (_profileSwitch.canResumeFast()) {
// Keep the acknowledged RX packet tuple until its preamble changes.
if (preambleLengthLoRa != symbols) _profilePacketDirty = true;
preambleLengthLoRa = symbols;
return RADIOLIB_ERR_NONE;
}
_profileSwitch.invalidate();
_profilePacketDirty = false;
return LR1110::setPreambleLength(symbols);
}
int16_t setFrequency(float freq) {
if (_profileSwitch.canResumeFast() && freq == freqMHz) return RADIOLIB_ERR_NONE;
if (!_profileSwitch.canResumeFast()) _profileSwitch.invalidate();
const int16_t rc = LR1110::setFrequency(freq);
if (rc != RADIOLIB_ERR_NONE) _profileSwitch.invalidate();
return rc;
}
int16_t setBandwidth(float bw, bool high = false) {
_profileSwitch.modulationValid = false;
return LR1110::setBandwidth(bw, high);
}
int16_t setSpreadingFactor(uint8_t sf, bool legacy = false) {
_profileSwitch.modulationValid = false;
return LR1110::setSpreadingFactor(sf, legacy);
}
int16_t setCodingRate(uint8_t cr, bool longInterleave = false) {
_profileSwitch.modulationValid = false;
return LR1110::setCodingRate(cr, longInterleave);
}
// A single acknowledged SetModulationParams replaces three RadioLib
// setters. Keep RadioLib's cached tuple and automatic LDRO calculation.
int16_t setLoRaModulationParams(float bw, uint8_t sf, uint8_t cr) {
if (sf < 5 || sf > 12) return RADIOLIB_ERR_INVALID_SPREADING_FACTOR;
if (cr < 4 || cr > 8) return RADIOLIB_ERR_INVALID_CODING_RATE;
uint8_t bwCode;
if (fabsf(bw - 62.5f) < 0.01f) bwCode = RADIOLIB_LR11X0_LORA_BW_62_5;
else if (fabsf(bw - 125.0f) < 0.01f) bwCode = RADIOLIB_LR11X0_LORA_BW_125_0;
else if (fabsf(bw - 250.0f) < 0.01f) bwCode = RADIOLIB_LR11X0_LORA_BW_250_0;
else if (fabsf(bw - 500.0f) < 0.01f) bwCode = RADIOLIB_LR11X0_LORA_BW_500_0;
else return RADIOLIB_ERR_INVALID_BANDWIDTH;
if (!_profileSwitch.canResumeFast()) {
uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
const int16_t rc = getPacketType(&type);
if (rc != RADIOLIB_ERR_NONE) return rc;
if (type != RADIOLIB_LR11X0_PACKET_TYPE_LORA) return RADIOLIB_ERR_WRONG_MODEM;
}
const uint8_t effectiveLdro = ldroAuto
? (float(uint32_t(1) << sf) / bw >= 16.0f
? RADIOLIB_LR11X0_LORA_LDRO_ENABLED : RADIOLIB_LR11X0_LORA_LDRO_DISABLED)
: ldrOptimize;
const bool unchanged = _profileSwitch.matchesModulation(sf, bwCode, cr - 4, effectiveLdro);
const auto oldSf = spreadingFactor, oldBw = bandwidth, oldCr = codingRate, oldLdro = ldrOptimize;
const auto oldBwKhz = bandwidthKhz;
spreadingFactor = sf;
bandwidth = bwCode;
bandwidthKhz = bw;
codingRate = cr - 4;
if (unchanged) {
ldrOptimize = effectiveLdro;
return RADIOLIB_ERR_NONE;
}
const int16_t rc = setModulationParamsLoRa(sf, bwCode, codingRate, effectiveLdro);
_profileSwitch.modulationResult(rc, sf, bwCode, codingRate, ldrOptimize);
if (rc != RADIOLIB_ERR_NONE) {
spreadingFactor = oldSf;
bandwidth = oldBw;
bandwidthKhz = oldBwKhz;
codingRate = oldCr;
ldrOptimize = oldLdro;
}
return rc;
}
// Apply the measured TCXO delay on every initialization, including recovery.
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7,
uint8_t syncWord = RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, int8_t power = 10,
uint16_t preambleLength = 8, float tcxoVoltage = 1.6) {
_profileSwitch.invalidate();
_profilePacketDirty = false;
int16_t state = LR1110::begin(freq, bw, sf, cr, syncWord, power, preambleLength,
tcxoVoltage);
if (state == RADIOLIB_ERR_NONE) state = applyMeshCoreTcxoDelay();
@@ -186,12 +352,68 @@ class CustomLR1110 : public LR1110 {
bool getRxBoostedGainMode() const { return _rx_boosted; }
int16_t startReceive() override {
if (_profileSwitch.canResumeFast()) {
_profileSwitch.rxValid = false; // fail closed until the RX command ACKs
#ifdef MC_LR1110_HIL
uint32_t segment = DWT->CYCCNT;
#endif
int16_t rc = RADIOLIB_ERR_NONE;
#ifdef MC_LR1110_HIL
if (hilInjectRxTimeout) {
hilInjectRxTimeout = false;
rc = setRx(1);
if (rc == RADIOLIB_ERR_NONE) delayMicroseconds(150);
}
if (rc == RADIOLIB_ERR_NONE && hilFastClearMode == 0)
rc = clearIrqState(RADIOLIB_LR11X0_IRQ_ALL);
else if (rc == RADIOLIB_ERR_NONE && hilFastClearMode == 2)
#else
if (rc == RADIOLIB_ERR_NONE)
#endif
{
uint32_t pending = 0;
rc = snapshotIrqAfterRxExit(&pending);
#ifdef MC_LR1110_HIL
if (pending) ++hilPendingIrqSnapshots;
#endif
if (rc == RADIOLIB_ERR_NONE && pending)
rc = clearIrqState(RADIOLIB_LR11X0_IRQ_ALL);
}
#ifdef MC_LR1110_HIL
fastClearCycles += DWT->CYCCNT - segment;
segment = DWT->CYCCNT;
#endif
if (rc == RADIOLIB_ERR_NONE && _profilePacketDirty) {
rc = setPacketParamsLoRa(preambleLengthLoRa, headerType,
RADIOLIB_LR11X0_MAX_PACKET_LENGTH, crcTypeLoRa, invertIQEnabled);
}
#ifdef MC_LR1110_HIL
fastPacketCycles += DWT->CYCCNT - segment;
segment = DWT->CYCCNT;
#endif
if (rc == RADIOLIB_ERR_NONE) {
rxTimeout = RADIOLIB_LR11X0_RX_TIMEOUT_INF;
mod->setRfSwitchState(Module::MODE_RX);
rc = setRx(rxTimeout);
}
#ifdef MC_LR1110_HIL
fastSetRxCycles += DWT->CYCCNT - segment;
#endif
stagedMode = RADIOLIB_RADIO_MODE_NONE;
if (rc == RADIOLIB_ERR_NONE) ++_profileFastResumes;
if (rc == RADIOLIB_ERR_NONE) _profilePacketDirty = false;
_profileSwitch.rxResult(rc, true);
return rc;
}
// Keep preamble detection visible to CAD and route header errors to DIO1
// so the wrapper can reset the RX path before another packet is read.
return LR1110::startReceive(
const int16_t rc = LR1110::startReceive(
RADIOLIB_LR11X0_RX_TIMEOUT_INF,
RADIOLIB_IRQ_RX_DEFAULT_FLAGS | (1UL << RADIOLIB_IRQ_PREAMBLE_DETECTED),
RADIOLIB_IRQ_RX_DEFAULT_MASK | (1UL << RADIOLIB_IRQ_HEADER_ERR), 0);
_profileSwitch.rxResult(rc, true);
if (rc == RADIOLIB_ERR_NONE) _profilePacketDirty = false;
return rc;
}
// BUSY high means the chip is asleep (RX duty-cycle sleep window) or mid
@@ -19,6 +19,19 @@ public:
void setDeepInitCallback(DeepInitCallback callback) { _deep_init = callback; }
protected:
void beginProfileRetune(bool continuousRx) override {
static_cast<CustomLR1110*>(_radio)->beginProfileSwitch(continuousRx);
}
void endProfileRetune(bool success) override {
static_cast<CustomLR1110*>(_radio)->endProfileSwitch(success);
}
void setProfileStandbyWarm(bool enabled) override {
static_cast<CustomLR1110*>(_radio)->setProfileStandbyWarm(enabled);
}
public:
void powerOff() {
if (isCarrierWaveActive()) setCarrierWave(0, 0);
_radio->standby(); _radio->sleep();
@@ -26,11 +39,18 @@ public:
protected:
bool applyParams(float freq, float bw, uint8_t sf, uint8_t cr) override {
if (static_cast<CustomLR1110*>(_radio)->profileSwitchFailed()) return false;
#if MC_LR1110_FAST_PROFILE_SWITCH
bool success = ((CustomLR1110 *)_radio)->setFrequency(freq) == RADIOLIB_ERR_NONE
&& ((CustomLR1110 *)_radio)->setLoRaModulationParams(bw, sf, cr) == RADIOLIB_ERR_NONE
&& updatePreamble(sf, bw);
#else
bool success = ((CustomLR1110 *)_radio)->setFrequency(freq) == RADIOLIB_ERR_NONE
&& ((CustomLR1110 *)_radio)->setSpreadingFactor(sf) == RADIOLIB_ERR_NONE
&& ((CustomLR1110 *)_radio)->setBandwidth(bw) == RADIOLIB_ERR_NONE
&& ((CustomLR1110 *)_radio)->setCodingRate(cr) == RADIOLIB_ERR_NONE
&& updatePreamble(sf, bw);
#endif
if (!success) return false;
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForParams(sf, bw));
+76 -5
View File
@@ -6,7 +6,22 @@
#include "SX1262ProfileSwitchState.h"
#ifndef MC_SX1262_FAST_PROFILE_SWITCH
#define MC_SX1262_FAST_PROFILE_SWITCH 0
// CustomSX1262 targets use direct radio I/O unless a board opts out. Keep
// the owned RX-to-RX path available across those boards, including roles that
// did not previously need a local profile scanner.
#define MC_SX1262_FAST_PROFILE_SWITCH 1
#endif
#ifndef MC_SX1262_FAST_FS
#define MC_SX1262_FAST_FS MC_SX1262_FAST_PROFILE_SWITCH
#endif
#ifndef MC_SX1262_FAST_PACKET_CACHE
#define MC_SX1262_FAST_PACKET_CACHE MC_SX1262_FAST_PROFILE_SWITCH
#endif
#if (MC_SX1262_FAST_FS || MC_SX1262_FAST_PACKET_CACHE) && !MC_SX1262_FAST_PROFILE_SWITCH
#error "SX1262 SetFs/packet reuse requires the owned fast profile-switch path"
#endif
#ifndef SX126X_TX_BUSY_TIMEOUT_MS
@@ -39,6 +54,11 @@ class CustomSX1262 : public SX1262 {
#ifdef MC_SX1262_HIL
// Same-image lab baseline: force only 0x8B, preserving fast RX ownership.
void hilInvalidateModulation() { _profileSwitch.invalidateModulation(); }
// Same-image A/B overrides; these default off on every HIL reboot.
bool hilUseFsOnRetune = false;
bool hilSkipUnchangedPacket = false;
float hilFrequencyMHz() const { return freqMHz; }
uint32_t hilFsEntries = 0, hilPacketSkips = 0;
#endif
int16_t restoreTcxoAfterSleep() {
@@ -56,9 +76,22 @@ class CustomSX1262 : public SX1262 {
int16_t standby() override {
const bool alreadyAwake = !_coldStandby && _profileSwitch.active && _profileSwitch.rxValid;
if (!alreadyAwake) _profileSwitch.invalidate();
int16_t rc = alreadyAwake
? SX1262::standby(RADIOLIB_SX126X_STANDBY_XOSC, false)
: _coldStandby ? SX1262::standby(RADIOLIB_SX126X_STANDBY_RC) : SX1262::standby();
int16_t rc;
bool useFs = MC_SX1262_FAST_FS != 0;
#ifdef MC_SX1262_HIL
useFs = hilUseFsOnRetune;
#endif
if (alreadyAwake && useFs) {
getMod()->setRfSwitchState(Module::MODE_IDLE);
rc = setFs();
#ifdef MC_SX1262_HIL
if (rc == RADIOLIB_ERR_NONE) ++hilFsEntries;
#endif
} else {
rc = alreadyAwake
? SX1262::standby(RADIOLIB_SX126X_STANDBY_XOSC, false)
: _coldStandby ? SX1262::standby(RADIOLIB_SX126X_STANDBY_RC) : SX1262::standby();
}
if (rc == RADIOLIB_ERR_NONE) rc = restoreTcxoAfterSleep();
if (rc != RADIOLIB_ERR_NONE) _coldStandby = true;
_profileSwitch.standbyResult(rc);
@@ -97,9 +130,31 @@ class CustomSX1262 : public SX1262 {
preambleLengthLoRa = symbols;
return RADIOLIB_ERR_NONE;
}
_profileSwitch.invalidatePacket();
return SX1262::setPreambleLength(symbols);
}
// Ordinary packet setters may rewrite the hardware even when the LoRa
// software fields later return to their old values. Never reuse an RX
// acknowledgement across them, including when a setter reports failure.
int16_t setCRC(uint8_t len, uint16_t initial = 0x1D0F,
uint16_t polynomial = 0x1021, bool inverted = true) {
_profileSwitch.invalidatePacket();
return SX1262::setCRC(len, initial, polynomial, inverted);
}
int16_t implicitHeader(size_t len) {
_profileSwitch.invalidatePacket();
return SX1262::implicitHeader(len);
}
int16_t explicitHeader() {
_profileSwitch.invalidatePacket();
return SX1262::explicitHeader();
}
int16_t invertIQ(bool enable) override {
_profileSwitch.invalidatePacket();
return SX1262::invertIQ(enable);
}
// Ordinary setters can change hardware or leave RadioLib's fields updated
// after a failed write. They cannot preserve our acknowledged hop tuple.
int16_t setBandwidth(float bw) override {
@@ -449,11 +504,23 @@ class CustomSX1262 : public SX1262 {
// Existing continuous RX already established buffer bases and the
// MeshCore IRQ map (including preamble detection). No TX/CAD/sleep/
// reset/staging may intervene without revoking that context.
bool skipPacket = MC_SX1262_FAST_PACKET_CACHE != 0;
#ifdef MC_SX1262_HIL
skipPacket = hilSkipUnchangedPacket;
#endif
skipPacket = skipPacket && _profileSwitch.matchesPacket(
preambleLengthLoRa, crcTypeLoRa, implicitLen,
headerType, invertIQEnabled);
_profileSwitch.rxValid = false; // fail closed on any command error
int16_t rc = clearIrqStatus();
if (rc == RADIOLIB_ERR_NONE) {
#ifdef MC_SX1262_HIL
if (rc == RADIOLIB_ERR_NONE && skipPacket) ++hilPacketSkips;
#endif
if (rc == RADIOLIB_ERR_NONE && !skipPacket) {
rc = setPacketParams(preambleLengthLoRa, crcTypeLoRa, implicitLen,
headerType, invertIQEnabled);
_profileSwitch.packetResult(rc, preambleLengthLoRa, crcTypeLoRa,
implicitLen, headerType, invertIQEnabled);
}
if (rc == RADIOLIB_ERR_NONE) {
rxTimeout = RADIOLIB_SX126X_RX_TIMEOUT_INF;
@@ -476,6 +543,10 @@ class CustomSX1262 : public SX1262 {
&& getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA;
_coldStandby = rc != RADIOLIB_ERR_NONE;
_profileSwitch.rxResult(rc, reusable);
if (rc == RADIOLIB_ERR_NONE && reusable) {
_profileSwitch.packetResult(rc, preambleLengthLoRa, crcTypeLoRa,
implicitLen, headerType, invertIQEnabled);
}
return rc;
}
@@ -0,0 +1,16 @@
#pragma once
#include <hal/Arduino/ArduinoHal.h>
// RadioLib's Arduino HAL transfers one byte at a time. ESP32 SPIClass can
// transfer each LR1110 command in one transaction while retaining RadioLib's
// existing CS, BUSY, status and transaction handling. LR1110 permits 16 MHz.
class Esp32BufferedRadioHal : public ArduinoHal {
public:
explicit Esp32BufferedRadioHal(SPIClass& bus, uint32_t hz = 16000000)
: ArduinoHal(bus, SPISettings(hz, MSBFIRST, SPI_MODE0)) {}
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override {
if (len) spi->transferBytes(out, in, len);
}
};
@@ -0,0 +1,68 @@
#pragma once
#include <stdint.h>
// A short-lived, acknowledged continuous-RX context. It is never valid after
// sleep, TX/CAD staging, an unrelated standby, reset, or a failed command.
struct LR1110ProfileSwitchState {
bool enabled;
bool rxValid = false;
bool open = false;
bool active = false;
bool standbyReady = false;
int16_t error = 0;
bool modulationValid = false;
uint8_t modulationSf = 0, modulationBw = 0, modulationCr = 0, modulationLdro = 0;
explicit LR1110ProfileSwitchState(bool enable) : enabled(enable) {}
void invalidate() {
rxValid = active = standbyReady = modulationValid = false;
}
void begin(bool continuousRx, bool warm) {
open = true;
error = 0;
standbyReady = false;
active = enabled && rxValid && continuousRx && warm;
}
void standbyResult(int16_t result) {
if (result != 0) {
if (open) error = result;
invalidate();
} else if (active) {
standbyReady = true;
}
}
bool canResumeFast() const {
return open && active && rxValid && standbyReady && error == 0;
}
bool matchesModulation(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro) const {
return canResumeFast() && modulationValid && modulationSf == sf
&& modulationBw == bw && modulationCr == cr && modulationLdro == ldro;
}
void modulationResult(int16_t result, uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro) {
if (result != 0) {
if (open) error = result;
invalidate();
} else {
modulationSf = sf;
modulationBw = bw;
modulationCr = cr;
modulationLdro = ldro;
modulationValid = true;
}
}
bool failed() const { return open && error != 0; }
void rxResult(int16_t result, bool reusable) {
if (result != 0) {
if (open) error = result;
invalidate();
} else {
rxValid = enabled && reusable;
standbyReady = false;
}
}
void end(bool success) {
if (!success) invalidate();
open = active = standbyReady = false;
error = 0;
}
};
@@ -0,0 +1,16 @@
#pragma once
#include <hal/Arduino/ArduinoHal.h>
// nRF52840 SPIClass::transfer(uint8_t) starts one SPIM transaction per byte.
// RadioLib sends whole command buffers; keep its CS, BUSY, and status handling
// but transfer each buffer in one SPIM transaction. LR1110 supports 16 MHz SPI.
class Nrf52BufferedRadioHal : public ArduinoHal {
public:
explicit Nrf52BufferedRadioHal(SPIClass& bus, uint32_t hz = 16000000)
: ArduinoHal(bus, SPISettings(hz, MSBFIRST, SPI_MODE0)) {}
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override {
if (len) spi->transfer(out, in, len);
}
};
@@ -1,4 +1,5 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
// A short-lived capability for reusing a fully configured continuous-RX
@@ -12,12 +13,17 @@ struct SX1262ProfileSwitchState {
int16_t error = 0;
bool modulationValid = false;
uint8_t modulationSf = 0, modulationBw = 0, modulationCr = 0, modulationLdro = 0;
bool packetValid = false;
size_t packetPreamble = 0;
uint8_t packetCrc = 0, packetImplicitLen = 0, packetHeader = 0, packetIq = 0;
explicit SX1262ProfileSwitchState(bool enable) : enabled(enable) {}
void invalidateModulation() { modulationValid = false; }
void invalidatePacket() { packetValid = false; }
void invalidate() {
rxValid = active = standbyReady = false;
invalidateModulation();
invalidatePacket();
}
void begin(bool continuousRx, bool warm) {
open = true;
@@ -52,6 +58,26 @@ struct SX1262ProfileSwitchState {
modulationLdro = ldro;
modulationValid = true;
}
bool matchesPacket(size_t preamble, uint8_t crc, uint8_t implicitLen,
uint8_t header, uint8_t iq) const {
return canResumeFast() && packetValid && packetPreamble == preamble
&& packetCrc == crc && packetImplicitLen == implicitLen
&& packetHeader == header && packetIq == iq;
}
void packetResult(int16_t result, size_t preamble, uint8_t crc,
uint8_t implicitLen, uint8_t header, uint8_t iq) {
if (result != 0) {
if (open) error = result;
invalidate();
return;
}
packetPreamble = preamble;
packetCrc = crc;
packetImplicitLen = implicitLen;
packetHeader = header;
packetIq = iq;
packetValid = true;
}
bool failed() const { return open && error != 0; }
void rxResult(int16_t result, bool reusable) {
if (result != 0) {