Hey
This patch allows maemo-mapper to load gpx tracks from a wintec gps.
You have to install gpsbabel to /usr/bin or the menu items won't
activate. The gps needs to be connected to load the log. For a recent
(but not packaged) gpsbabel: http://www.daria.co.uk/gps/
It's a quick and dirty thing and my first real work in scratchbox
(just noticed vim wasn't expanding tabs to spaces, blah).
One reason I wanted to get this out there is so it would be clear
there are downsides to running gpsd. We'd have to stop gpsd during the
track transfer if it was in the loop.
Working with a logging gps can be useful if you want to save the
n800's batteries. I sometimes leave the n800 off and let the gps log
things by itself. The next time I'm hiking I do not want to have to
drop to a shell to pull this off :)
Brad
Index: src/maemo-mapper.c
===================================================================
--- src/maemo-mapper.c (revision 110)
+++ src/maemo-mapper.c (working copy)
@@ -1061,6 +1061,8 @@
static GtkWidget *_menu_track_distlast_item = NULL;
static GtkWidget *_menu_track_distfirst_item = NULL;
static GtkWidget *_menu_track_clear_item = NULL;
+static GtkWidget *_menu_track_load_gps_item = NULL;
+static GtkWidget *_menu_track_clear_gps_item = NULL;
/* Menu items for the "Maps" submenu. */
static GtkWidget *_menu_maps_submenu = NULL;
@@ -1215,6 +1217,9 @@
static gchar XML_TZONE[7];
static gint _gmtoffset = 0;
+static gboolean _gpsbabel_present = FALSE;
+static gchar *_rfcomm_device = NULL;
+
/****************************************************************************
* ABOVE: DATA **************************************************************
****************************************************************************/
@@ -1290,6 +1295,10 @@
menu_cb_track_distfirst(GtkAction *action);
static gboolean
menu_cb_track_clear(GtkAction *action);
+static gboolean
+menu_cb_track_load_gps(GtkAction *action);
+static gboolean
+menu_cb_track_clear_gps(GtkAction *action);
/* Callbacks for the "Maps" submenu. */
static gboolean
@@ -3866,7 +3875,10 @@
_connect_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE,
G_IO_OUT, channel_cb_connect, NULL, NULL);
}
- g_free(fdpath);
+ if(_rfcomm_device) {
+ g_free(_rfcomm_device);
+ }
+ _rfcomm_device = fdpath;
vprintf("%s(): return\n", __PRETTY_FUNCTION__);
}
@@ -5287,6 +5299,10 @@
FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_reset_item),
FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(_menu_track_load_gps_item),
+ FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(_menu_track_clear_gps_item),
+ FALSE);
}
}
else if(!_rcvr_mac || strcmp(_rcvr_mac,
@@ -6157,6 +6173,12 @@
= gtk_menu_item_new_with_label(_("Show Distance from Beginning")));
gtk_menu_append(submenu, _menu_track_clear_item
= gtk_menu_item_new_with_label(_("Clear")));
+ gtk_menu_append(submenu, _menu_track_load_gps_item
+ = gtk_menu_item_new_with_label(_("Load track from logging gps")));
+ gtk_widget_set_sensitive(GTK_WIDGET(_menu_track_load_gps_item), _enable_gps && _gpsbabel_present);
+ gtk_menu_append(submenu, _menu_track_clear_gps_item
+ = gtk_menu_item_new_with_label(_("Clear tracks in logging gps")));
+ gtk_widget_set_sensitive(GTK_WIDGET(_menu_track_clear_gps_item), _enable_gps && _gpsbabel_present);
/* The "Maps" submenu. */
gtk_menu_append(menu, menu_item
@@ -6330,7 +6352,12 @@
G_CALLBACK(menu_cb_track_distfirst), NULL);
g_signal_connect(G_OBJECT(_menu_track_clear_item), "activate",
G_CALLBACK(menu_cb_track_clear), NULL);
+ g_signal_connect(G_OBJECT(_menu_track_load_gps_item), "activate",
+ G_CALLBACK(menu_cb_track_load_gps), NULL);
+ g_signal_connect(G_OBJECT(_menu_track_clear_gps_item), "activate",
+ G_CALLBACK(menu_cb_track_clear_gps), NULL);
+
/* Connect the "Maps" signals. */
g_signal_connect(G_OBJECT(_menu_maps_repoman_item), "activate",
G_CALLBACK(menu_cb_maps_repoman), NULL);
@@ -8105,6 +8132,8 @@
config_init();
+ _gpsbabel_present = g_file_test("/usr/bin/gpsbabel", G_FILE_TEST_EXISTS);
+
/* Initialize _program. */
_program = HILDON_PROGRAM(hildon_program_get_instance());
g_set_application_name("Maemo Mapper");
@@ -10635,6 +10664,67 @@
}
static gboolean
+menu_cb_track_load_gps(GtkAction *action)
+{
+ gchar *buffer;
+ gint size;
+ gchar command[256];
+ char *tmpfile = "/tmp/tracklog.gpx";
+ char *file_uri_str;
+ pid_t pid;
+ int status;
+
+ printf("%s()\n", __PRETTY_FUNCTION__);
+
+ // would work better with a popen if the gpx parser could use a stream
+
+ if(!(pid = fork())) {
+ unlink(tmpfile);
+ execl("/usr/bin/gpsbabel", "/usr/bin/gpsbabel", "-t", "-i", "wbt", "-f", _rfcomm_device, "-o", "gpx", "-F", tmpfile, NULL);
+ exit(-1);
+ }
+
+ waitpid(pid, &status, 0);
+
+ if(WEXITSTATUS(status) == 0) {
+ file_uri_str = gnome_vfs_get_uri_from_local_path(tmpfile);
+ if(GNOME_VFS_OK == gnome_vfs_read_entire_file(file_uri_str, &size, &buffer))
+ {
+ if(parse_gpx(&_track, buffer, size, -1))
+ {
+ map_force_redraw();
+ MACRO_BANNER_SHOW_INFO(_window, _("Track Logs Opened"));
+ }
+ else
+ popup_error(_window, _("Error parsing log."));
+ g_free(buffer);
+ } else
+ MACRO_BANNER_SHOW_INFO(_window, _("Couldn't open logfile"));
+ } else
+ MACRO_BANNER_SHOW_INFO(_window, _("Couldn't run gpsbabel"));
+
+ vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
+ return TRUE;
+}
+
+static gboolean
+menu_cb_track_clear_gps(GtkAction *action)
+{
+ pid_t pid;
+ int status;
+
+ if(!(pid = fork())) {
+ execl("/usr/bin/gpsbabel", "/usr/bin/gpsbabel", "-t", "-i", "wbt,erase", "-f", _rfcomm_device, "-o", "gpx", "-F", "/dev/null", NULL);
+ exit(-1);
+ }
+ waitpid(pid, &status, 0);
+ if(WEXITSTATUS(status)) {
+ MACRO_BANNER_SHOW_INFO(_window, _("Couldn't Clear Log"));
+ }
+ return TRUE;
+}
+
+static gboolean
menu_cb_show_tracks(GtkAction *action)
{
printf("%s()\n", __PRETTY_FUNCTION__);
@@ -12431,6 +12521,8 @@
gps_show_info();
gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item), _enable_gps);
gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_reset_item), _enable_gps);
+ gtk_widget_set_sensitive(GTK_WIDGET(_menu_track_load_gps_item), _enable_gps && _gpsbabel_present);
+ gtk_widget_set_sensitive(GTK_WIDGET(_menu_track_clear_gps_item), _enable_gps && _gpsbabel_present);
vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
return TRUE;
_______________________________________________
maemo-developers mailing list
[email protected]
https://lists.maemo.org/mailman/listinfo/maemo-developers