feat(repeater): blink on|off, txpwr with RadioLib's verdict; UF2 flash helper
blink: a fixed burst is a race against walking to the bench -- 30 blinks (~7 s) was not enough to find the board in time. `blink on` now runs until `blink off`, with a 10-minute backstop so a node left blinking does not quietly eat a battery. Cap on the counted form raised to 999. txpwr: `set tx` cannot tell you whether the radio took the value. It clamps to -9..30, saves the pref and replies "OK", but SX1262 accepts only -9..+22 and rejects the rest WITHOUT touching the PA -- so `get tx` can report a power the radio never had. An earlier sweep here measured +2 dBm and -9 dBm as RSSI -44.1 and -44.0 at a witness and concluded runtime tx power "does not work"; that conclusion rested on an instrument that could not distinguish a refused request from a link that does not care. RadioLibWrapper::setTxPower keeps the status now (the signature stays void, it implements an upstream callback), and `txpwr [dBm]` reports it. It deliberately does not write the pref, so a sweep cannot leave a node booting at some experimental power. xiao_uf2_flash.sh: the 1200-baud touch is roughly a coin flip on this build. Today it worked twice, then wedged x4, then wedged x1 -- and a wedged board is gone from USB *and* BLE, does not recover on its own (waited 400 s) and needs a physical replug. Not a "too soon after boot" effect: x1 had been up 23 minutes. Double-tap RESET into UF2 is reliable and takes seconds, so this makes that the easy path. It refuses to act when several UF2 drives are present rather than guessing, since they are all labelled XIAO-SENSE. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29d620e1a6
commit
59e974854f
4 files changed
+116
-16
No files matched your search
@@ -1629,6 +1629,10 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
||||
// since a board with no data cable and no BLE cannot be identified at all.
|
||||
extern bool identHandleCommand(const char* command, char* reply);
|
||||
if (identHandleCommand(command, reply)) return;
|
||||
// CUSTOM (TeTeHacko): `txpwr [dBm]` — set output power and report RadioLib's
|
||||
// verdict, which `set tx` swallows. See main.cpp.
|
||||
extern bool txPwrHandleCommand(const char* command, char* reply);
|
||||
if (txPwrHandleCommand(command, reply)) return;
|
||||
#if defined(BLE_PIN_CODE) && defined(NRF52_PLATFORM)
|
||||
// CUSTOM (TeTeHacko): `ble on|off|ble` — implemented in main.cpp (BLE console).
|
||||
// Available from serial, the BLE console and remotely via MC (admin remote CLI).
|
||||
|
||||
@@ -45,11 +45,22 @@
|
||||
#define RPT_IDENT_LED_MS 120 // half-period; 120 ms reads as a clear flash
|
||||
#endif
|
||||
|
||||
// `blink on` keeps going until `blink off`, because a fixed burst is a race
|
||||
// against how long it takes to walk to the bench -- the first version capped at
|
||||
// 30 blinks (~7 s) and that was not enough to find the board. Held blinking
|
||||
// still expires on its own: a node left blinking would quietly eat a battery,
|
||||
// and on a mounted node nobody would notice.
|
||||
#ifndef RPT_IDENT_HOLD_MS
|
||||
#define RPT_IDENT_HOLD_MS (10UL * 60UL * 1000UL) // 10 min
|
||||
#endif
|
||||
|
||||
#ifdef RPT_IDENT_LED_PIN
|
||||
static uint8_t ident_edges_left = 0; // remaining on/off transitions
|
||||
static uint16_t ident_edges_left = 0; // remaining on/off transitions
|
||||
static bool ident_led_on = false;
|
||||
static unsigned long ident_next_ms = 0;
|
||||
static bool ident_pin_ready = false;
|
||||
static bool ident_hold = false; // blink until told to stop
|
||||
static unsigned long ident_hold_until = 0;
|
||||
|
||||
// LED_STATE_ON is 0 on XIAO (active low) and 1 elsewhere; go through it rather
|
||||
// than hard-coding HIGH/LOW, or the "blink" is an unlit board on half the fleet.
|
||||
@@ -57,27 +68,51 @@ static inline void identLedWrite(bool on) {
|
||||
digitalWrite(RPT_IDENT_LED_PIN, on ? LED_STATE_ON : !LED_STATE_ON);
|
||||
}
|
||||
|
||||
static void identStart(int blinks) {
|
||||
if (blinks < 1) blinks = 1;
|
||||
if (blinks > 30) blinks = 30;
|
||||
static void identBegin() {
|
||||
if (!ident_pin_ready) {
|
||||
pinMode(RPT_IDENT_LED_PIN, OUTPUT);
|
||||
ident_pin_ready = true;
|
||||
}
|
||||
ident_edges_left = (uint8_t)(blinks * 2); // one on + one off per blink
|
||||
ident_led_on = true;
|
||||
identLedWrite(true);
|
||||
ident_next_ms = millis() + RPT_IDENT_LED_MS;
|
||||
}
|
||||
|
||||
static void identStart(int blinks) {
|
||||
if (blinks < 1) blinks = 1;
|
||||
if (blinks > 999) blinks = 999;
|
||||
ident_hold = false;
|
||||
ident_edges_left = (uint16_t)(blinks * 2); // one on + one off per blink
|
||||
identBegin();
|
||||
}
|
||||
|
||||
static void identHold(bool on) {
|
||||
ident_hold = on;
|
||||
ident_edges_left = 0;
|
||||
if (on) {
|
||||
ident_hold_until = millis() + RPT_IDENT_HOLD_MS;
|
||||
identBegin();
|
||||
} else if (ident_pin_ready) {
|
||||
identLedWrite(false);
|
||||
}
|
||||
}
|
||||
|
||||
static void identStop() { identHold(false); }
|
||||
|
||||
static void identTick() {
|
||||
if (ident_edges_left == 0) return;
|
||||
if ((long)(millis() - ident_next_ms) < 0) return;
|
||||
ident_edges_left--;
|
||||
if (ident_edges_left == 0) {
|
||||
identLedWrite(false); // always finish dark, never leave it lit
|
||||
if (ident_hold) {
|
||||
if ((long)(millis() - ident_hold_until) >= 0) { identStop(); return; }
|
||||
} else if (ident_edges_left == 0) {
|
||||
return;
|
||||
}
|
||||
if ((long)(millis() - ident_next_ms) < 0) return;
|
||||
if (!ident_hold) {
|
||||
ident_edges_left--;
|
||||
if (ident_edges_left == 0) {
|
||||
identLedWrite(false); // always finish dark, never leave it lit
|
||||
return;
|
||||
}
|
||||
}
|
||||
ident_led_on = !ident_led_on;
|
||||
identLedWrite(ident_led_on);
|
||||
ident_next_ms = millis() + RPT_IDENT_LED_MS;
|
||||
@@ -89,10 +124,22 @@ static void identTick() {
|
||||
bool identHandleCommand(const char* command, char* reply) {
|
||||
if (memcmp(command, "blink", 5) != 0 || (command[5] != 0 && command[5] != ' ')) return false;
|
||||
#ifdef RPT_IDENT_LED_PIN
|
||||
int n = (command[5] == ' ') ? atoi(&command[6]) : 6;
|
||||
if (n == 0) n = 6;
|
||||
identStart(n);
|
||||
sprintf(reply, "OK - blinking %d times", n > 30 ? 30 : (n < 1 ? 1 : n));
|
||||
const char* arg = (command[5] == ' ') ? &command[6] : "";
|
||||
while (*arg == ' ') arg++;
|
||||
if (strcmp(arg, "on") == 0) {
|
||||
identHold(true);
|
||||
sprintf(reply, "OK - blinking until `blink off` (or %lu min)",
|
||||
(unsigned long)(RPT_IDENT_HOLD_MS / 60000UL));
|
||||
} else if (strcmp(arg, "off") == 0) {
|
||||
identStop();
|
||||
strcpy(reply, "OK - blinking off");
|
||||
} else {
|
||||
int n = arg[0] ? atoi(arg) : 6;
|
||||
if (n < 1) n = 6;
|
||||
if (n > 999) n = 999;
|
||||
identStart(n);
|
||||
sprintf(reply, "OK - blinking %d times", n);
|
||||
}
|
||||
#else
|
||||
strcpy(reply, "ERR: no spare LED on this board");
|
||||
#endif
|
||||
@@ -386,6 +433,37 @@ SimpleMeshTables tables;
|
||||
|
||||
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
|
||||
|
||||
// CUSTOM (TeTeHacko): `txpwr [dBm]` -- set LoRa output power and report what
|
||||
// RadioLib actually did with the request.
|
||||
//
|
||||
// `set tx` cannot answer that. It clamps to -9..30, saves the pref and replies
|
||||
// "OK", but SX1262 accepts only -9..+22 and rejects anything outside that range
|
||||
// WITHOUT touching the PA -- so `get tx` can report a power the radio never took.
|
||||
// A power sweep built on that is measuring nothing, and an earlier sweep here was
|
||||
// in exactly that position: +2 dBm and -9 dBm both produced RSSI -44.1/-44.0 at a
|
||||
// witness, with no way to tell "the radio ignored me" from "the link does not
|
||||
// care". This is the missing instrument for that measurement.
|
||||
//
|
||||
// Deliberately does NOT write the pref, so a sweep cannot leave a node booting
|
||||
// at some experimental power; use `set tx` when the value should persist.
|
||||
// Status 0 = RADIOLIB_ERR_NONE, -13 = RADIOLIB_ERR_INVALID_OUTPUT_POWER.
|
||||
bool txPwrHandleCommand(const char* command, char* reply) {
|
||||
if (memcmp(command, "txpwr", 5) != 0 || (command[5] != 0 && command[5] != ' ')) return false;
|
||||
if (command[5] == ' ') {
|
||||
int dbm = atoi(&command[6]);
|
||||
radio_driver.setTxPower((int8_t) dbm);
|
||||
int16_t st = radio_driver.getLastTxPowerStatus();
|
||||
sprintf(reply, "%s - txpwr %d dBm, RadioLib status %d%s", st == RADIOLIB_ERR_NONE ? "OK" : "ERR",
|
||||
dbm, (int) st,
|
||||
st == RADIOLIB_ERR_INVALID_OUTPUT_POWER ? " (out of range, PA UNCHANGED)" : "");
|
||||
} else {
|
||||
sprintf(reply, "txpwr: last request %d dBm, status %d (SX1262 accepts -9..22)",
|
||||
(int) radio_driver.getLastTxPowerRequested(),
|
||||
(int) radio_driver.getLastTxPowerStatus());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void halt() {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,13 @@ uint32_t RadioLibWrapper::getRngSeed() {
|
||||
}
|
||||
|
||||
void RadioLibWrapper::setTxPower(int8_t dbm) {
|
||||
_radio->setOutputPower(dbm);
|
||||
// CUSTOM (TeTeHacko): keep the status. The signature is an upstream callback
|
||||
// and has to stay void, but the return value must not be thrown away: SX1262
|
||||
// accepts only -9..+22 dBm and rejects the rest WITHOUT touching the PA, while
|
||||
// `set tx` clamps to -9..30, saves the pref and replies "OK". Without this,
|
||||
// "the radio refused" and "the radio changed" look identical from the console.
|
||||
_last_txpow_dbm = dbm;
|
||||
_last_txpow_status = _radio->setOutputPower(dbm);
|
||||
}
|
||||
|
||||
void RadioLibWrapper::idle() {
|
||||
|
||||
@@ -12,6 +12,8 @@ protected:
|
||||
uint16_t _num_floor_samples;
|
||||
int32_t _floor_sample_sum;
|
||||
uint8_t _preamble_sf;
|
||||
int16_t _last_txpow_status; // CUSTOM (TeTeHacko): see getLastTxPowerStatus()
|
||||
int8_t _last_txpow_dbm;
|
||||
|
||||
void idle();
|
||||
void startRecv();
|
||||
@@ -20,7 +22,8 @@ protected:
|
||||
virtual void doResetAGC();
|
||||
|
||||
public:
|
||||
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board), _preamble_sf(0) { n_recv = n_sent = 0; }
|
||||
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board), _preamble_sf(0),
|
||||
_last_txpow_status(0), _last_txpow_dbm(0) { n_recv = n_sent = 0; }
|
||||
|
||||
void begin() override;
|
||||
virtual void powerOff() { _radio->sleep(); }
|
||||
@@ -41,6 +44,15 @@ public:
|
||||
virtual void setParams(float freq, float bw, uint8_t sf, uint8_t cr) = 0;
|
||||
uint32_t getRngSeed();
|
||||
void setTxPower(int8_t dbm);
|
||||
// CUSTOM (TeTeHacko): RadioLib status of the LAST setTxPower() call.
|
||||
// setTxPower() has to stay void (it implements an upstream callback), but
|
||||
// discarding the status made a failed change indistinguishable from a
|
||||
// successful one: SX1262 only accepts -9..+22 dBm and REJECTS anything else
|
||||
// without touching the PA, while `set tx` clamps to -9..30, saves the pref and
|
||||
// answers "OK". The node then reports a tx power the radio never took.
|
||||
// 0 = RADIOLIB_ERR_NONE, -13 = RADIOLIB_ERR_INVALID_OUTPUT_POWER.
|
||||
int16_t getLastTxPowerStatus() const { return _last_txpow_status; }
|
||||
int8_t getLastTxPowerRequested() const { return _last_txpow_dbm; }
|
||||
|
||||
virtual float getCurrentRSSI() =0;
|
||||
virtual uint8_t getSpreadingFactor() const { return LORA_SF; }
|
||||
|
||||
Reference in new issue
Block a user