From 6c6df28b856c4a7e58bc2d642f5992e677459109 Mon Sep 17 00:00:00 2001 From: daijoubu Date: Tue, 9 Jun 2026 19:54:27 -0700 Subject: [PATCH] fix(gps): clamp negative uBlox nano field before millis conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The nano field in UBX-NAV-TIMEUTC and UBX-NAV-PVT messages is int32_t and legitimately goes negative near second boundaries. Dividing without clamping produced a large positive uint16_t (e.g. -50ms → 65486 ms), setting the RTC ~64 seconds fast on first GPS lock. Once set, rtcHasTime() prevents correction until reboot. Clamp to zero before the division on both message handlers. --- src/main/io/gps_ublox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/io/gps_ublox.c b/src/main/io/gps_ublox.c index 4fd0c332a21..95feedabb6c 100755 --- a/src/main/io/gps_ublox.c +++ b/src/main/io/gps_ublox.c @@ -635,7 +635,7 @@ static bool gpsParseFrameUBLOX(void) gpsSolDRV.time.hours = _buffer.timeutc.hour; gpsSolDRV.time.minutes = _buffer.timeutc.min; gpsSolDRV.time.seconds = _buffer.timeutc.sec; - gpsSolDRV.time.millis = _buffer.timeutc.nano / (1000*1000); + gpsSolDRV.time.millis = (uint16_t)(MAX(0, _buffer.timeutc.nano) / (1000*1000)); gpsSolDRV.flags.validTime = true; } else { @@ -674,7 +674,7 @@ static bool gpsParseFrameUBLOX(void) gpsSolDRV.time.hours = _buffer.pvt.hour; gpsSolDRV.time.minutes = _buffer.pvt.min; gpsSolDRV.time.seconds = _buffer.pvt.sec; - gpsSolDRV.time.millis = _buffer.pvt.nano / (1000*1000); + gpsSolDRV.time.millis = (uint16_t)(MAX(0, _buffer.pvt.nano) / (1000*1000)); gpsSolDRV.flags.validTime = true; } else {