]> err.no Git - mapper/commitdiff
Small filter fixes
authorKaj-Michael Lang <milang@onion.tal.org>
Thu, 17 Jan 2008 10:43:10 +0000 (12:43 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Thu, 17 Jan 2008 10:43:10 +0000 (12:43 +0200)
src/Makefile.am
src/config-gconf.c
src/config-gconf.h
src/filter-gui.c
src/filter.c [new file with mode: 0644]
src/filter.h [new file with mode: 0644]
src/gps-nmea-parse.c
src/osm.h
src/settings.h
src/track.h

index cc8afd871ce75c26208c1f93e4eed81675205433..27ec9db213e0b5ffa4cbaed501857b9f82d5c2c5 100644 (file)
@@ -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 \
index 63d79f5f94b577dc955f63f902db79592d6008fa..0819af9649af56d7235d64836dd80a02aa936ffc 100644 (file)
@@ -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. */
 {
index 49baa15109d563049f23e49191853e77cd9b4857..c8e3be5dcacc058e862a180c0073806197e39193 100644 (file)
@@ -1,14 +1,18 @@
 #ifndef _CONFIG_GCONF_H
 #define _CONFIG_GCONF_H
 
+#include <gconf/gconf-client.h>
+#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
index 4c034b859620355f92ff2d92426d8b5fcbeacbd0..d04f16d3a683bc220f97579e76dade768878b5fb 100644 (file)
@@ -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 (file)
index 0000000..7bd3bc3
--- /dev/null
@@ -0,0 +1,56 @@
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#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->hdop<f->hdop || f->hdop==0.0) && (gps->vdop<f->vdop || 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)<f->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 (file)
index 0000000..34a2e96
--- /dev/null
@@ -0,0 +1,26 @@
+#include "config.h"
+#include <glib.h>
+
+#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
index 6aaf3b27b232ff5b55d44dd050f3c12f51201fa5..5c2ba16945abddee8573525ceb4041909b364a92 100644 (file)
@@ -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();
        }
 }
 
index a5727e8a4c64f30c75e8ee5da288aa11b1c4ecca..28ccfb3724ebdf844057e52ee9d6a27b9f8de787 100644 (file)
--- 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;
index fcb0ab0f9756c3f9ebe661c74fd8565450eabee2..b55a5ffaeb9f5f9fe2695d1d02e3662197e5dbad 100644 (file)
@@ -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;
index 20750de8f44de40abd7591324322e0dce09dc693..6cec294755b62498db45eb17e7171fb38d32bf87 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <glib.h>
 #include <sqlite3.h>
+#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 (?,?,?,?);