From 8bf51b2e71e4583dfce86ee0b5ac807ac19bd25f Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 21 Mar 2008 14:41:46 +0200 Subject: [PATCH] GPS simulator changes: - Set start position to home if set - If destination is set, try to travel towards it, otherwise use the old random way. --- src/gps.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/gps.c b/src/gps.c index 718dd55..fadb66c 100644 --- a/src/gps.c +++ b/src/gps.c @@ -402,8 +402,14 @@ static void gps_simulate_start(Gps *gps) { g_assert(gps); -gps->data.lat=60.45; -gps->data.lon=22.26; +if (_home.valid) { + gps->data.lat=_home.lat; + gps->data.lon=_home.lon; +} else { + gps->data.lat=60.45; + gps->data.lon=22.26; +} + gps->io.conn=RCVR_FIXED; gps->data.fix=FIX_2D; gps->data.satinview=0; @@ -415,25 +421,36 @@ static gboolean gps_simulate_move(Gps *gps) { static gdouble slat=0, slon=0; -gdouble plat, plon; +gdouble plat, plon, accel; gfloat h; g_assert(gps); -if (g_random_double()<0.2) { - slat=g_random_double_range(-0.0009, 0.0009); - slon=g_random_double_range(-0.0009, 0.0009); +if (_dest.valid) { + _dest.angle=calculate_course(_dest.lat,_dest.lon, gps->data.lat, gps->data.lon); + + accel=0.005*g_random_double(); + slat=accel*cos(_dest.angle); + slon=accel*sin(_dest.angle); + g_debug("Sim: %f %f %f %f", slat, slon, accel, _dest.angle); +} else { + if (g_random_double()<0.2) { + slat=g_random_double_range(-0.0009, 0.0009); + slon=g_random_double_range(-0.0009, 0.0009); + } } plat=gps->data.lat; plon=gps->data.lon; gps->data.lat+=slat; gps->data.lon+=slon; + BOUND(gps->data.lat, -80.0, 80.0); BOUND(gps->data.lon, -80.0, 80.0); g_debug("Sim: %f %f", gps->data.lat, gps->data.lon); -gps->data.speed=1+g_random_double_range(0.1, 10.0); +gps->data.speed=0; + h=calculate_course(plat, plon, gps->data.lat, gps->data.lon); gps->data.heading=(h<0) ? 360+h : h; gps->data.time=time(NULL); -- 2.39.5