diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-07 16:00:59 +0100 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-07 16:00:59 +0100 |
commit | fe279d340dccdd40ebfade4c53893e8f7a77b45e (patch) | |
tree | 6ca7e8517507e097097a45cca384c51d343b5fc7 /src/drivers | |
parent | 417a82c699c2512ca3b8998c91c9d77f5d826edb (diff) | |
parent | 6ed2f77ca5c713e537c8fd4a9aacd7adc7887f53 (diff) | |
download | px4-firmware-fe279d340dccdd40ebfade4c53893e8f7a77b45e.tar.gz px4-firmware-fe279d340dccdd40ebfade4c53893e8f7a77b45e.tar.bz2 px4-firmware-fe279d340dccdd40ebfade4c53893e8f7a77b45e.zip |
Merge remote-tracking branch 'upstream/master' into dev_ros
Conflicts:
Makefile
Diffstat (limited to 'src/drivers')
-rw-r--r-- | src/drivers/gps/mtk.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/drivers/gps/mtk.cpp b/src/drivers/gps/mtk.cpp index c0c47073b..c112f65a8 100644 --- a/src/drivers/gps/mtk.cpp +++ b/src/drivers/gps/mtk.cpp @@ -264,7 +264,7 @@ MTK::handle_message(gps_mtk_packet_t &packet) _gps_position->satellites_used = packet.satellites; /* convert time and date information to unix timestamp */ - struct tm timeinfo; //TODO: test this conversion + struct tm timeinfo; uint32_t timeinfo_conversion_temp; timeinfo.tm_mday = packet.date * 1e-4; @@ -280,8 +280,24 @@ MTK::handle_message(gps_mtk_packet_t &packet) timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; time_t epoch = mktime(&timeinfo); - _gps_position->time_utc_usec = epoch * 1e6; //TODO: test this - _gps_position->time_utc_usec += timeinfo_conversion_temp * 1e3; + if (epoch > GPS_EPOCH_SECS) { + // 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 = timeinfo_conversion_temp * 1000000ULL; + 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 += timeinfo_conversion_temp * 1000ULL; + } else { + _gps_position->time_utc_usec = 0; + } + _gps_position->timestamp_position = _gps_position->timestamp_time = hrt_absolute_time(); // Position and velocity update always at the same time |