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

Related: SYS#6222
This commit is contained in:
Oliver Smith 2022-12-14 18:47:28 +01:00
parent da8c043c7b
commit 54593d77f8
2 changed files with 28 additions and 3 deletions

View File

@ -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
if (gpsdata->online.tv_sec == 0)
return;
#else
if (gpsdata->online == 0)
return;
#endif
/* re-set the alarm to the timeout */
alarm(timeout);
@ -120,7 +125,11 @@ static int my_gps_mainloop(struct gps_data_t *gdata,
if (!gps_waiting(gdata, timeout)) {
return -1;
} else {
#if GPSD_API_MAJOR_VERSION >= 7
rc = gps_read(gdata, NULL, 0);
#else
rc = gps_read(gdata);
#endif
if (rc < 0)
return rc;
(*hook)(gdata);

View File

@ -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
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
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;
}
@ -160,7 +172,11 @@ static int my_gps_mainloop(struct gps_data_t *gdata,
if (!gps_waiting(gdata, timeout)) {
return -1;
} else {
#if GPSD_API_MAJOR_VERSION >= 7
rc = gps_read(gdata, NULL, 0);
#else
rc = gps_read(gdata);
#endif
if (rc < 0)
return rc;
(*hook)(gdata);