mirror of https://github.com/wb2osz/direwolf.git
Issue 241 - Catch up with new gpsd incompatbilities.
This commit is contained in:
parent
e2b32d1d2a
commit
74cf91cc98
106
src/dwgpsd.c
106
src/dwgpsd.c
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
// This file is part of Dire Wolf, an amateur radio packet TNC.
|
// 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
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -55,13 +55,11 @@
|
||||||
|
|
||||||
#include <gps.h>
|
#include <gps.h>
|
||||||
|
|
||||||
// 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.
|
#error libgps API version might be incompatible.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -116,7 +114,7 @@ static void * read_gpsd_thread (void *arg);
|
||||||
* shared region via dwgps_put_data.
|
* shared region via dwgps_put_data.
|
||||||
*
|
*
|
||||||
* The application calls dwgps_read to get the most
|
* 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
|
* Originally, I wanted to use the shared memory interface to gpsd
|
||||||
* because it is simpler and more efficient. Just access it when we
|
* 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
|
* 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
|
* 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.
|
* 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
|
* cd gpsd-3.11
|
||||||
* scons prefix=/usr libdir=lib/arm-linux-gnueabihf shm_export=True python=False
|
* scons prefix=/usr libdir=lib/arm-linux-gnueabihf shm_export=True python=False
|
||||||
* sudo scons udev-install
|
* sudo scons udev-install
|
||||||
*
|
*
|
||||||
* For now, we will use the socket interface. Maybe get back to this again someday.
|
* For now, we will use the socket interface. Maybe get back to this again someday.
|
||||||
*
|
*
|
||||||
* Update: January 2016.
|
* Update: January 2016.
|
||||||
*
|
*
|
||||||
* I'm told that the shared memory interface might work in Raspian, Jessie version.
|
* I'm told that the shared memory interface might work in Raspian, Jessie version.
|
||||||
* Haven't tried it yet.
|
* 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
|
#if ENABLE_GPSD
|
||||||
|
|
||||||
|
@ -255,10 +268,19 @@ static void * read_gpsd_thread (void *arg)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
|
// Example code found here:
|
||||||
|
// https://lists.nongnu.org/archive/html/gpsd-dev/2017-11/msg00001.html
|
||||||
|
|
||||||
if ( ! gps_waiting(&gpsdata, TIMEOUT * 1000000)) {
|
if ( ! gps_waiting(&gpsdata, TIMEOUT * 1000000)) {
|
||||||
text_color_set(DW_COLOR_ERROR);
|
text_color_set(DW_COLOR_ERROR);
|
||||||
dw_printf ("GPSD: Timeout waiting for GPS data.\n");
|
dw_printf ("------------------------------------------\n");
|
||||||
/* Fall thru to read which should get error and bail out. */
|
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
|
// 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.
|
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) {
|
switch (gpsdata.fix.mode) {
|
||||||
default:
|
default:
|
||||||
case MODE_NOT_SEEN:
|
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:
|
case MODE_NO_FIX:
|
||||||
if (info.fix >= DWFIX_2D) {
|
if (info.fix >= DWFIX_2D) {
|
||||||
text_color_set(DW_COLOR_INFO);
|
text_color_set(DW_COLOR_INFO);
|
||||||
|
@ -325,11 +378,7 @@ static void * read_gpsd_thread (void *arg)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data is available. */
|
if (gpsdata.stupid_status >= STATUS_FIX && gpsdata.fix.mode >= MODE_2D) {
|
||||||
// TODO: what is gpsdata.status?
|
|
||||||
|
|
||||||
|
|
||||||
if (gpsdata.status >= STATUS_FIX && gpsdata.fix.mode >= MODE_2D) {
|
|
||||||
|
|
||||||
info.dlat = isnan(gpsdata.fix.latitude) ? G_UNKNOWN : gpsdata.fix.latitude;
|
info.dlat = isnan(gpsdata.fix.latitude) ? G_UNKNOWN : gpsdata.fix.latitude;
|
||||||
info.dlon = isnan(gpsdata.fix.longitude) ? G_UNKNOWN : gpsdata.fix.longitude;
|
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);
|
info.speed_knots = isnan(gpsdata.fix.speed) ? G_UNKNOWN : (MPS_TO_KNOTS * gpsdata.fix.speed);
|
||||||
|
|
||||||
if (gpsdata.fix.mode >= MODE_3D) {
|
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);
|
info.timestamp = time(NULL);
|
||||||
if (s_debug >= 2) {
|
if (s_debug >= 2) {
|
||||||
|
@ -373,6 +428,7 @@ void dwgpsd_term (void) {
|
||||||
|
|
||||||
#if ENABLE_GPSD
|
#if ENABLE_GPSD
|
||||||
|
|
||||||
|
gps_stream (&gpsdata, WATCH_DISABLE, NULL);
|
||||||
gps_close (&gpsdata);
|
gps_close (&gpsdata);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue