From 74cf91cc98a00265af8a5fed9c7d68757953de2f Mon Sep 17 00:00:00 2001 From: wb2osz Date: Sat, 20 Jun 2020 20:49:00 -0400 Subject: [PATCH] Issue 241 - Catch up with new gpsd incompatbilities. --- src/dwgpsd.c | 106 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/src/dwgpsd.c b/src/dwgpsd.c index 890dd50..b9e5814 100644 --- a/src/dwgpsd.c +++ b/src/dwgpsd.c @@ -1,7 +1,7 @@ // // This file is part of Dire Wolf, an amateur radio packet TNC. // -// Copyright (C) 2013, 2014, 2015 John Langner, WB2OSZ +// Copyright (C) 2013, 2014, 2015, 2020 John Langner, WB2OSZ // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -55,13 +55,11 @@ #include -// Debian bug report: direwolf (1.2-1) FTBFS with libgps22 as part of the gpsd transition (#803605): -// dwgps.c claims to only support GPSD_API_MAJOR_VERSION 5, but also builds successfully with -// GPSD_API_MAJOR_VERSION 6 provided by libgps22 when the attached patch is applied. -// Also compatible with API 7 & 8 with conditional compilation later. +// An incompatibility was introduced with version 7 +// and again with 9 and again with 10. -#if GPSD_API_MAJOR_VERSION < 5 || GPSD_API_MAJOR_VERSION > 8 +#if GPSD_API_MAJOR_VERSION < 5 || GPSD_API_MAJOR_VERSION > 10 #error libgps API version might be incompatible. #endif @@ -116,7 +114,7 @@ static void * read_gpsd_thread (void *arg); * shared region via dwgps_put_data. * * The application calls dwgps_read to get the most - 8 recent information. + * recent information. * *--------------------------------------------------------------------*/ @@ -126,7 +124,7 @@ static void * read_gpsd_thread (void *arg); * Originally, I wanted to use the shared memory interface to gpsd * because it is simpler and more efficient. Just access it when we * actually need the data and we don't have a lot of extra unnecessary - * busy work going on. + * busy work going on constantly polling it when we don't need the information. * * The current version of gpsd, supplied with Raspian (Wheezy), is 3.6 from back in * May 2012, is missing support for the shared memory interface. @@ -142,13 +140,28 @@ static void * read_gpsd_thread (void *arg); * cd gpsd-3.11 * scons prefix=/usr libdir=lib/arm-linux-gnueabihf shm_export=True python=False * sudo scons udev-install - * + * * For now, we will use the socket interface. Maybe get back to this again someday. * * Update: January 2016. * * I'm told that the shared memory interface might work in Raspian, Jessie version. * Haven't tried it yet. + * + * June 2020: This is how to build the most recent. + * + * Based on https://www.satsignal.eu/raspberry-pi/UpdatingGPSD.html + * + * git clone https://gitlab.com/gpsd/gpsd.git gpsd-gitlab + * cd gpsd-gitlab + * scons --config=force + * scons + * sudo scons install + * + * The problem we have here is that the library is put in /usr/local/lib and direwolf + * can't find it there. Solution is to define environment variable: + * + * export LD_LIBRARY_PATH=/use/local/lib */ @@ -232,7 +245,7 @@ int dwgpsd_init (struct misc_config_s *pconfig, int debug) * *--------------------------------------------------------------------*/ -#define TIMEOUT 30 +#define TIMEOUT 15 #if ENABLE_GPSD @@ -255,10 +268,19 @@ static void * read_gpsd_thread (void *arg) while (1) { +// Example code found here: +// https://lists.nongnu.org/archive/html/gpsd-dev/2017-11/msg00001.html + if ( ! gps_waiting(&gpsdata, TIMEOUT * 1000000)) { text_color_set(DW_COLOR_ERROR); - dw_printf ("GPSD: Timeout waiting for GPS data.\n"); - /* Fall thru to read which should get error and bail out. */ + dw_printf ("------------------------------------------\n"); + dw_printf ("dwgpsd: Timeout waiting for GPS data.\n"); + dw_printf ("Is GPSD daemon running?\n"); + dw_printf ("Troubleshooting tip: Try running cgps or xgps.\n"); + dw_printf ("------------------------------------------\n"); + info.fix = DWFIX_ERROR; + SLEEP_MS(5000); + continue; } // https://github.com/wb2osz/direwolf/issues/196 @@ -290,16 +312,47 @@ static void * read_gpsd_thread (void *arg) break; // Jump out of loop and terminate thread. } +#if GPSD_API_MAJOR_VERSION >= 9 + +// The gps.h revision history says: +// * mark altitude in gps_fix_t as deprecated and undefined +// This seems really stupid to me. +// If it is deprecated and undefined then take it out. Someone trying to use +// it would get a compile error and know that something needs to be done. +// Instead we all just go merrily on our way using a field that is [allegedly] undefined. +// Why not simply add more variables with different definitions of altitude +// and keep the original variable working as it always did? +// If it is truly undefined, as the comment would have us believe, numerous +// people will WASTE VAST AMOUNTS OF TIME pondering why altitude is now broken in +// their applications. + +#define stupid_altitude altMSL +#else +#define stupid_altitude altitude +#endif + +#if GPSD_API_MAJOR_VERSION >= 10 + +// They did it again. Whimsical incompatibilities that cause +// pain and aggravation for everyone trying to use this library. +// +// error: ‘struct gps_data_t’ has no member named ‘status’ +// +// Yes, I can understand that it is a more logical place but it breaks +// all existing code that uses this. +// I'm really getting annoyed about wasting so much time on keeping up with all +// of these incompatibilities that are completely unnecessary. + +#define stupid_status fix.status +#else +#define stupid_status status +#endif + + // Inform user about change in fix status. + switch (gpsdata.fix.mode) { default: case MODE_NOT_SEEN: - if (info.fix >= DWFIX_2D) { - text_color_set(DW_COLOR_INFO); - dw_printf ("GPSD: Lost location fix.\n"); - } - info.fix = DWFIX_NOT_SEEN; - break; - case MODE_NO_FIX: if (info.fix >= DWFIX_2D) { text_color_set(DW_COLOR_INFO); @@ -325,11 +378,7 @@ static void * read_gpsd_thread (void *arg) break; } - /* Data is available. */ - // TODO: what is gpsdata.status? - - - if (gpsdata.status >= STATUS_FIX && gpsdata.fix.mode >= MODE_2D) { + if (gpsdata.stupid_status >= STATUS_FIX && gpsdata.fix.mode >= MODE_2D) { info.dlat = isnan(gpsdata.fix.latitude) ? G_UNKNOWN : gpsdata.fix.latitude; info.dlon = isnan(gpsdata.fix.longitude) ? G_UNKNOWN : gpsdata.fix.longitude; @@ -337,9 +386,15 @@ static void * read_gpsd_thread (void *arg) info.speed_knots = isnan(gpsdata.fix.speed) ? G_UNKNOWN : (MPS_TO_KNOTS * gpsdata.fix.speed); if (gpsdata.fix.mode >= MODE_3D) { - info.altitude = isnan(gpsdata.fix.altitude) ? G_UNKNOWN : gpsdata.fix.altitude; + info.altitude = isnan(gpsdata.fix.stupid_altitude) ? G_UNKNOWN : gpsdata.fix.stupid_altitude; } } + else { + // Keep the last known location. + // Using info.fix, the caller knows if the location is current (DWFIX_[23]D), + // last known (DWFIX_NONE), or never known (DWFIX_NOT_SEEN). + info.fix = DWFIX_NO_FIX; + } info.timestamp = time(NULL); if (s_debug >= 2) { @@ -373,6 +428,7 @@ void dwgpsd_term (void) { #if ENABLE_GPSD + gps_stream (&gpsdata, WATCH_DISABLE, NULL); gps_close (&gpsdata); #endif