From ebe1da7059253c70ebda64a7b55a1c6ba1a9dd88 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 17 Jan 2008 12:43:10 +0200 Subject: [PATCH] Small filter fixes --- src/Makefile.am | 1 + src/config-gconf.c | 33 +++++++++++++++----------- src/config-gconf.h | 6 ++++- src/filter-gui.c | 32 ++++++++++++------------- src/filter.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ src/filter.h | 26 ++++++++++++++++++++ src/gps-nmea-parse.c | 37 ++++------------------------- src/osm.h | 12 +++++----- src/settings.h | 16 ------------- src/track.h | 1 + 10 files changed, 135 insertions(+), 85 deletions(-) create mode 100644 src/filter.c create mode 100644 src/filter.h diff --git a/src/Makefile.am b/src/Makefile.am index cc8afd8..27ec9db 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,6 +46,7 @@ mapper_LDADD = $(GLIBGTK_LIBS) $(GTKHTML_LIBS) \ mapper_SOURCES = utils.c \ file.c \ gpx.c \ + filter.c \ gps.c \ gps-browse.c \ gps-nmea-parse.c \ diff --git a/src/config-gconf.c b/src/config-gconf.c index 63d79f5..0819af9 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -54,6 +54,7 @@ #include "ui-common.h" #include "settings.h" #include "gpx.h" +#include "filter.h" void config_update_proxy(void) @@ -205,15 +206,15 @@ return TRUE; } gboolean -config_save_filter(void) +config_save_filter(GpsTrackFilter *f) { /* Filtering */ -gconf_client_set_bool(gconf_client, GCONF_KEY_GPS_FILTER, _gps_filter, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, _filter_hdop, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_VDOP, _filter_vdop, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_ANGLE, _filter_angle, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_OSM, _filter_osm, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_MAXDROP, _filter_maxdrop, NULL); +gconf_client_set_bool(gconf_client, GCONF_KEY_GPS_FILTER, f->enabled, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, f->hdop, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_VDOP, f->vdop, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_ANGLE, f->angle, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_OSM, f->osm, NULL); +gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_MAXDROP, f->maxdrop, NULL); gconf_client_suggest_sync(gconf_client, NULL); return TRUE; @@ -487,13 +488,17 @@ BOUND(_voice_pitch, 10, 99); /* Get Always Keep On flag. Default is FALSE. */ _always_keep_on = gconf_client_get_bool(gconf_client,GCONF_KEY_ALWAYS_KEEP_ON, NULL); -_gps_filter = gconf_client_get_bool(gconf_client, GCONF_KEY_GPS_FILTER, NULL); -_filter_hdop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, NULL); -_filter_vdop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_VDOP, NULL); -_filter_angle = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_ANGLE, NULL); -_filter_osm = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_OSM, NULL); -_filter_maxdrop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_MAXDROP, NULL); -BOUND(_filter_maxdrop, 0, 60); +filter.enabled = gconf_client_get_bool(gconf_client, GCONF_KEY_GPS_FILTER, NULL); +filter.hdop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, NULL); +filter.vdop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_VDOP, NULL); +filter.angle = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_ANGLE, NULL); +filter.osm = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_OSM, NULL); +filter.maxdrop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_MAXDROP, NULL); +filter.drop_cnt=0; +BOUND(filter.maxdrop, 0, 60); +BOUND(filter.hdop, 0, 50); +BOUND(filter.vdop, 0, 50); +BOUND(filter.angle, 0, 45); /* Get Units. Default is UNITS_KM. */ { diff --git a/src/config-gconf.h b/src/config-gconf.h index 49baa15..c8e3be5 100644 --- a/src/config-gconf.h +++ b/src/config-gconf.h @@ -1,14 +1,18 @@ #ifndef _CONFIG_GCONF_H #define _CONFIG_GCONF_H +#include +#include "filter.h" + GConfClient *gconf_client; void config_init(void); gboolean config_save_repo(void); gboolean config_load_repo(void); gboolean config_save_home(void); -gboolean config_save_filter(void); gboolean config_save(void); void config_update_proxy(void); +gboolean config_save_filter(GpsTrackFilter *f); + #endif diff --git a/src/filter-gui.c b/src/filter-gui.c index 4c034b8..d04f16d 100644 --- a/src/filter-gui.c +++ b/src/filter-gui.c @@ -41,7 +41,7 @@ #include "bt.h" #include "ui-common.h" #include "settings.h" - +#include "filter.h" #include "hildon-wrappers.h" GtkWidget *dialog; @@ -74,7 +74,7 @@ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), gtk_table_attach(GTK_TABLE(table), chk_gps_filter = gtk_check_button_new_with_label(_("Enable track filter")), 0, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_gps_filter), _gps_filter); +gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_gps_filter), filter.enabled); gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Horizontal DOP limit")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); @@ -99,25 +99,25 @@ gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Track point drop lim gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); gtk_table_attach(GTK_TABLE(table), num_maxdrop = gtk_hscale_new_with_range(0, 60, 1), 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_gps_filter), _gps_filter); -gtk_range_set_value(GTK_RANGE(num_hdop), _filter_hdop); -gtk_range_set_value(GTK_RANGE(num_vdop), _filter_vdop); -gtk_range_set_value(GTK_RANGE(num_angle), _filter_angle); -gtk_range_set_value(GTK_RANGE(num_osm_dist), _filter_osm); -gtk_range_set_value(GTK_RANGE(num_maxdrop), _filter_maxdrop); +gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_gps_filter), filter.enabled); +gtk_range_set_value(GTK_RANGE(num_hdop), filter.hdop); +gtk_range_set_value(GTK_RANGE(num_vdop), filter.vdop); +gtk_range_set_value(GTK_RANGE(num_angle), filter.angle); +gtk_range_set_value(GTK_RANGE(num_osm_dist), filter.osm); +gtk_range_set_value(GTK_RANGE(num_maxdrop), filter.maxdrop); gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); gtk_widget_show_all(dialog); if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - _filter_angle = gtk_range_get_value(GTK_RANGE(num_angle)); - _filter_hdop = gtk_range_get_value(GTK_RANGE(num_hdop)); - _filter_vdop = gtk_range_get_value(GTK_RANGE(num_vdop)); - _filter_osm = gtk_range_get_value(GTK_RANGE(num_osm_dist)); - _filter_maxdrop = gtk_range_get_value(GTK_RANGE(num_maxdrop)); - _gps_filter = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_gps_filter)); - - config_save_filter(); + filter.angle=gtk_range_get_value(GTK_RANGE(num_angle)); + filter.hdop=gtk_range_get_value(GTK_RANGE(num_hdop)); + filter.vdop=gtk_range_get_value(GTK_RANGE(num_vdop)); + filter.osm=gtk_range_get_value(GTK_RANGE(num_osm_dist)); + filter.maxdrop=gtk_range_get_value(GTK_RANGE(num_maxdrop)); + filter.enabled=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_gps_filter)); + + config_save_filter(&filter); } gtk_widget_destroy(dialog); diff --git a/src/filter.c b/src/filter.c new file mode 100644 index 0000000..7bd3bc3 --- /dev/null +++ b/src/filter.c @@ -0,0 +1,56 @@ +#include "config.h" + +#include +#include + +#include "gps.h" +#include "osm.h" +#include "filter.h" + +/** + * Check track filter against GPS values + * return TRUE if point is ok, FALSE if it should be skipped + */ +gboolean +filter_check(GpsTrackFilter *f, GpsData *gps, osm_location *location) +{ +if (f->enabled==FALSE) + return TRUE; + +if (f->drop_cnt>f->maxdrop) { + f->drop_cnt=0; + return TRUE; +} + +if ((gps->hdophdop || f->hdop==0.0) && (gps->vdopvdop || f->vdop==0.0)) { + f->drop_cnt=0; + return TRUE; +} + +if (fabs(gps->heading-gps->lheading)>f->angle || f->angle==0.0 ) { + f->drop_cnt=0; + return TRUE; +} + +if (!location->street) { + f->drop_cnt=0; + return TRUE; +} + +if (location->street && location->street->dist>f->osm) { + f->drop_cnt=0; + return TRUE; +} + +f->drop_cnt++; +#if 0 +g_printf("*** Filtering by: [%s %s %s %s] A: %f (%d)\n", + gps->hdop>f->hdop ? "HDOP" : "-", + gps->vdop>f->vdop ? "VDOP" : "-", + (fabs(gps->heading-gps->lheading)angle) ? "Angle" : "-", + (location->street && (location->street->dist>f->osm)) ? "OSM" : "-", + fabs(gps->heading-gps->lheading), f->drop_cnt); +#endif +return FALSE; +} + diff --git a/src/filter.h b/src/filter.h new file mode 100644 index 0000000..34a2e96 --- /dev/null +++ b/src/filter.h @@ -0,0 +1,26 @@ +#include "config.h" +#include + +#ifndef _FILTER_H +#define _FILTER_H + +#include "gpsdata.h" +#include "osm.h" + +typedef struct _gps_track_filter GpsTrackFilter; +struct _gps_track_filter { + gboolean enabled; + gdouble hdop; + gdouble vdop; + gdouble angle; + gdouble osm; + gdouble min_speed; + guint maxdrop; + guint drop_cnt; +}; + +GpsTrackFilter filter; + +gboolean filter_check(GpsTrackFilter *f, GpsData *gps, osm_location *location); + +#endif diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index 6aaf3b2..5c2ba16 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -52,9 +52,6 @@ #include "gtkgps.h" #include "gtkcompass.h" -#define GPS_FILTER_MAX_SKIP (10) -static gint track_drop_cnt=0; - gboolean channel_cb_error(GIOChannel *src, GIOCondition condition, gpointer data) { @@ -182,35 +179,11 @@ channel_parse_rmc(gchar * sentence) /* Add new data to track only if we have a fix */ _track_store=TRUE; - /* XXX: Set filter logic somewhere else */ - - if ((_conn_state == RCVR_FIXED) && (_track_store==TRUE)) { - if ((_gps_filter==TRUE) && (track_drop_cnt<_filter_maxdrop)) { - gps_integerize_data(&_gps, &_pos); - if ( (_gps.hdop<_filter_hdop || _filter_hdop==0.0) && - (_gps.vdop<_filter_vdop || _filter_vdop==0.0) && - (fabs(_gps.heading-_gps.lheading)>_filter_angle || _filter_angle==0.0 ) && - (_map_location_known==TRUE && (_map_location_dist<_filter_osm || _map_location_dist==0.0)) ) { - track_add(_pos.time, newly_fixed); - _gps.lheading=_gps.heading; - track_drop_cnt=0; - } else { - track_drop_cnt++; - g_printf("*** Filtering by: [%s %s %s %s] A: %f (%d)\n", - _gps.hdop>_filter_hdop ? "HDOP" : "-", - _gps.vdop>_filter_vdop ? "VDOP" : "-", - (fabs(_gps.heading-_gps.lheading)<_filter_angle) ? "Angle" : "-", - (_map_location_known==TRUE && (_map_location_dist>_filter_osm)) ? "OSM" : "-", - fabs(_gps.heading-_gps.lheading), track_drop_cnt); - } - map_refresh_mark(); - } else { - track_drop_cnt=0; - gps_integerize_data(&_gps, &_pos); - track_add(_pos.time, newly_fixed); - _gps.lheading=_gps.heading; - map_refresh_mark(); - } + if ((_conn_state==RCVR_FIXED) && (_track_store==TRUE) && filter_check(&filter, &_gps, &map_loc)==TRUE) { + gps_integerize_data(&_gps, &_pos); + track_add(_pos.time, newly_fixed); + _gps.lheading=_gps.heading; + map_refresh_mark(); } } diff --git a/src/osm.h b/src/osm.h index a5727e8..28ccfb3 100644 --- a/src/osm.h +++ b/src/osm.h @@ -196,8 +196,8 @@ struct _osm_place { guint32 id; node_type_t type; gchar *name; - gint lat; - gint lon; + gint32 lat; + gint32 lon; gdouble dist; guint32 isin_p; guint32 isin_c; @@ -208,8 +208,8 @@ typedef struct _osm_way_node osm_way_node; struct _osm_way_node { guint32 id; guint32 flags; - gint lat; - gint lon; + gint32 lat; + gint32 lon; }; /* Way */ @@ -251,8 +251,8 @@ struct _osm_location { osm_place *secondary; gboolean changed; gboolean valid; - gint lat; - gint lon; + gint32 lat; + gint32 lon; gfloat heading; gfloat speed; gint nfcnt; diff --git a/src/settings.h b/src/settings.h index fcb0ab0..b55a5ff 100644 --- a/src/settings.h +++ b/src/settings.h @@ -21,22 +21,6 @@ gboolean _fullscreen; gboolean _enable_gps; gboolean _gps_info; -struct _track_filter { - gboolean enabled; - gdouble hdop; - gdouble vdop; - gdouble angle; - gdouble osm; - gdouble maxdrop; -}; - -gboolean _gps_filter; -gdouble _filter_hdop; -gdouble _filter_vdop; -gdouble _filter_angle; -gdouble _filter_osm; -gdouble _filter_maxdrop; - gint _show_tracks; gboolean _show_scale; gboolean _show_velvec; diff --git a/src/track.h b/src/track.h index 20750de..6cec294 100644 --- a/src/track.h +++ b/src/track.h @@ -3,6 +3,7 @@ #include #include +#include "filter.h" #define TRACK_SQL_SELECT_TRACKS "select id,name,slat,slon,elat,elon,len,sdate,edate from tracks order by sdate" #define TRACK_SQL_INSERT_TRACK "insert into tracks (id,name,sloc,sdate) values (?,?,?,?); -- 2.39.5