1From b2dfb6c27fcf4ddae87b0e99492f4bb8472fa39a Mon Sep 17 00:00:00 2001 2From: Eneas U de Queiroz <cotequeiroz@gmail.com> 3Date: Thu, 13 Feb 2020 17:26:41 -0300 4Subject: [PATCH] pud: adapt to API changes in gpsd 3.20 5 6The timestamp fields were changed from double to struct timespec, and 7the geoid separation field was moved to fix.geoid_sep. 8 9Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com> 10 11[Retrieved from: 12https://github.com/OLSR/olsrd/commit/b2dfb6c27fcf4ddae87b0e99492f4bb8472fa39a] 13Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 14--- 15 lib/pud/src/gpsdclient.c | 36 ++++++++++++++++++++++++++++++++---- 16 1 file changed, 32 insertions(+), 4 deletions(-) 17 18diff --git a/lib/pud/src/gpsdclient.c b/lib/pud/src/gpsdclient.c 19index 9e7fb708d..2a7a26eef 100644 20--- a/lib/pud/src/gpsdclient.c 21+++ b/lib/pud/src/gpsdclient.c 22@@ -79,6 +79,23 @@ static void gpsdError(const char *s) { 23 syslog(LOG_ERR, "gpsd error: %s", s); 24 } 25 26+#if GPSD_API_MAJOR_VERSION >= 9 27+static double time_as_double(struct timespec *ts) { 28+ return (ts->tv_sec + ts->tv_nsec * 1e-9); 29+} 30+ 31+static bool is_online(struct gps_data_t *gpsdata) { 32+ return !!gpsdata->online.tv_sec; 33+} 34+#else 35+ 36+#define time_as_double(x) *(x) 37+ 38+static bool is_online(struct gps_data_t *gpsdata) { 39+ return !!gpsdata->online; 40+} 41+#endif 42+ 43 /* standard parsing of a GPS data source spec */ 44 void gpsdParseSourceSpec(char *arg, GpsDaemon *gpsDaemon) { 45 if (!arg // 46@@ -298,8 +315,8 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon 47 8, // 48 dev->parity, // 49 dev->stopbits, // 50- dev->cycle, // 51- dev->mincycle); 52+ time_as_double(&dev->cycle), // 53+ time_as_double(&dev->mincycle)); 54 55 connectionTracking->devSeen[i] = true; 56 connectionTracking->dev[i] = *dev; 57@@ -367,11 +384,18 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon 58 nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_SMASK); 59 60 /* date & time */ 61+#if GPSD_API_MAJOR_VERSION >= 9 62+ if (gpsdata->fix.time.tv_sec > 0) { 63+ struct tm *time = gmtime(&gpsdata->fix.time.tv_sec); 64+ unsigned int hsec = (unsigned int) (gpsdata->fix.time.tv_nsec / 10000000); 65+#else 66 if (!isNaN(gpsdata->fix.time)) { 67 double seconds; 68 double fraction = modf(fabs(gpsdata->fix.time), &seconds); 69 long sec = lrint(seconds); 70 struct tm *time = gmtime(&sec); 71+ unsigned int hsec = (unsigned int) lrint(fraction * 100); 72+#endif 73 if (time) { 74 info->utc.year = (unsigned int) time->tm_year + 1900; 75 info->utc.mon = (unsigned int) time->tm_mon + 1; 76@@ -379,7 +403,7 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon 77 info->utc.hour = (unsigned int) time->tm_hour; 78 info->utc.min = (unsigned int) time->tm_min; 79 info->utc.sec = (unsigned int) time->tm_sec; 80- info->utc.hsec = (unsigned int) lrint(fraction * 100); 81+ info->utc.hsec = hsec; 82 83 nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_UTCDATE | NMEALIB_PRESENT_UTCTIME); 84 } 85@@ -387,7 +411,7 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon 86 gpsdata->set &= ~TIME_SET; 87 88 /* sig & fix */ 89- if (!gpsdata->online) { 90+ if (!is_online(gpsdata)) { 91 gpsdata->fix.mode = MODE_NO_FIX; 92 } 93 94@@ -454,7 +478,11 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon 95 if ((gpsdata->fix.mode >= MODE_3D) // 96 && !isNaN(gpsdata->fix.altitude)) { 97 info->elevation = gpsdata->fix.altitude; 98+#if GPSD_API_MAJOR_VERSION >= 9 99+ info->height = gpsdata->fix.geoid_sep; 100+#else 101 info->height = gpsdata->separation; 102+#endif 103 nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_ELV | NMEALIB_PRESENT_HEIGHT); 104 } 105 gpsdata->set &= ~ALTITUDE_SET; 106