This is the new version of gpsd/libgps; as of this writing the latest release
(2.95) is API version 4; but the head of their git master branch is API version
5 and qgpsdevice wouldn't even compile with it; now it both compiles and works,
and will still work with older versions of libgps via conditional compilation.

Also improved some error diagnostics relating to gpsd.

Signed-off-by: David Favro <merkaar...@meta-dynamic.com>
---
 src/GPS/qgpsdevice.cpp |   42 +++++++++++++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/src/GPS/qgpsdevice.cpp b/src/GPS/qgpsdevice.cpp
index 52acbdb..43977d2 100644
--- a/src/GPS/qgpsdevice.cpp
+++ b/src/GPS/qgpsdevice.cpp
@@ -35,6 +35,11 @@
 #endif
 #include <math.h>
 
+#ifdef USE_GPSD_LIB
+    #include <cerrno>
+    #include <cstring> // strerror()
+#endif
+
 #include "Preferences/MerkaartorPreferences.h"
 
 /* GPSSLOTFORWARDER */
@@ -955,11 +960,14 @@ void QGPSDDevice::run()
     QEventLoop l;
 
     Server = new gpsmm();
+    errno = 0;
     gpsdata = 
Server->open(M_PREFS->getGpsdHost().toAscii().data(),QString::number(M_PREFS->getGpsdPort()).toAscii().data());
     if (!gpsdata) {
 //        QMessageBox::critical(NULL, tr("GPSD connection error"),
 //                              tr("Unable to connect to 
%1:%2").arg(M_PREFS->getGpsdHost()).arg(QString::number(M_PREFS->getGpsdPort())),
 QMessageBox::Ok);
-        qDebug() << tr("Unable to connect to 
%1:%2").arg(M_PREFS->getGpsdHost()).arg(QString::number(M_PREFS->getGpsdPort()));
+       QString msg( (errno<0) ? gps_errstr(errno) : strerror(errno) );
+       qDebug() << tr("Unable to connect to 
%1:%2").arg(M_PREFS->getGpsdHost()).arg(QString::number(M_PREFS->getGpsdPort()))
+               << ": " << msg;
         return;
     }
 
@@ -979,9 +987,23 @@ void QGPSDDevice::run()
 
 void QGPSDDevice::onDataAvailable()
 {
-    gpsdata = Server->poll();
-    if (!gpsdata)
-        return;
+    #if GPSD_API_MAJOR_VERSION < 5
+       gpsdata = Server->poll();
+       if (!gpsdata)
+           return;
+    #else
+       if ( Server->waiting() )
+           {
+           errno = 0;
+           gpsdata = Server->read();
+           if ( gpsdata == 0 )
+               {
+               QString msg( (errno==0) ? "socket to gpsd was closed" : 
strerror(errno) );
+               qDebug() << "gpsmm::read() failed: " << msg;
+               return;
+               }
+           }
+    #endif
 
     setFixStatus(StatusVoid);
     switch (gpsdata->fix.mode) {
@@ -1040,11 +1062,13 @@ void QGPSDDevice::onDataAvailable()
 void QGPSDDevice::onLinkReady()
 {
     if (!Server) return;
-#if GPSD_API_MAJOR_VERSION > 3
-    gpsdata = Server->stream(WATCH_ENABLE);
-#else
-    gpsdata = Server->query("w+x\n");
-#endif
+    #if GPSD_API_MAJOR_VERSION > 3
+       gpsdata = Server->stream(WATCH_ENABLE);
+       if ( gpsdata == 0 )
+           qDebug() << "gpsmm::stream() failed: " << gps_errstr(errno) << '\n';
+    #else
+       gpsdata = Server->query("w+x\n");
+    #endif
 }
 #else /*USE_GPSD_LIB*/
 QGPSDDevice::QGPSDDevice(const QString& device)
-- 
1.7.0.4


_______________________________________________
Merkaartor mailing list
Merkaartor@openstreetmap.org
http://lists.openstreetmap.org/listinfo/merkaartor

Reply via email to