Merge branch 'restore/upstream-duty-cycle' into restore/fem-rxgain
This commit is contained in:
commit
ae9c01f0b7
5 files changed
+44
-9
No files matched your search
+5
-1
@@ -47,7 +47,11 @@ Remaining integration points in upstream files:
|
||||
bytes of a legacy (headerless) file, whose payload begins with the `mqtt_origin`
|
||||
string. Bump `MQTT_PREFS_VERSION` when the payload layout changes incompatibly; a file
|
||||
whose version this firmware doesn't recognize is left untouched and the in-memory prefs
|
||||
fall back to defaults (no downgrade, no misread).
|
||||
fall back to defaults (no downgrade, no misread). `saveMQTTPrefs()` also refuses to
|
||||
write while such a file is present (`_mqtt_prefs_hold`), so a `set` command after a
|
||||
firmware downgrade can't clobber the newer config — observer settings changed in that
|
||||
state simply don't persist. The frozen legacy layouts are pinned with `static_assert`s
|
||||
in `CommonCLI.h`, so every target build re-verifies the fleet's file offsets.
|
||||
|
||||
Adding a field to the current version stays backward compatible: append it to the end
|
||||
of `MQTTPrefs`. An older, shorter payload still loads and the missing tail keeps its
|
||||
|
||||
@@ -206,7 +206,7 @@ void AlertReporter::formatAge(unsigned long age_ms, char* out, size_t out_size)
|
||||
}
|
||||
|
||||
void AlertReporter::onLoop(unsigned long now_ms) {
|
||||
if (!_prefs || !_obs->alert_enabled) return;
|
||||
if (!_prefs || !_obs || !_obs->alert_enabled) return;
|
||||
if (!_mesh) return;
|
||||
|
||||
// Throttle: ~5 s cadence. The thresholds are minutes-scale so this is fine.
|
||||
|
||||
@@ -49,6 +49,12 @@ static const size_t LEGACY_MQTT_GAP_6SLOT = 306 + 6 * 186; // 1422
|
||||
static const size_t LEGACY_MQTT_GAP_3SLOT = 306 + 3 * 186; // 864
|
||||
static const size_t LEGACY_OBS_TAIL_MAX = 124; // rx_boosted(1) + flood(2) + snmp(25) + watchdog(1) + alert block(95)
|
||||
|
||||
// Bytes savePrefs() writes after owner_info (offsets 290-294): rx_boosted_gain,
|
||||
// flood_max_unscoped, flood_max_advert, radio_fem_rxgain, cad_enabled. loadPrefsInt()
|
||||
// treats any larger remainder as a legacy MQTT-gap file — keep this in sync with the
|
||||
// trailing writes in savePrefs() whenever an upstream merge appends /com_prefs fields.
|
||||
static const size_t COM_PREFS_TAIL_BYTES = 5;
|
||||
|
||||
|
||||
void CommonCLI::loadPrefs(FILESYSTEM* fs) {
|
||||
bool is_fresh_install = false;
|
||||
@@ -154,11 +160,10 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
// (upstream defaults: FEM RX gain on, CAD off) — overwritten below if present.
|
||||
_prefs->radio_fem_rxgain = 1;
|
||||
_prefs->cad_enabled = 0;
|
||||
// New-format tail is 5 bytes (rx_boosted_gain, flood_max_unscoped/advert,
|
||||
// radio_fem_rxgain, cad_enabled). A larger `extra` means an old fork file with
|
||||
// the legacy MQTT gap; detect and recover it below.
|
||||
// A remainder larger than the new-format tail means an old fork file with the
|
||||
// legacy MQTT gap; detect and recover it below.
|
||||
size_t extra = file.available();
|
||||
if (extra > 5) {
|
||||
if (extra > COM_PREFS_TAIL_BYTES) {
|
||||
_com_prefs_needs_upgrade = true;
|
||||
size_t gap = 0;
|
||||
if (extra > LEGACY_MQTT_GAP_6SLOT && extra <= LEGACY_MQTT_GAP_6SLOT + LEGACY_OBS_TAIL_MAX) {
|
||||
@@ -363,6 +368,7 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
||||
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
|
||||
// MQTT/observer settings are stored in /mqtt_prefs, not here. No zero-gap is
|
||||
// written anymore — /com_prefs holds only the (non-observer) fields below.
|
||||
// These trailing writes are COM_PREFS_TAIL_BYTES; keep the two in sync.
|
||||
file.write((uint8_t *)&_prefs->rx_boosted_gain, sizeof(_prefs->rx_boosted_gain)); // 290
|
||||
file.write((uint8_t *)&_prefs->flood_max_unscoped, sizeof(_prefs->flood_max_unscoped)); // 291
|
||||
file.write((uint8_t *)&_prefs->flood_max_advert, sizeof(_prefs->flood_max_advert)); // 292
|
||||
@@ -395,6 +401,7 @@ static File openMqttPrefsRead(FILESYSTEM* fs) {
|
||||
void CommonCLI::loadMQTTPrefs(FILESYSTEM* fs) {
|
||||
// Initialize with defaults first
|
||||
setMQTTPrefsDefaults(&_mqtt_prefs);
|
||||
_mqtt_prefs_hold = false;
|
||||
|
||||
// Whether the loaded /mqtt_prefs already contained the observer fields (snmp/
|
||||
// watchdog/alert) appended in Phase 2 — if not, they may be carried over from an
|
||||
@@ -428,8 +435,10 @@ void CommonCLI::loadMQTTPrefs(FILESYSTEM* fs) {
|
||||
}
|
||||
} else {
|
||||
// Unknown (newer) version: don't risk misreading a layout we don't know.
|
||||
// Keep defaults for this boot and leave the file untouched (no downgrade).
|
||||
MESH_DEBUG_PRINTLN("MQTT: /mqtt_prefs version unsupported, using defaults");
|
||||
// Keep defaults for this boot and hold the file so later savePrefs()
|
||||
// calls can't overwrite the newer config (no downgrade).
|
||||
_mqtt_prefs_hold = true;
|
||||
MESH_DEBUG_PRINTLN("MQTT: /mqtt_prefs version unsupported, using defaults (file preserved)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -628,6 +637,13 @@ void CommonCLI::loadMQTTPrefs(FILESYSTEM* fs) {
|
||||
}
|
||||
|
||||
void CommonCLI::saveMQTTPrefs(FILESYSTEM* fs) {
|
||||
if (_mqtt_prefs_hold) {
|
||||
// /mqtt_prefs was written by newer firmware; overwriting it here (v1 header +
|
||||
// this boot's defaults) would destroy that config. Observer settings changed
|
||||
// this boot are not persisted until current-or-older firmware is flashed.
|
||||
MESH_DEBUG_PRINTLN("MQTT: /mqtt_prefs from newer firmware, not overwriting");
|
||||
return;
|
||||
}
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
fs->remove("/mqtt_prefs");
|
||||
File file = fs->open("/mqtt_prefs", FILE_O_WRITE);
|
||||
|
||||
@@ -242,6 +242,17 @@ struct Legacy6SlotMQTTPrefs {
|
||||
char mqtt_ntp_server[64];
|
||||
};
|
||||
|
||||
// The legacy layouts above describe files already written to the deployed fleet's
|
||||
// flash, so their sizes are frozen forever — loadMQTTPrefs() tells the eras apart
|
||||
// by file size and reads each file as a raw struct dump. These asserts pin the
|
||||
// layouts on every target toolchain; if one fires, the compiler (or an edit to a
|
||||
// legacy struct or MAX_MQTT_SLOTS) has changed a layout and fleet files would be
|
||||
// read at wrong offsets.
|
||||
static_assert(sizeof(MQTTPrefsHeader) == 8, "versioned /mqtt_prefs header must stay 8 bytes");
|
||||
static_assert(sizeof(OldMQTTPrefs) == 472, "frozen pre-slot /mqtt_prefs layout changed");
|
||||
static_assert(sizeof(ThreeSlotMQTTPrefs) == 1464, "frozen 3-slot /mqtt_prefs layout changed");
|
||||
static_assert(sizeof(Legacy6SlotMQTTPrefs) == 2904, "frozen deployed-fleet /mqtt_prefs layout changed");
|
||||
|
||||
// Observer settings captured from the trailing block of an old-format /com_prefs
|
||||
// (fork firmware that predates the NodePrefs -> MQTTPrefs split). loadPrefsInt()
|
||||
// fills this in when it detects the old file layout; loadMQTTPrefs() then applies
|
||||
@@ -373,6 +384,10 @@ class CommonCLI {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
MQTTPrefs _mqtt_prefs;
|
||||
LegacyObserverTail _legacy_tail;
|
||||
// /mqtt_prefs carries a version newer than this firmware understands (a downgrade).
|
||||
// The in-memory prefs run on defaults and saveMQTTPrefs() must not overwrite the
|
||||
// file, or the first `set` command would destroy the newer config.
|
||||
bool _mqtt_prefs_hold = false;
|
||||
#endif
|
||||
bool _com_prefs_needs_upgrade = false; // old-format /com_prefs detected; rewrite once after load
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ protected:
|
||||
|
||||
void idle() override;
|
||||
void startRecv() override;
|
||||
int16_t performChannelScan();
|
||||
float packetScoreInt(float snr, int sf, int packet_len);
|
||||
virtual bool isReceivingPacket() =0;
|
||||
virtual void doResetAGC();
|
||||
@@ -55,6 +54,7 @@ public:
|
||||
virtual uint8_t getSpreadingFactor() const { return LORA_SF; }
|
||||
static uint16_t preambleLengthForSF(uint8_t sf) { return sf <= 8 ? 32 : 16; }
|
||||
void updatePreamble(uint8_t sf) { _preamble_sf = sf; _radio->setPreambleLength(preambleLengthForSF(sf)); }
|
||||
virtual int16_t performChannelScan();
|
||||
|
||||
int getNoiseFloor() const override { return _noise_floor; }
|
||||
void triggerNoiseFloorCalibrate(int threshold) override;
|
||||
|
||||
Reference in new issue
Block a user