aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/gps
diff options
context:
space:
mode:
authortstellanova <tstellanova+github@gmail.com>2013-08-28 08:49:21 -0700
committertstellanova <tstellanova+github@gmail.com>2013-08-28 08:49:21 -0700
commitf2f66432d76dad2587d3e8089d0c728eb8fdf2ae (patch)
tree8fd5dac96847e46d95e4f7b2c3f1ff8f37b4c4c6 /src/drivers/gps
parent007f4d79cbd7edec6fb69e4556f35bac8dce72f2 (diff)
downloadpx4-firmware-f2f66432d76dad2587d3e8089d0c728eb8fdf2ae.tar.gz
px4-firmware-f2f66432d76dad2587d3e8089d0c728eb8fdf2ae.tar.bz2
px4-firmware-f2f66432d76dad2587d3e8089d0c728eb8fdf2ae.zip
Grab UTC time from GPS
Diffstat (limited to 'src/drivers/gps')
-rw-r--r--src/drivers/gps/ubx.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/drivers/gps/ubx.cpp b/src/drivers/gps/ubx.cpp
index b579db715..ba5d14cc4 100644
--- a/src/drivers/gps/ubx.cpp
+++ b/src/drivers/gps/ubx.cpp
@@ -42,13 +42,14 @@
*
* @see http://www.u-blox.com/images/downloads/Product_Docs/u-blox6_ReceiverDescriptionProtocolSpec_%28GPS.G6-SW-10018%29.pdf
*/
-
-#include <unistd.h>
-#include <stdio.h>
-#include <poll.h>
+#include <assert.h>
#include <math.h>
+#include <poll.h>
+#include <stdio.h>
#include <string.h>
-#include <assert.h>
+#include <time.h>
+#include <unistd.h>
+
#include <systemlib/err.h>
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_gps_position.h>
@@ -452,7 +453,16 @@ UBX::handle_message()
timeinfo.tm_min = packet->min;
timeinfo.tm_sec = packet->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?
+ timespec ts;
+ ts.tv_sec = epoch;
+ ts.tv_nsec = packet->time_nanoseconds;
+ clock_settime(CLOCK_REALTIME,&ts);
+#endif
+
_gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this
_gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f);
_gps_position->timestamp_time = hrt_absolute_time();