diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index c33cadda..43c82da4 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -195,7 +195,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { stats.n_packets_recv = radio_driver.getPacketsRecv(); stats.n_packets_sent = radio_driver.getPacketsSent(); stats.total_air_time_secs = getTotalAirTime() / 1000; - stats.total_up_time_secs = _ms->getMillis() / 1000; + stats.total_up_time_secs = getUptimeSecs(); stats.n_sent_flood = getNumSentFlood(); stats.n_sent_direct = getNumSentDirect(); stats.n_recv_flood = getNumRecvFlood(); @@ -254,6 +254,14 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { if (packet->isRouteFlood() && packet->path_len >= _prefs.flood_max) return false; return true; } + + uint32_t getUptimeSecs() const { + if (_cli.bootTime == 0) { + return _ms->getMillis() / 1000; + } else { + return (getRTCClock()->getCurrentTime() - _cli.bootTime); + } + } const char* getLogDateTime() override { static char tmp[32]; @@ -647,6 +655,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void setLoggingOn(bool enable) override { _logging = enable; } + void setBootTime(uint32_t boot_time) { + _cli.bootTime = boot_time; + } + void eraseLogFile() override { _fs->remove(PACKET_LOG_FILE); } diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index f5c1e9dc..76098483 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -305,7 +305,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { stats.n_packets_recv = radio_driver.getPacketsRecv(); stats.n_packets_sent = radio_driver.getPacketsSent(); stats.total_air_time_secs = getTotalAirTime() / 1000; - stats.total_up_time_secs = _ms->getMillis() / 1000; + stats.total_up_time_secs = getUptimeSecs(); stats.n_sent_flood = getNumSentFlood(); stats.n_sent_direct = getNumSentDirect(); stats.n_recv_flood = getNumRecvFlood(); @@ -403,6 +403,14 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { return (int) ((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time); } + uint32_t getUptimeSecs() const { + if (_cli.bootTime == 0) { + return _ms->getMillis() / 1000; + } else { + return (getRTCClock()->getCurrentTime() - _cli.bootTime); + } + } + const char* getLogDateTime() override { static char tmp[32]; uint32_t now = getRTCClock()->getCurrentTime(); @@ -807,6 +815,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { } } + void setBootTime(uint32_t boot_time) { + _cli.bootTime = boot_time; // set the boot time for CLI + } + void setLoggingOn(bool enable) override { _logging = enable; } void eraseLogFile() override { diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 323f3633..289128bc 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -143,6 +143,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch } else if (memcmp(command, "clock sync", 10) == 0) { uint32_t curr = getRTCClock()->getCurrentTime(); if (sender_timestamp > curr) { + if (bootTime == 0) { + _callbacks->setBootTime(sender_timestamp - (millis()/1000)); + } getRTCClock()->setCurrentTime(sender_timestamp + 1); uint32_t now = getRTCClock()->getCurrentTime(); DateTime dt = DateTime(now); @@ -162,6 +165,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch uint32_t secs = _atoi(&command[5]); uint32_t curr = getRTCClock()->getCurrentTime(); if (secs > curr) { + if (bootTime == 0) { + _callbacks->setBootTime(sender_timestamp - (millis()/1000)); + } getRTCClock()->setCurrentTime(secs); uint32_t now = getRTCClock()->getCurrentTime(); DateTime dt = DateTime(now); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 1778c715..6ee26323 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -45,6 +45,7 @@ class CommonCLICallbacks { virtual void formatNeighborsReply(char *reply) = 0; virtual const uint8_t* getSelfIdPubKey() = 0; virtual void clearStats() = 0; + virtual void setBootTime(uint32_t bootTime) = 0; }; class CommonCLI { @@ -65,6 +66,7 @@ class CommonCLI { CommonCLI(mesh::MainBoard& board, mesh::RTCClock& rtc, NodePrefs* prefs, CommonCLICallbacks* callbacks) : _board(&board), _rtc(&rtc), _prefs(prefs), _callbacks(callbacks) { } + uint32_t bootTime = 0; void loadPrefs(FILESYSTEM* _fs); void savePrefs(FILESYSTEM* _fs); void handleCommand(uint32_t sender_timestamp, const char* command, char* reply);