]> err.no Git - mapper/blobdiff - src/gps.c
Add header and cast properly.
[mapper] / src / gps.c
index 942a341dbc9aae35d78b1b728d27d43154e9470e..1962f5deef4d126a52a61d7702d68f7a365c9728 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -55,7 +55,7 @@
 
 #ifdef WITH_GPSBT
 #include <gpsbt.h>
-static gpsbt_t ctx = {0};
+static gpsbt_t ctx;
 #endif
 
 static gboolean gps_channel_cb_error(GIOChannel *src, GIOCondition condition, gpointer data);
@@ -277,7 +277,7 @@ switch (gps->io.type) {
                return FALSE;
 }
 e=errno;
-g_debug("GPS: Error %d", e);
+g_debug("GPS: Error %d (%s)", e, strerror(e));
 
 /* The socket is non blocking so handle it */
 if (r != 0) {
@@ -299,6 +299,11 @@ if (r != 0) {
 #endif
                return FALSE;
        break;
+       case ECONNREFUSED:
+               g_printerr("*** Connection refused.\n");
+               gps_disconnect(gps);
+               return FALSE;
+       break;
        default:
                /* Connection failed.  Disconnect and try again later. */
                g_printerr("### Connect failed, retrying... %d %d\n", e, r);
@@ -505,14 +510,22 @@ switch (gps->io.type) {
                }
 #ifdef WITH_GPSBT
                if (gps->io.type==GPS_IO_GPSD) {
-                       gint r;
-                       gchar ebuf[128];
-                       r=gpsbt_start(NULL, 0, 0, 0, ebuf, 128, 0, &ctx);
-                       if (r!=0) {
-                               g_warning("Failed to start gpsd");
+                       gchar errbuf[255];
+
+                       /* Force correct gpsd binary */
+                       setenv ("GPSD_PROG", "/usr/sbin/gpsd", 1);
+
+                       memset(&ctx, 0, sizeof(ctx))
+                       memset(&errbuf, 0, sizeof(errbuf))
+                       errno=0;
+
+                       if (gpsbt_start(NULL, 0, 0, 0, errbuf, sizeof(errbuf), 0, &ctx)!=0)
+                               g_warning("Failed to start gpsd: %d (%s) %s\n", errno, strerror(errno), errbuff);
                                return FALSE;
                        } else {
-                               /* */
+                               g_debug("Waiting for gpsd");
+                               sleep(2);
+                               g_debug("Done wating");
                        }
                }
 #endif