Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Correct command arguments for 'geo fix', but support backward compati…
Browse files Browse the repository at this point in the history
…ble use.

Change-Id: Id4f427dfb918d69e3fb52725cbe88bce1666dddc
  • Loading branch information
Tim Baverstock committed Dec 1, 2010
1 parent 68235cf commit 4afdaf1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGES.TXT
Expand Up @@ -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.

Expand Down
38 changes: 21 additions & 17 deletions android/console.c
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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, ",,,," );
}
Expand All @@ -2267,8 +2270,9 @@ static const CommandDefRec geo_commands[] =
NULL, do_geo_nmea, NULL },

{ "fix", "send a simple GPS fix",
"'geo fix <longitude> <latitude> [<altitude> [<satellites>]]' allows you to send a\r\n"
"simple GPS fix to the emulated system. the parameters are:\r\n\r\n"
"'geo fix <longitude> <latitude> [<altitude> [<satellites>]]'\r\n"
" allows you to send a simple GPS fix to the emulated system.\r\n"
" The parameters are:\r\n\r\n"
" <longitude> longitude, in decimal degrees\r\n"
" <latitude> latitude, in decimal degrees\r\n"
" <altitude> optional altitude in meters\r\n"
Expand Down

0 comments on commit 4afdaf1

Please sign in to comment.