]> err.no Git - mapper/commitdiff
Start to separate UI from GPS connection and parsing.
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 28 Jan 2008 17:15:33 +0000 (19:15 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 28 Jan 2008 17:15:33 +0000 (19:15 +0200)
- Build a library for handling gps connection and NMEA parsing in preparation
  for the future home applet.
- Use callback for interesting events.

15 files changed:
src/Makefile.am
src/config-gconf.c
src/gps-bluetooth-bluez.c
src/gps-conn.c
src/gps-nmea-parse.c
src/gps-nmea-parse.h
src/gps.c
src/gps.h
src/gpx.h
src/mapper.c
src/track.c
src/track.h
src/ui-common.c
src/ui-common.h
src/utils.h

index 2c68ade76dff873aac34150e103f497136b09df0..76d06cc140ba14e0524eb12350bfd6ffcf90778b 100644 (file)
@@ -41,15 +41,13 @@ mapper_LDADD = $(GLIBGTK_LIBS) $(GTKHTML_LIBS) \
        $(SQLITE_LIBS) $(LIBCURL_LIBS) \
        $(DBUS_GLIB_LIBS) $(BLUEZ_LIBS) \
        $(GYPSY_LIBS) $(LIBGPSBT_LIBS) \
-       -lm libgtkgps.la libosmdb.la
+       -lm libgtkgps.la libosmdb.la libmappergps.la
 
 mapper_SOURCES = utils.c \
        file.c \
        gpx.c \
        filter.c \
-       gps.c \
        gps-browse.c \
-       gps-nmea-parse.c \
        gps-panels.c \
        gps-conn.c \
        cb.c \
@@ -77,27 +75,23 @@ mapper_SOURCES = utils.c \
        search.c \
        mapper.c
 
+osm2db_CFLAGS = $(EXPAT_CFLAGS) $(SQLITE_CFLAGS) $(GLIBGTK_CFLAGS)
+osm2db_LDADD = $(EXPAT_LIBS) $(SQLITE_LIBS) $(GLIBGTK_LIBS) $(BZ2_LIBS) -lm libosmdb.la
+osm2db_SOURCES = osm.c
+
+lib_LTLIBRARIES = libgtkgps.la libosmdb.la libmappergps.la
+
+libmappergps_la_SOURCES = gps.c        gps-nmea-parse.c
 if HAVE_BLUEZ_DBUS_BT
-mapper_SOURCES+=gps-bluetooth-bluez.c gps-bluetooth-bluez-marshal.c
+libmappergps_la_SOURCES+=gps-bluetooth-bluez.c gps-bluetooth-bluez-marshal.c
 endif
 
 if HAVE_HILDON_DBUS_BT
-mapper_SOURCES+=gps-bluetooth-maemo.c gps-bluetooth-maemo-marshal.c 
+libmappergps_la_SOURCES+=gps-bluetooth-maemo.c gps-bluetooth-maemo-marshal.c 
 endif
-
-#if HAVE_GPSD
-#mapper_SOURCES+=gps-gpsd.c
-#endif
-
-#if HAVE_GYPSY
-#mapper_SOURCES+=gps-gypsy.c
-#endif
-
-osm2db_CFLAGS = $(EXPAT_CFLAGS) $(SQLITE_CFLAGS) $(GLIBGTK_CFLAGS)
-osm2db_LDADD = $(EXPAT_LIBS) $(SQLITE_LIBS) $(GLIBGTK_LIBS) $(BZ2_LIBS) -lm libosmdb.la
-osm2db_SOURCES = osm.c
-
-lib_LTLIBRARIES = libgtkgps.la libosmdb.la
+libmappergps_la_CFLAGS = $(GLIBGTK_CFLAGS) $(LIBGPSBT_CFLAGS) $(defines) 
+libmappergps_la_LIBADD = $(GLIBGTK_LIBS) $(LIBGPSBT_LIBS)
+libmappergps_la_LDFLAGS = -lm -no-undefined
 
 libgtkgps_la_SOURCES = gtkgps.c gtkcompass.c
 libgtkgps_la_CFLAGS = $(GLIBGTK_CFLAGS) $(defines)
index 64fc4f8cf355f2d035b1e9ddba8ee4f293759e59..e90ae2f0c33170644ecf0786411a11d7a8a57150 100644 (file)
@@ -442,6 +442,7 @@ if (value) {
 } else {
        _gps->io.type=GPS_IO_SIMULATION;
 }
+g_debug("GPS Type: %d", _gps->io.type);
 
 /* Get Auto-Download.  Default is FALSE. */
 _auto_download = gconf_client_get_bool(gconf_client, GCONF_KEY_AUTO_DOWNLOAD, NULL);
index ff0339157f90876516425447e9a33f489a39c56e..fee8da239c6647ede13d910bf056988ac2acb7b2 100644 (file)
@@ -7,13 +7,11 @@
 #include <stddef.h>
 #include <libintl.h>
 #include <locale.h>
-#include <math.h>
 #include <errno.h>
 #include <sys/wait.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 #include <fcntl.h>
-#include <gconf/gconf-client.h>
 
 #include <sys/socket.h>
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/rfcomm.h>
 
 #include "bluetooth-scan.h"
-#include "gps.h"
-#include "map.h"
 #include "utils.h"
 #include "mapper-types.h"
 #include "settings.h"
 #include "ui-common.h"
-#include "gps-conn.h"
 
 gint 
 scan_start_search(ScanInfo * scan_info)
index 5aab9306ae90635292796c817ab70e2cf08b2d3a..a841f1c84eb273ed9264514861588d1081d7b905 100644 (file)
@@ -57,7 +57,6 @@ gps_conn_set_state(Gps *gps, GpsConnState new_conn_state)
 {
 switch (gps->io.conn=new_conn_state) {
        case RCVR_OFF:
-               _enable_gps=FALSE;
                set_action_activate("gps_enabled", FALSE);
        case RCVR_FIXED:
                if (connect_banner) {
index dee16731c73215f5a4cdc85e1d58a76fe15957d2..810791a8a52b898413ef6b15e2a03f302cdc83e4 100644 (file)
 #include <math.h>
 #include <errno.h>
 #include <glib/gstdio.h>
-#include <gtk/gtk.h>
 #include <fcntl.h>
-#include <libxml/parser.h>
 
 #include "utils.h"
 #include "gps.h"
-#include "mapper-types.h"
-#include "ui-common.h"
-#include "map.h"
-#include "track.h"
-#include "route.h"
-#include "gps-panels.h"
-#include "settings.h"
-#include "gps-conn.h"
-#include "gtkgps.h"
-#include "gtkcompass.h"
+#include "gps-nmea-parse.h"
+
+#define DELIM ","
 
 static void
-gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
+gps_nmea_parse_rmc(Gps *gps, gchar *sentence)
 {
        /* Recommended Minimum Navigation Information C
         *  1) UTC Time
@@ -73,9 +64,7 @@ gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
        gdouble tmpd = 0.f;
        guint tmpi = 0;
        gboolean newly_fixed = FALSE;
-       vprintf("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
-
-#define DELIM ","
+       g_debug("%s(): %s", __PRETTY_FUNCTION__, sentence);
 
        /* Parse time. */
        token = strsep(&sentence, DELIM);
@@ -94,7 +83,7 @@ gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
                /* Data is invalid - not enough satellites?. */
                if (gps->io.conn != RCVR_UP) {
                        gps_conn_set_state(gps, RCVR_UP);
-                       track_add(NULL, FALSE);
+                       /* track_add(NULL, FALSE); */
                }
        }
 
@@ -155,20 +144,16 @@ gps_nmea_parse_rmc(Gps *gps, gchar * sentence)
                strcat(gpsdate, token);
                strptime(gpsdate, "%H%M%S%d%m%y", &time);
                gps->data.time = mktime(&time) + _gmtoffset;
-       } else
+       } else {
                gps->data.time = time(NULL);
-
-       /* Add new data to track only if we have a fix */
-       _track_store=TRUE;
+       }
 
        gps_data_integerize(&gps->data);
-       gps_display_data_speed(info_banner.speed, gps->data.speed);
 
-       if ((gps->io.conn==RCVR_FIXED) && (_track_store==TRUE) && filter_check(&filter, &gps->data, &map_loc)==TRUE) {
-               track_add(&_gps->data, newly_fixed);
-               gps->data.lheading=gps->data.heading;
-               map_refresh_mark();
+       if ((gps->io.conn==RCVR_FIXED) && (gps->update_location!=NULL)) {
+               gps->update_location(gps, newly_fixed);
        }
+       gps->data.lheading=gps->data.heading;
 }
 
 static void
@@ -201,9 +186,7 @@ gps_nmea_parse_gga(Gps *gps, gchar * sentence)
           15. the checksum data
         */
        gchar *token;
-       vprintf("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
-
-#define DELIM ","
+       g_debug("%s(): %s", __PRETTY_FUNCTION__, sentence);
 
        /* Skip Fix time */
        token = strsep(&sentence, DELIM);
@@ -256,8 +239,6 @@ gps_nmea_parse_gsa(Gps *gps, gchar * sentence)
 
        g_debug("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
 
-#define DELIM ","
-
        /* Skip Auto selection. */
        token = strsep(&sentence, DELIM);
 
@@ -372,40 +353,35 @@ gps_nmea_parse_gsv(Gps *gps, gchar * sentence)
                        if (gps->io.conn==RCVR_UP) {
                                gdouble fraction = running_total * sqrt(num_sats_used) / num_sats_used / 100.0;
                                BOUND(fraction, 0.0, 1.0);
-                               gps_conn_set_progress(gps, fraction);
+                               if (gps->connection_progress!=NULL)
+                                       gps->connection_progress(gps, fraction);
                        }
                        running_total=0;
                        num_sats_used=0;
                }
                satcnt = 0;
-
-               /* Keep awake while they watch the progress bar. */
-               KEEP_DISPLAY_ON();
        }
 }
 
 gboolean
-gps_nmea_parse(gchar *data)
+gps_nmea_parse(Gps *gps)
 {
-Gps *gps=_gps;
-
-if (!strncmp(data + 3, "GSV", 3)) {
-       if (gps->io.conn==RCVR_UP)
-               gps_nmea_parse_gsv(gps, data + 7);
-} else if (!strncmp(data + 3, "RMC", 3))
-       gps_nmea_parse_rmc(gps, data + 7);
-else if (!strncmp(data + 3, "GGA", 3))
-       gps_nmea_parse_gga(gps, data + 7);
-else if (!strncmp(data + 3, "GSA", 3))
-       gps_nmea_parse_gsa(gps, data + 7);
-else g_debug("Unknown NMEA: [%s]\n", data);
-g_free(data);
-
-if (_gps_info)
-       gps_display_data(&gps->data);
-
-if (_satdetails_on)
-       gps_display_details(&gps->data);
+g_assert(gps);
+g_assert(gps->io.nmea);
+
+g_debug("%s(): %s", __PRETTY_FUNCTION__, gps->io.nmea);
+
+if (!strncmp(gps->io.nmea + 3, "GSV", 3)) {
+       gps_nmea_parse_gsv(gps, gps->io.nmea + 7);
+} else if (!strncmp(gps->io.nmea + 3, "RMC", 3))
+       gps_nmea_parse_rmc(gps, gps->io.nmea + 7);
+else if (!strncmp(gps->io.nmea + 3, "GGA", 3))
+       gps_nmea_parse_gga(gps, gps->io.nmea + 7);
+else if (!strncmp(gps->io.nmea + 3, "GSA", 3))
+       gps_nmea_parse_gsa(gps, gps->io.nmea + 7);
+else g_printerr("Unknown NMEA: [%s]\n", gps->io.nmea);
+g_free(gps->io.nmea);
+gps->io.nmea=NULL;
 
 return FALSE;
 }
index 569ffae5d2c28badd57786c3ba7442b8ed3a7801..fa21042be8bd729f060c9da71c98e2afc10c9f26 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _GPS_NMEA_PARSE_H
 #define _GPS_NMEA_PARSE_H
 
-gboolean gps_nmea_parse(gchar *data);
+#include "gps.h"
+
+gboolean gps_nmea_parse(Gps *gps);
 
 #endif
index 227122e936a2c6611942171aa0a4d0f02809f425..08e3f316d7cc060f9b2ddde248d49e20ae7b0361 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -43,9 +43,8 @@
 #include "gps.h"
 #include "latlon.h"
 #include "map.h"
-#include "gps-nmea-parse.h"
 #include "gps-conn.h"
-#include "track.h"
+#include "gps-nmea-parse.h"
 
 #ifdef WITH_HILDON_DBUS_BT
 #include <bt-dbus.h>
@@ -66,18 +65,26 @@ static gboolean gps_connect_file(Gps *gps, gchar *file);
 #define GPSD_PORT (2947)
 
 const GpsTypes gps_types[] = {
-       { GPS_IO_RFCOMM,                "Direct bluetooth connection", TRUE, TRUE},
-       { GPS_IO_HILDON_DBUS,   "Hildon D-Bus", TRUE, TRUE },
-       { GPS_IO_BLUEZ_DBUS,    "Blues D-Bus", TRUE, TRUE},
+#ifdef WITH_BLUEZ
+       { GPS_IO_RFCOMM,                "Bluetooth connection (old)", TRUE, TRUE},
+#endif
+#ifdef WITH_HILDON_DBUS_BT
+       { GPS_IO_HILDON_DBUS,   "Bluetooth connection (btconn)", TRUE, TRUE },
+#endif
+#ifdef WITH_BLUEZ_DBUS_BT
+       { GPS_IO_BLUEZ_DBUS,    "Bluetooth connection (new)", TRUE, TRUE},
+#endif
+       { GPS_IO_GPSD,                  "GPSD Connection", FALSE, TRUE},
        { GPS_IO_FILE,                  "File or device", FALSE, TRUE},
        { GPS_IO_TCP,                   "TCP Connection", FALSE, TRUE},
-       { GPS_IO_GPSD,                  "GPSD", FALSE, TRUE},
+#ifdef WITH_GYPSY
        { GPS_IO_GYPSY,                 "Gypsy", FALSE, TRUE},
-       { GPS_IO_SIMULATION,    "Simulation", FALSE, FALSE},
+#endif
+       { GPS_IO_SIMULATION,    "Simulation (random)", FALSE, FALSE},
        { 0 }
 };
 
-GpsTypes *
+const GpsTypes *
 gps_get_supported_types(void) 
 {
 return gps_types;
@@ -97,10 +104,15 @@ gps->io.fd=-1;
 gps->io.address=NULL;
 gps->io.type=type;
 gps->io.conn=RCVR_OFF;
+gps->io.nmea=NULL;
 gps->data.lat=60.20;
 gps->data.lon=22.20;
 gps->connection_error=NULL;
 gps->connection_retry=NULL;
+gps->connection_progress=NULL;
+gps->update_location=NULL;
+gps->update_info=NULL;
+gps->update_satellite=NULL;
 gps_data_integerize(&gps->data);
 return gps;
 }
@@ -241,20 +253,25 @@ static gboolean
 gps_connect_socket(Gps *gps)
 {
 gint r, e;
+g_assert(gps);
+
 switch (gps->io.type) {
-#ifdef WITH_BLUEZ
        case GPS_IO_RFCOMM:
+#ifdef WITH_BLUEZ
+               g_debug("RFCOMM: %d", gps->io.fd);
                r=connect(gps->io.fd, (struct sockaddr *)&gps->io.rcvr_addr_rc, sizeof(gps->io.rcvr_addr_rc));
-       break;
 #endif
+       break;
        case GPS_IO_TCP:
        case GPS_IO_GPSD:
+               g_debug("TCP: %d", gps->io.fd);
                r=connect(gps->io.fd, (struct sockaddr *)&gps->io.rcvr_addr_in, sizeof(gps->io.rcvr_addr_in));
        break;
        default:
                return FALSE;
 }
 e=errno;
+g_debug("GPS: Error %d", e);
 
 /* The socket is non blocking so handle it */
 if (r != 0) {
@@ -263,12 +280,12 @@ if (r != 0) {
        case EBUSY:
        case EINPROGRESS:
        case EALREADY:
-               g_printf("*** Connection in progress... %d %d\n", e, r);
+               g_printerr("*** Connection in progress... %d %d\n", e, r);
                perror("INFO: ");
                return TRUE;
        break;
        case EHOSTUNREACH:
-               g_printf("*** Bluetooth/GPS device not found.\n");
+               g_printerr("*** Bluetooth/GPS device not found.\n");
                gps_disconnect(gps);
 #if 0
         set_action_activate("gps_enable", FALSE);
@@ -278,7 +295,7 @@ if (r != 0) {
        break;
        default:
                /* Connection failed.  Disconnect and try again later. */
-               g_printf("### Connect failed, retrying... %d %d\n", e, r);
+               g_printerr("### Connect failed, retrying... %d %d\n", e, r);
                perror("ERROR: ");
                gps_disconnect(gps);
                gps_connect_later(gps);
@@ -396,9 +413,10 @@ h=calculate_course(plat, plon, gps->data.lat, gps->data.lon);
 gps->data.heading=(h<0) ? 360+h : h;
 gps->data.time=time(NULL);
 gps_data_integerize(&gps->data);
-track_add(&gps->data, FALSE);
+if (gps->update_location!=NULL) {
+       gps->update_location(gps, FALSE);
+}
 gps->data.lheading=gps->data.heading;
-map_refresh_mark();
 
 return gps->io.conn==RCVR_FIXED ? TRUE : FALSE;
 }
@@ -423,8 +441,8 @@ gps_read_channel_connect(Gps *gps)
 gps->io.channel=g_io_channel_unix_new(gps->io.fd);
 g_io_channel_set_encoding(gps->io.channel, NULL, NULL);
 g_io_channel_set_flags(gps->io.channel, G_IO_FLAG_NONBLOCK, NULL);
-gps->io.error_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, gps_channel_cb_error, NULL, NULL);
-gps->io.connect_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, gps_channel_cb_connect, NULL, NULL);
+gps->io.error_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, gps_channel_cb_error, gps, NULL);
+gps->io.connect_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, gps_channel_cb_connect, gps, NULL);
 gps->io.clater_sid=0;
 }
 
@@ -454,7 +472,7 @@ switch (gps->io.type) {
        break;
        case GPS_IO_TCP:
        case GPS_IO_GPSD:
-               if (gps->io.conn==RCVR_DOWN && gps->io.address) {
+               if (gps->io.conn<=RCVR_DOWN && gps->io.address) {
                        gps->io.fd=socket(AF_INET, SOCK_STREAM, 0);
                        if (gps->io.fd==-1) {
                                g_debug("Failed to create socket\n");
@@ -479,8 +497,8 @@ switch (gps->io.type) {
                }
 #endif
        break;
-       case GPS_IO_HILDON_DBUS:
 #ifdef WITH_HILDON_DBUS_BT
+       case GPS_IO_HILDON_DBUS:
                if (NULL == (gps->io.dbus_conn=dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) {
                        g_printerr("Failed to get D-Bus connection.");
                        return FALSE;
@@ -499,15 +517,14 @@ switch (gps->io.type) {
                                G_TYPE_BOOLEAN, &mybool,
                                G_TYPE_INVALID);
                }
-#endif
-               return FALSE;
        break;
-       case GPS_IO_RFCOMM:
+#endif
 #ifdef WITH_BLUEZ
+       case GPS_IO_RFCOMM:
                if (!gps->io.address)
                        return FALSE;
 
-               if (gps->io.conn==RCVR_DOWN && gps->io.address) {
+               if (gps->io.conn<=RCVR_DOWN && gps->io.address) {
                        gps->io.fd=socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
 
                        /* If file descriptor creation failed, try again later.  Note that
@@ -524,7 +541,6 @@ switch (gps->io.type) {
                        str2ba(gps->io.address, &gps->io.rcvr_addr_rc.rc_bdaddr);
                }
 #endif
-               return FALSE;
        break;
        case GPS_IO_SIMULATION:
                /* Set a periodic cb to generate random movement */
@@ -533,6 +549,7 @@ switch (gps->io.type) {
                return FALSE;
        break;
        default:
+               g_printerr("Unknown GPS connection type\n");
                return FALSE;
        break;
 }
@@ -608,8 +625,9 @@ Gps *gps=(Gps *)data;
 g_assert(data);
 /* An error has occurred - re-connect(). */
 gps_disconnect(gps);
-track_add(NULL, FALSE);
-/* _speed_excess = FALSE; */
+
+if (gps->connection_error!=NULL)
+       gps->connection_error(gps, "GPS Connection error");
 
 if (gps->io.conn > RCVR_OFF) {
        gps_conn_set_state(gps, RCVR_DOWN);
@@ -651,8 +669,9 @@ switch (status) {
                                if (*sptr)
                                        *sptr = '\0';   /* take checksum out of the buffer. */
 
-                               data=g_strdup(gps->io.buffer);
-                               g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)gps_nmea_parse, data, NULL);
+                               gps->io.nmea=g_strdup(gps->io.buffer);
+                               g_assert(gps->io.nmea);
+                               g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)gps_nmea_parse, gps, NULL);
                        } else {
                                /* There was a checksum, and it was bad. */
                                g_printerr("%s: Bad checksum in NMEA sentence:\n%s\n", __PRETTY_FUNCTION__, gps->io.buffer);
@@ -671,15 +690,34 @@ switch (status) {
                        gps->io.curr -= (eol - gps->io.buffer + 1);
                }
        }
+       gps->io.errors=0;
+       gps->io.again=0;
        break;
        case G_IO_STATUS_ERROR:
        case G_IO_STATUS_EOF:
                gps_disconnect(gps);
                gps_connect_later(gps);
                gps->io.errors++;
+               if (gps->io.errors>10) {
+                       if (gps->connection_error==NULL)
+                               return FALSE;
+                       else {
+                               gps->connection_error(gps, "GPS data read error.");                     
+                       }
+               }
                return FALSE;
        break;
        case G_IO_STATUS_AGAIN:
+               gps->io.again++;
+               if (gps->io.again>20) {
+                       gps_disconnect(gps);
+                       gps_connect_later(gps);
+                       if (gps->connection_error==NULL)
+                               return FALSE;
+                       else {
+                               gps->connection_error(gps, "GPS connection deadlock.");
+                       }
+               }
                return TRUE;
        break;
        default:
index c4a4e02008ad93238ca5eb7931300abb7748edd9..fa7afdac02ece1491119f5788471927d6068712a 100644 (file)
--- a/src/gps.h
+++ b/src/gps.h
@@ -90,11 +90,13 @@ struct _GpsIO {
        guint error_sid;
        guint input_sid;
        guint clater_sid;
-       guint errors;
+       guint errors; /* G_IO_STATUS_ERRROR counter */
+       guint again; /* G_IO_STATUS_AGAIN counter */
        /* Input buffer */
        gchar buffer[GPS_READ_BUF_SIZE];
        gchar *curr;
        gchar *last;
+       /* Latest NMEA line, ready for parsing */
        gchar *nmea;
 };
 
@@ -107,16 +109,26 @@ struct _Gps {
        GpsIO io;
        GpsData data;
        /* Event callbacks */
+
        /* On errors */
        gboolean(* connection_error) (Gps *gps, const gchar *error_str);
+
        /* Connection retry */
        gboolean(* connection_retry) (Gps *gps, const gchar *error_str);
+
+       /* Connection progress */
+       gboolean(* connection_progress)(Gps *gps, gdouble fix);
+
+       /* New location */
+       void(* update_location)(Gps *gps, gboolean newly_fixed);
+       void(* update_satellite)(Gps *gps);
+       void(* update_info)(Gps *gps);
 };
 
 Gps *_gps;
 gint _gmtoffset;
 
-GpsTypes *gps_get_supported_types(void);
+const GpsTypes *gps_get_supported_types(void);
 
 Gps *gps_new(GpsIOSourceType type);
 void gps_set_address(Gps *gps, gchar *address, guint port);
index 0a0981209af8122f461401f9094e8c07c33c758c..febce87e7c75395bdcf949aedf1f04d4b8da3d9d 100644 (file)
--- a/src/gpx.h
+++ b/src/gpx.h
@@ -2,6 +2,7 @@
 #define _GPX_H
 
 #include <glib.h>
+#include <libgnomevfs/gnome-vfs.h>
 #include "path.h"
 
 void gpx_init(void);
index 60374a704a3b8a48afa64fab2f56cd5b41d42773..bb51c85c2705ae582140d9b8b513dfc91668e1ae 100644 (file)
@@ -58,6 +58,7 @@
 #include "mapper-types.h"
 #include "settings.h"
 #include "gps.h"
+#include "gps-conn.h"
 #include "map.h"
 #include "route.h"
 #include "track.h"
@@ -287,6 +288,11 @@ switch (mis) {
                /* XXX: Load GPS configuration, then create gps */
                _gps=gps_new(GPS_IO_SIMULATION);
                _gps->connection_retry=gps_retry_connection;
+               _gps->connection_error=NULL;
+               _gps->connection_progress=gps_conn_set_progress;
+               _gps->update_location=gps_location_update;
+               _gps->update_info=gps_info_update;
+
                timezone_init();
                gpx_init();
                variables_init();
index 800cd0fbe6cf0009e5a506d4dfa4625743337804..20f0eb8ac0cac8fc631e284427c251f6777213b7 100644 (file)
@@ -1,5 +1,8 @@
 #include <config.h>
 
+#include <libgnomevfs/gnome-vfs.h>
+#include <sqlite3.h>
+
 #include "utils.h"
 #include "gps.h"
 #include "map.h"
@@ -193,7 +196,7 @@ if (gps && show_directions && _next_way_dist_squared < (announce_thres_unsquared
 KEEP_DISPLAY_ON();
 }
 
-void 
+gboolean 
 track_insert_break(void)
 {
 if (_track.tail->unity) {
@@ -215,9 +218,9 @@ if ((x1 < BUF_WIDTH_PIXELS) && ((unsigned)y1 < BUF_HEIGHT_PIXELS))
                x1 - _draw_width, y1 - _draw_width,
                2 * _draw_width, 2 * _draw_width, 0,
                360 * 64);
-} else {
-       MACRO_BANNER_SHOW_INFO(_window, _("Break already inserted."));
+       return TRUE;
 }
+return FALSE;
 }
 
 gboolean
index 51f761a0bcd600dd81feb8e57ad49598bf661179..9c4bd8472e2daae731798c7bbc092f5dd8fd9f31 100644 (file)
@@ -25,7 +25,7 @@ void track_init(void);
 void track_deinit(void);
 
 void track_add(GpsData *gps, gboolean newly_fixed);
-void track_insert_break(void);
+gboolean track_insert_break(void);
 gboolean track_insert_mark(void);
 gboolean track_save(void);
 gboolean track_open(void);
index 9d14e13b19f4c9f6e287f5e51f61c67b07e64663..1fe5f20d49317650e97139f179466f853e0656b2 100644 (file)
@@ -32,6 +32,7 @@
 #include "db.h"
 #include "gps-panels.h"
 #include "gps-conn.h"
+#include "filter.h"
 #include "settings-gui.h"
 
 /* Callbacks */
@@ -799,6 +800,32 @@ if (dialog)
        gtk_widget_destroy(dialog);
 }
 
+gboolean
+gps_info_update(Gps *gps)
+{
+g_assert(gps);
+if (_gps_info)
+    gps_display_data(&gps->data);
+
+if (_satdetails_on)
+    gps_display_details(&gps->data);
+
+gps_display_data_speed(info_banner.speed, gps->data.speed);
+
+return TRUE;
+}
+
+gboolean
+gps_location_update(Gps *gps, gboolean newly_fixed)
+{
+g_assert(gps);
+if (filter_check(&filter, &gps->data, &map_loc)==TRUE) {
+       track_add(&_gps->data, newly_fixed);
+       map_refresh_mark();
+}
+return TRUE;
+}
+
 /**
  * Simple dialog to ask if we should try to reconnect to GPS
  * returns TRUE or FALSE
@@ -809,6 +836,7 @@ gps_retry_connection(Gps *gps, const gchar *error)
 GtkWidget *confirm;
 gboolean r;
 
+g_assert(gps);
 confirm=hildon_note_new_confirmation(GTK_WINDOW(_window), _("Failed to connect to GPS receiver. Retry?"));
 r=(GTK_RESPONSE_OK==gtk_dialog_run(GTK_DIALOG(confirm))) ? TRUE : FALSE;
 gtk_widget_destroy(confirm);
index f4359eef674e3acdad7c3074a067b6cfb20eeaaf..d3213e9eac634166bf3f3d4fd49244296223957c 100644 (file)
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 #include <fcntl.h>
-#include <gdk/gdkkeysyms.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <curl/multi.h>
-#include <gconf/gconf-client.h>
-#include <libxml/parser.h>
 
 #include "gps.h"
 #include "mapper-types.h"
@@ -132,6 +127,9 @@ void set_action_activate(const char *name, gboolean active);
 GtkWidget *progress_dialog(const gchar *title, GtkWidget *progress);
 void progress_dialog_remove(GtkWidget *dialog);
 
+/* XXX: Not the right place but.. */
+gboolean gps_info_update(Gps *gps);
+gboolean gps_location_update(Gps *gps, gboolean newly_fixed);
 gboolean gps_retry_connection(Gps *gps, const gchar *error);
 
 #endif
index a1e1467d85575c1a352b62810f07dbefa2a3d880..53a647120964fcc6b4f1764ecbaa4ddca474bdd9 100644 (file)
@@ -76,7 +76,6 @@
     if(error_check == (str)) \
     { \
         g_printerr("Line %d: Failed to parse string as int: %s\n", __LINE__, str); \
-        MACRO_BANNER_SHOW_INFO(_window, _("Invalid NMEA input from receiver!")); \
         return; \
     } \
 }
@@ -86,7 +85,6 @@
     if(error_check == (str)) \
     { \
         g_printerr("Failed to parse string as float: %s\n", str); \
-        MACRO_BANNER_SHOW_INFO(_window, _("Invalid NMEA input from receiver!")); \
         return; \
     } \
 }