From: <d_...@us...> - 2008-12-22 12:56:46
|
Revision: 2216 http://gpsdrive.svn.sourceforge.net/gpsdrive/?rev=2216&view=rev Author: d_s_e Date: 2008-12-22 11:59:44 +0000 (Mon, 22 Dec 2008) Log Message: ----------- - moved gpsd connection to use libgps (satellite status window updated soon...) Modified Paths: -------------- trunk/src/CMakeLists.txt trunk/src/gps_handler.c trunk/src/gps_handler.h trunk/src/gpsdrive.c trunk/src/gpsdrive.h trunk/src/gpsdrive_config.c trunk/src/gpsdrive_config.h trunk/src/gpsproto.h trunk/src/main_gui.c trunk/src/settings.c trunk/src/speech.c trunk/src/track.c trunk/src/unit_test.c Modified: trunk/src/CMakeLists.txt =================================================================== --- trunk/src/CMakeLists.txt 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/CMakeLists.txt 2008-12-22 11:59:44 UTC (rev 2216) @@ -7,8 +7,8 @@ find_package(Freetype2 REQUIRED) find_package(SQLite3 REQUIRED) find_package(CURL REQUIRED) +find_package(Gps REQUIRED) - if (MAEMO) find_package(Hildon REQUIRED) add_definitions(-DMAEMO) @@ -63,6 +63,7 @@ ${CURL_INCLUDE_DIRS} ${SPEECHD_INCLUDE_DIRS} ${HILDON_INCLUDE_DIR} + ${GPS_INCLUDE_DIRS} ) set(GPSDRIVE_LINK_LIBRARIES @@ -81,6 +82,7 @@ ${CURL_LIBRARIES} ${SPEECHD_LIBRARIES} ${HILDON_LIBRARIES} + ${GPS_LIBRARIES} ) set(gpsdrive_SRCS @@ -116,7 +118,6 @@ map_projection.c navigation.c navigation_gui.c - nmea_handler.c os_specific.c poi.c poi_gui.c Modified: trunk/src/gps_handler.c =================================================================== --- trunk/src/gps_handler.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gps_handler.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -22,31 +22,15 @@ *********************************************************************/ -#include "config.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <glib.h> +#include <gps.h> #include "config.h" -#include "gettext.h" #include "gpsdrive.h" -#include "icons.h" #include "gps_handler.h" -#include "nmea_handler.h" -#include <errno.h> -#include <fcntl.h> -#include <math.h> -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <time.h> -#include <unistd.h> - -#include <dlfcn.h> -#include <semaphore.h> - #include "gpsdrive_config.h" #include "gui.h" @@ -62,898 +46,151 @@ # define N_(String) (String) # endif -#ifdef DBUS -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <dbus/dbus-glib.h> -static DBusHandlerResult dbus_signal_handler ( - DBusConnection* connection, DBusMessage* message); -static DBusHandlerResult dbus_handle_gps_fix (DBusMessage* message); -#endif +/* How often do we ask for positioning data */ +#define GPS_TIMER 500 + extern gint mydebug; -gint gps_handler_debug = 0; - -extern gint maploaded; - -extern gchar utctime[20], loctime[20]; -extern gint havepos, haveposcount; -extern gint blink, gblink, xoff, yoff; -extern gdouble milesconv; -extern gchar mapfilename[1024]; -extern gint satlist[MAXSATS][4], satlistdisp[MAXSATS][4], satbit; -extern gint sats_used, sats_in_view; -extern gchar *buffer, *big; -fd_set readmask; -extern struct timeval timeout; -extern gdouble earthr; -extern gint timeoutcount; -extern gint simpos_timeout; -extern GdkPixbuf *satsimage; -extern gchar dgpsserver[80], dgpsport[10]; -extern gchar gpsdservername[200]; -extern GtkWidget *frame_statusbar; extern coordinate_struct coords; extern currentstatus_struct current; -// ---------------------- NMEA -extern gint haveRMCsentence; -extern gdouble NMEAsecs; -extern gint NMEAoldsecs; -/* if we get data from gpsd in NMEA format haveNMEA is TRUE */ -gchar nmeamodeandport[50]; -gint haveNMEA; -gint useDBUS; +static gint gps_timeout_source = 0; -#ifdef DBUS -DBusError dbuserror; -DBusConnection* connection; -struct dbus_gps_fix { - gdouble time; /* Time as time_t with optional fractional seconds */ - gint32 mode; /* Fix type - * 0 = Not seen. 1 = No fix. 2/3 = 2D/3D fix - * We use -1 to identify that the current fix - * is * already processed */ - gdouble ept; /* Expected time uncertainty */ - gdouble latitude; /* Latitude in degrees (valid if mode >= 2) */ - gdouble longitude; /* Longitude in degrees (valid if mode >= 2) */ - gdouble eph; /* Horizontal position uncertainty, meters */ - gdouble altitude; /* Altitude in meters (valid if mode == 3) */ - gdouble epv; /* Vertical position uncertainty, meters */ - gdouble track; /* Course made good (relative to true north) */ - gdouble epd; /* Track uncertainty, degrees */ - gdouble speed; /* Speed over ground, meters/sec */ - gdouble eps; /* Speed uncertainty, meters/sec */ - gdouble climb; /* Vertical speed, meters/sec */ - gdouble epc; /* Vertical speed uncertainty */ -}; -struct dbus_gps_fix dbus_old_fix, dbus_current_fix; -#ifndef NAN -#define NAN (0.0/0.0) -#endif -#endif -gint bigp = 0, bigpGGA = 0, bigpRME = 0, bigpGSA = 0, bigpGSV = 0; -gint lastp = 0, lastpGGA = 0, lastpRME = 0, lastpGSA = 0, lastpGSV = 0; -gint sock = -1; +static struct gps_data_t *gpsdata; +// double online; /* NZ if GPS is on line, 0 if not. */ +// +// struct gps_fix_t fix; +// { +// int mode; /* Mode of fix */ +// #define MODE_NOT_SEEN 0 /* mode update not seen yet */ +// #define MODE_NO_FIX 1 /* none */ +// #define MODE_2D 2 /* good for latitude/longitude */ +// #define MODE_3D 3 /* good for altitude/climb too */ +// double latitude; /* Latitude in degrees (valid if mode >= 2) */ +// double longitude; /* Longitude in degrees (valid if mode >= 2) */ +// double eph; /* Horizontal position uncertainty, meters */ +// double altitude; /* Altitude in meters (valid if mode == 3) */ +// double epv; /* Vertical position uncertainty, meters */ +// double speed; /* Speed over ground, meters/sec */ +// double climb; /* Vertical speed, meters/sec */ +// }; +// +// /* GPS status -- always valid */ +// int status; /* Do we have a fix? */ +//#define STATUS_NO_FIX 0 /* no */ +//#define STATUS_FIX 1 /* yes, without DGPS */ +//#define STATUS_DGPS_FIX 2 /* yes, with DGPS */ +// +// /* satellite status -- valid when satellites > 0 */ +// int satellites_used; /* Number of satellites used in solution */ +// int used[MAXCHANNELS]; /* PRNs of satellites used in solution */ +// int satellites; /* # of satellites in view */ +// int PRN[MAXCHANNELS]; /* PRNs of satellite */ +// int elevation[MAXCHANNELS]; /* elevation of satellite */ +// int azimuth[MAXCHANNELS]; /* azimuth */ +// int ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */ -gint convertGSV (char *f); - /* ***************************************************************************** + * close connection to gpsd */ void -gpsd_close () +gps_hook_cb (struct gps_data_t *data, gchar *buf) { - if (sock != -1) { - socket_close (sock); - sock = -1; - } -} + if (mydebug > 20) + g_print ("gps_hook_cb ()\n"); -/* ***************************************************************************** - */ -#ifdef DBUS -void -init_dbus_current_fix() -{ - // Preserve the time - dbus_current_fix.mode = 0; - dbus_current_fix.ept = NAN; - dbus_current_fix.latitude = NAN; - dbus_current_fix.longitude = NAN; - dbus_current_fix.eph = NAN; - dbus_current_fix.altitude = NAN; - dbus_current_fix.epv = NAN; - dbus_current_fix.track = NAN; - dbus_current_fix.epd = NAN; - dbus_current_fix.speed = NAN; - dbus_current_fix.eps = NAN; - dbus_current_fix.climb = NAN; - dbus_current_fix.epc = NAN; -} + if (data->status == STATUS_NO_FIX) + return; -void init_dbus(){ - haveNMEA = TRUE; - - memset(&dbus_old_fix, 0, sizeof(struct dbus_gps_fix)); - init_dbus_current_fix(); - dbus_current_fix.time = 0.0; // Time is not set in init_dbus_current_time - - dbus_error_init (&dbuserror); - - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbuserror); - if (dbus_error_is_set (&dbuserror)) { - g_print ("%s: %s", dbuserror.name, dbuserror.message); - exit(0); + if (mydebug > 40) + { + g_print (" Fix Status: %d\n Fix Mode: %d\n", data->status, data->fix.mode); + g_print (" Sats used: %d of %d\n", data->satellites_used, data->satellites); + g_print (" Position: %.6f / %.6f\n", data->fix.latitude, data->fix.longitude); + g_print (" Speed: %.1f m/s\n Altitude: %.1f m\n\n", + data->fix.speed, data->fix.altitude); } - - dbus_bus_add_match (connection, "type='signal'", &dbuserror); - if (dbus_error_is_set (&dbuserror)) { - g_print (_("unable to add match for signals %s: %s"), dbuserror.name, dbuserror.message); - exit(0); - } - if (!dbus_connection_add_filter (connection, (DBusHandleMessageFunction)dbus_signal_handler, NULL, NULL)) { - g_print (_("unable to register filter with the connection")); - exit(0); - } - - g_strlcpy (nmeamodeandport, - _("DBUS Mode"), sizeof (nmeamodeandport)); - dbus_connection_setup_with_g_main (connection, NULL); -} + current.gps_status = data->status; + current.gps_mode = data->fix.mode; + coords.current_lat = data->fix.latitude; + coords.current_lon = data->fix.longitude; + current.altitude = data->fix.altitude; + current.gps_sats_used = data->satellites_used; + current.gps_sats_in_view = data->satellites; + current.groundspeed = data->fix.speed * 3.6; + current.heading = data->fix.track; + current.gps_hdop = data->hdop; + current.gps_eph = data->fix.eph; + current.gps_epv = data->fix.epv; -#endif - -/* ****************************************************************** - * Initialize nmea socket to - * look if we have an open socket "sock" and close it - * the try to reconnect to gpsd - * If we're successfull we set - * nmeamodeandport = "Sting with description of connection" - * sock = the open socket - * if we're not successfull we set - * simmode = TRUE - * haveNMEA = FALSE - */ -void -init_nmea_socket () -{ - struct sockaddr_in server; - struct hostent *server_data; - { - /* open socket to port */ - if (sock != -1) - { - socket_close (sock); - sock = -1; - } - sock = socket (AF_INET, SOCK_STREAM, 0); - if (sock < 0) - { - perror (_("Can't open socket for port ")); - fprintf (stderr, "error: %d\n", errno); - if (local_config.simmode == SIM_AUTO) - current.simmode = TRUE; - haveNMEA = FALSE; - if (simpos_timeout == 0) - simpos_timeout = - gtk_timeout_add (300, (GtkFunction) simulated_pos, 0); - memset (satlist, 0, sizeof (satlist)); - memset (satlistdisp, 0, sizeof (satlist)); - sats_used = sats_in_view = 0; - if (satsimage != NULL) - g_object_unref (satsimage); - satsimage = NULL; - return; - } - server.sin_family = AF_INET; - /* We retrieve the IP address of the server from its name: */ - if ((server_data = gethostbyname (SERVERNAME)) == NULL) - { - fprintf (stderr, - _("\nCannot connect to %s: unknown host\n"), SERVERNAME); - exit (1); - } - memcpy (&server.sin_addr, server_data->h_addr, server_data->h_length); - server.sin_port = htons (SERVERPORT2); - - /* We initiate the connection */ - if (connect (sock, (struct sockaddr *) &server, sizeof server) < 0) - { - server.sin_port = htons (SERVERPORT); /* We try second port */ - /* We initiate the connection */ - if (connect (sock, (struct sockaddr *) &server, sizeof server) < 0) - { - haveNMEA = FALSE; - if (local_config.simmode == SIM_AUTO) - current.simmode = TRUE; - } - else - { - timeoutcount = 0; - haveNMEA = TRUE; - if (local_config.simmode == SIM_AUTO) - current.simmode = FALSE; - g_strlcpy (nmeamodeandport, - _("NMEA Mode, Port 2222"), sizeof (nmeamodeandport)); - g_strlcat (nmeamodeandport, "/", sizeof (nmeamodeandport)); - g_strlcat (nmeamodeandport, gpsdservername, - sizeof (nmeamodeandport)); - } - } - else - { - g_strlcpy (nmeamodeandport, _("NMEA Mode, Port 2947"), - sizeof (nmeamodeandport)); - g_strlcat (nmeamodeandport, "/", sizeof (nmeamodeandport)); - g_strlcat (nmeamodeandport, gpsdservername, sizeof (nmeamodeandport)); - send (sock, "R\n", 2, 0); - timeoutcount = 0; - haveNMEA = TRUE; - if (local_config.simmode == SIM_AUTO) - current.simmode = FALSE; - } - } } -/* ****************************************************************** - */ -gint -initgps () +gboolean +gps_query_data_cb (gpointer data) { + if (current.importactive) + return TRUE; -#ifdef DBUS - if (useDBUS) { - init_dbus(); - } else -#endif + /* query gpsd for data: + * s - get fix mode + * o - get time/position/velocity data + * y - get satellite info + */ + gps_query (gpsdata, "soy\n"); - init_nmea_socket (); - /* We test for gpsd serving */ - - if (haveNMEA) - { - if (local_config.simmode == SIM_AUTO) - current.simmode = FALSE; - if (simpos_timeout != 0 && local_config.simmode != SIM_ON) - { - g_source_remove (simpos_timeout); - simpos_timeout = 0; - } - } - - return FALSE; /* to remove timer */ + return (TRUE); } /* ***************************************************************************** + * close connection to gpsd */ -#ifdef DBUS -static DBusHandlerResult dbus_signal_handler ( - DBusConnection* connection, DBusMessage* message) { - /* dummy, need to use the variable for some reason */ - connection = NULL; - - if (dbus_message_is_signal (message, "org.gpsd", "fix")) - return dbus_handle_gps_fix (message); - /* - * ignore all other messages - */ - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - void -dbus_process_fix(gint early) +gpsd_disconnect (void) { - struct tm time; - time_t ttime; - double direction; - - if (!early && (dbus_current_fix.mode==-1)) { - /* We have handled this one, so clean the mode and bail out */ - dbus_current_fix.mode = 0; - return; - } - - /* - * Handle the data - */ - /* Set utctime */ - ttime = dbus_current_fix.time; - gmtime_r (&ttime, &time); - g_snprintf (utctime, sizeof (utctime), "%02d:%02d.%02d ", time.tm_hour, time.tm_min, time.tm_sec); - g_snprintf (loctime, sizeof (loctime), "%02d:%02d ", - (time.tm_hour + current.timezone + 24)%24, time.tm_min); - NMEAsecs = dbus_current_fix.time; // Use this value to judge timeout - /* Bail out if we have no fix */ - current.gpsfix = 0; // Handled later. - if (dbus_current_fix.mode>1) { - current.gpsfix = dbus_current_fix.mode; - haveRMCsentence = TRUE; - haveposcount++; - if (haveposcount == 3) - rebuildtracklist(); - } else { - current.gpsfix = 1; - haveRMCsentence = FALSE; - haveposcount = 0; - dbus_old_fix = dbus_current_fix; - init_dbus_current_fix(); - if (early) - dbus_current_fix.mode = -1; - storepoint(); - return; - } - /* Handle latitude */ - if (!gui_status.expmode && !current.simmode) - coords.current_lat = dbus_current_fix.latitude; - /* Handle longitude */ - if (!gui_status.expmode && !current.simmode) - coords.current_lon = dbus_current_fix.longitude; - /* Handle speed */ - if (__finite(dbus_current_fix.speed)) - current.groundspeed = dbus_current_fix.speed * 3.6; // Convert m/s to km/h - else if (dbus_old_fix.mode>1) { - gdouble timediff = dbus_current_fix.time-dbus_old_fix.time; - current.groundspeed = (timediff>0)?(calcdist2(dbus_old_fix.longitude, dbus_old_fix.latitude) * 3600 / timediff) : 0.0; - } - /* Handle bearing */ - if (__finite(dbus_current_fix.track)) - direction = dbus_current_fix.track * M_PI / 180; // Convert to radians - else if (dbus_old_fix.mode>1) { - gdouble lon2 = coords.current_lon * M_PI / 180; - gdouble lon1 = dbus_old_fix.longitude * M_PI / 180; - gdouble lat2 = coords.current_lat * M_PI /180; - gdouble lat1 = dbus_old_fix.latitude * M_PI / 180; - if ((lat1 != lat2) || (lon1 != lon2)) - direction = atan2(sin(lon2-lon1)*cos(lat2), - cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1)); - } - if ( mydebug + gps_handler_debug > 80 ) - g_print("gps_handler: DBUS fix: %6.0f %10.6f/%10.6f sp:%5.2f(%5.2f) crs:%5.1f(%5.2f)\n", dbus_current_fix.time, - dbus_current_fix.latitude, dbus_current_fix.longitude, dbus_current_fix.speed, current.groundspeed, - dbus_current_fix.track, direction * 180 / M_PI); - /* Handle altitude */ - if (dbus_current_fix.mode>2) { - current.gpsfix = 3; - current.altitude = dbus_current_fix.altitude; - } - /* Handle positional error */ - current.gps_precision = dbus_current_fix.eph; - - dbus_old_fix = dbus_current_fix; - init_dbus_current_fix(); - if (early) - dbus_current_fix.mode = -1; - storepoint(); + if (gpsdata) + gps_close (gpsdata); } -static DBusHandlerResult dbus_handle_gps_fix (DBusMessage* message) { - - DBusError error; - double temp_time; - struct dbus_gps_fix fix; - dbus_error_init(&error); - - dbus_message_get_args(message, - &error, - DBUS_TYPE_DOUBLE, &temp_time, - DBUS_TYPE_INT32, &fix.mode, - DBUS_TYPE_DOUBLE, &fix.ept, - DBUS_TYPE_DOUBLE, &fix.latitude, - DBUS_TYPE_DOUBLE, &fix.longitude, - DBUS_TYPE_DOUBLE, &fix.eph, - DBUS_TYPE_DOUBLE, &fix.altitude, - DBUS_TYPE_DOUBLE, &fix.epv, - DBUS_TYPE_DOUBLE, &fix.track, - DBUS_TYPE_DOUBLE, &fix.epd, - DBUS_TYPE_DOUBLE, &fix.speed, - DBUS_TYPE_DOUBLE, &fix.eps, - DBUS_TYPE_DOUBLE, &fix.climb, - DBUS_TYPE_DOUBLE, &fix.epc, - DBUS_TYPE_INVALID); - fix.time = floor(temp_time); - - if ( mydebug + gps_handler_debug > 80 ) { - g_print("gps_handler: DBUS raw: ti:%6.0f mode:%d ept:%f %10.6f/%10.6f eph:%f\n", fix.time, fix.mode, fix.ept, fix.latitude, fix.longitude, fix.eph); - g_print(" alt:%6.2f epv:%f crs:%5.1f edp:%f sp:%5.2f eps:%f cl:%f epc:%f\n", fix.altitude, fix.epv, fix.track, fix.epd, fix.speed, fix.eps, fix.climb, fix.epc); - } - - /* Unfortunately gpsd dbus data is sometimes split over several messages */ - /* so we have to accumulate them... */ - - if (fix.time!=dbus_current_fix.time) - dbus_process_fix(FALSE); - // if mode is -1 we already processed it, so bail out - if (dbus_current_fix.mode==-1) - return DBUS_HANDLER_RESULT_HANDLED; - dbus_current_fix.time = fix.time; - if (__finite(fix.latitude)) - if (__isnan(dbus_current_fix.latitude) || (fix.mode>dbus_current_fix.mode)) - dbus_current_fix.latitude = fix.latitude; - if (__finite(fix.longitude)) - if (__isnan(dbus_current_fix.longitude) || (fix.mode>dbus_current_fix.mode)) - dbus_current_fix.longitude = fix.longitude; - if (__finite(fix.eph)) - if (__isnan(dbus_current_fix.eph) || (fix.mode>dbus_current_fix.mode)) - dbus_current_fix.eph = fix.eph; - if (__finite(fix.altitude)) - if (__isnan(dbus_current_fix.altitude) || (fix.mode>dbus_current_fix.mode)) - dbus_current_fix.altitude = fix.altitude; - if (__finite(fix.track)) - if (__isnan(dbus_current_fix.track) || (fix.mode>dbus_current_fix.mode)) - dbus_current_fix.track = fix.track; - if (__finite(fix.speed)) - if (__isnan(dbus_current_fix.speed) || (fix.mode>dbus_current_fix.mode)) - dbus_current_fix.speed = fix.speed; - if (fix.mode>dbus_current_fix.mode) - dbus_current_fix.mode = fix.mode; - - /* Do an early process if we have all important data to prevent lag. */ - /* We do not consider positional error and altitude important for gpsdrive =) */ - /* To soothe everybody, usually a valid altitude comes with the fix */ - if ((dbus_current_fix.mode>1) && __finite(dbus_current_fix.latitude) && __finite(dbus_current_fix.longitude) - && __finite(dbus_current_fix.track) && __finite(dbus_current_fix.speed)) - dbus_process_fix(TRUE); - - return DBUS_HANDLER_RESULT_HANDLED; -} -#endif - -gint -get_position_data_cb (GtkWidget * widget, guint * datum) +/* ***************************************************************************** + * open connection to gpsd + */ +gboolean +gpsd_connect (gboolean reconnect) { - gint e = 0, j = 0, i = 0, found = 0, foundGSV = 0, foundGGA = - 0, foundGSA = 0, foundRME = 0; - gdouble secs = 0, tx, ty, lastdirection; - typedef struct - { - gchar *a1; - gchar *a2; - gchar *a3; - } - argument; - argument *argumente; - char tok[1000]; - int tilimit; - - if (current.importactive) - return TRUE; - - - if ((timeoutcount > 30 - mydebug - gps_handler_debug)) - g_print ("*** %d. timeout getting data from GPS receiver!\n", - timeoutcount); - - tilimit = 10; - - if (timeoutcount > tilimit) initgps(); - - if (timeoutcount > tilimit) - { - gtk_statusbar_pop (GTK_STATUSBAR (frame_statusbar), current.statusbar_id); - gtk_statusbar_push (GTK_STATUSBAR (frame_statusbar), current.statusbar_id, - _("Timeout getting data from GPS receiver!")); - current.gpsfix = 0; - haveposcount = 0; - memset (satlist, 0, sizeof (satlist)); - memset (satlistdisp, 0, sizeof (satlist)); - } - - - argumente = NULL; - if (!haveRMCsentence) - { - secs = NMEAsecs; - - if (secs >= 1.0) + /* close connection first on reconnect request */ + if (reconnect && gpsdata) { - tx = (2 * earthr * M_PI / 360) * cos (M_PI * coords.current_lat / - 180.0) * - (coords.current_lon - coords.old_lon); - ty = (2 * earthr * M_PI / 360) * (coords.current_lat - coords.old_lat); -#define MINMOVE 4.0 - if (((fabs (tx)) > MINMOVE) || (((fabs (ty)) > MINMOVE))) - { - lastdirection = current.heading; - if (ty == 0) - current.heading = 0.0; - else - current.heading = atan (tx / ty); - if (!finite (current.heading)) - current.heading = lastdirection; - if (ty < 0) - current.heading = M_PI + current.heading; - if (current.heading >= (2 * M_PI)) - current.heading -= 2 * M_PI; - if (current.heading < 0) - current.heading += 2 * M_PI; - - current.groundspeed = milesconv * sqrt (tx * tx + ty * ty) * 3.6 / secs; - coords.old_lat = coords.current_lat; - coords.old_lon = coords.current_lon; - } - else if (secs > 4.0) - current.groundspeed = 0.0; - - if (current.groundspeed > 2000) - current.groundspeed = 0; - if (current.groundspeed < 3.6) - current.groundspeed = 0; - - if ( mydebug + gps_handler_debug > 80 ) - g_print ("gps_handler: Time: %f\n", secs); + g_source_remove (gps_timeout_source); + gps_close (gpsdata); } - /* display status line */ - if (gui_status.expmode) - display_status (_("Press middle mouse button for navigation")); - - } - - /* only if we have no NMEA, means no measured position */ - if (!haveNMEA) - { - /* display status line */ - if (!current.simmode) - display_status (_("No GPS used")); - else if (maploaded && !gui_status.expmode) - display_status (_("Simulation mode")); - else if (gui_status.expmode) - display_status (_("Press middle mouse button for sim mode")); - - - return TRUE; - } - -#ifdef DBUS - if (useDBUS) { - if (NMEAoldsecs == floor(NMEAsecs)) { - timeoutcount++; - return TRUE; - } - NMEAoldsecs = floor(NMEAsecs); - timeoutcount = 0; - if (current.gpsfix > 1) { - if (gui_status.expmode) - display_status (_("Press middle mouse button for navigation")); - else - display_status (nmeamodeandport); - } else - display_status(_("Not enough satellites in view!")); - } else { -#endif - /* this is the NMEA reading part. data comes from port 2222 served by gpsd */ - FD_ZERO (&readmask); - FD_SET (sock, &readmask); - timeout.tv_sec = 0; - timeout.tv_usec = 100000; - if (select (FD_SETSIZE, &readmask, NULL, NULL, &timeout) < 0) - { - timeoutcount++; - perror ("select() call"); - } - if (FD_ISSET (sock, &readmask)) - { - if ((e = recv(sock, buffer, 2000, 0)) <= 0) { - perror ("read from gpsd connection"); - timeoutcount ++; - } - buffer[e] = 0; - if ((bigp + e) < MAXBIG) + /* try to open connection */ + gpsdata = gps_open (local_config.gpsd_server, local_config.gpsd_port); + if (!gpsdata) { - if (mydebug + gps_handler_debug>30) - g_print ("gps_handler: gpsd: !!bigp:%d, e: %d!! , strlen big:%Zu\n" - , bigp, e, strlen (big)); - g_strlcat (big, buffer, MAXBIG); - bigp += e; - bigpGSA = bigpRME = bigpGSV = bigpGGA = bigp; - - for (i = bigp; i > lastp; i--) - { - if (big[i] == '$') - { - /* collect string for position data $GPRMC */ - if ((big[i + 3] == 'R') - && (big[i + 4] == 'M') && (big[i + 5] == 'C')) - { - found = 0; - if ( mydebug + gps_handler_debug > 80 ) - g_print ("gps_handler: gpsd: found #RMC#\n"); - for (j = i; j <= bigp; j++) - if (big[j] == 13) - { - found = j; - break; - } - if (found != 0) - { - strncpy (tok, (big + i), found - i); - tok[found - i] = 0; - lastp = found; - timeoutcount = 0; - - /* we have the $GPRMC string completed, now parse it */ - if (checksum (tok) == TRUE) - convertRMC (tok); - - /* display the position and map in the statusline */ - if (current.gpsfix > 1) - { - if (gui_status.expmode) - display_status - (_ - ("Press middle mouse button for navigation")); - else - display_status (nmeamodeandport); - } - else - display_status - (_("Not enough satellites in view!")); - } - } - } - } - - /* collect string for satellite data $GPGSV */ - for (i = bigpGSV; i > lastpGSV; i--) - { - if (big[i] == '$') - { - - if ((big[i + 3] == 'G') - && (big[i + 4] == 'S') && (big[i + 5] == 'V')) - { - foundGSV = 0; - if ( mydebug + gps_handler_debug > 80 ) - g_print ("gpsd: found #GSV#, bigpGSV: %d\n", bigpGSV); - for (j = i; j <= bigpGSV; j++) - if (big[j] == 13) - { - foundGSV = j; - break; - } - if (foundGSV != 0) - { - gint lenstr; - lenstr = foundGSV - i; - if ((lenstr) > 200) - { - g_print - ("Error in line %d, found GSV=%d,i=%d, diff=%d\n", - __LINE__, foundGSV, i, lenstr); - lenstr = 200; - } - if (i > foundGSV) - { - g_print - ("Error in line %d, found GSV=%d,i=%d, diff=%d\n", - __LINE__, foundGSV, i, lenstr); - lenstr = 0; - } - if (lenstr < 0) - { - g_print - ("Error in line %d, foundGSV=%d,i=%d, lenstr=%d\n", - __LINE__, foundGSV, i, lenstr); - lenstr = 0; - } - if (lenstr != 0) - { - strncpy (tok, (big + i), lenstr); - tok[lenstr] = 0; - - if (checksum (tok) == TRUE) - { - if ((convertGSV (tok)) == TRUE) - lastpGSV = foundGSV; - } - } - } - } - } - } - - - /* collect string for altitude from $GPGGA if available */ - for (i = bigpGGA; i > lastpGGA; i--) - { - if (big[i] == '$') - { - - if ((big[i + 3] == 'G') - && (big[i + 4] == 'G') && (big[i + 5] == 'A')) - { - foundGGA = 0; - if ( mydebug + gps_handler_debug > 80 ) - g_print ("gps_handler: gpsd: found #GGA#\n"); - timeoutcount = 0; - - for (j = i; j <= bigpGGA; j++) - if (big[j] == 13) - { - foundGGA = j; - break; - } - if (foundGGA != 0) - { - gint lenstr; - lenstr = foundGGA - i; - if ((lenstr) > 200) - { - g_print - ("Error in line %d, foundGGA=%d,i=%d, diff=%d\n", - __LINE__, foundGGA, i, lenstr); - lenstr = 200; - } - if (i > foundGGA) - { - g_print - ("Error in line %d, foundGGA=%d,i=%d, diff=%d\n", - __LINE__, foundGGA, i, lenstr); - lenstr = 0; - } - if (lenstr != 0) - { - strncpy (tok, (big + i), lenstr); - tok[lenstr] = 0; - lastpGGA = foundGGA; - - if (checksum (tok) == TRUE) - convertGGA (tok); - if (current.gpsfix > 1) - { - if (gui_status.expmode) - display_status - (_ - ("Press middle mouse button for navigation")); - else - display_status (nmeamodeandport); - } - else - display_status - (_("Not enough satellites in view!")); - - } - } - } - } - } - - /* collect string for precision from $PGRME if available */ - for (i = bigpRME; i > lastpRME; i--) - { - if (big[i] == '$') - { - - if ((big[i + 1] == 'P') - && (big[i + 2] == 'G') - && (big[i + 3] == 'R') - && (big[i + 4] == 'M') && (big[i + 5] == 'E')) - { - foundRME = 0; - if ( mydebug + gps_handler_debug > 80 ) - g_print ("gps_handler: gpsd: found #RME#\n"); - for (j = i; j <= bigpRME; j++) - if (big[j] == 13) - { - foundRME = j; - break; - } - if (foundRME != 0) - { - gint lenstr; - lenstr = foundRME - i; - if ((lenstr) > 200) - { - g_print - ("Error in line %d, foundRME=%d,i=%d, diff=%d\n", - __LINE__, foundRME, i, lenstr); - lenstr = 200; - } - if (i > foundRME) - { - g_print - ("Error in line %d, foundRME=%d,i=%d, diff=%d\n", - __LINE__, foundRME, i, lenstr); - lenstr = 0; - } - if (lenstr != 0) - { - strncpy (tok, (big + i), lenstr); - tok[lenstr] = 0; - lastpRME = foundRME; - - if (checksum (tok) == TRUE) - convertRME (tok); - } - } - } - } - } - - /* collect string for precision from $GPGSA if available */ - for (i = bigpGSA; i > lastpGSA; i--) - { - if (big[i] == '$') - { - - if ((big[i + 1] == 'G') - && (big[i + 2] == 'P') - && (big[i + 3] == 'G') - && (big[i + 4] == 'S') && (big[i + 5] == 'A')) - { - foundGSA = 0; - if ( mydebug + gps_handler_debug > 80 ) - g_print ("gps_handler: gpsd: found #GSA#\n"); - for (j = i; j <= bigpGSA; j++) - if (big[j] == 13) - { - foundGSA = j; - break; - } - if (foundGSA != 0) - { - gint lenstr; - lenstr = foundGSA - i; - if ((lenstr) > 200) - { - g_print - ("Error in line %d, foundGSA=%d,i=%d, diff=%d\n", - __LINE__, foundGSA, i, lenstr); - lenstr = 200; - } - if (i > foundGSA) - { - g_print - ("Error in line %d, foundGSA=%d,i=%d, diff=%d\n", - __LINE__, foundGSA, i, lenstr); - lenstr = 0; - } - if (lenstr != 0) - { - strncpy (tok, (big + i), lenstr); - tok[lenstr] = 0; - lastpGSA = foundGSA; - - if (checksum (tok) == TRUE) - convertGSA (tok); - } - } - } - } - } - - - - if ( mydebug + gps_handler_debug > 80 ) - { - g_print ("gps_handler: gpsd: size:%d lastp: %d \n", e, lastp); - g_print ("gps_handler: gpsd: buffer: %s\n", buffer); - } - + g_print ("Can't connect to gps daemon on %s:%s, disabling GPS support!\n", + local_config.gpsd_server, local_config.gpsd_port); + current.gps_mode = MODE_NOT_SEEN; + if (local_config.simmode == SIM_AUTO) + current.simmode = TRUE; + return FALSE; } - else - { - lastp = lastpGGA = lastpGSV = lastpRME = lastpGSA = 0; - bigp = e; - g_strlcpy (big, buffer, MAXBIG); - } + g_print ("Connection to GPS Daemon on %s:%s established.\n", + local_config.gpsd_server, local_config.gpsd_port); + if (local_config.simmode == SIM_AUTO) + current.simmode = FALSE; - } - else - { - timeoutcount++; - } -#ifdef DBUS - } -#endif + /* set hook function to handle gps data */ + gps_set_raw_hook (gpsdata, (gpointer) gps_hook_cb); + /* set up function to poll periodically for new data */ + gps_timeout_source = g_timeout_add (GPS_TIMER, gps_query_data_cb, NULL); - return (TRUE); + return TRUE; } Modified: trunk/src/gps_handler.h =================================================================== --- trunk/src/gps_handler.h 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gps_handler.h 2008-12-22 11:59:44 UTC (rev 2216) @@ -1,6 +1,6 @@ /*********************************************************************** -Copyright (c) 2001,2002 Fritz Ganter <ga...@ga...> +Copyright (c) 2008 Guenther Meyer <d.s.e (at) sordidmusic (dot) com> Website: www.gpsdrive.de/ @@ -21,40 +21,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *********************************************************************/ -/* -$Log$ -Revision 1.5 2006/08/08 08:19:32 tweety -rename callback startgpsd_cb -Revision 1.4 2006/02/05 16:38:05 tweety -reading floats with scanf looks at the locale LANG= -so if you have a locale de_DE set reading way.txt results in clearing the -digits after the '.' -For now I set the LC_NUMERIC always to en_US, since there we have . defined for numbers -Revision 1.3 1994/06/10 02:11:00 tweety -move nmea handling to it's own file Part 1 - -Revision 1.2 2005/10/10 13:17:52 tweety -DBUS Support for connecting to gpsd -you need to use ./configure --enable-dbus to enable it during compile -Author: "Belgabor" <bel...@gm...> - -Revision 1.1 2005/08/13 10:16:02 tweety -extract all/some gps_handling parts to File src/gps_handler.c - - -*/ - - #ifndef GPS_HANDLER_H #define GPS_HANDLER_H #include <gtk/gtk.h> -gint initgps (); -void gpsd_close(); +gboolean gpsd_connect (gboolean reconnect); +void gpsd_disconnect (); #endif /* GPS_HANDLER_H */ Modified: trunk/src/gpsdrive.c =================================================================== --- trunk/src/gpsdrive.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gpsdrive.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -97,7 +97,6 @@ #include "waypoint.h" #include "routes.h" #include "gps_handler.h" -#include "nmea_handler.h" #include "map_handler.h" #include "import_map.h" @@ -265,17 +264,13 @@ GtkWidget *addwaypointwindow; gint oldbat = 125, oldloading = FALSE; gint bat, loading; -gchar gpsdservername[200], setpositionname[80]; +gchar setpositionname[80]; -gint havealtitude = FALSE; -gint usedgps = FALSE; -gchar dgpsserver[80], dgpsport[10]; GtkWidget *explore_bt; extern gint PSIZE; GdkPixbuf *batimage = NULL; GdkPixbuf *temimage = NULL; GdkPixbuf *satsimage = NULL; -gint sats_used = 0, sats_in_view = 0; gint numgrids = 4, scroll = TRUE; gchar utctime[20], loctime[20]; gint redrawtimeout; @@ -317,7 +312,6 @@ gchar messagename[40], messagesendtext[1024], messageack[100]; gint statuslock = 0, gpson = FALSE; int messagenumber = 0, didrootcheck = 0; -int timerto = 0; GtkTextBuffer *getmessagebuffer; int newdata = FALSE; @@ -327,13 +321,6 @@ int storetz = FALSE; -// ---------------------- for nmea_handler.c -extern FILE *nmeaout; -/* if we get data from gpsd in NMEA format haveNMEA is TRUE */ -extern gint haveNMEA, useDBUS; -extern gint bigp , bigpGGA , bigpRME , bigpGSA, bigpGSV; -extern gint lastp, lastpGGA, lastpRME, lastpGSA, lastpGSV; - extern GtkWidget *main_window; extern GtkWidget *frame_statusbar; extern GtkWidget *main_table; @@ -554,7 +541,7 @@ if ( mydebug > 10 ) { - if (current.gpsfix > 1) + if (current.gps_mode > GPSMODE_NO_FIX) g_print ("***Position: %f %f***\n", coords.current_lat, coords.current_lon); else @@ -640,8 +627,11 @@ local_config.maxcpuload = 1; if (local_config.maxcpuload > 95) local_config.maxcpuload = 95; - if (!haveNMEA) + +//TODO: is this right/necessary? + if (current.gps_status == GPS_NO_FIX) expose_gpsfix (NULL, 0); + if (pleasepollme) { pleasepollme++; @@ -1074,7 +1064,7 @@ if (local_config.showdestline) draw_destination_line (); - if (current.gpsfix > 1 || blink) + if (current.gps_status > GPS_NO_FIX || blink) { if (gui_status.expmode) { @@ -1174,7 +1164,7 @@ blink = TRUE; else { - if (current.gpsfix < 2) + if (current.gps_status == GPS_NO_FIX) blink = !blink; } @@ -1780,18 +1770,6 @@ /* ***************************************************************************** - * should I use DGPS-IP? - */ -gint -usedgps_cb (GtkWidget * widget, guint datum) -{ - usedgps = !usedgps; - current.needtosave = TRUE; - return TRUE; -} - - -/* ***************************************************************************** * Update the checkbox for Explore-Mode */ void @@ -2130,7 +2108,7 @@ usr2handler (int sig) { g_print (_("\nGot SIGUSR2; restarting GPS connection.\n")); - initgps (); + gpsd_connect (TRUE); } @@ -2201,7 +2179,8 @@ else if (g_ascii_strncasecmp (option, "-N", 2) == 0 || g_ascii_strncasecmp (option, "--nmeaout", 9) == 0) { - nmeaout = opennmea (value); + //TODO: enable nmea writing again (is this really useful?) + //nmeaout = opennmea (value); } return TRUE; @@ -2218,6 +2197,8 @@ { GError *error = NULL; gboolean show_version = FALSE; + gchar *t_buf_gpsdserver = NULL; + gchar *t_buf_gpsdport = NULL; GOptionContext *opt_context = g_option_context_new (_("Navigation System")); const gchar opt_desc[] = N_("Website: http://www.gpsdrive.de"); @@ -2238,12 +2219,12 @@ _("having only a single button, for example when using a touchscreen"), NULL}, {"verbose", 'v', 0, G_OPTION_ARG_NONE, &debug, _("show some debug info"), NULL}, - {"use-DBUS", 'x', 0, G_OPTION_ARG_NONE, &useDBUS, - _("use DBUS for communication with gpsd; this disables socket communication"), NULL}, {"alt-offset", 'A', 0, G_OPTION_ARG_INT, &local_config.normalnull, _("correct the altitude by adding this value"), _("<OFFSET>")}, - {"gpsd-server", 'B', 0, G_OPTION_ARG_STRING, &gpsdservername, - _("servername for NMEA server (if gpsd runs on another host)"), _("<SERVER>")}, + {"gpsd-server", 'B', 0, G_OPTION_ARG_STRING, &t_buf_gpsdserver, + _("address for GPSD server (if gpsd runs on another host)"), _("<SERVER>")}, + {"gpsd-port", 'P', 0, G_OPTION_ARG_STRING, &t_buf_gpsdport, + _("port for server (if gpsd runs on another host)"), _("<PORT>")}, {"config-file", 'C', 0, G_OPTION_ARG_CALLBACK, parse_options_cb, _("set config file to use"), _("<FILE>")}, {"debug", 'D', 0, G_OPTION_ARG_INT, &mydebug, @@ -2306,19 +2287,12 @@ coords.current_lon = coords.zero_lon = 11.57532 + f; /* zero_lat and zero_lon are overwritten by config file, */ - g_strlcpy (dgpsserver, "dgps.wsrcc.com", sizeof (dgpsserver)); - g_strlcpy (dgpsport, "2104", sizeof (dgpsport)); - g_strlcpy (gpsdservername, "127.0.0.1", sizeof (gpsdservername)); g_strlcpy (current.target, " ", sizeof (current.target)); g_strlcpy (utctime, _("n/a"), sizeof (utctime)); g_strlcpy (oldangle, _("none"), sizeof (oldangle)); pixelfact = MAPSCALE / PIXELFACT; g_strlcpy (oldfilename, "", sizeof (oldfilename)); maploaded = FALSE; - haveNMEA = FALSE; - current.gpsfix = 0; - current.gps_precision = (-1.0); - current.gps_hdop = (-1.0); gblink = blink = FALSE; haveposcount = debug = 0; current.heading = current.bearing = 0.0; @@ -2347,9 +2321,7 @@ buffer = g_new (char, 2010); big = g_new0 (char, MAXBIG + 10); //big[0] = 0; - - timeoutcount = lastp = bigp = bigpRME = bigpGSA = bigpGSV = bigpGGA = 0; - lastp = lastpGGA = lastpGSV = lastpRME = lastpGSA = 0; + gcount = xoff = yoff = 0; hours = minutes = 99; milesconv = 1.0; @@ -2416,7 +2388,7 @@ /* init config struct with default values */ config_init (); - + check_and_create_files(); mapdl_init (); @@ -2473,15 +2445,22 @@ g_print (_("Parsing of options failed: %s\n"), error->message); exit (EXIT_FAILURE); } + if (t_buf_gpsdserver) + { + g_strlcpy (local_config.gpsd_server, t_buf_gpsdserver, + sizeof (local_config.gpsd_server)); + g_free (t_buf_gpsdserver); + } + if (t_buf_gpsdport) + { + g_strlcpy (local_config.gpsd_port, t_buf_gpsdport, + sizeof (local_config.gpsd_port)); + g_free (t_buf_gpsdport); + } if (ignorechecksum) g_print ("\nWARNING: NMEA checksum test switched off!\n\n"); -#ifndef DBUS - if (useDBUS) - g_print ("\nWARNING: You need to enable DBUS support with 'cmake -DWITH_DBUS=ON ..\n"); -#endif - if ( mydebug >99 ) g_print ("options parsed\n"); @@ -2516,10 +2495,10 @@ } } - /* if we want NMEA mode, gpsd must be running and we connect to port 2222 */ - /* An alternate gpsd server may be on 2947, we try it also */ - initgps (); + /* try to connect to gpsd */ + gpsd_connect (FALSE); + /* all position calculations are made in the expose callback */ // g_signal_connect (GTK_OBJECT (map_drawingarea), // "expose_event", GTK_SIGNAL_FUNC (expose_cb), NULL); @@ -2616,7 +2595,6 @@ * to become commonplace (>2.14), replace g_timeout_add(1000,...) with * g_timeout_add_seconds(1, ...) etc., as appropriate. */ - timerto = g_timeout_add (TIMER, (GtkFunction) get_position_data_cb, NULL); redrawtimeout = g_timeout_add (200, (GtkFunction) calldrawmarker_cb, NULL); /* if we started in simulator mode we have a little move roboter */ @@ -2625,8 +2603,8 @@ g_print ("Enabling simulation mode\n"); simpos_timeout = g_timeout_add (300, (GtkFunction) simulated_pos, 0); } - if (nmeaout) - g_timeout_add (1000, (GtkFunction) write_nmea_cb, NULL); +// if (nmeaout) +// g_timeout_add (1000, (GtkFunction) write_nmea_cb, NULL); id_timeout_track = g_timeout_add (local_config.track_interval *1000, (GtkFunction) storetrack_cb, 0); g_timeout_add (TRIPMETERTIMEOUT*1000, (GtkFunction) update_tripdata_cb, 0); @@ -2696,7 +2674,10 @@ if (current.kismetsock != -1) close (current.kismetsock); - gpsd_close(); + + /* close connection to gpsd */ + gpsd_disconnect (); + if (sockfd != -1) close (sockfd); Modified: trunk/src/gpsdrive.h =================================================================== --- trunk/src/gpsdrive.h 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gpsdrive.h 2008-12-22 11:59:44 UTC (rev 2216) @@ -39,6 +39,23 @@ #define ARRAY_SIZE(x) ((sizeof (x))/(sizeof ((x)[0]))) +/* GPS modes (as defined by libgps) */ +enum +{ + GPSMODE_NOT_SEEN, + GPSMODE_NO_FIX, + GPSMODE_2D, + GPSMODE_3D +}; + +/* GPS fix status (as definde by libgps) */ +enum +{ + GPS_NO_FIX, + GPS_FIX, + GPS_DGPS_FIX +}; + /* Coordinate formats */ enum { @@ -144,8 +161,6 @@ /* How often do we redraw the screen (in milliseconds) */ #define REDRAWTIMER 300 -/* How often do we ask for positioning data */ -#define TIMER 500 /* maximum number of waypoints to draw at one time */ /* HB Nov 2008: is this really needed? */ @@ -329,10 +344,13 @@ gint statusbar_id; /* context_id of current statusbar message */ gboolean simmode; /* Status of Simulation mode */ gint kismetsock; /* Kismet socket, -1 if not available */ - gint gpsfix; /* Status of GPS: - * 0: No GPS, 1: No Fix, 2: 2D Fix, 3: 3D Fix */ - gdouble gps_precision; - gdouble gps_hdop; + gint gps_mode; /* gps status */ + gint gps_status; /* gps fix mode */ + gdouble gps_hdop; /* gps horizontal dilution of position */ + gdouble gps_eph; /* gps estimated horizontal error in meters */ + gdouble gps_epv; /* gps estimated vertical error in meters */ + gint gps_sats_used; /* number of satellites currently used */ + gint gps_sats_in_view; /* number of satellites currently seen */ GTimeVal last3dfixtime; /* saves time of last 3D Fix. Hack for jumping * altitude display caused by bad nmea data */ gboolean needtosave; /* flag if config has to be saved */ Modified: trunk/src/gpsdrive_config.c =================================================================== --- trunk/src/gpsdrive_config.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gpsdrive_config.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -50,7 +50,6 @@ extern gint displaymap_top; extern gint mydebug; extern gint setdefaultpos; -extern gint usedgps; extern gdouble milesconv; extern double dbdistance; extern int dbusedist; @@ -182,12 +181,6 @@ fprintf (fp, "osmdbfile = "); fprintf (fp, "%s\n", local_config.osm_dbfile); - fprintf (fp, "usedgps = "); - if (usedgps == 0) - fprintf (fp, "0\n"); - else - fprintf (fp, "1\n"); - fprintf (fp, "mapdir = "); fprintf (fp, "%s\n", local_config.dir_maps); fprintf (fp, "trackdir = "); @@ -430,8 +423,6 @@ else if ( (strcmp(par1, "osmdbfile")) == 0) g_strlcpy (local_config.osm_dbfile, par2, sizeof (local_config.osm_dbfile)); - else if ( (strcmp(par1, "usedgps")) == 0) - usedgps = atoi (par2); else if ( (strcmp(par1, "mapdir")) == 0) g_strlcpy (local_config.dir_maps, par2, sizeof (local_config.dir_maps)); @@ -810,4 +801,8 @@ /* run a normal GUI by default */ local_config.embeddable_gui = FALSE; + + /* set gpsd default values */ + g_strlcpy (local_config.gpsd_server, "127.0.0.1", sizeof (local_config.gpsd_server)); + g_strlcpy (local_config.gpsd_port, "2947", sizeof (local_config.gpsd_port)); } Modified: trunk/src/gpsdrive_config.h =================================================================== --- trunk/src/gpsdrive_config.h 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gpsdrive_config.h 2008-12-22 11:59:44 UTC (rev 2216) @@ -136,6 +136,8 @@ gint kismet_serverport; gchar screenshot_dir[1000]; gboolean embeddable_gui; /* use GtkPlug instead of GtkWindow for main_window */ + gchar gpsd_server[200]; + gchar gpsd_port[6]; } local_gpsdrive_config; Modified: trunk/src/gpsproto.h =================================================================== --- trunk/src/gpsproto.h 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/gpsproto.h 2008-12-22 11:59:44 UTC (rev 2216) @@ -29,7 +29,6 @@ void setroutetarget (); gint initgps (); gint defaultserver_cb (GtkWidget * widget, guint datum); -gint usedgps_cb (GtkWidget * widget, guint datum); void saytargettext (gchar * filename, gchar * target); void display_dsc (void); void coordinate2gchar (gchar * text, gint buff_size, gdouble pos, gint islat, gint mode); Modified: trunk/src/main_gui.c =================================================================== --- trunk/src/main_gui.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/main_gui.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -91,8 +91,6 @@ extern gint mydebug; extern gint debug; extern gint iszoomed, xoff, yoff; -extern gint sats_used, sats_in_view; -extern gint haveNMEA; extern gdouble wp_saved_target_lat; extern gdouble wp_saved_target_lon; @@ -854,7 +852,7 @@ g_strlcpy (head, _("Altitude"), sizeof (head)); - if (current.gpsfix == 3) + if (current.gps_mode == GPSMODE_3D) g_get_current_time (¤t.last3dfixtime); g_get_current_time (&t_now); @@ -996,11 +994,6 @@ } case DASH_GPSPRECISION: { - // TODO: This should show EPE values once we switched - // to libgps, because they do a better predication of - // what's going on for the end user. - // Until then, we show PDOP and number of satellites, - // if available. gint pfd_size; gchar *font_prec; PangoFontDescription *pfd; @@ -1014,9 +1007,9 @@ g_strlcpy (head, _("GPS Precision"), sizeof (head)); g_snprintf (content, sizeof (content), - "<span color=\"%s\" font_desc=\"%s\">HDOP: %.1f\nSats: %d/%d</span>", + "<span color=\"%s\" font_desc=\"%s\">EPH: %.1f m\nEPV: %.1f m</span>", local_config.color_dashboard, font_prec, - current.gps_hdop, sats_used, sats_in_view); + current.gps_eph, current.gps_epv); pango_font_description_free (pfd); g_free (font_prec); @@ -1029,7 +1022,7 @@ case DASH_TIME: { g_strlcpy (head, _("Current Time"), sizeof (head)); - if (current.gpsfix > 1) + if (current.gps_status > GPS_NO_FIX) { g_snprintf (content, sizeof (content), "<span color=\"%s\" font_desc=\"%s\">" @@ -1207,28 +1200,26 @@ } else { - switch (current.gpsfix) + switch (current.gps_mode) { - case 0: + case GPSMODE_NOT_SEEN: { gdk_gc_set_foreground (kontext_gpsfix, &colors.red); break; } - case 1: + case GPSMODE_NO_FIX: { gdk_gc_set_foreground (kontext_gpsfix, &colors.red); pango_layout_set_text (layout_gpsfix, "No Fix", -1); break; } - case 2: + case GPSMODE_2D: { - // TODO: have a look at the nmea parsing - // to avoid "jumping" between 2D and 3D gdk_gc_set_foreground (kontext_gpsfix, &colors.green); pango_layout_set_text (layout_gpsfix, "2D Fix", -1); break; } - case 3: + case GPSMODE_3D: { gdk_gc_set_foreground (kontext_gpsfix, &colors.green); pango_layout_set_text (layout_gpsfix, "3D Fix", -1); @@ -1249,10 +1240,10 @@ gdk_gc_set_line_attributes (kontext_gpsfix, t_wx, 0, 0, 0); for (i=1; i<13; i++) { - if (i > sats_in_view) + if (i > current.gps_sats_in_view) gdk_gc_set_foreground (kontext_gpsfix, &colors.grey); - else if (i > sats_used) + else if (i > current.gps_sats_used) gdk_gc_set_foreground (kontext_gpsfix, &colors.darkgrey); gdk_draw_line (drawable_gpsfix, kontext_gpsfix, @@ -1286,7 +1277,7 @@ if ( mydebug > 50 ) g_print ("expose_sats_cb ()\n"); - if (!haveNMEA) + if (current.gps_status = GPS_NO_FIX) return TRUE; drawable_sats = drawing_sats->window; @@ -1325,7 +1316,7 @@ gdk_gc_set_line_attributes (kontext_sats, bx, 0, 0, 0); for (i=0; i<12; i++) { - if (i==sats_in_view) + if (i == current.gps_sats_in_view) gdk_gc_set_foreground (kontext_sats, &colors.black); gdk_draw_line (drawable_sats, kontext_sats, x/2+12 + i*(bx+4)+bx/2 , w/2+12 , x/2+12 + i*(bx+4) + bx/2 , w-12); @@ -1384,8 +1375,10 @@ coordinate2gchar(slat, sizeof(slat), coords.current_lat, TRUE, local_config.coordmode); coordinate2gchar(slon, sizeof(slon), coords.current_lon, FALSE, local_config.coordmode); g_snprintf (t_buf, sizeof (t_buf), - "Latitude: %s\nLongitude: %s\nAltitude: %.1f m\nUTC Time: %s\nHDOP: %.1f", - slat, slon, current.altitude, utctime, current.gps_hdop); + "Latitude: %s\nLongitude: %s\nAltitude: %.1f m\nUTC Time:" + " %s\nEPH: %.1f m / EPV: %.1f m", + slat, slon, current.altitude, utctime, + current.gps_eph, current.gps_epv); layout_sats = gtk_widget_create_pango_layout (drawing_sats, t_buf); pfd_sats = pango_font_description_from_string ("Sans Bold 10"); pango_layout_set_font_description (layout_sats, pfd_sats); Modified: trunk/src/settings.c =================================================================== --- trunk/src/settings.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/settings.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -117,7 +117,7 @@ { g_print ("\nReinitializing connection to GPSd ...\n"); - initgps (); + gpsd_connect (TRUE); g_print ("GPSd initialization complete.\n"); gtk_statusbar_push (GTK_STATUSBAR (frame_statusbar), @@ -826,7 +826,7 @@ local_config.simmode = value; if (value == SIM_AUTO) { - if (current.gpsfix < 2) + if (current.gps_mode < GPSMODE_2D) current.simmode = TRUE; else current.simmode = FALSE; Modified: trunk/src/speech.c =================================================================== --- trunk/src/speech.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/speech.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -301,7 +301,7 @@ if (angle < 0.0) angle = 360 + angle; - if (!current.simmode && !current.gpsfix) + if (!current.simmode && current.gps_status == GPS_NO_FIX) { if( (1 == speechcount) && local_config.sound_gps ) { Modified: trunk/src/track.c =================================================================== --- trunk/src/track.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/track.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -66,7 +66,6 @@ extern gdouble milesconv; extern GtkWidget *main_window; extern gdouble hdop; -extern gint sats_used; extern gpx_info_struct gpx_info; extern guint8 linestyles[][4]; @@ -149,13 +148,6 @@ if (gui_status.expmode) return TRUE; - -#ifdef DBUS_ENABLE - /* If we use DBUS track points are usually stored by the DBUS signal handler */ - /* Only store them by timer if we are in explore mode */ - if ( useDBUS && !current.simmode ) - return TRUE; -#endif storepoint(); @@ -168,8 +160,8 @@ { gint so; - /* g_print("Havepos: %d\n", current.gpsfix); */ - if ((!current.simmode && current.gpsfix < 2) || gui_status.expmode /* ||((!local_config.simmode &&haveposcount<3)) */ ) /* we have no valid position */ + /* g_print("Havepos: %d\n", current.gps_status); */ + if ((!current.simmode && current.gps_status == GPS_NO_FIX) || gui_status.expmode /* ||((!local_config.simmode &&haveposcount<3)) */ ) /* we have no valid position */ { add_trackpoint (1001.0, 1001.0, 1001.0, 1001.0, -1.0, -1.0, 0, 0, NULL); } @@ -178,7 +170,7 @@ add_trackpoint (coords.current_lat, coords.current_lon, current.altitude, RAD2DEG (current.heading), current.groundspeed, current.gps_hdop, - current.gpsfix, sats_used, NULL); + current.gps_mode, current.gps_sats_used, NULL); if (local_config.savetrack) do_incremental_save(); } Modified: trunk/src/unit_test.c =================================================================== --- trunk/src/unit_test.c 2008-12-19 17:27:50 UTC (rev 2215) +++ trunk/src/unit_test.c 2008-12-22 11:59:44 UTC (rev 2216) @@ -35,7 +35,6 @@ #include <config.h> #include <math.h> #include "battery.h" -#include "nmea_handler.h" #include "gui.h" #include "gpsdrive_config.h" @@ -81,94 +80,6 @@ /* ****************************************************************** - * Test the nmea parser, simply check if the right position is set after parsing - */ -gint unit_test_nmea() -{ - gint errors = 0; - if (mydebug > 0) - printf ("\n"); - printf ("Testing nmea handler\n"); - - typedef struct - { - gdouble should_lat, should_lon; - char *nmea_string; - } test_struct; - test_struct test_array[] = { - /* nothing happens (lat/lon) with these nmea sentences - {55.6403, 12.6378, "$GPGSV,3,1,10,29,66,286,43,28,57,126,35,26,57,290,45,08,51,073,29*7E" }, - {55.6403, 12.6378, "$GPGSV,3,2,10,10,34,201,40,27,25,076,00,19,14,033,00,21,12,305,27*75" }, - {55.6403, 12.6378, "$GPGSV,3,3,10,15,11,329,00,18,11,325,00*79" }, - {55.6403, 12.6378, "$GPGSA,A,3,10,28,26,29,08,21,,,,,,,2.5,1.4,2.0*3D" }, - {55.6403, 12.6378, "$GPGSA,A,3,10,28,26,29,08,21,,,,,,,2.5,1.4,2.0*3D" }, - */ - /* unsuported sentence for nmea reading - {55.64039333333, 12.63781833333, "$GPGLL,5538.4236,N,01238.2691,E,122041.481,A*31" }, - {-55.640395, 12.63783, "$GPGLL,5538.4237,S,01238.2698,E,122040.481,A*38" }, - */ - - { 55.640393333, 12.637818333, "$GPRMC,122041.481,A,5538.4236,N,01238.2691,E,0.000000,214.43,010806,,*09" }, - { 55.640395, -12.63783, "$GPRMC,122040.481,A,5538.4237,N,01238.2698,W,0.000000,214.43,010806,,*12" }, - { 55.640395, 12.63783, "$GPRMC,122040.481,A,5538.4237,N,01238.2698,E,0.000000,214.43,010806,,*00" }, - {-55.640395, -12.63783, "$GPRMC,122040.481,A,5538.4237,S,01238.2698,W,0.000000,214.43,010806,,*0F" }, - {-55.640395, 12.63783, "$GPRMC,122040.481,A,5538.4237,S,01238.2698,E,0.000000,214.43,010806,,*1D" }, - - { 52.299051666, 9.638140, "$GPRMC,165318.993,A,5217.9431,N,00938.2884,E,000.0,000.0,010806,001.1,E*66"}, - - { 55.640393333, 12.637818333, "$GPGGA,122041.481,5538.4236,N,01238.2691,E,2,06,1.4,40.4,M,41.4,M,1.1,0000*46" }, - { 55.640395, 12.63783, "$GPGGA,122040.481,5538.4237,N,01238.2698,E,2,06,1.4,39.8,M,41.4,M,1.1,0000*4D" }, - { 48.117500,11.595000, "$GPGGA,125500.481,4807.0500,N,01135.7000,E,2,06,1.4,39.8,M,41.4,M,1.1,0000*40" }, - {-99,-99,""}, - }; - gint i; - gdouble diff; - for (i = 0; test_array[i].should_lat != -99; i++) - { - haveRMCsentence=FALSE; - newdata=TRUE; - gui_status.expmode=FALSE; - //strncpy ( serialdata, test_array[i].nmea_string,sizeof (serialdata)); - get_position_data_cb(NULL,NULL); - - int ok=TRUE; - - diff = fabs(coords.current_lat - test_array[i].should_lat); - if ( diff > 0.000001 ) - { - printf ("!!!! ERROR wrong lat diff: %f\n",diff); - ok=FALSE; - } - diff = fabs(coords.current_lon - test_array[i].should_lon); - if ( diff >0.000001 ) - { - printf ("!!!! ERROR wrong lon diff: %f\n",diff); - ok=FALSE; - } - if ( ! ok ) { - printf ("!!!! ERROR is %f,%f\n" - " should %f,%f\n" - " nmea: %s\n", - coords.current_lat,coords.current_lon, - test_array[i].should_lat,test_array[i].should_lon, - test_array[i].nmea_string - ); - errors++; - } else { - if ( mydebug>1 ) - printf ("parsing OK; values: %f,%f\t" - " nmea: %s\n", - coords.current_lat,coords.current_lon, - test_array[i].nmea_string - ); - - } - } - - return errors; -} - -/* ****************************************************************** * Unit Tests * in this function some of the internal functions of gpsdrive are called * with known parameters. The results then are checked to what is expected. @@ -827,9 +738,6 @@ } - // ------------------------------------------------------------------ - //errors += unit_test_nmea(); - set_unittest_timer(); if (errors > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |