diff --git a/src/modules/uavcan/sensors/gnss.cpp b/src/modules/uavcan/sensors/gnss.cpp index 625c2ac7af..1e5f366db2 100644 --- a/src/modules/uavcan/sensors/gnss.cpp +++ b/src/modules/uavcan/sensors/gnss.cpp @@ -346,6 +346,23 @@ void UavcanGnssBridge::process_fixx(const uavcan::ReceivedDataStructure } } +//TODO px4_clock_settime does nothing on the Snapdragon platform +#ifndef __PX4_QURT + + // If we haven't already done so, set the system clock using GPS data + if (valid_pos_cov && !_system_clock_set) { + timespec ts; + memset(&ts, 0, sizeof(ts)); + // get the whole microseconds + ts.tv_sec = report.time_utc_usec / 1000000ULL; + // get the remainder microseconds and convert to nanoseconds + ts.tv_nsec = (report.time_utc_usec % 1000000ULL) * 1000; + px4_clock_settime(CLOCK_REALTIME, &ts); + _system_clock_set = true; + } + +#endif + report.satellites_used = msg.sats_used; // Using PDOP for HDOP and VDOP diff --git a/src/modules/uavcan/sensors/gnss.hpp b/src/modules/uavcan/sensors/gnss.hpp index da5b6ffda8..2018a71266 100644 --- a/src/modules/uavcan/sensors/gnss.hpp +++ b/src/modules/uavcan/sensors/gnss.hpp @@ -111,4 +111,6 @@ private: orb_advert_t _report_pub; ///< uORB pub for gnss position int _orb_sub_gnss = -1; ///< uORB sub for gnss position, used for bridging uORB --> UAVCAN + + bool _system_clock_set = false; ///< Have we set the system clock at least once from GNSS data? };