Merge remote-tracking branch 'origin/keymindCascade' into keymindCascade
This commit is contained in:
commit
e8ac3ddc6b
41 files changed
+2542
-92
No files matched your search
@@ -94,6 +94,9 @@ public:
|
||||
virtual bool supportsMeshtext() const { return false; }
|
||||
virtual bool supportsEthernetTunnel() const { return false; }
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
// Check the requested antenna power at the prospective beacon frequency.
|
||||
// Validation must not retune the radio or alter its current power setting.
|
||||
virtual bool validateBeaconPower(float, int8_t) const { return false; }
|
||||
virtual RadioParamApplyResult prepareBeaconTransmit(const RadioProfileParams&, int8_t) {
|
||||
return RadioParamApplyResult::FAILED;
|
||||
}
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
|
||||
#include <helpers/BeaconFrames.h>
|
||||
#include <helpers/radiolib/RadioPowerLimits.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace mesh {
|
||||
@@ -12,7 +11,7 @@ bool Mesh::validateTextBeacon(const BeaconSlot& slot) const {
|
||||
if (!beacon::validText(slot.text) || slot.hops > 7
|
||||
|| !RadioProfiles::valid(slot.radio)
|
||||
|| !RadioProfiles::safePreamble(slot.radio, slot.radio.preamble ? slot.radio.preamble : 32)
|
||||
|| slot.power < -9 || !isLoRaTxPowerValid(slot.power, slot.radio.freq)
|
||||
|| !_radio->validateBeaconPower(slot.radio.freq, slot.power)
|
||||
|| !_radio->validateProfile(slot.radio)) return false;
|
||||
if (slot.radio.protocol == RadioProfileProtocol::MeshCore) return true;
|
||||
#if MESH_ENABLE_MESHTEXT_WIRE
|
||||
|
||||
@@ -21,10 +21,14 @@ void ArduinoSerialInterface::resetReceiveState() {
|
||||
_frame_len = 0;
|
||||
rx_len = 0;
|
||||
_last_rx_byte_ms = 0;
|
||||
_receive_capacity_paused = false;
|
||||
_receive_capacity_paused_at = 0;
|
||||
}
|
||||
|
||||
void ArduinoSerialInterface::serviceReceiveTimeout() {
|
||||
updateReceiveCapacityPause(millis());
|
||||
if (_state != RECV_STATE_IDLE && _serial != nullptr
|
||||
&& !_receive_capacity_paused
|
||||
&& _serial->available() == 0
|
||||
&& (uint32_t)(millis() - _last_rx_byte_ms) >= RX_FRAME_TIMEOUT_MS) {
|
||||
// A truncated length-prefixed frame must not hold the MCU awake forever or
|
||||
@@ -33,6 +37,40 @@ void ArduinoSerialInterface::serviceReceiveTimeout() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ArduinoSerialInterface::responseCapacityAvailable() const {
|
||||
if (!_flow_ctl || _tx_queue_len < TX_QUEUE_SIZE) return true;
|
||||
// Match enqueueFrame(): a required reply may replace an unsent best-effort
|
||||
// push, but the prefix of a partly sent frame must remain intact.
|
||||
for (uint8_t i = _tx_offset == 0 ? 0 : 1; i < _tx_queue_len; ++i) {
|
||||
const TxFrame& frame = _tx_queue[i];
|
||||
if (!mesh::companionFrameRequiresDelivery(&frame.buf[3], frame.len - 3)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ArduinoSerialInterface::updateReceiveCapacityPause(uint32_t now) {
|
||||
if (_state == RECV_STATE_IDLE) {
|
||||
_receive_capacity_paused = false;
|
||||
_receive_capacity_paused_at = 0;
|
||||
return;
|
||||
}
|
||||
const bool pause = !responseCapacityAvailable();
|
||||
if (pause && !_receive_capacity_paused) {
|
||||
// Backpressure must not retroactively extend an already expired frame.
|
||||
if ((uint32_t)(now - _last_rx_byte_ms) >= RX_FRAME_TIMEOUT_MS) return;
|
||||
_receive_capacity_paused = true;
|
||||
_receive_capacity_paused_at = now;
|
||||
} else if (!pause && _receive_capacity_paused) {
|
||||
// Bytes retained for reply capacity keep the framing budget they had when
|
||||
// RX was paused, even if the host takes a long time to resume reading.
|
||||
_last_rx_byte_ms += (uint32_t)(now - _receive_capacity_paused_at);
|
||||
_receive_capacity_paused = false;
|
||||
_receive_capacity_paused_at = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ArduinoSerialInterface::resetTransmitState() {
|
||||
_tx_queue_len = 0;
|
||||
_tx_offset = 0;
|
||||
@@ -82,6 +120,7 @@ bool ArduinoSerialInterface::enqueueFrame(const uint8_t src[], size_t len) {
|
||||
frame.buf[1] = (uint8_t)(len & 0xFF);
|
||||
frame.buf[2] = (uint8_t)(len >> 8);
|
||||
memcpy(&frame.buf[3], src, len);
|
||||
updateReceiveCapacityPause(millis());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -204,6 +243,7 @@ bool ArduinoSerialInterface::isConnected() const {
|
||||
void ArduinoSerialInterface::loop() {
|
||||
serviceReceiveTimeout();
|
||||
serviceTransmit();
|
||||
updateReceiveCapacityPause(millis());
|
||||
}
|
||||
|
||||
bool ArduinoSerialInterface::isReadBusy() const {
|
||||
@@ -240,6 +280,7 @@ size_t ArduinoSerialInterface::writeFrame(const uint8_t src[], size_t len) {
|
||||
}
|
||||
if (!enqueueFrame(src, len)) return 0;
|
||||
serviceTransmit();
|
||||
updateReceiveCapacityPause(millis());
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -255,7 +296,12 @@ size_t ArduinoSerialInterface::checkRecvFrame(uint8_t dest[]) {
|
||||
if (_serial == nullptr || dest == nullptr) return 0;
|
||||
serviceReceiveTimeout();
|
||||
serviceTransmit();
|
||||
updateReceiveCapacityPause(millis());
|
||||
if (_passthroughMode) return 0;
|
||||
// Immediate command handlers do not retain rejected replies. Leave the
|
||||
// complete input and any partial parser state untouched until one required
|
||||
// response can be admitted, rather than executing a command without a reply.
|
||||
if (!responseCapacityAvailable()) return 0;
|
||||
|
||||
// Newly arriving bytes belong to the next mesh loop; a continuously writing
|
||||
// host must not keep the radio/watchdog loop trapped in this parser.
|
||||
|
||||
@@ -38,6 +38,8 @@ private:
|
||||
uint32_t _last_frame_ms;
|
||||
uint32_t _completed_frame_count;
|
||||
uint32_t _last_rx_byte_ms;
|
||||
uint32_t _receive_capacity_paused_at;
|
||||
bool _receive_capacity_paused;
|
||||
bool _has_received_frame;
|
||||
Stream* _serial;
|
||||
const char* _controlSequence;
|
||||
@@ -51,6 +53,8 @@ private:
|
||||
bool checkControlLineByte(uint8_t c);
|
||||
void resetReceiveState();
|
||||
void serviceReceiveTimeout();
|
||||
bool responseCapacityAvailable() const;
|
||||
void updateReceiveCapacityPause(uint32_t now);
|
||||
void resetTransmitState();
|
||||
bool enqueueFrame(const uint8_t src[], size_t len);
|
||||
void serviceTransmit();
|
||||
@@ -63,6 +67,7 @@ public:
|
||||
_controlSequenceCursor(nullptr), _secondaryControlSequenceCursor(nullptr),
|
||||
_frame_len(0), rx_len(0),
|
||||
_last_frame_ms(0), _completed_frame_count(0), _last_rx_byte_ms(0),
|
||||
_receive_capacity_paused_at(0), _receive_capacity_paused(false),
|
||||
_has_received_frame(false),
|
||||
_serial(nullptr), _controlSequence(nullptr),
|
||||
_secondaryControlSequence(nullptr), _conn_check(nullptr),
|
||||
@@ -114,11 +119,13 @@ public:
|
||||
// Optional: queue complete frames and drain one at a time according to the
|
||||
// stream's TX capacity, so short writes cannot discard or interleave bytes.
|
||||
// Report busy while a frame remains queued so bulk streams get paced.
|
||||
// Defer input, including control lines, while a required reply cannot fit.
|
||||
// Only enable this for streams which really implement availableForWrite()
|
||||
// (USB-CDC does, the Print default returns 0).
|
||||
void enableFlowControl(bool enable) {
|
||||
if (!enable) resetTransmitState();
|
||||
_flow_ctl = enable;
|
||||
updateReceiveCapacityPause(millis());
|
||||
}
|
||||
|
||||
// BaseSerialInterface methods
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <Mesh.h>
|
||||
#include <helpers/FilePresence.h>
|
||||
#include <helpers/MeshtextChat.h>
|
||||
#include <helpers/UTF8Helpers.h>
|
||||
#include <Arduino.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@@ -75,12 +76,15 @@ bool decodeSlot(const uint8_t bytes[RecordSize], BeaconSlot& slot) {
|
||||
slot.power = int8_t(bytes[13]); slot.preset = bytes[14]; slot.hops = bytes[15];
|
||||
slot.enabled = true;
|
||||
memcpy(slot.text, bytes + 17, BeaconSlot::TextCapacity);
|
||||
const size_t text_length = strlen(slot.text);
|
||||
// Reject noncanonical trailing data instead of carrying hidden text bytes.
|
||||
for (size_t i = strlen(slot.text) + 1; i < BeaconSlot::TextCapacity; ++i)
|
||||
for (size_t i = text_length + 1; i < BeaconSlot::TextCapacity; ++i)
|
||||
if (slot.text[i]) return false;
|
||||
for (const unsigned char* c = reinterpret_cast<const unsigned char*>(slot.text); *c; ++c)
|
||||
if (*c < 32 || *c == 127) return false;
|
||||
return isfinite(slot.radio.freq) && isfinite(slot.radio.bw)
|
||||
return validUtf8PrefixLength(slot.text, text_length) == text_length
|
||||
&& RadioProfiles::valid(slot.radio)
|
||||
&& RadioProfiles::safePreamble(slot.radio, slot.radio.preamble ? slot.radio.preamble : 32)
|
||||
&& (slot.radio.protocol != RadioProfileProtocol::Meshtext
|
||||
|| (slot.preset <= uint8_t(mt::Preset::LongSlow) && slot.radio.preamble == 16));
|
||||
}
|
||||
@@ -218,7 +222,9 @@ BeaconManager::ReadResult BeaconManager::readConfig(
|
||||
}
|
||||
crc = crcUpdate(crc, bytes, sizeof(bytes));
|
||||
BeaconSlot slot;
|
||||
if (!decodeSlot(bytes, slot) || (slot.enabled && (!mesh_ || !mesh_->validateTextBeacon(slot)))
|
||||
// Disk validity is independent of the current board's radio capabilities.
|
||||
// Preserve unsupported slots so an upgrade can still query/repair them.
|
||||
if (!decodeSlot(bytes, slot)
|
||||
|| (slot.enabled && slot.radio.protocol == RadioProfileProtocol::Meshtext && !header[6]))
|
||||
valid = false;
|
||||
if (output) output[i] = slot;
|
||||
@@ -254,14 +260,19 @@ BeaconManager::ReadResult BeaconManager::readIds(const char* path, uint32_t& las
|
||||
bool BeaconManager::commit(const char* path, const char* backup,
|
||||
const char* temporary, bool& hold) {
|
||||
bool active_present = false, backup_present = false;
|
||||
bool active_backed_up = false;
|
||||
if (!filePresence(fs_, path, active_present) || !filePresence(fs_, backup, backup_present)) return false;
|
||||
if (active_present) {
|
||||
if (backup_present && !fs_->remove(backup)) return false;
|
||||
if (!fs_->rename(path, backup)) return false;
|
||||
active_backed_up = true;
|
||||
backup_present = true;
|
||||
}
|
||||
if (!fs_->rename(temporary, path)) {
|
||||
if (backup_present && !fs_->rename(backup, path)) hold = true;
|
||||
// A pre-existing backup can be older than an already transmitted ID.
|
||||
// Roll back only the active image moved by this transaction; promoting
|
||||
// an unrelated backup could make that ID reusable after the next boot.
|
||||
if (active_backed_up && !fs_->rename(backup, path)) hold = true;
|
||||
return false;
|
||||
}
|
||||
// A leftover backup after a successful commit is harmless. Never choose it
|
||||
@@ -398,7 +409,9 @@ void BeaconManager::loop(uint32_t now) {
|
||||
if (hour > 0 && handled_hour_ != hour) {
|
||||
const unsigned index = unsigned((hour - 1) % SlotCount);
|
||||
BeaconSlot& slot = slots_[index];
|
||||
if (!slot.enabled) handled_hour_ = hour;
|
||||
// A retained slot may be unsupported by this board or firmware. Skip it
|
||||
// before allocating a durable Meshtext packet ID or entering the TX queue.
|
||||
if (!slot.enabled || !mesh_->validateTextBeacon(slot)) handled_hour_ = hour;
|
||||
else {
|
||||
uint64_t guard = last_send_ && elapsed_ - last_send_ < HourMillis
|
||||
? HourMillis - (elapsed_ - last_send_) : 0;
|
||||
|
||||
@@ -34,6 +34,35 @@ static unsigned parseDays(const char* text) {
|
||||
} while (*text);
|
||||
return days;
|
||||
}
|
||||
|
||||
// MGR2 has three or four decimal version bytes, followed only by an optional
|
||||
// release/build label. Keep that label opaque for existing tagged builds.
|
||||
static bool parseManagementFirmwareVersion(const char* text, uint32_t& version) {
|
||||
if (!text) return false;
|
||||
if (*text == 'v') ++text;
|
||||
uint32_t packed = 0;
|
||||
unsigned components = 0;
|
||||
while (true) {
|
||||
if (*text < '0' || *text > '9') return false;
|
||||
unsigned component = 0;
|
||||
do {
|
||||
const unsigned digit = *text++ - '0';
|
||||
if (component > (255U - digit) / 10U) return false;
|
||||
component = component * 10U + digit;
|
||||
} while (*text >= '0' && *text <= '9');
|
||||
packed = (packed << 8) | component;
|
||||
++components;
|
||||
if (*text != '.') break;
|
||||
if (components == 4) return false;
|
||||
++text;
|
||||
}
|
||||
if (components < 3) return false;
|
||||
if (*text && ((*text != '-' && *text != '+') || !text[1])) return false;
|
||||
if (components == 3) packed <<= 8;
|
||||
version = packed;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct ManagementReporter::Working {
|
||||
History history;
|
||||
Extrema during_report;
|
||||
@@ -201,11 +230,9 @@ void ManagementReporter::snapshot() {
|
||||
#endif
|
||||
// If EndF is absent, only publish a version we can parse unambiguously.
|
||||
if (!(valid & FIRMWARE)) {
|
||||
unsigned major = 0, minor = 0, patch = 0, pre = 0;
|
||||
const char* version = callbacks.getFirmwareVer(); if (*version == 'v') ++version;
|
||||
const int n = sscanf(version, "%u.%u.%u.%u", &major, &minor, &patch, &pre);
|
||||
if (n >= 3 && major <= 255 && minor <= 255 && patch <= 255 && pre <= 255) {
|
||||
write32(p + 28, major << 24 | minor << 16 | patch << 8 | pre); valid |= FIRMWARE;
|
||||
uint32_t version;
|
||||
if (parseManagementFirmwareVersion(callbacks.getFirmwareVer(), version)) {
|
||||
write32(p + 28, version); valid |= FIRMWARE;
|
||||
}
|
||||
}
|
||||
write16(p + 76, valid);
|
||||
|
||||
@@ -114,8 +114,12 @@ bool FolderMotaStore::finalize() {
|
||||
}
|
||||
|
||||
bool FolderMotaStore::reopen() {
|
||||
_reopen_io_error = false;
|
||||
uint8_t pl[5];
|
||||
if (!txn(MS_OP_STAT, _mid, 4, pl, 5)) return false;
|
||||
if (!txn(MS_OP_STAT, _mid, 4, pl, 5)) {
|
||||
_reopen_io_error = true;
|
||||
return false;
|
||||
}
|
||||
if (pl[0] == 0) return false; // host has no partial/complete file -> start fresh
|
||||
uint32_t total = rd_u32le(pl + 1);
|
||||
if (total < 13) return false; // implausible container
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
void clear() override { _total = 0; }
|
||||
bool finalize() override;
|
||||
bool reopen() override; // OP_STAT: adopt an existing file for resume
|
||||
bool reopenHadIoError() const override { return _reopen_io_error; }
|
||||
bool canReconnect() const override { return true; }
|
||||
|
||||
// A host-backed store is fully random-access, so it needs no pinned-meta RAM page and no layout planning.
|
||||
@@ -58,6 +59,7 @@ private:
|
||||
MotaStreamWritePolicy _write_policy;
|
||||
uint8_t _mid[4] = {0, 0, 0, 0};
|
||||
uint32_t _total = 0;
|
||||
bool _reopen_io_error = false;
|
||||
};
|
||||
|
||||
} // namespace ota
|
||||
|
||||
@@ -773,7 +773,9 @@ static __attribute__((noinline)) bool handle_control_command(
|
||||
return true;
|
||||
}
|
||||
snprintf(reply, 160, "OK %s mid=%s -> %s (primary traffic)",
|
||||
result == OtaManager::PULL_RESUMED ? "resuming" : "pulling", midhx, dname);
|
||||
c.manager.fetchState() == OtaManager::PAUSED
|
||||
? "paused (folder I/O error; reconnect to resume)"
|
||||
: result == OtaManager::PULL_RESUMED ? "resuming" : "pulling", midhx, dname);
|
||||
|
||||
// ---- discard the current session (e.g. a stalled old fetch) to free the slot ----
|
||||
} else if (is_cmd(a, "drop|cancel|stop", &rest)) {
|
||||
|
||||
@@ -1572,10 +1572,21 @@ OtaManager::PullResult OtaManager::startFetch(const uint8_t* mid, uint32_t targe
|
||||
// A validate pull is a FRESH seed capture, not a resume: the store already holds the seed's payload (not a
|
||||
// real partial), so never adopt it via resumeStaged - always re-begin and run the manifest->leaves->diff.
|
||||
const bool automatic = !_have_desired_mid && _desired_target == 0 && !_archive_fetch;
|
||||
if (!validate && resumeStagedFor(mid, automatic)) return PULL_RESUMED; // adopt a partial container left in the store
|
||||
memcpy(_fid, mid, 4);
|
||||
_have = 0; _fbc = 0; _ftotal = 0; _fflags = 0;
|
||||
_observed_path_transmissions = 0; // learn the actual source/relay path from this fetch's replies
|
||||
if (!validate) {
|
||||
if (resumeStagedFor(mid, automatic)) return PULL_RESUMED;
|
||||
if (_fetch_error == FETCH_ERROR_STORAGE) {
|
||||
// A failed host read cannot authorize BEGIN to erase a valid partial.
|
||||
// IDLE records that adoption itself must be retried on reconnect; no
|
||||
// fresh-container initialization has been authorized yet.
|
||||
_fstate = PAUSED;
|
||||
_paused_from = IDLE;
|
||||
clearReassembly();
|
||||
return PULL_STARTED;
|
||||
}
|
||||
}
|
||||
_fstate = WANT_MANIFEST;
|
||||
_mf_total = 0; _mf_mask = 0; _mf_len = 0; _mf_retries = 0; _loop_last_mfmask = 0; // fresh manifest reassembly
|
||||
memset(_mf_buf, 0, sizeof(_mf_buf));
|
||||
@@ -1616,7 +1627,14 @@ bool OtaManager::pauseFetchForDisconnect() {
|
||||
|
||||
bool OtaManager::resumeFetchAfterReconnect() {
|
||||
if (_fstate != PAUSED || !_fetch) return false;
|
||||
if (_paused_from == WANT_MANIFEST || _paused_from == WANT_LEAVES) {
|
||||
if (_paused_from == IDLE) {
|
||||
// The first resume probe lost its link before it could establish whether
|
||||
// staging was usable. Retry it before allowing a fresh initialization.
|
||||
uint8_t mid[4]; memcpy(mid, _fid, sizeof(mid));
|
||||
_fstate = IDLE;
|
||||
PullResult result = startFetch(mid, _fexpected_target, _validate);
|
||||
if ((result != PULL_STARTED && result != PULL_RESUMED) || _fstate == PAUSED) return false;
|
||||
} else if (_paused_from == WANT_MANIFEST || _paused_from == WANT_LEAVES) {
|
||||
// begin/header/manifest/trailer may only have partly reached the host.
|
||||
// Re-request the manifest and run the full initialization transaction.
|
||||
// Leaf-diff also restarts initialization: the reconnected host may have
|
||||
@@ -1859,15 +1877,23 @@ bool OtaManager::resumeStagedFor(const uint8_t* want_mid, bool automatic_resume)
|
||||
const uint32_t expected_target = automatic_resume
|
||||
? (_migration_target ? _migration_target : _target)
|
||||
: _fexpected_target;
|
||||
if (!_fetch->reopenFor(want_mid, expected_target)) return false;
|
||||
auto readFailure = [&]() {
|
||||
if (_fetch->canReconnect()) _fetch_error = FETCH_ERROR_STORAGE;
|
||||
return false;
|
||||
};
|
||||
if (!_fetch->reopenFor(want_mid, expected_target)) {
|
||||
return _fetch->reopenHadIoError() ? readFailure() : false;
|
||||
}
|
||||
uint32_t total = _fetch->staged_size();
|
||||
uint8_t hdr[8];
|
||||
if (total < 8u + MOTA_MFL + 5u || !_fetch->read(0, hdr, sizeof(hdr))
|
||||
|| memcmp(hdr, MOTA_MAGIC, 4) != 0 || rd_u32le(hdr + 4) != total) return false;
|
||||
if (total < 8u + MOTA_MFL + 5u) return false;
|
||||
if (!_fetch->read(0, hdr, sizeof(hdr))) return readFailure();
|
||||
if (memcmp(hdr, MOTA_MAGIC, 4) != 0 || rd_u32le(hdr + 4) != total) return false;
|
||||
// read + parse the stored manifest (everything before leaves[]) to recompute the geometry
|
||||
uint8_t mbuf[MOTA_MFL];
|
||||
MotaManifest m;
|
||||
if (!_fetch->read(8, mbuf, sizeof(mbuf)) || !mota_parse_manifest(mbuf, sizeof(mbuf), m)) return false;
|
||||
if (!_fetch->read(8, mbuf, sizeof(mbuf))) return readFailure();
|
||||
if (!mota_parse_manifest(mbuf, sizeof(mbuf), m)) return false;
|
||||
if (want_mid && memcmp(m.merkle_root, want_mid, 4) != 0) return false; // a different fw is staged
|
||||
// A boot-time resume is an automatic fetch decision and therefore belongs
|
||||
// only to this node. An explicit pull retains target=0 as an intentional
|
||||
@@ -1896,8 +1922,8 @@ bool OtaManager::resumeStagedFor(const uint8_t* want_mid, bool automatic_resume)
|
||||
uint32_t payload_off = leaves_off + bc * 4;
|
||||
if ((uint64_t)payload_off + m.payload_size + 5 != total) return false; // geometry must match the header
|
||||
uint8_t trailer[5];
|
||||
if (!_fetch->read(total - sizeof(trailer), trailer, sizeof(trailer))
|
||||
|| memcmp(trailer, MOTA_TRAILER, sizeof(trailer)) != 0) return false;
|
||||
if (!_fetch->read(total - sizeof(trailer), trailer, sizeof(trailer))) return readFailure();
|
||||
if (memcmp(trailer, MOTA_TRAILER, sizeof(trailer)) != 0) return false;
|
||||
|
||||
_wire_v2_session = _wire_v2_enabled;
|
||||
_wire_v2_confirmed = false;
|
||||
|
||||
@@ -70,6 +70,12 @@ public:
|
||||
(void)want_mid; (void)expected_target; return reopen();
|
||||
}
|
||||
|
||||
// A failed reopen normally means no usable container, so a new pull may
|
||||
// begin by erasing it. Reconnectable stores must distinguish an I/O failure:
|
||||
// an unavailable host has not established that its staged bytes are invalid.
|
||||
// Query only after reopen()/reopenFor() returned false.
|
||||
virtual bool reopenHadIoError() const { return false; }
|
||||
|
||||
// External host stores can disappear temporarily while retaining their file.
|
||||
// Preserve the selected fetch on an I/O failure until that link reconnects.
|
||||
virtual bool canReconnect() const { return false; }
|
||||
|
||||
@@ -139,6 +139,12 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
bool checkBeaconOutputPower(float frequency_mhz, int8_t dbm) const override {
|
||||
(void)frequency_mhz;
|
||||
return dbm >= _min_dbm && dbm <= _max_dbm;
|
||||
}
|
||||
#endif
|
||||
// Emit a gain-control code. Override for a PA driven by PWM or an external
|
||||
// DAC instead of the MCU's own.
|
||||
virtual void writeGainControl(uint8_t code) {
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "RadioLibWrappers.h"
|
||||
#include "RadioInterruptEvents.h"
|
||||
#include "RadioProfileChip.h"
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
#include "RadioPowerLimits.h"
|
||||
#endif
|
||||
#include <new>
|
||||
#if defined(ESP32_PLATFORM)
|
||||
#include <esp_heap_caps.h>
|
||||
@@ -559,6 +562,39 @@ mesh::RadioParamApplyResult RadioLibWrapper::tuneProfile(uint8_t profile) {
|
||||
}
|
||||
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
bool RadioLibWrapper::validateBeaconPower(float frequency_mhz, int8_t power) const {
|
||||
return isfinite(frequency_mhz) && mesh::isLoRaTxPowerValid(power, frequency_mhz)
|
||||
&& checkBeaconOutputPower(frequency_mhz, power);
|
||||
}
|
||||
|
||||
bool RadioLibWrapper::checkBeaconOutputPower(float frequency_mhz, int8_t power) const {
|
||||
(void)frequency_mhz;
|
||||
#if MESH_RADIO_PROFILE_CHIP == 1276
|
||||
// SX127x's setter automatically selects RFO below 2 dBm. Its two-argument
|
||||
// checker assumes PA_BOOST, so use the same selection as setOutputPower().
|
||||
return static_cast<SX1276*>(_radio)->checkOutputPower(power, nullptr, power < 2)
|
||||
== RADIOLIB_ERR_NONE;
|
||||
#elif MESH_RADIO_PROFILE_CHIP == 1272
|
||||
return static_cast<SX1272*>(_radio)->checkOutputPower(power, nullptr, power < 2)
|
||||
== RADIOLIB_ERR_NONE;
|
||||
#elif MESH_RADIO_PROFILE_CHIP == 1121
|
||||
// RadioLib's checker uses its current band. Validate the prospective band
|
||||
// without changing the cached frequency or triggering a hardware retune.
|
||||
if (frequency_mhz > 1000.0f) return power >= -18 && power <= 13;
|
||||
#ifdef LR1121_FORCE_HP_PA
|
||||
return power >= -9 && power <= 22;
|
||||
#else
|
||||
return power >= -17 && power <= 22;
|
||||
#endif
|
||||
#elif MESH_RADIO_PROFILE_CHIP == 2021
|
||||
return mesh::lr2021::isHighBand(frequency_mhz)
|
||||
? power >= -19 && power <= 12 : power >= -9 && power <= 22;
|
||||
#else
|
||||
// These RadioLib checkers inspect configuration only; no SPI is performed.
|
||||
return _radio->checkOutputPower(power, nullptr) == RADIOLIB_ERR_NONE;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t RadioLibWrapper::getBeaconAirtime(const mesh::RadioProfileParams& p, int length) {
|
||||
if (length <= 0 || length > MAX_TRANS_UNIT || !validateProfile(p)) return 0;
|
||||
const uint16_t preamble = p.protocol == mesh::RadioProfileProtocol::Meshtext
|
||||
@@ -596,7 +632,8 @@ mesh::RadioParamApplyResult RadioLibWrapper::prepareBeaconTransmit(
|
||||
_hil_beacon_tx_frequency_mhz = 0;
|
||||
if (!mesh::hilTransmitFrequencyAllowed(p.freq)) return Result::FAILED;
|
||||
#endif
|
||||
if (!_params_valid || !_dbm_valid || !getBeaconAirtime(p, MAX_TRANS_UNIT)) return Result::FAILED;
|
||||
if (!_params_valid || !_dbm_valid || !getBeaconAirtime(p, MAX_TRANS_UNIT)
|
||||
|| !validateBeaconPower(p.freq, power)) return Result::FAILED;
|
||||
if (isCalibratingNoiseFloor()) return Result::BUSY;
|
||||
|
||||
beginProfileRetune(isInRecvMode() && !_rx_ps_armed && !_rx_ps_enabled);
|
||||
|
||||
@@ -272,6 +272,11 @@ protected:
|
||||
virtual int16_t applyCachedTxPower(int8_t dbm) {
|
||||
return _radio->setOutputPower(dbm);
|
||||
}
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
// External amplifiers override this in antenna dBm. The public capability
|
||||
// still checks the board's explicit limits before consulting this hook.
|
||||
virtual bool checkBeaconOutputPower(float frequency_mhz, int8_t dbm) const;
|
||||
#endif
|
||||
virtual bool applyRxBoostedGainMode(bool) { return false; }
|
||||
virtual int16_t enterCarrierWave() { return _radio->transmitDirect(); }
|
||||
virtual bool validateMorseFrequency(float frequency_mhz) const {
|
||||
@@ -409,6 +414,7 @@ public:
|
||||
mesh::RadioParamApplyResult prepareTransmitProfile(uint8_t profile) override;
|
||||
mesh::RadioParamApplyResult prepareTransmitProfile(uint8_t profile, bool reply_rx_override) override;
|
||||
#if MESH_ENABLE_TX_BEACONS
|
||||
bool validateBeaconPower(float frequency_mhz, int8_t power) const override;
|
||||
mesh::RadioParamApplyResult prepareBeaconTransmit(const mesh::RadioProfileParams& params,
|
||||
int8_t power) override;
|
||||
mesh::RadioParamApplyResult restoreBeaconReceive() override;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
// -1: no reliable observation, 0: confirmed non-RX mode, 1: RX.
|
||||
// GetStatus is C0 followed by one response byte (Semtech sx126x driver).
|
||||
// RadioLib's pinned getStatus() requests zero payload bytes and returns zero.
|
||||
// RadioLib 7.8.1 also reads that response directly. This probe additionally
|
||||
// avoids waiting on BUSY, preserves the SPI layout and checks transport errors.
|
||||
template <typename Radio>
|
||||
inline int8_t sx126xReceiveMode(Radio* radio) {
|
||||
Module* module = radio->getMod();
|
||||
|
||||
Reference in new issue
Block a user