$(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 \
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)
} 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);
#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)
{
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) {
#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
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);
/* 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); */
}
}
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
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);
g_debug("%s(): %s\n", __PRETTY_FUNCTION__, sentence);
-#define DELIM ","
-
/* Skip Auto selection. */
token = strsep(&sentence, DELIM);
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;
}
#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
#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>
#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;
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;
}
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) {
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);
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);
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;
}
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;
}
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");
}
#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;
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
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 */
return FALSE;
break;
default:
+ g_printerr("Unknown GPS connection type\n");
return FALSE;
break;
}
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);
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);
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:
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;
};
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);
#define _GPX_H
#include <glib.h>
+#include <libgnomevfs/gnome-vfs.h>
#include "path.h"
void gpx_init(void);
#include "mapper-types.h"
#include "settings.h"
#include "gps.h"
+#include "gps-conn.h"
#include "map.h"
#include "route.h"
#include "track.h"
/* 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();
#include <config.h>
+#include <libgnomevfs/gnome-vfs.h>
+#include <sqlite3.h>
+
#include "utils.h"
#include "gps.h"
#include "map.h"
KEEP_DISPLAY_ON();
}
-void
+gboolean
track_insert_break(void)
{
if (_track.tail->unity) {
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
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);
#include "db.h"
#include "gps-panels.h"
#include "gps-conn.h"
+#include "filter.h"
#include "settings-gui.h"
/* Callbacks */
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
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);
#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"
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
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; \
} \
}
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; \
} \
}