Skip to content

Commit

Permalink
Stop past timestamps from setting our system time RTC (#4704)
Browse files Browse the repository at this point in the history
* Ignore attempts to set times in the past (before our build epoch)

* TRONK
  • Loading branch information
thebentern authored Sep 14, 2024
1 parent b59bd6f commit 35cfe43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ build_flags = -Wno-missing-field-initializers
-DRADIOLIB_EXCLUDE_APRS
-DRADIOLIB_EXCLUDE_LORAWAN
-DMESHTASTIC_EXCLUDE_DROPZONE=1
-DBUILD_EPOCH=$UNIX_TIME
;-D OLED_PL

monitor_speed = 115200
Expand Down
6 changes: 6 additions & 0 deletions src/gps/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate)
static uint32_t lastSetMsec = 0;
uint32_t now = millis();
uint32_t printableEpoch = tv->tv_sec; // Print lib only supports 32 bit but time_t can be 64 bit on some platforms
#ifdef BUILD_EPOCH
if (tv->tv_sec < BUILD_EPOCH) {
LOG_WARN("Ignoring time (%ld) before build epoch (%ld)!\n", printableEpoch, BUILD_EPOCH);
return false;
}
#endif

bool shouldSet;
if (forceUpdate) {
Expand Down

0 comments on commit 35cfe43

Please sign in to comment.