From 4afdaf1285ecdcbcfeac6d3e9be0b9b0de0e2b07 Mon Sep 17 00:00:00 2001 From: Tim Baverstock Date: Thu, 25 Nov 2010 16:04:04 +0000 Subject: Correct command arguments for 'geo fix', but support backward compatible use. Change-Id: Id4f427dfb918d69e3fb52725cbe88bce1666dddc --- CHANGES.TXT | 5 +++++ android/console.c | 38 +++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CHANGES.TXT b/CHANGES.TXT index 183c45e..5cb31d4 100644 --- a/CHANGES.TXT +++ b/CHANGES.TXT @@ -59,6 +59,11 @@ OTHER: satellites to emulate. The number must be an integer between 1 and 12, (1 is the default). + - fixed a bug in parameter handling: the implementation disagreed with the + documentation, requiring an additional dummy fourth argument. Now four or + five parameters are accepted (for backwards compatibility), but the last is + always the satellite count. + - Add a PulseAudio audio backend on Linux. It will be used by default unless it's impossible to connect to the PA daemon. diff --git a/android/console.c b/android/console.c index 4f1a976..42addba 100644 --- a/android/console.c +++ b/android/console.c @@ -2138,10 +2138,11 @@ do_geo_nmea( ControlClient client, char* args ) static int do_geo_fix( ControlClient client, char* args ) { -#define MAX_GEO_PARAMS 5 + // GEO_SAT2 provides bug backwards compatibility. + enum { GEO_LONG = 0, GEO_LAT, GEO_ALT, GEO_SAT, GEO_SAT2, NUM_GEO_PARAMS }; char* p = args; - int n_params = 0; - double params[ MAX_GEO_PARAMS ]; + int top_param = -1; + double params[ NUM_GEO_PARAMS ]; int n_satellites = 1; static int last_time = 0; @@ -2160,8 +2161,8 @@ do_geo_fix( ControlClient client, char* args ) return -1; } - params[n_params++] = val; - if (n_params >= MAX_GEO_PARAMS) + params[++top_param] = val; + if (top_param + 1 == NUM_GEO_PARAMS) break; p = end; @@ -2170,15 +2171,17 @@ do_geo_fix( ControlClient client, char* args ) } /* sanity check */ - if (n_params < 2) { + if (top_param < GEO_LAT) { control_write( client, "KO: not enough arguments: see 'help geo fix' for details\r\n" ); return -1; } - /* check number of satellites, must be between 1 and 12 */ - if (n_params >= 4) { - n_satellites = (int) params[4]; - if (n_satellites != params[4] || n_satellites < 1 || n_satellites > 12) { + /* check number of satellites, must be integer between 1 and 12 */ + if (top_param >= GEO_SAT) { + int sat_index = (top_param >= GEO_SAT2) ? GEO_SAT2 : GEO_SAT; + n_satellites = (int) params[sat_index]; + if (n_satellites != params[sat_index] + || n_satellites < 1 || n_satellites > 12) { control_write( client, "KO: invalid number of satellites. Must be an integer between 1 and 12\r\n"); return -1; } @@ -2214,7 +2217,7 @@ do_geo_fix( ControlClient client, char* args ) /* then the latitude */ hemi = 'N'; - val = params[1]; + val = params[GEO_LAT]; if (val < 0) { hemi = 'S'; val = -val; @@ -2227,7 +2230,7 @@ do_geo_fix( ControlClient client, char* args ) /* the longitude */ hemi = 'E'; - val = params[0]; + val = params[GEO_LONG]; if (val < 0) { hemi = 'W'; val = -val; @@ -2242,9 +2245,9 @@ do_geo_fix( ControlClient client, char* args ) stralloc_add_format( s, ",1,%02d,", n_satellites ); /* optional altitude + bogus diff */ - if (n_params >= 3) { - stralloc_add_format( s, ",%.1g,M,0.,M", params[2] ); - last_altitude = params[2]; + if (top_param >= GEO_ALT) { + stralloc_add_format( s, ",%.1g,M,0.,M", params[GEO_ALT] ); + last_altitude = params[GEO_ALT]; } else { stralloc_add_str( s, ",,,," ); } @@ -2267,8 +2270,9 @@ static const CommandDefRec geo_commands[] = NULL, do_geo_nmea, NULL }, { "fix", "send a simple GPS fix", - "'geo fix [ []]' allows you to send a\r\n" - "simple GPS fix to the emulated system. the parameters are:\r\n\r\n" + "'geo fix [ []]'\r\n" + " allows you to send a simple GPS fix to the emulated system.\r\n" + " The parameters are:\r\n\r\n" " longitude, in decimal degrees\r\n" " latitude, in decimal degrees\r\n" " optional altitude in meters\r\n" -- cgit v1.1