From 7d04c4d01608cb4c651c3fc3a7eefb35da41d813 Mon Sep 17 00:00:00 2001 From: martin-s Date: Fri, 19 Dec 2008 22:03:52 +0000 Subject: [PATCH] Fix:vehicle_gpsd:Auto-Start gpsd on maemo git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1839 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/configure.in | 9 ++++++++- navit/navit/navit.c | 1 + navit/navit/vehicle.c | 1 + navit/navit/vehicle/gpsd/Makefile.am | 4 ++-- navit/navit/vehicle/gpsd/vehicle_gpsd.c | 27 +++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/navit/configure.in b/navit/configure.in index fdaa1fe..d6b96c5 100644 --- a/navit/configure.in +++ b/navit/configure.in @@ -90,12 +90,19 @@ test x"${AVOID_UNALIGNED}" = xyes && AC_DEFINE(AVOID_UNALIGNED,[],Define to avoi AC_ARG_ENABLE(avoid-float, [ --enable-avoid-float avoid floating point calculations], AVOID_FLOAT=$enableval, AVOID_FLOAT=no) test x"${AVOID_FLOAT}" = xyes && AC_DEFINE(AVOID_FLOAT,[],Define to avoid floating point) -AC_ARG_ENABLE(hildon, [ --enable-hildon build with maemo/hildon support], enable_hildon=$enableval, enable_hildon=no) +AC_ARG_ENABLE(hildon, [ --disable-hildon build without maemo/hildon support], enable_hildon=$enableval, enable_hildon=yes) if test "x${enable_hildon}" = "xyes" ; then PKG_CHECK_MODULES(HILDON, hildon-1 >= 0.9.9, , [ AC_MSG_RESULT(no) enable_hildon=no ]) + PKG_CHECK_MODULES(GPSBT, gpsbt, [ + AC_DEFINE(HAVE_GPSBT, 1, [Have the gpsbt library]) + AC_SUBST(GPSBT_CFLAGS) + AC_SUBST(GPSBT_LIBS) + ], [ + AC_MSG_RESULT(no) + ]) if test x"${enable_hildon}" = xyes ; then AC_DEFINE(USE_HILDON, 1, [Build with maemo/hildon support]) AC_SUBST(HILDON_CFLAGS) diff --git a/navit/navit/navit.c b/navit/navit/navit.c index f9503fc..8543af6 100644 --- a/navit/navit/navit.c +++ b/navit/navit/navit.c @@ -2021,6 +2021,7 @@ void navit_destroy(struct navit *this_) { /* TODO: destroy objects contained in this_ */ + vehicle_destroy(this_->vehicle->vehicle); main_remove_navit(this_); char *center_file = navit_get_center_file(TRUE); navit_write_center_to_file(this_, center_file); diff --git a/navit/navit/vehicle.c b/navit/navit/vehicle.c index f52f9ce..cf63a3c 100644 --- a/navit/navit/vehicle.c +++ b/navit/navit/vehicle.c @@ -230,6 +230,7 @@ vehicle_remove_attr(struct vehicle *this_, struct attr *attr) void vehicle_destroy(struct vehicle *this_) { + this_->meth.destroy(this_->priv); callback_list_destroy(this_->cbl); attr_list_free(this_->attrs); g_free(this_); diff --git a/navit/navit/vehicle/gpsd/Makefile.am b/navit/navit/vehicle/gpsd/Makefile.am index b41529b..7a52b18 100644 --- a/navit/navit/vehicle/gpsd/Makefile.am +++ b/navit/navit/vehicle/gpsd/Makefile.am @@ -1,5 +1,5 @@ include $(top_srcdir)/Makefile.inc -AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=vehicle_gpsd +AM_CPPFLAGS = @NAVIT_CFLAGS@ @GPSBT_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=vehicle_gpsd modulevehicle_LTLIBRARIES = libvehicle_gpsd.la libvehicle_gpsd_la_SOURCES = vehicle_gpsd.c -libvehicle_gpsd_la_LIBADD = @GPSD_LIBS@ +libvehicle_gpsd_la_LIBADD = @GPSD_LIBS@ @GPSBT_LIBS@ diff --git a/navit/navit/vehicle/gpsd/vehicle_gpsd.c b/navit/navit/vehicle/gpsd/vehicle_gpsd.c index 2025fda..5d0c62b 100644 --- a/navit/navit/vehicle/gpsd/vehicle_gpsd.c +++ b/navit/navit/vehicle/gpsd/vehicle_gpsd.c @@ -22,6 +22,10 @@ #include #include #include +#ifdef HAVE_GPSBT +#include +#include +#endif #include "debug.h" #include "callback.h" #include "plugin.h" @@ -189,6 +193,19 @@ vehicle_gpsd_try_open(gpointer *data) static void vehicle_gpsd_open(struct vehicle_priv *priv) { +#ifdef HAVE_GPSBT + char errstr[256] = ""; + /* We need to start gpsd (via gpsbt) first. */ + errno = 0; + memset(&priv->context, 0, sizeof(gpsbt_t)); + if(gpsbt_start(NULL, 1, 0, 0, errstr, sizeof(errstr), + 0, &priv->context) < 0) { + dbg(0,"Error connecting to GPS with gpsbt: (%d) %s (%s)\n", + errno, strerror(errno), errstr); + } + sleep(1); /* give gpsd time to start */ + dbg(1,"gpsbt_start: completed\n"); +#endif priv->retry_timer=0; if (vehicle_gpsd_try_open((gpointer *)priv)) { priv->retry_timer = g_timeout_add(priv->retry_interval*1000, (GSourceFunc)vehicle_gpsd_try_open, (gpointer *)priv); @@ -199,6 +216,9 @@ static void vehicle_gpsd_close(struct vehicle_priv *priv) { GError *error = NULL; +#ifdef HAVE_GPSBT + int err; +#endif if (priv->watch) { g_source_remove(priv->watch); @@ -216,6 +236,13 @@ vehicle_gpsd_close(struct vehicle_priv *priv) gps_close(priv->gps); priv->gps = NULL; } +#ifdef HAVE_GPSBT + err = gpsbt_stop(&priv->context); + if (err < 0) { + dbg(0,"Error %d while gpsbt_stop", err); + } + dbg(1,"gpsbt_stop: completed, (%d)",err); +#endif } static gboolean -- 2.7.4