olsrd: update to 0.9.8
[openadk.git] / package / olsrd / patches / patch-lib_pud_src_gpsdclient_c
blobfc71997fcf33bcc9a234a90f0cdff3355a329720
1 --- olsrd-0.9.8.orig/lib/pud/src/gpsdclient.c   2019-08-11 10:09:47.000000000 +0200
2 +++ olsrd-0.9.8/lib/pud/src/gpsdclient.c        2024-02-29 11:26:48.195242832 +0100
3 @@ -79,6 +79,23 @@ static void gpsdError(const char *s) {
4    syslog(LOG_ERR, "gpsd error: %s", s);
5  }
6  
7 +#if GPSD_API_MAJOR_VERSION >= 9
8 +static double time_as_double(struct timespec *ts) {
9 + return (ts->tv_sec + ts->tv_nsec * 1e-9);
12 +static bool is_online(struct gps_data_t *gpsdata) {
13 +  return !!gpsdata->online.tv_sec;
15 +#else
17 +#define time_as_double(x) *(x)
19 +static bool is_online(struct gps_data_t *gpsdata) {
20 +  return !!gpsdata->online;
22 +#endif
24  /* standard parsing of a GPS data source spec */
25  void gpsdParseSourceSpec(char *arg, GpsDaemon *gpsDaemon) {
26    if (!arg //
27 @@ -298,8 +315,8 @@ void nmeaInfoFromGpsd(struct gps_data_t
28              8, //
29              dev->parity, //
30              dev->stopbits, //
31 -            dev->cycle, //
32 -            dev->mincycle);
33 +            time_as_double(&dev->cycle), //
34 +            time_as_double(&dev->mincycle));
36          connectionTracking->devSeen[i] = true;
37          connectionTracking->dev[i] = *dev;
38 @@ -353,11 +370,6 @@ void nmeaInfoFromGpsd(struct gps_data_t
39            );
41    gpsdata->set &= ~STATUS_SET; /* always valid */
42 -  if (gpsdata->status == STATUS_NO_FIX) {
43 -    nmeaInfoClear(info);
44 -    nmeaTimeSet(&info->utc, &info->present, NULL);
45 -    return;
46 -  }
48    if (!gpsdata->set) {
49      return;
50 @@ -367,11 +379,18 @@ void nmeaInfoFromGpsd(struct gps_data_t
51    nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_SMASK);
53    /* date & time */
54 +#if GPSD_API_MAJOR_VERSION >= 9
55 +  if (gpsdata->fix.time.tv_sec > 0) {
56 +    struct tm *time = gmtime(&gpsdata->fix.time.tv_sec);
57 +    unsigned int hsec = (unsigned int) (gpsdata->fix.time.tv_nsec / 10000000);
58 +#else
59    if (!isNaN(gpsdata->fix.time)) {
60      double seconds;
61      double fraction = modf(fabs(gpsdata->fix.time), &seconds);
62      long sec = lrint(seconds);
63      struct tm *time = gmtime(&sec);
64 +    unsigned int hsec = (unsigned int) lrint(fraction * 100);
65 +#endif
66      if (time) {
67        info->utc.year = (unsigned int) time->tm_year + 1900;
68        info->utc.mon = (unsigned int) time->tm_mon + 1;
69 @@ -379,7 +398,7 @@ void nmeaInfoFromGpsd(struct gps_data_t
70        info->utc.hour = (unsigned int) time->tm_hour;
71        info->utc.min = (unsigned int) time->tm_min;
72        info->utc.sec = (unsigned int) time->tm_sec;
73 -      info->utc.hsec = (unsigned int) lrint(fraction * 100);
74 +      info->utc.hsec = hsec;
76        nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_UTCDATE | NMEALIB_PRESENT_UTCTIME);
77      }
78 @@ -387,7 +406,7 @@ void nmeaInfoFromGpsd(struct gps_data_t
79    gpsdata->set &= ~TIME_SET;
81    /* sig & fix */
82 -  if (!gpsdata->online) {
83 +  if (!is_online(gpsdata)) {
84      gpsdata->fix.mode = MODE_NO_FIX;
85    }
87 @@ -454,7 +473,11 @@ void nmeaInfoFromGpsd(struct gps_data_t
88    if ((gpsdata->fix.mode >= MODE_3D) //
89        && !isNaN(gpsdata->fix.altitude)) {
90      info->elevation = gpsdata->fix.altitude;
91 +#if GPSD_API_MAJOR_VERSION >= 9
92 +    info->height = gpsdata->fix.geoid_sep;
93 +#else
94      info->height = gpsdata->separation;
95 +#endif
96      nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_ELV | NMEALIB_PRESENT_HEIGHT);
97    }
98    gpsdata->set &= ~ALTITUDE_SET;