From 6e4e52d181242c83ae8d4c2ee531ca8c73bca206 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Sun, 18 Oct 2026 22:48:49 +0200 Subject: [PATCH] =?UTF-8?q?companion:=20clkreboot=20srovn=C3=A1=20hodiny?= =?UTF-8?q?=20nap=C5=99ed=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- examples/companion_radio/MyMesh.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 32b7a7f1..7ec3960b 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -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;