]> err.no Git - mapper/commitdiff
Parse directly but update informations in callbacks only if we got a sentence that...
authorKaj-Michael Lang <milang@onion.tal.org>
Tue, 29 Jan 2008 17:05:47 +0000 (19:05 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Tue, 29 Jan 2008 17:05:47 +0000 (19:05 +0200)
src/cb.c
src/gps-nmea-parse.c
src/gps.c
src/gps.h
src/gpsdata.h
src/maemo-osso.c
src/map.c
src/track.c
src/track.h
src/ui-common.c
src/ui-common.h

index a96c2902d1802e1d57089e7ed82fc00a0530964a..35251003cc7763f1c85ee2bcaab5afbd467ac339 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -445,7 +445,7 @@ if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
        if (_gps->io.conn > RCVR_OFF)
                gps_conn_set_state(_gps, RCVR_OFF);
        gps_disconnect(_gps);
-       track_add(NULL, FALSE);
+       track_add(NULL);
        _speed_excess=FALSE;
 }
 if (_enable_gps==FALSE)
@@ -1059,7 +1059,7 @@ unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon);
 /* Move mark to new location. */
 map_refresh_mark();
 _gps->data.time=time(NULL);
-track_add(&_gps->data, FALSE);
+track_add(&_gps->data);
 
 return TRUE;
 }
index 05a7597e468f98c4d40a41a4c935be24098f6a9d..96bcbe373d4acbfc59c264f61da5a2ed0cd2979c 100644 (file)
@@ -82,8 +82,10 @@ gps_nmea_parse_rmc(Gps *gps, gchar *sentence)
        if (token && *token == 'A') {
                /* Data is valid. */
                if (gps->io.conn != RCVR_FIXED) {
-                       newly_fixed = TRUE;
+                       gps->data.newly_fixed = TRUE;
                        gps_conn_set_state(gps, RCVR_FIXED);
+               } else {
+                       gps->data.newly_fixed = FALSE;
                }
        } else {
                /* Data is invalid - not enough satellites?. */
@@ -155,10 +157,6 @@ gps_nmea_parse_rmc(Gps *gps, gchar *sentence)
        }
 
        gps_data_integerize(&gps->data);
-
-       if ((gps->io.conn==RCVR_FIXED) && (gps->update_location!=NULL)) {
-               gps->update_location(gps, newly_fixed);
-       }
        gps->data.lheading=gps->data.heading;
 }
 
@@ -374,7 +372,7 @@ gps_nmea_parse(Gps *gps)
 {
 g_assert(gps);
 
-g_debug("NMEA: %s", gps->io.nmea);
+g_debug("NMEA2 %d %s", gps->io.nmea_cnt, gps->io.nmea);
 
 if (!gps->io.nmea)
        return FALSE;
@@ -384,15 +382,27 @@ if (strlen(gps->io.nmea)<NMEA_PRLEN+1)
 
 if (!strncmp(gps->io.nmea, NMEA_GSV, NMEA_PRLEN)) {
        gps_nmea_parse_gsv(gps, gps->io.nmea + NMEA_PRLEN+1);
-} else if (!strncmp(gps->io.nmea, NMEA_RMC, NMEA_PRLEN))
+       if (gps->update_satellite)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_satellite, gps, NULL);
+
+} else if (!strncmp(gps->io.nmea, NMEA_RMC, NMEA_PRLEN)) {
        gps_nmea_parse_rmc(gps, gps->io.nmea + NMEA_PRLEN+1);
-else if (!strncmp(gps->io.nmea, NMEA_GGA, NMEA_PRLEN))
+       if ((gps->io.conn==RCVR_FIXED) && (gps->update_location!=NULL))
+               gps->update_location(gps);
+
+} else if (!strncmp(gps->io.nmea, NMEA_GGA, NMEA_PRLEN)) {
        gps_nmea_parse_gga(gps, gps->io.nmea + NMEA_PRLEN+1);
-else if (!strncmp(gps->io.nmea, NMEA_GSA, NMEA_PRLEN))
+       if (gps->update_info)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_info, gps, NULL);
+
+} else if (!strncmp(gps->io.nmea, NMEA_GSA, NMEA_PRLEN)) {
        gps_nmea_parse_gsa(gps, gps->io.nmea + NMEA_PRLEN+1);
-else g_printerr("Unknown NMEA: [%s]\n", gps->io.nmea);
-g_free(gps->io.nmea);
-gps->io.nmea=NULL;
+       if (gps->update_satellite)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_satellite, gps, NULL);
+       if (gps->update_info)
+               g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_info, gps, NULL);
+
+} else g_printerr("Unknown NMEA: [%s]\n", gps->io.nmea);
 
 return FALSE;
 }
index 15cb552a640e91a012c6a1572ff8e1e9d8dadffd..3e4c63cc64fe5788e6530fe7025d5e5a3f7c4c51 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -105,6 +105,7 @@ gps->io.address=NULL;
 gps->io.type=type;
 gps->io.conn=RCVR_OFF;
 gps->io.nmea=NULL;
+gps->io.nmea_cnt=0;
 gps->data.lat=60.20;
 gps->data.lon=22.20;
 gps->connection_error=NULL;
@@ -414,7 +415,7 @@ gps->data.heading=(h<0) ? 360+h : h;
 gps->data.time=time(NULL);
 gps_data_integerize(&gps->data);
 if (gps->update_location!=NULL) {
-       gps->update_location(gps, FALSE);
+       gps->update_location(gps);
 }
 gps->data.lheading=gps->data.heading;
 
@@ -669,15 +670,13 @@ switch (status) {
                                if (*sptr)
                                        *sptr = '\0';   /* take checksum out of the buffer. */
 
-                               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);
+                               gps->io.nmea_cnt++;
+                               gps->io.nmea=gps->io.buffer;
 
-                               if (gps->update_info)
-                                       g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_info, gps, NULL);
+                               g_assert(gps->io.nmea);
+                               g_debug("NMEA1 %d: (%s)", gps->io.nmea_cnt, gps->io.nmea);
 
-                               if (gps->update_satellite)
-                                       g_idle_add_full(G_PRIORITY_DEFAULT, (GSourceFunc)gps->update_satellite, gps, NULL);
+                               gps_nmea_parse(gps);
                        } 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);
index f2758fc9ffa0d30a24a80192b172fdb548dc60c1..8b21bef7fd479d98d8318a065c4db52209e8345d 100644 (file)
--- a/src/gps.h
+++ b/src/gps.h
@@ -97,6 +97,7 @@ struct _GpsIO {
        gchar *curr;
        gchar *last;
        /* Latest NMEA line, ready for parsing */
+       guint nmea_cnt;
        gchar *nmea;
 };
 
@@ -120,7 +121,7 @@ struct _Gps {
        gboolean(* connection_progress)(Gps *gps, gdouble fix);
 
        /* New location */
-       void(* update_location)(Gps *gps, gboolean newly_fixed);
+       gboolean(* update_location)(Gps *gps);
        gboolean(* update_satellite)(Gps *gps);
        gboolean(* update_info)(Gps *gps);
 };
index fe755183aca89c824eac5839ce5b0b838715e7ce..dc75484968b8bb1067e1276fd2fe830c5c618547 100644 (file)
@@ -34,6 +34,7 @@ struct _GpsData {
        guint unity;
        time_t time;
        GpsFix fix;
+       gboolean newly_fixed;
        guint fixquality;
        gfloat speed;
        gfloat maxspeed;
index 9521c3447f20071e01790fa8a72fa8c165d71c46..9f6354bfdf35388822f1dfa4cc6a0f952541278e 100644 (file)
@@ -74,7 +74,7 @@ if (state->system_inactivity_ind) {
                                gconf_client_clear_cache(gconf_client);
                                gps_conn_set_state(_gps, RCVR_OFF);
                                gps_disconnect(_gps);
-                               track_add(NULL, FALSE);
+                               track_add(NULL);
                                /* Pretend autoroute is in progress to avoid download. */
                                if (_autoroute_data.enabled)
                                        _autoroute_data.in_progress = TRUE;
index 88348c7e8a7f2540e7650af38a1b94da8ac6d9cc..39feb42adad0dec35bd47eaf6b7b20d6dbf09e99 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -1097,7 +1097,7 @@ unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon);
 _gps->data.speed=20.f;
 gps_data_integerize(&_gps->data);
 _gps->data.time=time(NULL);
-track_add(&_gps->data, FALSE);
+track_add(&_gps->data);
 map_refresh_mark();
 }
 
index 20f0eb8ac0cac8fc631e284427c251f6777213b7..d401ada60394d0ffb3dc61658268287acc1c7e64 100644 (file)
@@ -125,7 +125,7 @@ if (_track.head != _track.tail) {
  * in the track).
  */
 void 
-track_add(GpsData *gps, gboolean newly_fixed)
+track_add(GpsData *gps)
 {
 gboolean show_directions = TRUE;
 gint announce_thres_unsquared;
@@ -139,7 +139,7 @@ if (!gps) {
 if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->unity-_track.tail->unity) > _draw_width) {
 
        /* If gps is available, update the nearest-waypoint data. */
-       if (gps && _route.head != _route.tail && (newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) {
+       if (gps && _route.head != _route.tail && (gps->newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) {
                /* Nearest waypoint has changed - re-render paths. */
                map_render_paths();
                MACRO_QUEUE_DRAW_AREA();
index 9c4bd8472e2daae731798c7bbc092f5dd8fd9f31..7786c987a7e0fac531232fb7e323a9af27387904 100644 (file)
@@ -24,7 +24,7 @@ struct {
 void track_init(void);
 void track_deinit(void);
 
-void track_add(GpsData *gps, gboolean newly_fixed);
+void track_add(GpsData *gps);
 gboolean track_insert_break(void);
 gboolean track_insert_mark(void);
 gboolean track_save(void);
index 61c5000d1ac00bfd248cee76c7471be27735b416..de8bd6a4654ab4b4fd67090521ed984a3544f5a1 100644 (file)
@@ -815,6 +815,7 @@ return FALSE;
 gboolean
 gps_satellite_update(Gps *gps)
 {
+g_assert(gps);
 if (_satdetails_on)
     gps_display_details(&gps->data);
 
@@ -822,14 +823,14 @@ return FALSE;
 }
 
 gboolean
-gps_location_update(Gps *gps, gboolean newly_fixed)
+gps_location_update(Gps *gps)
 {
 g_assert(gps);
 if (filter_check(&filter, &gps->data, &map_loc)==TRUE) {
-       track_add(&_gps->data, newly_fixed);
+       track_add(&_gps->data);
        map_refresh_mark();
 }
-return TRUE;
+return FALSE;
 }
 
 /**
index d3213e9eac634166bf3f3d4fd49244296223957c..7c9c029eda1b29b79dd40050ece6c167a18cb8f9 100644 (file)
@@ -129,7 +129,7 @@ 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_location_update(Gps *gps);
 gboolean gps_retry_connection(Gps *gps, const gchar *error);
 
 #endif