From 1e618a7eb07edc79cc0effba4f9d3bdde5dc2f07 Mon Sep 17 00:00:00 2001 From: Tom Willow Date: Sat, 27 Dec 2025 08:50:37 +0800 Subject: [PATCH] gps: use UTC timestamp when GPS fixed (#26127) --- src/modules/mavlink/streams/GPS2_RAW.hpp | 8 +++++++- src/modules/mavlink/streams/GPS_RAW_INT.hpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/mavlink/streams/GPS2_RAW.hpp b/src/modules/mavlink/streams/GPS2_RAW.hpp index 08f80877d9..025421e471 100644 --- a/src/modules/mavlink/streams/GPS2_RAW.hpp +++ b/src/modules/mavlink/streams/GPS2_RAW.hpp @@ -68,7 +68,13 @@ private: hrt_abstime now{}; if (_sensor_gps_sub.update(&gps)) { - msg.time_usec = gps.timestamp; + if (gps.time_utc_usec > 0) { + msg.time_usec = gps.timestamp; + + } else { + msg.time_usec = gps.time_utc_usec; + } + msg.fix_type = gps.fix_type; msg.lat = static_cast(round(gps.latitude_deg * 1e7)); msg.lon = static_cast(round(gps.longitude_deg * 1e7)); diff --git a/src/modules/mavlink/streams/GPS_RAW_INT.hpp b/src/modules/mavlink/streams/GPS_RAW_INT.hpp index ca2077d5a7..a3b7620fb7 100644 --- a/src/modules/mavlink/streams/GPS_RAW_INT.hpp +++ b/src/modules/mavlink/streams/GPS_RAW_INT.hpp @@ -68,7 +68,13 @@ private: hrt_abstime now{}; if (_sensor_gps_sub.update(&gps)) { - msg.time_usec = gps.timestamp; + if (gps.time_utc_usec > 0) { + msg.time_usec = gps.timestamp; + + } else { + msg.time_usec = gps.time_utc_usec; + } + msg.fix_type = gps.fix_type; msg.lat = static_cast(round(gps.latitude_deg * 1e7)); msg.lon = static_cast(round(gps.longitude_deg * 1e7));