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;