From 2e70a5fd6414bcf0ea7d296908432a9f9dce723a Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 29 Jan 2008 19:05:47 +0200 Subject: [PATCH] Parse directly but update informations in callbacks only if we got a sentence that changes something. --- src/cb.c | 4 ++-- src/gps-nmea-parse.c | 34 ++++++++++++++++++++++------------ src/gps.c | 15 +++++++-------- src/gps.h | 3 ++- src/gpsdata.h | 1 + src/maemo-osso.c | 2 +- src/map.c | 2 +- src/track.c | 4 ++-- src/track.h | 2 +- src/ui-common.c | 7 ++++--- src/ui-common.h | 2 +- 11 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/cb.c b/src/cb.c index a96c290..3525100 100644 --- 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; } diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index 05a7597..96bcbe3 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -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)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; } diff --git a/src/gps.c b/src/gps.c index 15cb552..3e4c63c 100644 --- 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); diff --git a/src/gps.h b/src/gps.h index f2758fc..8b21bef 100644 --- 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); }; diff --git a/src/gpsdata.h b/src/gpsdata.h index fe75518..dc75484 100644 --- a/src/gpsdata.h +++ b/src/gpsdata.h @@ -34,6 +34,7 @@ struct _GpsData { guint unity; time_t time; GpsFix fix; + gboolean newly_fixed; guint fixquality; gfloat speed; gfloat maxspeed; diff --git a/src/maemo-osso.c b/src/maemo-osso.c index 9521c34..9f6354b 100644 --- a/src/maemo-osso.c +++ b/src/maemo-osso.c @@ -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; diff --git a/src/map.c b/src/map.c index 88348c7..39feb42 100644 --- 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(); } diff --git a/src/track.c b/src/track.c index 20f0eb8..d401ada 100644 --- a/src/track.c +++ b/src/track.c @@ -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(); diff --git a/src/track.h b/src/track.h index 9c4bd84..7786c98 100644 --- a/src/track.h +++ b/src/track.h @@ -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); diff --git a/src/ui-common.c b/src/ui-common.c index 61c5000..de8bd6a 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -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; } /** diff --git a/src/ui-common.h b/src/ui-common.h index d3213e9..7c9c029 100644 --- a/src/ui-common.h +++ b/src/ui-common.h @@ -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 -- 2.39.5