Skip to content

Fix repeater/room server uptime rollover issue. #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 13 additions & 1 deletion examples/simple_room_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/CommonCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/CommonCLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down