Preserve radio lab experiments and reuse unchanged SX1262 modulation
Skip redundant modulation writes during owned fast RX retunes when the last acknowledged SF/BW/CR/LDRO tuple matches. Invalidate that cache after ordinary setters, failed writes, and lifecycle changes. Include the remaining scan, preamble, settling, and memory-soak experiments, their collectors, validation notes, and original capture records. Preserve capture bytes across checkouts and keep private soak credentials local. Run lab collector and compiled contract tests in CI. Update the expectation, profile mapping, and result-buffer tests for the extended lab tools, and make the private WiFi override header optional for ordinary soak diagnostics. Validation: 145 host tests passed from the staged source snapshot. Clean heltec_v4_repeater and Xiao_S3_WIO_companion_radio_usb builds passed their RAM/flash gates. All 229 staged capture files retain their original bytes; all 75 local documentation links resolve in the clean snapshot.
This commit is contained in:
1 parent
55b4d8848d
commit
170c2c44b1
374 files changed
+412356
-100
No files matched your search
@@ -4,6 +4,9 @@
|
||||
#include <string.h>
|
||||
#include <WiFi.h>
|
||||
#include <helpers/esp32/WiFiRadioPolicy.h>
|
||||
#if defined(MESH_SOAK_WIFI_KEY_OVERRIDE)
|
||||
#include "../../../tools/hil/S3SoakWiFiKey.h"
|
||||
#endif
|
||||
|
||||
namespace mesh {
|
||||
namespace wifi {
|
||||
@@ -18,6 +21,9 @@ inline void setStationAutoReconnect(bool enabled) {
|
||||
}
|
||||
|
||||
inline wl_status_t beginStation(const char* ssid, const char* password) {
|
||||
#if defined(MESH_SOAK_WIFI_KEY_OVERRIDE)
|
||||
password = mesh::hil::soakStationPassword(password);
|
||||
#endif
|
||||
if (!kPrimaryEspNowRadio) {
|
||||
return WiFi.begin(ssid, password);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ class CustomSX1262 : public SX1262 {
|
||||
void endProfileSwitch(bool success) { _profileSwitch.end(success); }
|
||||
bool profileSwitchFailed() const { return _profileSwitch.failed(); }
|
||||
uint32_t getOptimizedProfileSwitches() const { return _profileFastResumes; }
|
||||
#ifdef MC_SX1262_HIL
|
||||
// Same-image lab baseline: force only 0x8B, preserving fast RX ownership.
|
||||
void hilInvalidateModulation() { _profileSwitch.invalidateModulation(); }
|
||||
#endif
|
||||
|
||||
int16_t restoreTcxoAfterSleep() {
|
||||
if (!_tcxoWakePending) return RADIOLIB_ERR_NONE;
|
||||
@@ -96,6 +100,25 @@ class CustomSX1262 : public SX1262 {
|
||||
return SX1262::setPreambleLength(symbols);
|
||||
}
|
||||
|
||||
// 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 {
|
||||
_profileSwitch.invalidateModulation();
|
||||
return SX1262::setBandwidth(bw);
|
||||
}
|
||||
int16_t setSpreadingFactor(uint8_t sf) override {
|
||||
_profileSwitch.invalidateModulation();
|
||||
return SX1262::setSpreadingFactor(sf);
|
||||
}
|
||||
int16_t setCodingRate(uint8_t cr, bool longInterleave = false) {
|
||||
_profileSwitch.invalidateModulation();
|
||||
return SX1262::setCodingRate(cr, longInterleave);
|
||||
}
|
||||
int16_t forceLDRO(bool enabled) {
|
||||
_profileSwitch.invalidateModulation();
|
||||
return SX1262::forceLDRO(enabled);
|
||||
}
|
||||
|
||||
// Apply one complete LoRa modulation tuple instead of three separate
|
||||
// SetModulationParams commands. Keep RadioLib's caches and automatic LDRO
|
||||
// calculation consistent with its ordinary SF/BW/CR setters. Caller must
|
||||
@@ -119,9 +142,18 @@ class CustomSX1262 : public SX1262 {
|
||||
return RADIOLIB_ERR_INVALID_BANDWIDTH;
|
||||
}
|
||||
if (getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
||||
_profileSwitch.invalidateModulation();
|
||||
return RADIOLIB_ERR_WRONG_MODEM;
|
||||
}
|
||||
|
||||
// Match the effective on-wire LDRO value, not merely the auto/manual
|
||||
// policy. autoLDRO() changes policy without writing the chip; SF/BW can
|
||||
// change its computed value. Keep the pinned RadioLib >=16 ms rule.
|
||||
const uint8_t effectiveLdro = ldroAuto
|
||||
? ((float(uint32_t(1) << sf) / bw) >= 16.0f ? 1 : 0)
|
||||
: ldrOptimize;
|
||||
const bool unchanged = _profileSwitch.matchesModulation(
|
||||
sf, codes[index], cr - 4, effectiveLdro);
|
||||
const auto oldSf = spreadingFactor;
|
||||
const auto oldBw = bandwidth;
|
||||
const auto oldBwKhz = bandwidthKhz;
|
||||
@@ -131,7 +163,12 @@ class CustomSX1262 : public SX1262 {
|
||||
bandwidth = codes[index];
|
||||
bandwidthKhz = bw;
|
||||
codingRate = cr - 4; // ordinary LoRa CR, not long-interleaving encoding
|
||||
if (unchanged) {
|
||||
ldrOptimize = effectiveLdro;
|
||||
return RADIOLIB_ERR_NONE; // no SetModulationParams (0x8B) needed
|
||||
}
|
||||
const int16_t state = setModulationParams(sf, bandwidth, codingRate, ldrOptimize);
|
||||
_profileSwitch.modulationResult(state, sf, bandwidth, codingRate, ldrOptimize);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
// The wrapper restores the physical tuple after a failed command.
|
||||
// Do not publish a new software tuple when hardware success is unknown.
|
||||
|
||||
@@ -10,9 +10,15 @@ struct SX1262ProfileSwitchState {
|
||||
bool active = false;
|
||||
bool standbyReady = false;
|
||||
int16_t error = 0;
|
||||
bool modulationValid = false;
|
||||
uint8_t modulationSf = 0, modulationBw = 0, modulationCr = 0, modulationLdro = 0;
|
||||
|
||||
explicit SX1262ProfileSwitchState(bool enable) : enabled(enable) {}
|
||||
void invalidate() { rxValid = active = standbyReady = false; }
|
||||
void invalidateModulation() { modulationValid = false; }
|
||||
void invalidate() {
|
||||
rxValid = active = standbyReady = false;
|
||||
invalidateModulation();
|
||||
}
|
||||
void begin(bool continuousRx, bool warm) {
|
||||
open = true;
|
||||
error = 0;
|
||||
@@ -28,6 +34,24 @@ struct SX1262ProfileSwitchState {
|
||||
}
|
||||
}
|
||||
bool canResumeFast() const { return open && active && rxValid && standbyReady && error == 0; }
|
||||
// Only trust an acknowledged tuple inside the same owned RX context. The
|
||||
// normal RadioLib software fields alone do not prove a write succeeded.
|
||||
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();
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user