Skip to content

Commit 27019b4

Browse files
committed
The constant thorn in my side.
1 parent 26727bb commit 27019b4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/dwgpsd.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/*------------------------------------------------------------------
2222
*
23-
* Module: dwgps.c
23+
* Module: dwgpsd.c
2424
*
2525
* Purpose: Interface to location data, i.e. GPS receiver.
2626
*
@@ -401,13 +401,15 @@ static void * read_gpsd_thread (void *arg)
401401

402402
if (/*gpsdata.stupid_status >= STATUS_FIX &&*/ gpsdata.fix.mode >= MODE_2D) {
403403

404-
info.dlat = isfinite(gpsdata.fix.latitude) ? gpsdata.fix.latitude : G_UNKNOWN;
405-
info.dlon = isfinite(gpsdata.fix.longitude) ? gpsdata.fix.longitude : G_UNKNOWN;
404+
#define GOOD(x) (isfinite(x) && ! isnan(x))
405+
406+
info.dlat = GOOD(gpsdata.fix.latitude) ? gpsdata.fix.latitude : G_UNKNOWN;
407+
info.dlon = GOOD(gpsdata.fix.longitude) ? gpsdata.fix.longitude : G_UNKNOWN;
406408
// When stationary, track is NaN which is not finite.
407-
info.track = isfinite(gpsdata.fix.track) ? gpsdata.fix.track : G_UNKNOWN;
408-
info.speed_knots = isfinite(gpsdata.fix.speed) ? (MPS_TO_KNOTS * gpsdata.fix.speed) : G_UNKNOWN;
409+
info.track = GOOD(gpsdata.fix.track) ? gpsdata.fix.track : G_UNKNOWN;
410+
info.speed_knots = GOOD(gpsdata.fix.speed) ? (MPS_TO_KNOTS * gpsdata.fix.speed) : G_UNKNOWN;
409411
if (gpsdata.fix.mode >= MODE_3D) {
410-
info.altitude = isfinite(gpsdata.fix.stupid_altitude) ? gpsdata.fix.stupid_altitude : G_UNKNOWN;
412+
info.altitude = GOOD(gpsdata.fix.stupid_altitude) ? gpsdata.fix.stupid_altitude : G_UNKNOWN;
411413
}
412414
// Otherwise keep last known altitude when we downgrade from 3D to 2D fix.
413415
// Caller knows altitude is outdated if info.fix == DWFIX_2D.

0 commit comments

Comments
 (0)