diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-12-15 14:05:41 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-12-15 14:05:41 +0000 |
commit | e11e2739ed561987ee7f6fa3bf458720b80daaab (patch) | |
tree | 322d595efd87580c0ce44670e6b60047b3c7ebb2 | |
parent | 669ad6b125218cc2d41e234af622f5cdf6ff03cf (diff) | |
download | gpsd-e11e2739ed561987ee7f6fa3bf458720b80daaab.tar.gz |
Uniform handling of unit-system defaults and -u in xgps, cgps, and lcdgps.
-rw-r--r-- | cgps.c | 79 | ||||
-rw-r--r-- | gps.xml | 37 | ||||
-rw-r--r-- | lcdgps.c | 27 | ||||
-rwxr-xr-x | xgps | 6 |
4 files changed, 97 insertions, 52 deletions
@@ -693,8 +693,35 @@ int main(int argc, char *argv[]) fd_set rfds; int data; + /*@ -observertrans @*/ + switch (gpsd_units()) + { + case imperial: + altfactor = METERS_TO_FEET; + altunits = "ft"; + speedfactor = MPS_TO_MPH; + speedunits = "mph"; + break; + case nautical: + altfactor = METERS_TO_FEET; + altunits = "ft"; + speedfactor = MPS_TO_KNOTS; + speedunits = "knots"; + break; + case metric: + altfactor = 1; + altunits = "m"; + speedfactor = MPS_TO_KPH; + speedunits = "kph"; + break; + default: + /* leave the default alone */ + break; + } + /*@ +observertrans @*/ + /* Process the options. Print help if requested. */ - while ((option = getopt(argc, argv, "hVl:smD:")) != -1) { + while ((option = getopt(argc, argv, "hVl:smuD:")) != -1) { switch (option) { case 'D': debug = atoi(optarg); @@ -708,6 +735,29 @@ int main(int argc, char *argv[]) case 's': silent_flag=true; break; + case 'u': + switch ( optarg[0] ) { + case 'i': + altfactor = METERS_TO_FEET; + altunits = "ft"; + speedfactor = MPS_TO_MPH; + speedunits = "mph"; + continue; + case 'n': + altfactor = METERS_TO_FEET; + altunits = "ft"; + speedfactor = MPS_TO_KNOTS; + speedunits = "knots"; + continue; + case 'm': + altfactor = 1; + altunits = "m"; + speedfactor = MPS_TO_KPH; + speedunits = "kph"; + continue; + default: + (void)fprintf(stderr, "Unknown -u argument: %s\n", optarg); + } case 'V': (void)fprintf(stderr, "xgps: %s (revision %s)\n", VERSION, REVISION); @@ -739,33 +789,6 @@ int main(int argc, char *argv[]) } else gpsd_source_spec(NULL, &source); - /*@ -observertrans @*/ - switch (gpsd_units()) - { - case imperial: - altfactor = METERS_TO_FEET; - altunits = "ft"; - speedfactor = MPS_TO_MPH; - speedunits = "mph"; - break; - case nautical: - altfactor = METERS_TO_FEET; - altunits = "ft"; - speedfactor = MPS_TO_KNOTS; - speedunits = "knots"; - break; - case metric: - altfactor = 1; - altunits = "m"; - speedfactor = MPS_TO_KPH; - speedunits = "kph"; - break; - default: - /* leave the default alone */ - break; - } - /*@ +observertrans @*/ - /* Open the stream to gpsd. */ /*@i@*/gpsdata = gps_open(source.server, source.port); if (!gpsdata) { @@ -24,7 +24,7 @@ <arg choice='opt'>-h </arg> <arg choice='opt'>-V </arg> <arg choice='opt'>-l <group><arg>d</arg><arg>m</arg><arg>s</arg></group></arg> - <arg choice='opt'>-u <group><arg>imperial</arg><arg>nautical</arg><arg>metric</arg></group></arg> + <arg choice='opt'>-u <group><arg>i</arg><arg>n</arg><arg>m</arg></group></arg> <group> <replaceable>server</replaceable> <group> @@ -52,15 +52,13 @@ </cmdsynopsis> <cmdsynopsis> <command>cgps</command> - <arg choice='opt'><replaceable>X-options</replaceable></arg> <arg choice='opt'>-D <replaceable>debug-level</replaceable></arg> <arg choice='opt'>-h </arg> <arg choice='opt'>-V </arg> - <arg choice='opt'>-speedunits <group choice='req'><arg>mph</arg><arg>kph</arg><arg>knots</arg></group></arg> - <arg choice='opt'>-altunits <group choice='req'><arg>feet</arg><arg>meters</arg></group></arg> <arg choice='opt'>-l <group><arg>d</arg><arg>m</arg><arg>s</arg></group></arg> <arg choice='opt'>-m </arg> <arg choice='opt'>-s </arg> + <arg choice='opt'>-u <group><arg>i</arg><arg>n</arg><arg>m</arg></group></arg> <group> <replaceable>server</replaceable> <group> @@ -119,10 +117,11 @@ degrees and is the default. The value 'm' produces degrees and decimal minutes. The value 's' produces degrees, minutes, and decimal seconds.</para> -<para><application>xgps</application> and -<application>cgps</application> look at variables in the environment -to figure out what units they should default to using for display. -Here are the variables and values they check:</para> +<para><application>xgps</application>, +<application>cgps</application>, and <application>ldcgps</application> +look at variables in the environment to figure out what units they +should default to using for display — imperial, nautical, or +metric. Here are the variables and values they check:</para> <screen> GPSD_UNITS one of: @@ -140,6 +139,15 @@ Here are the variables and values they check:</para> POSIX = miles/feet [other] = km/meters </screen> +<para>These preferences may be overridden by the <option>-u</option> +option.</para> + +<para>Where present, the <option>-u</option> option can be used to set +the system units for display; follow the keyword with 'i' for +'imperial' for American units (feet in altitude and error estimates, +miles per hour in speeds), 'n' for 'nautical' (feet in altitude and +error estimates, knots in speed) or 'm' for 'metric' (meters in +altitude and error estimates, kiliometers per hour in speeds). </para> <para> The <option>-D</option> option, when present, sets a debug level; it is primarily for use by GPSD developers. It enables @@ -170,13 +178,6 @@ dB. Square icons indicate WAAS/EGNOS satellites, circles indicate ordinary GPS satellites. Filled icons were used in the last fix, outline icons were not.</para> -<para>The <option>-u</option> option can be used to set the -system units for display; follow the keyword with 'imperial' for -American units (feet in altitude and error estimates, miles per hour -in speeds), 'nautical' (feet in altitude and error estimates, knots -in speed) or 'metric' (meters in altitude and error estimates, -kiliometers per hour in speeds). </para> - </refsect2> <refsect2><title>xgpsspeed</title> @@ -224,12 +225,6 @@ very expensive and nearly feature-free GPS receiver. Currently assumes a 4x40 LCD and writes data formatted to fit that size screen. Also displays 4- or 6-character Maidenhead grid square output.</para> -<para>Options are as for <application>cgps</application>, except: The -<option>-u</option> sets the display format the units used for -altitude and speed. The options are: <quote>i</quote> for Imperial -units (feet/miles-per-hour); <quote>n</quote> for nautical -(feet/knots); 'm' for metric (meters/kilometers-per-hour).</para> - </refsect2> <refsect2><title>gpxlogger</title> @@ -364,6 +364,33 @@ int main(int argc, char *argv[]) for(n=0;n<CLIMB;n++) climb[n]=0.0; #endif + /*@ -observertrans @*/ + switch (gpsd_units()) + { + case imperial: + altfactor = METERS_TO_FEET; + altunits = "ft"; + speedfactor = MPS_TO_MPH; + speedunits = "mph"; + break; + case nautical: + altfactor = METERS_TO_FEET; + altunits = "ft"; + speedfactor = MPS_TO_KNOTS; + speedunits = "knots"; + break; + case metric: + altfactor = 1; + altunits = "m"; + speedfactor = MPS_TO_KPH; + speedunits = "kph"; + break; + default: + /* leave the default alone */ + break; + } + /*@ +observertrans @*/ + /* Process the options. Print help if requested. */ while ((option = getopt(argc, argv, "Vhl:su:")) != -1) { switch (option) { @@ -28,14 +28,14 @@ class unit_adjustments: self.speedunits = "mph" if units is None: units = gps.client.gpsd_units() - if units in (gps.client.unspecified, gps.client.imperial, "imperial"): + if units in (gps.client.unspecified, gps.client.imperial, "imperial", "i"): pass - elif units in (gps.client.nautical, "nautical"): + elif units in (gps.client.nautical, "nautical", "n"): self.altfactor = gps.METERS_TO_FEET self.altunits = "ft" self.speedfactor = gps.MPS_TO_KNOTS self.speedunits = "knots" - elif units in (gps.client.metric, "metric"): + elif units in (gps.client.metric, "metric", "m"): self.altfactor = 1 self.altunits = "m" self.speedfactor = gps.MPS_TO_KPH |