Skip to content

Commit 7cd027f

Browse files
committed
Issue 295 - Yet another incompatible change for the libgps API.
1 parent 512e8f8 commit 7cd027f

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/dwgpsd.c

+24-13
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
// An incompatibility was introduced with version 7
6060
// and again with 9 and again with 10.
6161

62-
#if GPSD_API_MAJOR_VERSION < 5 || GPSD_API_MAJOR_VERSION > 10
62+
#if GPSD_API_MAJOR_VERSION < 5 || GPSD_API_MAJOR_VERSION > 11
6363
#error libgps API version might be incompatible.
6464
#endif
6565

@@ -348,6 +348,15 @@ static void * read_gpsd_thread (void *arg)
348348
#define stupid_status status
349349
#endif
350350

351+
352+
if (s_debug >= 3) {
353+
text_color_set(DW_COLOR_DEBUG);
354+
dw_printf ("gpsdata: status=%d, mode=%d, lat=%.6f, lon=%.6f, track=%.1f, speed=%.1f, alt=%.0f\n",
355+
gpsdata.stupid_status, gpsdata.fix.mode,
356+
gpsdata.fix.latitude, gpsdata.fix.longitude,
357+
gpsdata.fix.track, gpsdata.fix.speed, gpsdata.fix.stupid_altitude);
358+
}
359+
351360
// Inform user about change in fix status.
352361

353362
switch (gpsdata.fix.mode) {
@@ -378,23 +387,25 @@ static void * read_gpsd_thread (void *arg)
378387
break;
379388
}
380389

381-
if (gpsdata.stupid_status >= STATUS_FIX && gpsdata.fix.mode >= MODE_2D) {
382390

383-
info.dlat = isnan(gpsdata.fix.latitude) ? G_UNKNOWN : gpsdata.fix.latitude;
384-
info.dlon = isnan(gpsdata.fix.longitude) ? G_UNKNOWN : gpsdata.fix.longitude;
385-
info.track = isnan(gpsdata.fix.track) ? G_UNKNOWN : gpsdata.fix.track;
386-
info.speed_knots = isnan(gpsdata.fix.speed) ? G_UNKNOWN : (MPS_TO_KNOTS * gpsdata.fix.speed);
391+
// Oct. 2020 - 'status' is always zero for latest version of libgps so we can't use that anymore.
387392

393+
if (/*gpsdata.stupid_status >= STATUS_FIX &&*/ gpsdata.fix.mode >= MODE_2D) {
394+
395+
info.dlat = isfinite(gpsdata.fix.latitude) ? gpsdata.fix.latitude : G_UNKNOWN;
396+
info.dlon = isfinite(gpsdata.fix.longitude) ? gpsdata.fix.longitude : G_UNKNOWN;
397+
// When stationary, track is NaN which is not finite.
398+
info.track = isfinite(gpsdata.fix.track) ? gpsdata.fix.track : G_UNKNOWN;
399+
info.speed_knots = isfinite(gpsdata.fix.speed) ? (MPS_TO_KNOTS * gpsdata.fix.speed) : G_UNKNOWN;
388400
if (gpsdata.fix.mode >= MODE_3D) {
389-
info.altitude = isnan(gpsdata.fix.stupid_altitude) ? G_UNKNOWN : gpsdata.fix.stupid_altitude;
401+
info.altitude = isfinite(gpsdata.fix.stupid_altitude) ? gpsdata.fix.stupid_altitude : G_UNKNOWN;
390402
}
403+
// Otherwise keep last known altitude when we downgrade from 3D to 2D fix.
404+
// Caller knows altitude is outdated if info.fix == DWFIX_2D.
391405
}
392-
else {
393-
// Keep the last known location.
394-
// Using info.fix, the caller knows if the location is current (DWFIX_[23]D),
395-
// last known (DWFIX_NONE), or never known (DWFIX_NOT_SEEN).
396-
info.fix = DWFIX_NO_FIX;
397-
}
406+
// Otherwise keep the last known location which is better than totally lost.
407+
// Caller knows location is outdated if info.fix == DWFIX_NO_FIX.
408+
398409

399410
info.timestamp = time(NULL);
400411
if (s_debug >= 2) {

0 commit comments

Comments
 (0)