companion: clkreboot srovná hodiny napřed (#5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-18 22:48:49 +02:00
1 parent 21425b5d65
commit 6e4e52d181
1 file changed
+15
+15
View File
@@ -2117,6 +2117,8 @@ void MyMesh::enterCLIRescue() {
Serial.println("========= CLI Rescue =========");
}
extern "C" void retainedClockInvalidate() __attribute__((weak)); // NRF52Board.cpp
bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
while (*command == ' ') command++; // skip leading spaces
@@ -2143,6 +2145,19 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
return true;
}
// CUSTOM (TeTeHacko): the only way to move an over-set clock BACKWARDS.
// CMD_SET_DEVICE_TIME refuses to, and since the clock survives a warm reset on
// nRF52 (ArduinoHelpers.h) a plain `reboot` no longer drops it to the build
// epoch either -- without this a companion that is ahead stays ahead until its
// power is pulled. Same as the repeater's `clkreboot` (CommonCLI.cpp). Then set
// the right time again (the app, or `time` from a host); forward is allowed.
if (strcmp(command, "clkreboot") == 0) {
if (retainedClockInvalidate) retainedClockInvalidate();
getRTCClock()->setCurrentTime(FIRMWARE_BUILD_EPOCH);
board.reboot(); // doesn't return
return true;
}
if (strcmp(command, "poweroff") == 0 || strcmp(command, "shutdown") == 0) {
board.powerOff(); // doesn't return
return true;