From 1ab5bf43559413519d9b4e95273951eaa00da4b8 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 14 Sep 2024 07:44:40 -0500 Subject: [PATCH] Use the time.age() value to correct stale GPS times (#4705) * Use the time.age() value to correct stale GPS times * Trunk --------- Co-authored-by: Ben Meadors --- src/gps/GPS.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 046f277ff..8abb4edb1 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1539,7 +1539,7 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). */ struct tm t; - t.tm_sec = ti.second(); + t.tm_sec = ti.second() + round(ti.age() / 1000); t.tm_min = ti.minute(); t.tm_hour = ti.hour(); t.tm_mday = d.day(); @@ -1547,8 +1547,8 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s t.tm_year = d.year() - 1900; t.tm_isdst = false; if (t.tm_mon > -1) { - LOG_DEBUG("NMEA GPS time %02d-%02d-%02d %02d:%02d:%02d\n", d.year(), d.month(), t.tm_mday, t.tm_hour, t.tm_min, - t.tm_sec); + LOG_DEBUG("NMEA GPS time %02d-%02d-%02d %02d:%02d:%02d age %d\n", d.year(), d.month(), t.tm_mday, t.tm_hour, t.tm_min, + t.tm_sec, ti.age()); perhapsSetRTC(RTCQualityGPS, t); return true; } else @@ -1807,4 +1807,4 @@ void GPS::toggleGpsMode() enable(); } } -#endif // Exclude GPS \ No newline at end of file +#endif // Exclude GPS