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.

Related: SYS#6222
This commit is contained in:
Oliver Smith 2022-12-14 12:44:05 +01:00
parent da8c043c7b
commit d28feb6cb2
2 changed files with 19 additions and 11 deletions

View File

@ -42,6 +42,10 @@
#include <gps.h>
#if GPSD_API_MAJOR_VERSION < 11
# error "Your version of gpsd is too old, please upgrade."
#endif
#define NUM_RETRIES 60 /* Number of gpsd re-connects */
#define RETRY_SLEEP 1 /* Seconds to sleep between re-connects */
#define TIMEOUT 10 /* max Number of seconds without sentence */
@ -55,7 +59,7 @@ static void callback(struct gps_data_t *gpsdata)
{
/* we received some data but gpsd itself believes the receiver
* to be offline */
if (gpsdata->online == 0)
if (gpsdata->online.tv_sec == 0)
return;
/* re-set the alarm to the timeout */
@ -120,7 +124,7 @@ static int my_gps_mainloop(struct gps_data_t *gdata,
if (!gps_waiting(gdata, timeout)) {
return -1;
} else {
rc = gps_read(gdata);
rc = gps_read(gdata, NULL, 0);
if (rc < 0)
return rc;
(*hook)(gdata);

View File

@ -43,6 +43,10 @@
#include <gps.h>
#if GPSD_API_MAJOR_VERSION < 11
# error "Your version of gpsd is too old, please upgrade."
#endif
#define NUM_RETRIES 60 /* Number of gpsd re-connects */
#define RETRY_SLEEP 1 /* Seconds to sleep between re-connects */
@ -51,20 +55,17 @@ static struct gps_data_t gpsdata;
static void callback(struct gps_data_t *gpsdata)
{
struct timespec ts;
struct timeval tv;
time_t time;
char *timestr, *lf;
int rc;
if (!(gpsdata->set & TIME_SET))
return;
tv.tv_sec = gpsdata->fix.time;
/* FIXME: use the fractional part for microseconds */
tv.tv_usec = 0;
ts = gpsdata->fix.time;
time = tv.tv_sec;
timestr = ctime(&time);
timestr = ctime(&ts.tv_sec);
if (!timestr) {
syslog(LOG_ERR, "ctime failed");
timestr = "<unknown>";
@ -75,9 +76,9 @@ static void callback(struct gps_data_t *gpsdata)
*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);
timestr, gpsdata->set, gpsdata->fix.status, gpsdata->satellites_used);
if (gpsdata->status == 0) {
if (gpsdata->fix.status == 0) {
syslog(LOG_INFO, "%s: discarding; no fix yet\n", timestr);
return;
}
@ -87,7 +88,10 @@ static void callback(struct gps_data_t *gpsdata)
return;
}
tv.tv_sec = ts.tv_sec;
tv.tv_usec = ts.tv_nsec / 1000;
rc = settimeofday(&tv, NULL);
gps_close(gpsdata);
if (rc == 0) {
syslog(LOG_NOTICE, "Successfully set RTC time to GPSD time:"
@ -160,7 +164,7 @@ static int my_gps_mainloop(struct gps_data_t *gdata,
if (!gps_waiting(gdata, timeout)) {
return -1;
} else {
rc = gps_read(gdata);
rc = gps_read(gdata, NULL, 0);
if (rc < 0)
return rc;
(*hook)(gdata);