Absorbs 106 upstream commits. Seven files conflicted; the substantive one was upstream's new JSON ConfigSerializer (PR #2982), which replaces the binary /com_prefs layout with /prefs.json and makes NodePrefs a ConfigSerializer subclass. Prefs migration - Adopt upstream's ConfigSerializer. writeCommonPrefsImage() and its documented offsets (0-294) are deleted, along with the now-unreachable saveCommonPrefsImageAtomically()/CommonPrefsFileStore atomic rename path. - Load order is /prefs.json, then /com_prefs, then /node_prefs. Upstream dropped the /node_prefs fallback; it is restored here so devices that never advanced past that filename keep their config. - Legacy files are never removed, so migration cannot destroy its own source and a deferred or failed save simply retries next boot. - /com_prefs is treated as a format migration only, not an "upgrade", so it does not trip the bridge.source tx->rx flip on existing nodes. - The MQTTPrefsAtomicStore legacy gate is retained: the observer tail recovered from an old-format file still commits to /mqtt_prefs before /prefs.json is written. - MQTTPrefs and /mqtt_prefs are untouched; savePrefs keeps its save_mqtt parameter and now returns upstream's bool. Fixes to upstream code - RadioPrefs::structure() bound both "rxgain" and "fem_rxgain" to rx_boosted_gain, so radio_fem_rxgain was never persisted. Bound to the correct field. - discovery_mod_timestamp was dropped from structure(); it gates 'since'-filtered DISCOVER replies and is set on every config change, so losing it would silently stop discovery responses after a reboot. Added as "disc_mod". Merge artifacts repaired - Restored bblanchon/ArduinoJson to the native test env; a clean but wrong auto-merge at the lib_deps block boundary dropped it and broke all 19 host test suites. - Migrated the fork's WebConfig UITask screens off the removed DisplayDriver::Color enum to upstream's UIColor element types. - Removed duplicate getCADEnabled() definitions in companion MyMesh.cpp and simple_sensor SensorMesh.cpp that both sides had added. - Dropped memset(&_prefs, 0, ...) in the four example meshes; NodePrefs now has a vtable. guard gains an initializer that memset used to provide. Other resolutions - simple_room_server keeps both the fork's discover.* commands and upstream's new room.post. - docs/payloads.md taken from upstream, undoing content earlier merges had reverted (Control data section, split login tables). Verified: 273/273 host tests pass across native and native_kiss_modem; Heltec v3 repeater, repeater_observer_mqtt, room_server_observer_mqtt, sensor, and companion_radio_ble all build clean.
105 lines
3.6 KiB
C++
105 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include <Mesh.h>
|
|
#include <RadioLib.h>
|
|
|
|
struct PacketMillis {
|
|
uint32_t preambleMillis; // preamble-detect -> header-valid deadline
|
|
uint32_t payloadMillis; // header-valid -> rx-done deadline
|
|
};
|
|
|
|
class RadioLibWrapper : public mesh::Radio {
|
|
protected:
|
|
PhysicalLayer* _radio;
|
|
mesh::MainBoard* _board;
|
|
uint32_t n_recv, n_sent, n_recv_errors;
|
|
int16_t _noise_floor, _threshold;
|
|
bool _cad_enabled;
|
|
uint16_t _num_floor_samples;
|
|
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;
|
|
|
|
void idle() override;
|
|
void startRecv() override;
|
|
float packetScoreInt(float snr, int sf, int packet_len);
|
|
virtual bool isReceivingPacket() =0;
|
|
virtual void doResetAGC();
|
|
|
|
public:
|
|
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board), _preamble_sf(0) {
|
|
n_recv = n_sent = n_recv_errors = 0;
|
|
last_recv_millis = 0;
|
|
last_radio_interrupt_millis = 0;
|
|
_cad_enabled = false;
|
|
}
|
|
|
|
void begin() override;
|
|
virtual void powerOff() { _radio->sleep(); }
|
|
int recvRaw(uint8_t* bytes, int sz) override;
|
|
uint32_t getEstAirtimeFor(int len_bytes) override;
|
|
bool startSendRaw(const uint8_t* bytes, int len) override;
|
|
bool isSendComplete() override;
|
|
void onSendFinished() override;
|
|
bool isInRecvMode() const override;
|
|
bool isChannelActive();
|
|
|
|
bool isReceiving() override {
|
|
if (isReceivingPacket()) return true;
|
|
|
|
return isChannelActive();
|
|
}
|
|
|
|
virtual void setParams(float freq, float bw, uint8_t sf, uint8_t cr) = 0;
|
|
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 sf <= 8 ? 32 : 16; }
|
|
void updatePreamble(uint8_t sf) { _preamble_sf = sf; _radio->setPreambleLength(preambleLengthForSF(sf)); }
|
|
PacketMillis calcMaxPacketMillis(uint8_t sf, float bw, uint8_t cr, uint8_t preambleSymbols);
|
|
virtual int16_t performChannelScan();
|
|
|
|
int getNoiseFloor() const override { return _noise_floor; }
|
|
void triggerNoiseFloorCalibrate(int threshold) override;
|
|
void setCADEnabled(bool enable) override { _cad_enabled = enable; }
|
|
void resetAGC() override;
|
|
|
|
void loop() override;
|
|
|
|
uint32_t getPacketsRecv() const { return n_recv; }
|
|
uint32_t getPacketsRecvErrors() const override { return n_recv_errors; }
|
|
uint32_t getPacketsSent() const { return n_sent; }
|
|
void resetStats() { n_recv = n_sent = n_recv_errors = 0; }
|
|
|
|
uint8_t getRadioState() const override;
|
|
unsigned long getLastRecvMillis() const override { return last_recv_millis; }
|
|
unsigned long getLastRadioInterruptMillis() const override { return last_radio_interrupt_millis; }
|
|
|
|
virtual float getLastRSSI() const override;
|
|
virtual float getLastSNR() const override;
|
|
|
|
float packetScore(float snr, int packet_len) override { return packetScoreInt(snr, 10, packet_len); } // assume sf=10
|
|
|
|
virtual bool setRxBoostedGainMode(bool) { return false; }
|
|
virtual bool getRxBoostedGainMode() const { return false; }
|
|
};
|
|
|
|
/**
|
|
* \brief an RNG impl using the noise from the LoRa radio as entropy.
|
|
* NOTE: this is VERY SLOW! Use only for things like creating new LocalIdentity
|
|
*/
|
|
class RadioNoiseListener : public mesh::RNG {
|
|
PhysicalLayer* _radio;
|
|
public:
|
|
RadioNoiseListener(PhysicalLayer& radio): _radio(&radio) { }
|
|
|
|
void random(uint8_t* dest, size_t sz) override {
|
|
for (int i = 0; i < sz; i++) {
|
|
dest[i] = _radio->randomByte() ^ (::random(0, 256) & 0xFF);
|
|
}
|
|
}
|
|
};
|