aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/gps/ashtech.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/gps/ashtech.cpp')
-rw-r--r--src/drivers/gps/ashtech.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/drivers/gps/ashtech.cpp b/src/drivers/gps/ashtech.cpp
index 99dbe5984..a50767c22 100644
--- a/src/drivers/gps/ashtech.cpp
+++ b/src/drivers/gps/ashtech.cpp
@@ -99,21 +99,26 @@ int ASHTECH::handle_message(int len)
timeinfo.tm_sec = int(ashtech_sec);
time_t epoch = mktime(&timeinfo);
- uint64_t usecs = static_cast<uint64_t>((ashtech_sec - static_cast<uint64_t>(ashtech_sec))) * 1e6;
-
- // FMUv2+ boards have a hardware RTC, but GPS helps us to configure it
- // and control its drift. Since we rely on the HRT for our monotonic
- // clock, updating it from time to time is safe.
+ if (epoch > GPS_EPOCH_SECS) {
+ uint64_t usecs = static_cast<uint64_t>((ashtech_sec - static_cast<uint64_t>(ashtech_sec))) * 1e6;
+
+ // FMUv2+ boards have a hardware RTC, but GPS helps us to configure it
+ // and control its drift. Since we rely on the HRT for our monotonic
+ // clock, updating it from time to time is safe.
+
+ timespec ts;
+ ts.tv_sec = epoch;
+ ts.tv_nsec = usecs * 1000;
+ if (clock_settime(CLOCK_REALTIME, &ts)) {
+ warn("failed setting clock");
+ }
- timespec ts;
- ts.tv_sec = epoch;
- ts.tv_nsec = usecs * 1000;
- if (clock_settime(CLOCK_REALTIME, &ts)) {
- warn("failed setting clock");
+ _gps_position->time_utc_usec = static_cast<uint64_t>(epoch) * 1000000ULL;
+ _gps_position->time_utc_usec += usecs;
+ } else {
+ _gps_position->time_utc_usec = 0;
}
- _gps_position->time_utc_usec = static_cast<uint64_t>(epoch) * 1000000ULL;
- _gps_position->time_utc_usec += usecs;
_gps_position->timestamp_time = hrt_absolute_time();
}