0003-pud-adapt-to-API-changes-in-gpsd-3-20.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From b2dfb6c27fcf4ddae87b0e99492f4bb8472fa39a Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <cotequeiroz@gmail.com>
  3. Date: Thu, 13 Feb 2020 17:26:41 -0300
  4. Subject: [PATCH] pud: adapt to API changes in gpsd 3.20
  5. The timestamp fields were changed from double to struct timespec, and
  6. the geoid separation field was moved to fix.geoid_sep.
  7. Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
  8. [Retrieved from:
  9. https://github.com/OLSR/olsrd/commit/b2dfb6c27fcf4ddae87b0e99492f4bb8472fa39a]
  10. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  11. ---
  12. lib/pud/src/gpsdclient.c | 36 ++++++++++++++++++++++++++++++++----
  13. 1 file changed, 32 insertions(+), 4 deletions(-)
  14. diff --git a/lib/pud/src/gpsdclient.c b/lib/pud/src/gpsdclient.c
  15. index 9e7fb708d..2a7a26eef 100644
  16. --- a/lib/pud/src/gpsdclient.c
  17. +++ b/lib/pud/src/gpsdclient.c
  18. @@ -79,6 +79,23 @@ static void gpsdError(const char *s) {
  19. syslog(LOG_ERR, "gpsd error: %s", s);
  20. }
  21. +#if GPSD_API_MAJOR_VERSION >= 9
  22. +static double time_as_double(struct timespec *ts) {
  23. + return (ts->tv_sec + ts->tv_nsec * 1e-9);
  24. +}
  25. +
  26. +static bool is_online(struct gps_data_t *gpsdata) {
  27. + return !!gpsdata->online.tv_sec;
  28. +}
  29. +#else
  30. +
  31. +#define time_as_double(x) *(x)
  32. +
  33. +static bool is_online(struct gps_data_t *gpsdata) {
  34. + return !!gpsdata->online;
  35. +}
  36. +#endif
  37. +
  38. /* standard parsing of a GPS data source spec */
  39. void gpsdParseSourceSpec(char *arg, GpsDaemon *gpsDaemon) {
  40. if (!arg //
  41. @@ -298,8 +315,8 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon
  42. 8, //
  43. dev->parity, //
  44. dev->stopbits, //
  45. - dev->cycle, //
  46. - dev->mincycle);
  47. + time_as_double(&dev->cycle), //
  48. + time_as_double(&dev->mincycle));
  49. connectionTracking->devSeen[i] = true;
  50. connectionTracking->dev[i] = *dev;
  51. @@ -367,11 +384,18 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon
  52. 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 +403,7 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon
  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;
  75. nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_UTCDATE | NMEALIB_PRESENT_UTCTIME);
  76. }
  77. @@ -387,7 +411,7 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon
  78. gpsdata->set &= ~TIME_SET;
  79. /* sig & fix */
  80. - if (!gpsdata->online) {
  81. + if (!is_online(gpsdata)) {
  82. gpsdata->fix.mode = MODE_NO_FIX;
  83. }
  84. @@ -454,7 +478,11 @@ void nmeaInfoFromGpsd(struct gps_data_t *gpsdata, NmeaInfo *info, struct GpsdCon
  85. if ((gpsdata->fix.mode >= MODE_3D) //
  86. && !isNaN(gpsdata->fix.altitude)) {
  87. info->elevation = gpsdata->fix.altitude;
  88. +#if GPSD_API_MAJOR_VERSION >= 9
  89. + info->height = gpsdata->fix.geoid_sep;
  90. +#else
  91. info->height = gpsdata->separation;
  92. +#endif
  93. nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_ELV | NMEALIB_PRESENT_HEIGHT);
  94. }
  95. gpsdata->set &= ~ALTITUDE_SET;