fix #540 use gps to fix rtc clock drift every 12 hrs

1.2-legacy
Kevin Hester 2020-12-27 12:54:44 +08:00
rodzic 2edc6b363d
commit 21570fc24f
1 zmienionych plików z 16 dodań i 2 usunięć

Wyświetl plik

@ -31,9 +31,23 @@ void readFromRTC()
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
{
static uint32_t lastSetMsec = 0;
uint32_t now = millis();
bool shouldSet;
if (q > currentQuality) {
currentQuality = q;
DEBUG_MSG("Setting RTC %ld secs\n", tv->tv_sec);
shouldSet = true;
DEBUG_MSG("Upgrading time to RTC %ld secs (quality %d)\n", tv->tv_sec, q);
} else if(q == RTCQualityGPS && (now - lastSetMsec) > (12 * 60 * 60 * 1000L)) {
// Every 12 hrs we will slam in a new GPS time, to correct for local RTC clock drift
shouldSet = true;
DEBUG_MSG("Reapplying GPS time to correct clock drift %ld secs\n", tv->tv_sec);
}
else
shouldSet = false;
if (shouldSet) {
lastSetMsec = now;
#ifndef NO_ESP32
settimeofday(tv, NULL);
#else