aboutsummaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2015-01-04 10:44:40 +0100
committerLorenz Meier <lm@inf.ethz.ch>2015-01-04 10:45:20 +0100
commit50a00bee8ed56d41d1c3e74eaaa7997191793595 (patch)
treed043e9e03ca34ff0ed2b8704cf7b855b25dc06ff /src/drivers
parent96a8003826346dd75e336ac496a8527cf0b41a01 (diff)
downloadpx4-firmware-50a00bee8ed56d41d1c3e74eaaa7997191793595.tar.gz
px4-firmware-50a00bee8ed56d41d1c3e74eaaa7997191793595.tar.bz2
px4-firmware-50a00bee8ed56d41d1c3e74eaaa7997191793595.zip
GPS driver: UBX time handling for all protocol revisions
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/gps/ubx.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/drivers/gps/ubx.cpp b/src/drivers/gps/ubx.cpp
index 4563fb65c..c67965487 100644
--- a/src/drivers/gps/ubx.cpp
+++ b/src/drivers/gps/ubx.cpp
@@ -748,17 +748,19 @@ UBX::payload_rx_done(void)
timeinfo.tm_sec = _buf.payload_rx_nav_pvt.sec;
time_t epoch = mktime(&timeinfo);
-#ifndef CONFIG_RTC
- //Since we lack a hardware RTC, set the system time clock based on GPS UTC
- //TODO generalize this by moving into gps.cpp?
+ // 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 = _buf.payload_rx_nav_pvt.nano;
- clock_settime(CLOCK_REALTIME, &ts);
-#endif
+ if (clock_settime(CLOCK_REALTIME, &ts)) {
+ warn("failed setting clock");
+ }
- _gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this
- _gps_position->time_gps_usec += (uint64_t)(_buf.payload_rx_nav_pvt.nano * 1e-3f);
+ _gps_position->time_gps_usec = static_cast<uint64_t>(epoch) * 1000000ULL;
+ _gps_position->time_gps_usec += _buf.payload_rx_nav_timeutc.nano / 1000;
}
_gps_position->timestamp_time = hrt_absolute_time();
@@ -818,11 +820,10 @@ UBX::payload_rx_done(void)
timeinfo.tm_sec = _buf.payload_rx_nav_timeutc.sec;
time_t epoch = mktime(&timeinfo);
- // FMUv2+ have a hardware RTC, but GPS helps us to configure it
+ // 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.
- // TODO generalize this by moving into gps.cpp?
timespec ts;
ts.tv_sec = epoch;
ts.tv_nsec = _buf.payload_rx_nav_timeutc.nano;
@@ -830,7 +831,7 @@ UBX::payload_rx_done(void)
warn("failed setting clock");
}
- _gps_position->time_gps_usec = ((uint64_t)epoch) * 1000000ULL;
+ _gps_position->time_gps_usec = static_cast<uint64_t>(epoch) * 1000000ULL;
_gps_position->time_gps_usec += _buf.payload_rx_nav_timeutc.nano / 1000;
}