From da8c043c7b590d3199e1c9b590a01b5b27b0b41d Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 14 Dec 2022 12:43:37 +0100 Subject: [PATCH 1/2] gitignore: new file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa9e674 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/gps-watchdog +/gpsdate +/*.o -- 2.40.1 From 68bcf620b4dc37eefae009175b3edb7ef10a5f0a Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 14 Dec 2022 18:47:28 +0100 Subject: [PATCH 2/2] Fix build against gpsd >= 3.20 The previous version was written against gpsd 3.10. This also makes the date more precise, previously microseconds were set to 0. GPSD_API_MAJOR_VERSION is defined in gps.h, together with a changelog: https://gitlab.com/gpsd/gpsd/-/blob/master/include/gps.h Use Pau's compat_gps_read() from: https://gerrit.osmocom.org/c/osmocom-bb/+/11609 Related: SYS#6222 --- gps-watchdog.c | 19 ++++++++++++++++++- gpsdate.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/gps-watchdog.c b/gps-watchdog.c index ea72db3..a0bf24e 100644 --- a/gps-watchdog.c +++ b/gps-watchdog.c @@ -55,8 +55,13 @@ static void callback(struct gps_data_t *gpsdata) { /* we received some data but gpsd itself believes the receiver * to be offline */ +#if GPSD_API_MAJOR_VERSION >= 9 && GPSD_API_MINOR_VERSION >= 0 + if (gpsdata->online.tv_sec == 0) + return; +#else if (gpsdata->online == 0) return; +#endif /* re-set the alarm to the timeout */ alarm(timeout); @@ -109,6 +114,18 @@ static int osmo_daemonize(void) return 0; } +static inline int compat_gps_read(struct gps_data_t *data) +{ +/* API break in gpsd 6bba8b329fc7687b15863d30471d5af402467802 */ +#if GPSD_API_MAJOR_VERSION >= 7 && GPSD_API_MINOR_VERSION >= 0 + return gps_read(data, NULL, 0); +#elif GPSD_API_MAJOR_VERSION >= 5 + return gps_read(data); +#else + return gps_poll(data); +#endif +} + /* local copy, as the libgps official version ignores gps_read() result */ static int my_gps_mainloop(struct gps_data_t *gdata, int timeout, @@ -120,7 +137,7 @@ static int my_gps_mainloop(struct gps_data_t *gdata, if (!gps_waiting(gdata, timeout)) { return -1; } else { - rc = gps_read(gdata); + rc = compat_gps_read(gdata); if (rc < 0) return rc; (*hook)(gdata); diff --git a/gpsdate.c b/gpsdate.c index 375c517..66b964d 100644 --- a/gpsdate.c +++ b/gpsdate.c @@ -55,13 +55,19 @@ static void callback(struct gps_data_t *gpsdata) time_t time; char *timestr, *lf; int rc; + int status; if (!(gpsdata->set & TIME_SET)) return; +#if GPSD_API_MAJOR_VERSION >= 9 && GPSD_API_MINOR_VERSION >= 0 + tv.tv_sec = gpsdata->fix.time.tv_sec; + tv.tv_usec = gpsdata->fix.time.tv_nsec / 1000; +#else tv.tv_sec = gpsdata->fix.time; /* FIXME: use the fractional part for microseconds */ tv.tv_usec = 0; +#endif time = tv.tv_sec; timestr = ctime(&time); @@ -74,10 +80,16 @@ static void callback(struct gps_data_t *gpsdata) if (lf) *lf = '\0'; - syslog(LOG_DEBUG, "%s: gpsdate->set=0x%08"PRIu64"x status=%u sats_used=%u\n", - timestr, gpsdata->set, gpsdata->status, gpsdata->satellites_used); +#if GPSD_API_MAJOR_VERSION >= 10 && GPSD_API_MINOR_VERSION >= 0 + status = gpsdata->fix.status; +#else + status = gpsdata->status; +#endif - if (gpsdata->status == 0) { + syslog(LOG_DEBUG, "%s: gpsdate->set=0x%08"PRIu64"x status=%u sats_used=%u\n", + timestr, gpsdata->set, status, gpsdata->satellites_used); + + if (status == 0) { syslog(LOG_INFO, "%s: discarding; no fix yet\n", timestr); return; } @@ -149,6 +161,18 @@ static int osmo_daemonize(void) return 0; } +static inline int compat_gps_read(struct gps_data_t *data) +{ +/* API break in gpsd 6bba8b329fc7687b15863d30471d5af402467802 */ +#if GPSD_API_MAJOR_VERSION >= 7 && GPSD_API_MINOR_VERSION >= 0 + return gps_read(data, NULL, 0); +#elif GPSD_API_MAJOR_VERSION >= 5 + return gps_read(data); +#else + return gps_poll(data); +#endif +} + /* local copy, as the libgps official version ignores gps_read() result */ static int my_gps_mainloop(struct gps_data_t *gdata, int timeout, @@ -160,7 +184,7 @@ static int my_gps_mainloop(struct gps_data_t *gdata, if (!gps_waiting(gdata, timeout)) { return -1; } else { - rc = gps_read(gdata); + rc = compat_gps_read(gdata); if (rc < 0) return rc; (*hook)(gdata); -- 2.40.1