NodeMaintenance, build_version.py: back to the original formatting
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
46d33bd2b0
commit
73c1a7beb2
3 files changed
+86
-107
No files matched your search
@@ -7,10 +7,10 @@
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
extern "C" {
|
||||
void enterUf2Dfu(void);
|
||||
void enterSerialDfu(void);
|
||||
void enterOTADfu(void);
|
||||
extern uint32_t g_hardfault_record[4]; // NRF52Board.cpp, .noinit: magic, pc, lr, psr
|
||||
void enterUf2Dfu(void);
|
||||
void enterSerialDfu(void);
|
||||
void enterOTADfu(void);
|
||||
extern uint32_t g_hardfault_record[4]; // NRF52Board.cpp, .noinit: magic, pc, lr, psr
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -30,21 +30,21 @@ void NodeMaintenance::printBootDiag() {
|
||||
// the build epoch" from "restored something" -- and comparing against the
|
||||
// epoch of a DIFFERENT build of the same tree invents discrepancies that are
|
||||
// not there. Cost one wrong conclusion here.
|
||||
Serial.printf("boot: FIRMWARE_BUILD_EPOCH=%lu\n", (unsigned long)FIRMWARE_BUILD_EPOCH);
|
||||
Serial.printf("boot: FIRMWARE_BUILD_EPOCH=%lu\n", (unsigned long) FIRMWARE_BUILD_EPOCH);
|
||||
Serial.printf("boot: RESETREAS=0x%08lX%s%s%s%s%s\n", (unsigned long)rr,
|
||||
rr == 0 ? " (none set = power-on/brownout: power was removed)" : "",
|
||||
(rr & 0x01) ? " RESETPIN" : "", (rr & 0x02) ? " WATCHDOG" : "",
|
||||
(rr & 0x04) ? " SREQ(sw reset, e.g. `dfu`/`reboot`)" : "", (rr & 0x08) ? " LOCKUP(!)" : "");
|
||||
rr == 0 ? " (none set = power-on/brownout: power was removed)" : "",
|
||||
(rr & 0x01) ? " RESETPIN" : "",
|
||||
(rr & 0x02) ? " WATCHDOG" : "",
|
||||
(rr & 0x04) ? " SREQ(sw reset, e.g. `dfu`/`reboot`)" : "",
|
||||
(rr & 0x08) ? " LOCKUP(!)" : "");
|
||||
|
||||
volatile uint32_t *hf = g_hardfault_record;
|
||||
volatile uint32_t* hf = g_hardfault_record;
|
||||
if (hf[0] == 0xFA010DEB) {
|
||||
_hardfault[0] = hf[1];
|
||||
_hardfault[1] = hf[2];
|
||||
_hardfault[2] = hf[3];
|
||||
_hardfault[0] = hf[1]; _hardfault[1] = hf[2]; _hardfault[2] = hf[3];
|
||||
_hardfault_seen = true;
|
||||
Serial.printf("!!! HARDFAULT before last reboot: PC=%08lX LR=%08lX PSR=%08lX\n", (unsigned long)hf[1],
|
||||
(unsigned long)hf[2], (unsigned long)hf[3]);
|
||||
hf[0] = 0; // printed once; `get boot` keeps it until the next reset
|
||||
Serial.printf("!!! HARDFAULT before last reboot: PC=%08lX LR=%08lX PSR=%08lX\n",
|
||||
(unsigned long)hf[1], (unsigned long)hf[2], (unsigned long)hf[3]);
|
||||
hf[0] = 0; // printed once; `get boot` keeps it until the next reset
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -53,7 +53,7 @@ void NodeMaintenance::printBootDiag() {
|
||||
// Reboots it caused and the threshold backoff survive power loss in a small file,
|
||||
// written only right before such a reboot and once when the radio proves itself.
|
||||
|
||||
void NodeMaintenance::silenceLoad(uint8_t *backoff) {
|
||||
void NodeMaintenance::silenceLoad(uint8_t* backoff) {
|
||||
*backoff = 0;
|
||||
if (!_fs || !_fs->exists(RADIO_SILENCE_FILE)) return;
|
||||
#if defined(RP2040_PLATFORM)
|
||||
@@ -62,7 +62,7 @@ void NodeMaintenance::silenceLoad(uint8_t *backoff) {
|
||||
File f = _fs->open(RADIO_SILENCE_FILE);
|
||||
#endif
|
||||
if (!f) return;
|
||||
if (f.read((uint8_t *)&_silence_reboots, sizeof(_silence_reboots)) != sizeof(_silence_reboots)) {
|
||||
if (f.read((uint8_t*)&_silence_reboots, sizeof(_silence_reboots)) != sizeof(_silence_reboots)) {
|
||||
_silence_reboots = 0;
|
||||
}
|
||||
if (f.read(backoff, 1) != 1) *backoff = 0;
|
||||
@@ -80,12 +80,12 @@ void NodeMaintenance::silenceSave(uint8_t backoff) {
|
||||
File f = _fs->open(RADIO_SILENCE_FILE, "w", true);
|
||||
#endif
|
||||
if (!f) return;
|
||||
f.write((const uint8_t *)&_silence_reboots, sizeof(_silence_reboots));
|
||||
f.write((const uint8_t*)&_silence_reboots, sizeof(_silence_reboots));
|
||||
f.write(&backoff, 1);
|
||||
f.close();
|
||||
}
|
||||
|
||||
void NodeMaintenance::begin(FILESYSTEM *fs, NodePrefs *prefs, CommonCLICallbacks *callbacks) {
|
||||
void NodeMaintenance::begin(FILESYSTEM* fs, NodePrefs* prefs, CommonCLICallbacks* callbacks) {
|
||||
_fs = fs;
|
||||
_prefs = prefs;
|
||||
_callbacks = callbacks;
|
||||
@@ -94,59 +94,59 @@ void NodeMaintenance::begin(FILESYSTEM *fs, NodePrefs *prefs, CommonCLICallbacks
|
||||
_silence.begin(millis(), radioActivity(), backoff);
|
||||
_silence.setMinutes(_prefs->radio_silence_min);
|
||||
Serial.printf("boot: radio silence watchdog %u min, reboots %lu, backoff x%u\n",
|
||||
(unsigned)_silence.minutes(), (unsigned long)_silence_reboots,
|
||||
(unsigned)(1u << _silence.backoff()));
|
||||
(unsigned) _silence.minutes(), (unsigned long) _silence_reboots,
|
||||
(unsigned) (1u << _silence.backoff()));
|
||||
}
|
||||
|
||||
void NodeMaintenance::loop() {
|
||||
dfuTick();
|
||||
_fw.loop();
|
||||
switch (_silence.poll(millis(), radioActivity())) {
|
||||
case RadioSilenceWatchdog::KICK_RX:
|
||||
Serial.printf("radio silence: nothing received for %lu min, re-arming RX\n",
|
||||
(unsigned long)(_silence.quietMs(millis()) / 60000));
|
||||
_radio.kickRx();
|
||||
break;
|
||||
case RadioSilenceWatchdog::REBOOT:
|
||||
Serial.printf("radio silence: still nothing after %lu min, rebooting\n",
|
||||
(unsigned long)(_silence.quietMs(millis()) / 60000));
|
||||
_silence_reboots++;
|
||||
silenceSave(_silence.nextBackoff());
|
||||
delay(100); // let the line out
|
||||
_board.reboot();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case RadioSilenceWatchdog::KICK_RX:
|
||||
Serial.printf("radio silence: nothing received for %lu min, re-arming RX\n",
|
||||
(unsigned long) (_silence.quietMs(millis()) / 60000));
|
||||
_radio.kickRx();
|
||||
break;
|
||||
case RadioSilenceWatchdog::REBOOT:
|
||||
Serial.printf("radio silence: still nothing after %lu min, rebooting\n",
|
||||
(unsigned long) (_silence.quietMs(millis()) / 60000));
|
||||
_silence_reboots++;
|
||||
silenceSave(_silence.nextBackoff());
|
||||
delay(100); // let the line out
|
||||
_board.reboot();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (_silence.takeBackoffCleared()) silenceSave(0);
|
||||
}
|
||||
|
||||
bool NodeMaintenance::silenceCommand(const char *command, char *reply) {
|
||||
bool NodeMaintenance::silenceCommand(const char* command, char* reply) {
|
||||
if (strcmp(command, "get radio.reboots") == 0) {
|
||||
sprintf(reply, "> %lu", (unsigned long)_silence_reboots);
|
||||
sprintf(reply, "> %lu", (unsigned long) _silence_reboots);
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "get radio.silence") == 0) {
|
||||
if (_silence.minutes() == 0) {
|
||||
strcpy(reply, "> off");
|
||||
} else {
|
||||
sprintf(reply, "> %u min (now x%u), quiet %lu min, stage %u", (unsigned)_silence.minutes(),
|
||||
(unsigned)(1u << _silence.backoff()), (unsigned long)(_silence.quietMs(millis()) / 60000),
|
||||
(unsigned)_silence.stage());
|
||||
sprintf(reply, "> %u min (now x%u), quiet %lu min, stage %u",
|
||||
(unsigned) _silence.minutes(), (unsigned) (1u << _silence.backoff()),
|
||||
(unsigned long) (_silence.quietMs(millis()) / 60000), (unsigned) _silence.stage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set radio.silence ", 18) == 0) {
|
||||
const char *arg = &command[18];
|
||||
const char* arg = &command[18];
|
||||
bool numeric = *arg != 0 && strspn(arg, "0123456789") == strlen(arg);
|
||||
int m = strcmp(arg, "off") == 0 ? 0 : (numeric ? atoi(arg) : -1);
|
||||
if (m < 0 || m > RadioSilenceWatchdog::MAX_MINUTES) {
|
||||
sprintf(reply, "ERR - minutes 0..%u (0/off = disabled)", (unsigned)RadioSilenceWatchdog::MAX_MINUTES);
|
||||
sprintf(reply, "ERR - minutes 0..%u (0/off = disabled)", (unsigned) RadioSilenceWatchdog::MAX_MINUTES);
|
||||
return true;
|
||||
}
|
||||
_prefs->radio_silence_min = (uint16_t)m;
|
||||
_prefs->radio_silence_min = (uint16_t) m;
|
||||
_callbacks->savePrefs();
|
||||
_silence.setMinutes((uint16_t)m);
|
||||
_silence.setMinutes((uint16_t) m);
|
||||
strcpy(reply, "OK");
|
||||
return true;
|
||||
}
|
||||
@@ -214,25 +214,21 @@ void NodeMaintenance::dfuTick() {
|
||||
// from here, and it is exactly what detach() does on this chip.
|
||||
NRF_USBD->USBPULLUP = 0;
|
||||
delay(150);
|
||||
if (_dfu_mode == 1)
|
||||
enterSerialDfu();
|
||||
else if (_dfu_mode == 2)
|
||||
enterOTADfu();
|
||||
else
|
||||
enterUf2Dfu();
|
||||
if (_dfu_mode == 1) enterSerialDfu();
|
||||
else if (_dfu_mode == 2) enterOTADfu();
|
||||
else enterUf2Dfu();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool NodeMaintenance::dfuCommand(uint32_t sender_timestamp, const char *command, char *reply) {
|
||||
bool NodeMaintenance::dfuCommand(uint32_t sender_timestamp, const char* command, char* reply) {
|
||||
if (memcmp(command, "dfu", 3) != 0 || (command[3] != 0 && command[3] != ' ')) return false;
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (sender_timestamp != 0) {
|
||||
strcpy(reply, "ERR: dfu is local-only (would strand the node in the bootloader)");
|
||||
return true;
|
||||
}
|
||||
const char *arg = (command[3] == ' ') ? &command[4] : "";
|
||||
while (*arg == ' ')
|
||||
arg++;
|
||||
const char* arg = (command[3] == ' ') ? &command[4] : "";
|
||||
while (*arg == ' ') arg++;
|
||||
if (strcmp(arg, "serial") == 0) {
|
||||
strcpy(reply, "OK - rebooting into serial DFU (CDC only, no drive)");
|
||||
} else if (strcmp(arg, "ota") == 0) {
|
||||
@@ -251,7 +247,7 @@ bool NodeMaintenance::dfuCommand(uint32_t sender_timestamp, const char *command,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NodeMaintenance::handleCommand(uint32_t sender_timestamp, const char *command, char *reply) {
|
||||
bool NodeMaintenance::handleCommand(uint32_t sender_timestamp, const char* command, char* reply) {
|
||||
if (dfuCommand(sender_timestamp, command, reply)) return true;
|
||||
if (_fw.handleCommand(sender_timestamp, command, reply)) return true;
|
||||
if (silenceCommand(command, reply)) return true;
|
||||
@@ -259,10 +255,10 @@ bool NodeMaintenance::handleCommand(uint32_t sender_timestamp, const char *comma
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (_hardfault_seen) {
|
||||
sprintf(reply, "> RESETREAS=0x%08lX, HARDFAULT before it: PC=%08lX LR=%08lX PSR=%08lX",
|
||||
(unsigned long)_reset_reason, (unsigned long)_hardfault[0], (unsigned long)_hardfault[1],
|
||||
(unsigned long)_hardfault[2]);
|
||||
(unsigned long) _reset_reason, (unsigned long) _hardfault[0],
|
||||
(unsigned long) _hardfault[1], (unsigned long) _hardfault[2]);
|
||||
} else {
|
||||
sprintf(reply, "> RESETREAS=0x%08lX, no hardfault", (unsigned long)_reset_reason);
|
||||
sprintf(reply, "> RESETREAS=0x%08lX, no hardfault", (unsigned long) _reset_reason);
|
||||
}
|
||||
#else
|
||||
strcpy(reply, "> not recorded on this platform");
|
||||
|
||||
Reference in new issue
Block a user