patch-lib_pud_src_gpsdclient_c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. +#if GPSD_API_MAJOR_VERSION >= 9
  7. +static double time_as_double(struct timespec *ts) {
  8. + return (ts->tv_sec + ts->tv_nsec * 1e-9);
  9. +}
  10. +
  11. +static bool is_online(struct gps_data_t *gpsdata) {
  12. + return !!gpsdata->online.tv_sec;
  13. +}
  14. +#else
  15. +
  16. +#define time_as_double(x) *(x)
  17. +
  18. +static bool is_online(struct gps_data_t *gpsdata) {
  19. + return !!gpsdata->online;
  20. +}
  21. +#endif
  22. +
  23. /* standard parsing of a GPS data source spec */
  24. void gpsdParseSourceSpec(char *arg, GpsDaemon *gpsDaemon) {
  25. if (!arg //
  26. @@ -298,8 +315,8 @@ void nmeaInfoFromGpsd(struct gps_data_t
  27. 8, //
  28. dev->parity, //
  29. dev->stopbits, //
  30. - dev->cycle, //
  31. - dev->mincycle);
  32. + time_as_double(&dev->cycle), //
  33. + time_as_double(&dev->mincycle));
  34. connectionTracking->devSeen[i] = true;
  35. connectionTracking->dev[i] = *dev;
  36. @@ -353,11 +370,6 @@ void nmeaInfoFromGpsd(struct gps_data_t
  37. );
  38. gpsdata->set &= ~STATUS_SET; /* always valid */
  39. - if (gpsdata->status == STATUS_NO_FIX) {
  40. - nmeaInfoClear(info);
  41. - nmeaTimeSet(&info->utc, &info->present, NULL);
  42. - return;
  43. - }
  44. if (!gpsdata->set) {
  45. return;
  46. @@ -367,11 +379,18 @@ void nmeaInfoFromGpsd(struct gps_data_t
  47. nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_SMASK);
  48. /* date & time */
  49. +#if GPSD_API_MAJOR_VERSION >= 9
  50. + if (gpsdata->fix.time.tv_sec > 0) {
  51. + struct tm *time = gmtime(&gpsdata->fix.time.tv_sec);
  52. + unsigned int hsec = (unsigned int) (gpsdata->fix.time.tv_nsec / 10000000);
  53. +#else
  54. if (!isNaN(gpsdata->fix.time)) {
  55. double seconds;
  56. double fraction = modf(fabs(gpsdata->fix.time), &seconds);
  57. long sec = lrint(seconds);
  58. struct tm *time = gmtime(&sec);
  59. + unsigned int hsec = (unsigned int) lrint(fraction * 100);
  60. +#endif
  61. if (time) {
  62. info->utc.year = (unsigned int) time->tm_year + 1900;
  63. info->utc.mon = (unsigned int) time->tm_mon + 1;
  64. @@ -379,7 +398,7 @@ void nmeaInfoFromGpsd(struct gps_data_t
  65. info->utc.hour = (unsigned int) time->tm_hour;
  66. info->utc.min = (unsigned int) time->tm_min;
  67. info->utc.sec = (unsigned int) time->tm_sec;
  68. - info->utc.hsec = (unsigned int) lrint(fraction * 100);
  69. + info->utc.hsec = hsec;
  70. nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_UTCDATE | NMEALIB_PRESENT_UTCTIME);
  71. }
  72. @@ -387,7 +406,7 @@ void nmeaInfoFromGpsd(struct gps_data_t
  73. gpsdata->set &= ~TIME_SET;
  74. /* sig & fix */
  75. - if (!gpsdata->online) {
  76. + if (!is_online(gpsdata)) {
  77. gpsdata->fix.mode = MODE_NO_FIX;
  78. }
  79. @@ -454,7 +473,11 @@ void nmeaInfoFromGpsd(struct gps_data_t
  80. if ((gpsdata->fix.mode >= MODE_3D) //
  81. && !isNaN(gpsdata->fix.altitude)) {
  82. info->elevation = gpsdata->fix.altitude;
  83. +#if GPSD_API_MAJOR_VERSION >= 9
  84. + info->height = gpsdata->fix.geoid_sep;
  85. +#else
  86. info->height = gpsdata->separation;
  87. +#endif
  88. nmeaInfoSetPresent(&info->present, NMEALIB_PRESENT_ELV | NMEALIB_PRESENT_HEIGHT);
  89. }
  90. gpsdata->set &= ~ALTITUDE_SET;