From: Kaj-Michael Lang Date: Thu, 24 Jan 2008 16:46:44 +0000 (+0200) Subject: Small fixes to gps random simulator. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aae231ef935feb23d8f5c20a017ab7873be8b702;p=mapper Small fixes to gps random simulator. --- diff --git a/src/gps.c b/src/gps.c index 61cdc4e..fece5e4 100644 --- a/src/gps.c +++ b/src/gps.c @@ -73,7 +73,7 @@ gps->io.fd=-1; gps->io.address=NULL; gps->io.type=type; gps->io.conn=RCVR_OFF; -gps->data.lat=64.20; +gps->data.lat=60.20; gps->data.lon=22.20; gps_data_integerize(&gps->data); return gps; @@ -293,24 +293,43 @@ if (gps->io.type==GPS_IO_BLUEZ_DBUS && gps->io.rfcomm_req_proxy) { } +static void +gps_simulate_start(Gps *gps) +{ +gps->data.lat=60.45; +gps->data.lon=22.26; +gps->io.conn=RCVR_FIXED; +gps->data.fix=FIX_2D; +gps_data_integerize(&gps->data); +} + static gboolean -gps_simulate(Gps *gps) +gps_simulate_move(Gps *gps) { +static gdouble slat=0, slon=0; g_assert(gps); -gps->data.lat+=g_random_double_range(-0.0002,0.0002); -gps->data.lon+=g_random_double_range(-0.0002,0.0002); +if (g_random_double()<0.5) { + slat=g_random_double_range(-0.0003, 0.0003); + slon=g_random_double_range(-0.0003, 0.0003); +} +gps->data.lat+=slat; +gps->data.lon+=slon; BOUND(gps->data.lat, -80.0, 80.0); BOUND(gps->data.lon, -80.0, 80.0); -gps->data.speed=1+g_random_double_range(0.0,5.0); -gps->data.heading+=g_random_double_range(-2.0,2.0); + +g_debug("Sim: %f %f\n", gps->data.lat, gps->data.lon); + +gps->data.speed=1+g_random_double_range(0.1, 10.0); +gps->data.heading+=g_random_double_range(-4.0, 4.0); +BOUND(gps->data.heading, 0, 359); gps->data.time=time(NULL); gps_data_integerize(&gps->data); -track_add(gps, FALSE); +track_add(&gps->data, FALSE); gps->data.lheading=gps->data.heading; map_refresh_mark(); -return TRUE; +return gps->io.conn==RCVR_FIXED ? TRUE : FALSE; } /** @@ -430,12 +449,8 @@ switch (gps->io.type) { break; case GPS_IO_SIMULATION: /* Set a periodic cb to generate random movement */ - gps->data.lat=64.22; - gps->data.lat=22.22; - gps->io.conn=RCVR_FIXED; - gps->data.fix=FIX_2D; - gps_data_integerize(&gps->data); - gps->io.input_sid=g_timeout_add(1000, (GSourceFunc)gps_simulate, gps); + gps_simulate_start(gps); + gps->io.input_sid=g_timeout_add(1000, (GSourceFunc)gps_simulate_move, gps); return FALSE; break; default: