]> err.no Git - mapper/blobdiff - src/gps.c
Add header and cast properly.
[mapper] / src / gps.c
index 0523be5ce03136432e9487b915d6810770b81c23..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);
@@ -66,6 +66,8 @@ static gboolean gps_connect_file(Gps *gps, gchar *file);
 
 #define GPSD_NMEA "r+\r\n"
 #define GPSD_PORT (2947)
+#define LOCALHOST "127.0.0.1"
+#define GPS_DEVICE_FILE "/dev/ttyS0"
 
 const GpsTypes gps_types[] = {
 #ifdef WITH_BLUEZ
@@ -77,11 +79,11 @@ const GpsTypes gps_types[] = {
 #ifdef WITH_BLUEZ_DBUS_BT
        { GPS_IO_BLUEZ_DBUS,    "Bluetooth connection (new)", TRUE, TRUE, FALSE},
 #endif
-       { GPS_IO_GPSD,                  "GPSD Connection", FALSE, TRUE, TRUE, GPSD_PORT },
-       { GPS_IO_FILE,                  "File or device", FALSE, TRUE, FALSE},
-       { GPS_IO_TCP,                   "TCP Connection", FALSE, TRUE, TRUE, 1024 },
+       { GPS_IO_GPSD,                  "GPSD Connection", FALSE, TRUE, TRUE, GPSD_PORT, LOCALHOST },
+       { GPS_IO_FILE,                  "File or device", FALSE, TRUE, FALSE, 0, GPS_DEVICE_FILE },
+       { GPS_IO_TCP,                   "TCP Connection", FALSE, TRUE, TRUE, 1024, LOCALHOST },
 #ifdef WITH_GYPSY
-       { GPS_IO_GYPSY,                 "Gypsy", FALSE, TRUE, FALSE},
+       { GPS_IO_GYPSY,                 "Gypsy", FALSE, TRUE, FALSE },
 #endif
        { GPS_IO_SIMULATION,    "Simulation (random)", FALSE, FALSE, FALSE},
        { 0 }
@@ -191,12 +193,12 @@ if (gps->io.conn==RCVR_DOWN && gps->io.address) {
                } else {
                        /* Unknown error. */
                        g_printerr("Error: %s\n", error->message);
-                       gps_disconnect(_gps);
-                       gps_connect_later(_gps);        /* Try again later. */
+                       gps_disconnect(gps);
+                       gps_connect_later(gps); /* Try again later. */
                        return;
                }
        }
-       gps_connect_fd(fdpath);
+       gps_connect_file(gps, fdpath);
 }
 /* else { Looks like the middle of a disconnect.  Do nothing. } */
 }
@@ -275,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) {
@@ -297,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);
@@ -406,8 +413,8 @@ gfloat h;
 g_assert(gps);
 
 if (g_random_double()<0.5) {
-       slat=g_random_double_range(-0.0003, 0.0003);
-       slon=g_random_double_range(-0.0003, 0.0003);
+       slat=g_random_double_range(-0.0008, 0.0008);
+       slon=g_random_double_range(-0.0008, 0.0008);
 }
 plat=gps->data.lat;
 plon=gps->data.lon;
@@ -503,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
@@ -614,9 +629,9 @@ switch (gps->io.type) {
                        g_debug("GPS: Requesting NMEA mode from GPSD using cmd %s", GPSD_NMEA);
                        status=g_io_channel_write_chars(gps->io.channel, GPSD_NMEA, strlen(GPSD_NMEA), &written, &error);
                        if (status==G_IO_STATUS_NORMAL && written==strlen(GPSD_NMEA)) {
-                               g_debug("GPS: NMEA mode set (%d %d)", written, status);
+                               g_debug("GPS: NMEA mode set (%d %d)", (gint)written, (gint)status);
                        } else {
-                               g_printerr("Failed to set gpsd to NMEA mode: %d %d %s\n",status, written, error->message);
+                               g_printerr("Failed to set gpsd to NMEA mode: %d %d %s\n",(gint)status,(gint)written, error->message);
                                g_error_free(error);
                                gps_disconnect(gps);
                                gps_connect_later(gps);