From 472fc2ab9fe0bb573c8a16ab339a665c67236acc Mon Sep 17 00:00:00 2001 From: "Gary E. Miller" Date: Tue, 25 Sep 2018 13:41:54 -0700 Subject: cgps: tweak usage() output. --- cgps.c | 1072 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 535 insertions(+), 537 deletions(-) (limited to 'cgps.c') diff --git a/cgps.c b/cgps.c index f08bd12b..9244adfa 100644 --- a/cgps.c +++ b/cgps.c @@ -102,22 +102,20 @@ #include "gpsd_config.h" #include "gps.h" #include "gps_json.h" /* for GPS_JSON_RESPONSE_MAX */ -#include "compiler.h" /* for UNUSED */ +#include "compiler.h" /* for UNUSED */ #include "gpsdclient.h" #include "revision.h" #include "os_compat.h" static struct gps_data_t gpsdata; -static time_t status_timer; /* Time of last state change. */ -static int state = 0; /* or MODE_NO_FIX=1, MODE_2D=2, MODE_3D=3 */ +static time_t status_timer; /* Time of last state change. */ +static int state = 0; /* or MODE_NO_FIX=1, MODE_2D=2, MODE_3D=3 */ static float altfactor = METERS_TO_FEET; static float speedfactor = MPS_TO_MPH; static char *altunits = "ft"; static char *speedunits = "mph"; static struct fixsource_t source; -#ifdef CLIENTDEBUG_ENABLE static int debug; -#endif /* CLIENTDEBUG_ENABLE */ static WINDOW *datawin, *satellites, *messages; @@ -133,10 +131,10 @@ static bool compass_flag = false; #endif /* TRUENORTH */ /* pseudo-signals indicating reason for termination */ -#define CGPS_QUIT 0 /* voluntary termination */ -#define GPS_GONE -1 /* GPS device went away */ -#define GPS_ERROR -2 /* low-level failure in GPS read */ -#define GPS_TIMEOUT -3 /* low-level failure in GPS waiting */ +#define CGPS_QUIT 0 /* voluntary termination */ +#define GPS_GONE -1 /* GPS device went away */ +#define GPS_ERROR -2 /* low-level failure in GPS read */ +#define GPS_TIMEOUT -3 /* low-level failure in GPS waiting */ /* range test an int, return 4 chars + NUL */ static const char *int_to_str(int val, int min, int max) @@ -144,7 +142,7 @@ static const char *int_to_str(int val, int min, int max) static char buf[20]; if (val < min || val > max) { - return " n/a"; + return " n/a"; } (void)snprintf(buf, sizeof(buf), "%4d", val); return buf; @@ -156,7 +154,7 @@ static char *dop_to_str(double dop) static char buf[20]; if (isfinite(dop) == 0) { - return " n/a "; + return " n/a "; } (void)snprintf(buf, sizeof(buf), "%5.2f", dop); return buf; @@ -168,7 +166,7 @@ static char *ep_to_str(double ep, double factor, char *units) static char buf[128]; if (isfinite(ep) == 0) { - return " n/a "; + return " n/a "; } (void)snprintf(buf, sizeof(buf), "+/-%4.1f %.10s", ep * factor, units); return buf; @@ -180,14 +178,14 @@ static char *ecef_to_str(double pos, double vel, double factor, char *units) static char buf[128]; if (isfinite(pos) == 0) { - if (isfinite(vel) == 0) { - return " n/a n/a "; + if (isfinite(vel) == 0) { + return " n/a n/a "; } else { - (void)snprintf(buf, sizeof(buf), " n/a %8.3f%.4s/s", + (void)snprintf(buf, sizeof(buf), " n/a %8.3f%.4s/s", vel * factor, units); } } else { - (void)snprintf(buf, sizeof(buf), "% 14.3f%.4s %8.3f%.4s/s", + (void)snprintf(buf, sizeof(buf), "% 14.3f%.4s %8.3f%.4s/s", pos * factor, units, vel * factor, units); } return buf; @@ -198,14 +196,14 @@ static void die(int sig) { if (!isendwin()) { - /* Move the cursor to the bottom left corner. */ - (void)mvcur(0, COLS - 1, LINES - 1, 0); + /* Move the cursor to the bottom left corner. */ + (void)mvcur(0, COLS - 1, LINES - 1, 0); - /* Put input attributes back the way they were. */ - (void)echo(); + /* Put input attributes back the way they were. */ + (void)echo(); - /* Done with curses. */ - (void)endwin(); + /* Done with curses. */ + (void)endwin(); } /* We're done talking to gpsd. */ @@ -213,19 +211,19 @@ static void die(int sig) switch (sig) { case CGPS_QUIT: - break; + break; case GPS_GONE: - (void)fprintf(stderr, "cgps: GPS hung up.\n"); - break; + (void)fprintf(stderr, "cgps: GPS hung up.\n"); + break; case GPS_ERROR: - (void)fprintf(stderr, "cgps: GPS read returned error\n"); - break; + (void)fprintf(stderr, "cgps: GPS read returned error\n"); + break; case GPS_TIMEOUT: - (void)fprintf(stderr, "cgps: GPS timeout\n"); - break; + (void)fprintf(stderr, "cgps: GPS timeout\n"); + break; default: - (void)fprintf(stderr, "cgps: caught signal %d\n", sig); - break; + (void)fprintf(stderr, "cgps: caught signal %d\n", sig); + break; } /* Bye! */ @@ -271,182 +269,182 @@ static void windowsetup(void) #ifdef TRUENORTH if (compass_flag) { - if (ysize == MIN_COMPASS_DATAWIN_YSIZE) { - raw_flag = false; - window_ysize = MIN_COMPASS_DATAWIN_YSIZE; - } else if (ysize > MIN_COMPASS_DATAWIN_YSIZE) { - raw_flag = true; - window_ysize = MIN_COMPASS_DATAWIN_YSIZE; - } else { - (void)mvprintw(0, 0, - "Your screen must be at least 80x%d to run cgps.", - MIN_COMPASS_DATAWIN_YSIZE); - (void)refresh(); - (void)sleep(5); - die(0); - } + if (ysize == MIN_COMPASS_DATAWIN_YSIZE) { + raw_flag = false; + window_ysize = MIN_COMPASS_DATAWIN_YSIZE; + } else if (ysize > MIN_COMPASS_DATAWIN_YSIZE) { + raw_flag = true; + window_ysize = MIN_COMPASS_DATAWIN_YSIZE; + } else { + (void)mvprintw(0, 0, + "Your screen must be at least 80x%d to run cgps.", + MIN_COMPASS_DATAWIN_YSIZE); + (void)refresh(); + (void)sleep(5); + die(0); + } } else #endif /* TRUENORTH */ { - if (ysize > MAX_GPS_DATAWIN_YSIZE + 10) { - raw_flag = true; - show_ecefs = true; - show_more_dops = true; - window_ysize = MAX_GPS_DATAWIN_YSIZE + 7; - } else if (ysize > MAX_GPS_DATAWIN_YSIZE + 6) { - raw_flag = true; - show_ecefs = false; - show_more_dops = true; - window_ysize = MAX_GPS_DATAWIN_YSIZE + 4; - } else if (ysize > MAX_GPS_DATAWIN_YSIZE) { - raw_flag = true; - show_ecefs = false; - show_more_dops = false; - window_ysize = MAX_GPS_DATAWIN_YSIZE; - } else if (ysize == MAX_GPS_DATAWIN_YSIZE) { - raw_flag = false; - show_ecefs = false; - show_more_dops = false; - window_ysize = MAX_GPS_DATAWIN_YSIZE; - } else if (ysize > MIN_GPS_DATAWIN_YSIZE) { - raw_flag = true; - show_ecefs = false; - show_more_dops = false; - window_ysize = MIN_GPS_DATAWIN_YSIZE; - } else if (ysize == MIN_GPS_DATAWIN_YSIZE) { - raw_flag = false; - show_ecefs = false; - show_more_dops = false; - window_ysize = MIN_GPS_DATAWIN_YSIZE; - } else { - (void)mvprintw(0, 0, - "Your screen must be at least 80x%d to run cgps.", - MIN_GPS_DATAWIN_YSIZE); - (void)refresh(); - (void)sleep(5); - die(0); - } - display_sats = window_ysize - SATWIN_OVERHEAD - (int)raw_flag; + if (ysize > MAX_GPS_DATAWIN_YSIZE + 10) { + raw_flag = true; + show_ecefs = true; + show_more_dops = true; + window_ysize = MAX_GPS_DATAWIN_YSIZE + 7; + } else if (ysize > MAX_GPS_DATAWIN_YSIZE + 6) { + raw_flag = true; + show_ecefs = false; + show_more_dops = true; + window_ysize = MAX_GPS_DATAWIN_YSIZE + 4; + } else if (ysize > MAX_GPS_DATAWIN_YSIZE) { + raw_flag = true; + show_ecefs = false; + show_more_dops = false; + window_ysize = MAX_GPS_DATAWIN_YSIZE; + } else if (ysize == MAX_GPS_DATAWIN_YSIZE) { + raw_flag = false; + show_ecefs = false; + show_more_dops = false; + window_ysize = MAX_GPS_DATAWIN_YSIZE; + } else if (ysize > MIN_GPS_DATAWIN_YSIZE) { + raw_flag = true; + show_ecefs = false; + show_more_dops = false; + window_ysize = MIN_GPS_DATAWIN_YSIZE; + } else if (ysize == MIN_GPS_DATAWIN_YSIZE) { + raw_flag = false; + show_ecefs = false; + show_more_dops = false; + window_ysize = MIN_GPS_DATAWIN_YSIZE; + } else { + (void)mvprintw(0, 0, + "Your screen must be at least 80x%d to run cgps.", + MIN_GPS_DATAWIN_YSIZE); + (void)refresh(); + (void)sleep(5); + die(0); + } + display_sats = window_ysize - SATWIN_OVERHEAD - (int)raw_flag; } #ifdef TRUENORTH /* Set up the screen for either a compass or a gps receiver. */ if (compass_flag) { - /* We're a compass, set up accordingly. */ + /* We're a compass, set up accordingly. */ int row = 1; - datawin = newwin(window_ysize, DATAWIN_WIDTH, 0, 0); - (void)nodelay(datawin, (bool) TRUE); - if (raw_flag) { - messages = newwin(0, 0, window_ysize, 0); + datawin = newwin(window_ysize, DATAWIN_WIDTH, 0, 0); + (void)nodelay(datawin, (bool) TRUE); + if (raw_flag) { + messages = newwin(0, 0, window_ysize, 0); - (void)scrollok(messages, true); - (void)wsetscrreg(messages, 0, ysize - (window_ysize)); - } + (void)scrollok(messages, true); + (void)wsetscrreg(messages, 0, ysize - (window_ysize)); + } - (void)refresh(); + (void)refresh(); - /* Do the initial field label setup. */ - (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Time:"); - (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Heading:"); - (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Pitch:"); - (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Roll:"); - (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Dip:"); - (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Rcvr Type:"); - (void)wborder(datawin, 0, 0, 0, 0, 0, 0, 0, 0); + /* Do the initial field label setup. */ + (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Time:"); + (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Heading:"); + (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Pitch:"); + (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Roll:"); + (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Dip:"); + (void)mvwprintw(datawin, row++, DATAWIN_DESC_OFFSET, "Rcvr Type:"); + (void)wborder(datawin, 0, 0, 0, 0, 0, 0, 0, 0); } else #endif /* TRUENORTH */ { - /* We're a GPS, set up accordingly. */ + /* We're a GPS, set up accordingly. */ int row = 1; - datawin = newwin(window_ysize, DATAWIN_WIDTH, 0, 0); - satellites = - newwin(window_ysize, SATELLITES_WIDTH, 0, DATAWIN_WIDTH); - (void)nodelay(datawin, (bool) TRUE); - if (raw_flag) { - messages = - newwin(ysize - (window_ysize), xsize, window_ysize, 0); - - (void)scrollok(messages, true); - (void)wsetscrreg(messages, 0, ysize - (window_ysize)); - } - - (void)refresh(); - - /* Do the initial field label setup. */ - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Time:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Latitude:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Longitude:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Altitude:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Speed:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Heading:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Climb:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Status:"); - - /* Note that the following fields are exceptions to the - * sizing rule. The minimum window size does not include these - * fields, if the window is too small, they get excluded. This - * may or may not change if/when the output for these fields is - * fixed and/or people request their permanance. They're only - * there in the first place because I arbitrarily thought they - * sounded interesting. ;^) */ - - if (window_ysize >= MAX_GPS_DATAWIN_YSIZE) { - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Long Err (XDOP, EPX):"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Lat Err (YDOP, EPY):"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Alt Err (VDOP, EPV):"); - - if (show_more_dops) { - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "2D Err (HDOP, CEP):"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "3D Err (PDOP, SEP):"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Time Err (TDOP):"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Geo Err (GDOP):"); - } - - if (show_ecefs) { - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "ECEF X, VX:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "ECEF Y, VY:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "ECEF Z, VZ:"); - } - - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Speed Err (EPS):"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Head Err (EPD):"); - /* it's actually esr that thought *these* were interesting */ - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Time offset:"); - (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, - "Grid Square:"); - } - - (void)wborder(datawin, 0, 0, 0, 0, 0, 0, 0, 0); - /* PRN is not unique for all GNSS systems. - * Each GNSS (GPS, GALILEO, BeiDou, etc.) numbers their PRN from 1. - * What we really have here is USI, Universal Sat ID - * The USI for each GNSS satellite is unique, starting at 1. - * Not all GPS receivers compute the USI the same way. YMMV - * - * Javad (GREIS) GPS receivers compute USI this way: - * GPS is USI 1-37, GLONASS 38-70, GALILEO 71-119, SBAS 120-142, - * QZSS 193-197, BeiDou 211-247 - * - * Geostar GPS receivers compute USI this way: - * GPS is USI 1 to 32, SBAS is 33 to 64, GLONASS is 65 to 96 */ - (void)mvwaddstr(satellites, 1, 1, " PRN Elev Azim SNR Use "); - (void)wborder(satellites, 0, 0, 0, 0, 0, 0, 0, 0); + datawin = newwin(window_ysize, DATAWIN_WIDTH, 0, 0); + satellites = + newwin(window_ysize, SATELLITES_WIDTH, 0, DATAWIN_WIDTH); + (void)nodelay(datawin, (bool) TRUE); + if (raw_flag) { + messages = + newwin(ysize - (window_ysize), xsize, window_ysize, 0); + + (void)scrollok(messages, true); + (void)wsetscrreg(messages, 0, ysize - (window_ysize)); + } + + (void)refresh(); + + /* Do the initial field label setup. */ + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Time:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Latitude:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Longitude:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Altitude:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Speed:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Heading:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Climb:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, "Status:"); + + /* Note that the following fields are exceptions to the + * sizing rule. The minimum window size does not include these + * fields, if the window is too small, they get excluded. This + * may or may not change if/when the output for these fields is + * fixed and/or people request their permanance. They're only + * there in the first place because I arbitrarily thought they + * sounded interesting. ;^) */ + + if (window_ysize >= MAX_GPS_DATAWIN_YSIZE) { + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Long Err (XDOP, EPX):"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Lat Err (YDOP, EPY):"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Alt Err (VDOP, EPV):"); + + if (show_more_dops) { + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "2D Err (HDOP, CEP):"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "3D Err (PDOP, SEP):"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Time Err (TDOP):"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Geo Err (GDOP):"); + } + + if (show_ecefs) { + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "ECEF X, VX:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "ECEF Y, VY:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "ECEF Z, VZ:"); + } + + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Speed Err (EPS):"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Head Err (EPD):"); + /* it's actually esr that thought *these* were interesting */ + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Time offset:"); + (void)mvwaddstr(datawin, row++, DATAWIN_DESC_OFFSET, + "Grid Square:"); + } + + (void)wborder(datawin, 0, 0, 0, 0, 0, 0, 0, 0); + /* PRN is not unique for all GNSS systems. + * Each GNSS (GPS, GALILEO, BeiDou, etc.) numbers their PRN from 1. + * What we really have here is USI, Universal Sat ID + * The USI for each GNSS satellite is unique, starting at 1. + * Not all GPS receivers compute the USI the same way. YMMV + * + * Javad (GREIS) GPS receivers compute USI this way: + * GPS is USI 1-37, GLONASS 38-70, GALILEO 71-119, SBAS 120-142, + * QZSS 193-197, BeiDou 211-247 + * + * Geostar GPS receivers compute USI this way: + * GPS is USI 1 to 32, SBAS is 33 to 64, GLONASS is 65 to 96 */ + (void)mvwaddstr(satellites, 1, 1, " PRN Elev Azim SNR Use "); + (void)wborder(satellites, 0, 0, 0, 0, 0, 0, 0, 0); } } @@ -456,8 +454,8 @@ static void resize(int sig UNUSED) { if (!isendwin()) { - (void)endwin(); - windowsetup(); + (void)endwin(); + windowsetup(); } } @@ -469,37 +467,37 @@ static void update_compass_panel(struct gps_data_t *gpsdata) int row = 1; /* Print time/date. */ if (isfinite(gpsdata->fix.time) != 0) { - (void)unix_to_iso8601(gpsdata->fix.time, scr, sizeof(scr)); + (void)unix_to_iso8601(gpsdata->fix.time, scr, sizeof(scr)); } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the heading. */ if (isfinite(gpsdata->fix.track) != 0) { - (void)snprintf(scr, sizeof(scr), "%.1f degrees", gpsdata->fix.track); + (void)snprintf(scr, sizeof(scr), "%.1f degrees", gpsdata->fix.track); } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the climb. */ if (isfinite(gpsdata->fix.climb) != 0) { - (void)snprintf(scr, sizeof(scr), "%.2f", gpsdata->fix.climb); + (void)snprintf(scr, sizeof(scr), "%.2f", gpsdata->fix.climb); } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the speed. */ if (isfinite(gpsdata->fix.speed) != 0) - (void)snprintf(scr, sizeof(scr), "%.2f", gpsdata->fix.speed); + (void)snprintf(scr, sizeof(scr), "%.2f", gpsdata->fix.speed); else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the altitude. */ if (isfinite(gpsdata->fix.altitude) != 0) - (void)snprintf(scr, sizeof(scr), "%.3f", gpsdata->fix.altitude); + (void)snprintf(scr, sizeof(scr), "%.3f", gpsdata->fix.altitude); else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* When we need to fill in receiver type again, do it here. */ @@ -508,9 +506,9 @@ static void update_compass_panel(struct gps_data_t *gpsdata) (void)wrefresh(datawin); if (raw_flag && !silent_flag) { - /* Be quiet if the user requests silence. */ + /* Be quiet if the user requests silence. */ (void)waddstr(messages, message); - (void)wrefresh(messages); + (void)wrefresh(messages); } } #endif /* TRUENORTH */ @@ -523,7 +521,7 @@ static int sat_cmp(const void *p1, const void *p2) { if ( ((struct satellite_t*)p2)->used - ((struct satellite_t*)p1)->used ) { - return ((struct satellite_t*)p2)->used - ((struct satellite_t*)p1)->used; + return ((struct satellite_t*)p2)->used - ((struct satellite_t*)p1)->used; } return ((struct satellite_t*)p1)->PRN - ((struct satellite_t*)p2)->PRN; } @@ -544,15 +542,15 @@ static void update_gps_panel(struct gps_data_t *gpsdata, char *message) gpsdata->satellites_used); if (gpsdata->satellites_visible != 0) { - int sat_no; + int sat_no; int loop_end = (display_sats < gpsdata->satellites_visible) ? \ display_sats : gpsdata->satellites_visible; - qsort( gpsdata->skyview, gpsdata->satellites_visible, - sizeof( struct satellite_t), sat_cmp); - /* displayed all sats that fit, maybe all of them */ - for (sat_no = 0; sat_no < loop_end; sat_no++) { - int column = 1; /* column to write to */ + qsort( gpsdata->skyview, gpsdata->satellites_visible, + sizeof( struct satellite_t), sat_cmp); + /* displayed all sats that fit, maybe all of them */ + for (sat_no = 0; sat_no < loop_end; sat_no++) { + int column = 1; /* column to write to */ char *gnssid; if ( 0 == gpsdata->skyview[sat_no].svid) { @@ -587,138 +585,138 @@ static void update_gps_panel(struct gps_data_t *gpsdata, char *message) } (void)mvwaddstr(satellites, sat_no + 2, column, gnssid); - /* no GPS uses PRN 0, some use 255 for 'unknown' - * u-blox uses PRN 1-255, NMEA 4.0 uses 1-437 */ - column += 3; - (void)mvwaddstr(satellites, sat_no + 2, column, - int_to_str(gpsdata->skyview[sat_no].PRN, - 1, 438)); - /* u-blox uses -91 to signal something undocumented */ - column += 6; - (void)mvwaddstr(satellites, sat_no + 2, column, - int_to_str(gpsdata->skyview[sat_no].elevation, - -90, 90)); - column += 7; - (void)mvwaddstr(satellites, sat_no + 2, column, - int_to_str(gpsdata->skyview[sat_no].azimuth, + /* no GPS uses PRN 0, some use 255 for 'unknown' + * u-blox uses PRN 1-255, NMEA 4.0 uses 1-437 */ + column += 3; + (void)mvwaddstr(satellites, sat_no + 2, column, + int_to_str(gpsdata->skyview[sat_no].PRN, + 1, 438)); + /* u-blox uses -91 to signal something undocumented */ + column += 6; + (void)mvwaddstr(satellites, sat_no + 2, column, + int_to_str(gpsdata->skyview[sat_no].elevation, + -90, 90)); + column += 7; + (void)mvwaddstr(satellites, sat_no + 2, column, + int_to_str(gpsdata->skyview[sat_no].azimuth, 0, 359)); - column += 6; - (void)mvwaddstr(satellites, sat_no + 2, column, - int_to_str((int)round(gpsdata->skyview[sat_no].ss), - 0, 254)); - column += 6; - (void)mvwprintw(satellites, sat_no + 2, column, " %c ", - gpsdata->skyview[sat_no].used ? 'Y' : 'N'); - } + column += 6; + (void)mvwaddstr(satellites, sat_no + 2, column, + int_to_str((int)round(gpsdata->skyview[sat_no].ss), + 0, 254)); + column += 6; + (void)mvwprintw(satellites, sat_no + 2, column, " %c ", + gpsdata->skyview[sat_no].used ? 'Y' : 'N'); + } /* Display More... ? */ if (sat_no < gpsdata->satellites_visible) { - /* Too many sats to show them all, tell the user. */ - (void)mvwprintw(satellites, sat_no + 2, 1, "%s", "More..."); - } else { - /* Clear old data from the unused lines at bottom. */ - for ( ; sat_no < display_sats; sat_no++) { - (void)mvwprintw(satellites, sat_no + 2, 1, "%-*s", - SATELLITES_WIDTH - 3, ""); - } + /* Too many sats to show them all, tell the user. */ + (void)mvwprintw(satellites, sat_no + 2, 1, "%s", "More..."); + } else { + /* Clear old data from the unused lines at bottom. */ + for ( ; sat_no < display_sats; sat_no++) { + (void)mvwprintw(satellites, sat_no + 2, 1, "%-*s", + SATELLITES_WIDTH - 3, ""); + } /* remove More... */ - (void)mvwhline(satellites, sat_no + 2, 1, 0, 8); - } + (void)mvwhline(satellites, sat_no + 2, 1, 0, 8); + } /* turn off cursor */ - curs_set(0); + curs_set(0); } /* Print time/date. */ if (isfinite(gpsdata->fix.time) != 0) { - (void)unix_to_iso8601(gpsdata->fix.time, scr, sizeof(scr)); + (void)unix_to_iso8601(gpsdata->fix.time, scr, sizeof(scr)); } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 1, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the latitude. */ if (gpsdata->fix.mode >= MODE_2D && isfinite(gpsdata->fix.latitude) != 0) { - (void)snprintf(scr, sizeof(scr), " %s %c", - deg_to_str(deg_type, fabs(gpsdata->fix.latitude)), - (gpsdata->fix.latitude < 0) ? 'S' : 'N'); + (void)snprintf(scr, sizeof(scr), " %s %c", + deg_to_str(deg_type, fabs(gpsdata->fix.latitude)), + (gpsdata->fix.latitude < 0) ? 'S' : 'N'); } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 2, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the longitude. */ if (gpsdata->fix.mode >= MODE_2D && isfinite(gpsdata->fix.longitude) != 0) { - (void)snprintf(scr, sizeof(scr), " %s %c", - deg_to_str(deg_type, fabs(gpsdata->fix.longitude)), - (gpsdata->fix.longitude < 0) ? 'W' : 'E'); + (void)snprintf(scr, sizeof(scr), " %s %c", + deg_to_str(deg_type, fabs(gpsdata->fix.longitude)), + (gpsdata->fix.longitude < 0) ? 'W' : 'E'); } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 3, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the altitude. */ if (gpsdata->fix.mode >= MODE_3D && isfinite(gpsdata->fix.altitude) != 0) - (void)snprintf(scr, sizeof(scr), "%9.3f %s", - gpsdata->fix.altitude * altfactor, altunits); + (void)snprintf(scr, sizeof(scr), "%9.3f %s", + gpsdata->fix.altitude * altfactor, altunits); else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 4, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the speed. */ if (gpsdata->fix.mode >= MODE_2D && isfinite(gpsdata->fix.track) != 0) - (void)snprintf(scr, sizeof(scr), "%8.2f %s", - gpsdata->fix.speed * speedfactor, speedunits); + (void)snprintf(scr, sizeof(scr), "%8.2f %s", + gpsdata->fix.speed * speedfactor, speedunits); else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 5, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the heading. */ if (gpsdata->fix.mode >= MODE_2D && isfinite(gpsdata->fix.track) != 0) { - double magheading = true2magnetic(gpsdata->fix.latitude, - gpsdata->fix.longitude, - gpsdata->fix.track); - if (!magnetic_flag || isfinite(magheading) == 0) { - (void)snprintf(scr, sizeof(scr), "%5.1f deg (true)", - gpsdata->fix.track); - } else { - (void)snprintf(scr, sizeof(scr), "%5.1f deg (mag) ", - magheading); - } + double magheading = true2magnetic(gpsdata->fix.latitude, + gpsdata->fix.longitude, + gpsdata->fix.track); + if (!magnetic_flag || isfinite(magheading) == 0) { + (void)snprintf(scr, sizeof(scr), "%5.1f deg (true)", + gpsdata->fix.track); + } else { + (void)snprintf(scr, sizeof(scr), "%5.1f deg (mag) ", + magheading); + } } else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 6, DATAWIN_VALUE_OFFSET, " %-*s", 25, scr); /* Fill in the rate of climb. */ if (gpsdata->fix.mode >= MODE_3D && isfinite(gpsdata->fix.climb) != 0) - (void)snprintf(scr, sizeof(scr), "%8.2f %s/min", - gpsdata->fix.climb * altfactor * 60, altunits); + (void)snprintf(scr, sizeof(scr), "%8.2f %s/min", + gpsdata->fix.climb * altfactor * 60, altunits); else - (void)snprintf(scr, sizeof(scr), "n/a"); + (void)snprintf(scr, sizeof(scr), "n/a"); (void)mvwprintw(datawin, 7, DATAWIN_VALUE_OFFSET, "%-*s", 27, scr); /* Fill in the GPS status and the time since the last state * change. */ if (gpsdata->online == 0) { - newstate = 0; - (void)snprintf(scr, sizeof(scr), "OFFLINE"); + newstate = 0; + (void)snprintf(scr, sizeof(scr), "OFFLINE"); } else { - newstate = gpsdata->fix.mode; - switch (gpsdata->fix.mode) { - case MODE_2D: - (void)snprintf(scr, sizeof(scr), "2D %sFIX (%d secs)", - (gpsdata->status == - STATUS_DGPS_FIX) ? "DIFF " : "", - (int)(time(NULL) - status_timer)); - break; - case MODE_3D: - (void)snprintf(scr, sizeof(scr), "3D %sFIX (%d secs)", - (gpsdata->status == - STATUS_DGPS_FIX) ? "DIFF " : "", - (int)(time(NULL) - status_timer)); - break; - default: - (void)snprintf(scr, sizeof(scr), "NO FIX (%d secs)", - (int)(time(NULL) - status_timer)); - break; - } + newstate = gpsdata->fix.mode; + switch (gpsdata->fix.mode) { + case MODE_2D: + (void)snprintf(scr, sizeof(scr), "2D %sFIX (%d secs)", + (gpsdata->status == + STATUS_DGPS_FIX) ? "DIFF " : "", + (int)(time(NULL) - status_timer)); + break; + case MODE_3D: + (void)snprintf(scr, sizeof(scr), "3D %sFIX (%d secs)", + (gpsdata->status == + STATUS_DGPS_FIX) ? "DIFF " : "", + (int)(time(NULL) - status_timer)); + break; + default: + (void)snprintf(scr, sizeof(scr), "NO FIX (%d secs)", + (int)(time(NULL) - status_timer)); + break; + } } (void)mvwprintw(datawin, 8, DATAWIN_VALUE_OFFSET + 1, "%-*s", 26, scr); @@ -731,125 +729,125 @@ static void update_gps_panel(struct gps_data_t *gpsdata, char *message) * sounded interesting. ;^) */ if (window_ysize >= (MIN_GPS_DATAWIN_YSIZE + 5)) { - int row = 9; - char *ep_str = NULL; - char *dop_str = NULL; - - /* Fill in the estimated latitude position error, XDOP. */ - ep_str = ep_to_str(gpsdata->fix.epx, altfactor, altunits); - dop_str = dop_to_str(gpsdata->dop.xdop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%s, %-*s", - dop_str, 11, ep_str); - - /* Fill in the estimated longitude position error, YDOP. */ - ep_str = ep_to_str(gpsdata->fix.epy, altfactor, altunits); - dop_str = dop_to_str(gpsdata->dop.ydop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%s, %-*s", - dop_str, 11, ep_str); - - /* Fill in the estimated velocity error, VDOP. */ - ep_str = ep_to_str(gpsdata->fix.epv, altfactor, altunits); - dop_str = dop_to_str(gpsdata->dop.vdop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%s, %-*s", - dop_str, 11, ep_str); - - /* extra tall screen, show more DOPs */ - if (show_more_dops) { - double cep = NAN; /* 2D EP */ - double sep = NAN; /* 3D EP */ - - /* Calculate estimated 2D circular position error, CEP */ - if (isfinite(gpsdata->fix.epy) != 0 - && isfinite(gpsdata->fix.epy) != 0) { - /* http://gauss.gge.unb.ca/papers.pdf/gpsworld.may99.pdf */ - /* CEP is just the hypotenuse of the triangle of epx and epy */ - cep = sqrt((gpsdata->fix.epx * gpsdata->fix.epx) + - (gpsdata->fix.epy * gpsdata->fix.epy)); - if (isfinite(gpsdata->fix.epv) != 0) { + int row = 9; + char *ep_str = NULL; + char *dop_str = NULL; + + /* Fill in the estimated latitude position error, XDOP. */ + ep_str = ep_to_str(gpsdata->fix.epx, altfactor, altunits); + dop_str = dop_to_str(gpsdata->dop.xdop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%s, %-*s", + dop_str, 11, ep_str); + + /* Fill in the estimated longitude position error, YDOP. */ + ep_str = ep_to_str(gpsdata->fix.epy, altfactor, altunits); + dop_str = dop_to_str(gpsdata->dop.ydop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%s, %-*s", + dop_str, 11, ep_str); + + /* Fill in the estimated velocity error, VDOP. */ + ep_str = ep_to_str(gpsdata->fix.epv, altfactor, altunits); + dop_str = dop_to_str(gpsdata->dop.vdop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%s, %-*s", + dop_str, 11, ep_str); + + /* extra tall screen, show more DOPs */ + if (show_more_dops) { + double cep = NAN; /* 2D EP */ + double sep = NAN; /* 3D EP */ + + /* Calculate estimated 2D circular position error, CEP */ + if (isfinite(gpsdata->fix.epy) != 0 + && isfinite(gpsdata->fix.epy) != 0) { + /* http://gauss.gge.unb.ca/papers.pdf/gpsworld.may99.pdf */ + /* CEP is just the hypotenuse of the triangle of epx and epy */ + cep = sqrt((gpsdata->fix.epx * gpsdata->fix.epx) + + (gpsdata->fix.epy * gpsdata->fix.epy)); + if (isfinite(gpsdata->fix.epv) != 0) { /* SEP is the spherical (3D) error probability. * The square root of the sum of the squares of epx, epy, * and epv */ - sep = sqrt((gpsdata->fix.epx * gpsdata->fix.epx) + - (gpsdata->fix.epy * gpsdata->fix.epy) + - (gpsdata->fix.epv * gpsdata->fix.epv)); - } - } - - /* Fill in the estimated horizontal (2D) error, HDOP */ - ep_str = ep_to_str(cep, altfactor, altunits); - dop_str = dop_to_str(gpsdata->dop.hdop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, - "%s, %-*s", dop_str, 11, ep_str); - - /* (spherical) position error, 3D error, PDOP */ - ep_str = ep_to_str(sep, altfactor, altunits); - dop_str = dop_to_str(gpsdata->dop.pdop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, - "%s, %-*s", dop_str, 11, ep_str); - - /* time dilution of precision, TDOP */ - /* FIXME: time ep? */ - dop_str = dop_to_str(gpsdata->dop.tdop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", - 18, dop_str); - - /* geometric dilution of precision, GDOP */ - /* FIXME: gdop ep? */ - dop_str = dop_to_str(gpsdata->dop.gdop); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", - 18, dop_str); - - } + sep = sqrt((gpsdata->fix.epx * gpsdata->fix.epx) + + (gpsdata->fix.epy * gpsdata->fix.epy) + + (gpsdata->fix.epv * gpsdata->fix.epv)); + } + } + + /* Fill in the estimated horizontal (2D) error, HDOP */ + ep_str = ep_to_str(cep, altfactor, altunits); + dop_str = dop_to_str(gpsdata->dop.hdop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, + "%s, %-*s", dop_str, 11, ep_str); + + /* (spherical) position error, 3D error, PDOP */ + ep_str = ep_to_str(sep, altfactor, altunits); + dop_str = dop_to_str(gpsdata->dop.pdop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, + "%s, %-*s", dop_str, 11, ep_str); + + /* time dilution of precision, TDOP */ + /* FIXME: time ep? */ + dop_str = dop_to_str(gpsdata->dop.tdop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", + 18, dop_str); + + /* geometric dilution of precision, GDOP */ + /* FIXME: gdop ep? */ + dop_str = dop_to_str(gpsdata->dop.gdop); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", + 18, dop_str); + + } /* extra large screen, show ECEF */ if (show_ecefs) { - char *estr; + char *estr; - /* Fill in the ECEF's. */ - estr = ecef_to_str(gpsdata->fix.ecef.x, gpsdata->fix.ecef.vx, + /* Fill in the ECEF's. */ + estr = ecef_to_str(gpsdata->fix.ecef.x, gpsdata->fix.ecef.vx, 1, " m"); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET - 3, "%-*s", + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET - 3, "%-*s", 27, estr); - estr = ecef_to_str(gpsdata->fix.ecef.y, gpsdata->fix.ecef.vy, + estr = ecef_to_str(gpsdata->fix.ecef.y, gpsdata->fix.ecef.vy, 1, " m"); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET - 3, "%-*s", + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET - 3, "%-*s", 27, estr); - estr = ecef_to_str(gpsdata->fix.ecef.z, gpsdata->fix.ecef.vz, + estr = ecef_to_str(gpsdata->fix.ecef.z, gpsdata->fix.ecef.vz, 1, " m"); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET - 3, "%-*s", + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET - 3, "%-*s", 27, estr); } - /* Fill in the estimated speed error, EPS. */ - ep_str = ep_to_str(gpsdata->fix.eps, speedfactor, speedunits); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, - " %-*s", 11, - ep_str); - - /* Fill in the estimated track error, EPD. */ - ep_str = ep_to_str(gpsdata->fix.epd, speedfactor, "deg"); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", 18, - ep_str); - - /* Fill in the time offset, milliseconds. */ - if (isfinite(gpsdata->fix.time) != 0) - (void)snprintf(scr, sizeof(scr), "%6.3f sec", - (double)(timestamp()-gpsdata->fix.time)); - else - (void)snprintf(scr, sizeof(scr), " n/a"); - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", 18, - scr); - /* Fill in the grid square (esr thought *this* one was interesting). */ - if ((isfinite(gpsdata->fix.longitude) != 0 && - isfinite(gpsdata->fix.latitude) != 0)) - s = maidenhead(gpsdata->fix.latitude,gpsdata->fix.longitude); - else - s = "n/a"; - (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 9, "%-*s", - 18, s); + /* Fill in the estimated speed error, EPS. */ + ep_str = ep_to_str(gpsdata->fix.eps, speedfactor, speedunits); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, + " %-*s", 11, + ep_str); + + /* Fill in the estimated track error, EPD. */ + ep_str = ep_to_str(gpsdata->fix.epd, speedfactor, "deg"); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", 18, + ep_str); + + /* Fill in the time offset, milliseconds. */ + if (isfinite(gpsdata->fix.time) != 0) + (void)snprintf(scr, sizeof(scr), "%6.3f sec", + (double)(timestamp()-gpsdata->fix.time)); + else + (void)snprintf(scr, sizeof(scr), " n/a"); + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 8, "%-*s", 18, + scr); + /* Fill in the grid square (esr thought *this* one was interesting). */ + if ((isfinite(gpsdata->fix.longitude) != 0 && + isfinite(gpsdata->fix.latitude) != 0)) + s = maidenhead(gpsdata->fix.latitude,gpsdata->fix.longitude); + else + s = "n/a"; + (void)mvwprintw(datawin, row++, DATAWIN_VALUE_OFFSET + 9, "%-*s", + 18, s); } @@ -870,8 +868,8 @@ static void update_gps_panel(struct gps_data_t *gpsdata, char *message) /* Reset the status_timer if the state has changed. */ if (newstate != state) { - status_timer = time(NULL); - state = newstate; + status_timer = time(NULL); + state = newstate; } (void)wrefresh(datawin); @@ -881,17 +879,19 @@ static void update_gps_panel(struct gps_data_t *gpsdata, char *message) static void usage(char *prog) { (void)fprintf(stderr, - "Usage: %s [-h] [-V] [-l {d|m|s}] [server[:port:[device]]]\n\n" - " -h Show this help, then exit\n" - " -V Show version, then exit\n" - " -s Be silent (don't print raw gpsd data)\n" - " -l {d|m|s} Select lat/lon format\n" - " d = DD.ddddddd\n" - " m = DD MM.mmmmmm'\n" - " s = DD MM' SS.sssss\"\n" - " -m Display heading as the estimated magnetic heading\n" - " Valid only for USA (Lower 48 + AK) and Western Europe.\n", - prog); + "Usage: %s [-h] [-l {d|m|s}] [-m] [-s] [-V] " + "[server[:port:[device]]]\n\n" + " -D debug-level Set debug level\n" + " -h Show this help, then exit\n" + " -l {d|m|s} Select lat/lon format\n" + " d = DD.ddddddd\n" + " m = DD MM.mmmmmm'\n" + " s = DD MM' SS.sssss\"\n" + " -m Display heading as the estimated magnetic heading\n" + " Valid or USA (Lower 48 + AK) and Western Europe.\n" + " -s Be silent (don't print raw gpsd data)\n" + " -V Show version, then exit\n", + prog); exit(EXIT_FAILURE); } @@ -910,105 +910,103 @@ int main(int argc, char *argv[]) switch (gpsd_units()) { case imperial: - altfactor = METERS_TO_FEET; - altunits = "ft"; - speedfactor = MPS_TO_MPH; - speedunits = "mph"; - break; + 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; + 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; + altfactor = 1; + altunits = "m"; + speedfactor = MPS_TO_KPH; + speedunits = "kph"; + break; default: - /* leave the default alone */ - break; + /* leave the default alone */ + break; } /* Process the options. Print help if requested. */ - while ((option = getopt(argc, argv, "hVl:smu:D:")) != -1) { - switch (option) { -#ifdef CLIENTDEBUG_ENABLE - case 'D': - debug = atoi(optarg); - gps_enable_debug(debug, stderr); - break; -#endif /* CLIENTDEBUG_ENABLE */ - case 'm': - magnetic_flag = true; - break; - 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); - } - break; - case 'V': - (void)fprintf(stderr, "%s: %s (revision %s)\n", - argv[0], VERSION, REVISION); - exit(EXIT_SUCCESS); - case 'l': - switch (optarg[0]) { - case 'd': - deg_type = deg_dd; - continue; - case 'm': - deg_type = deg_ddmm; - continue; - case 's': - deg_type = deg_ddmmss; - continue; - default: - (void)fprintf(stderr, "Unknown -l argument: %s\n", optarg); - } - break; - case 'h': - default: - usage(argv[0]); - break; - } + while ((option = getopt(argc, argv, "D:hl:msu:V")) != -1) { + switch (option) { + case 'D': + debug = atoi(optarg); + gps_enable_debug(debug, stderr); + break; + case 'm': + magnetic_flag = true; + break; + 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); + } + break; + case 'V': + (void)fprintf(stderr, "%s: %s (revision %s)\n", + argv[0], VERSION, REVISION); + exit(EXIT_SUCCESS); + case 'l': + switch (optarg[0]) { + case 'd': + deg_type = deg_dd; + continue; + case 'm': + deg_type = deg_ddmm; + continue; + case 's': + deg_type = deg_ddmmss; + continue; + default: + (void)fprintf(stderr, "Unknown -l argument: %s\n", optarg); + } + break; + case 'h': + default: + usage(argv[0]); + break; + } } /* Grok the server, port, and device. */ if (optind < argc) { - gpsd_source_spec(argv[optind], &source); + gpsd_source_spec(argv[optind], &source); } else - gpsd_source_spec(NULL, &source); + gpsd_source_spec(NULL, &source); /* Open the stream to gpsd. */ if (gps_open(source.server, source.port, &gpsdata) != 0) { - (void)fprintf(stderr, - "cgps: no gpsd running or network error: %d, %s\n", - errno, gps_errstr(errno)); - exit(EXIT_FAILURE); + (void)fprintf(stderr, + "cgps: no gpsd running or network error: %d, %s\n", + errno, gps_errstr(errno)); + exit(EXIT_FAILURE); } /* note: we're assuming BSD-style reliable signals here */ @@ -1021,57 +1019,57 @@ int main(int argc, char *argv[]) status_timer = time(NULL); if (source.device != NULL) - flags |= WATCH_DEVICE; + flags |= WATCH_DEVICE; (void)gps_stream(&gpsdata, flags, source.device); /* heart of the client */ for (;;) { - int c; - - /* wait 1/2 second for gpsd */ - if (!gps_waiting(&gpsdata, 500000)) { - /* 240 tries at 0.5 seconds a try is a 2 minute timeout */ - if ( 240 < wait_clicks++ ) - die(GPS_TIMEOUT); - } else { - wait_clicks = 0; - errno = 0; + int c; + + /* wait 1/2 second for gpsd */ + if (!gps_waiting(&gpsdata, 500000)) { + /* 240 tries at 0.5 seconds a try is a 2 minute timeout */ + if ( 240 < wait_clicks++ ) + die(GPS_TIMEOUT); + } else { + wait_clicks = 0; + errno = 0; *message = '\0'; - if (gps_read(&gpsdata, message, sizeof(message)) == -1) { - (void)fprintf(stderr, "cgps: socket error 4\n"); - die(errno == 0 ? GPS_GONE : GPS_ERROR); - } else { - /* Here's where updates go now that things are established. */ + if (gps_read(&gpsdata, message, sizeof(message)) == -1) { + (void)fprintf(stderr, "cgps: socket error 4\n"); + die(errno == 0 ? GPS_GONE : GPS_ERROR); + } else { + /* Here's where updates go now that things are established. */ #ifdef TRUENORTH - if (compass_flag) - update_compass_panel(&gpsdata); - else + if (compass_flag) + update_compass_panel(&gpsdata); + else #endif /* TRUENORTH */ - update_gps_panel(&gpsdata, message); - } - } - - /* Check for user input. */ - c = wgetch(datawin); - - switch (c) { - /* Quit */ - case 'q': - die(CGPS_QUIT); - break; - - /* Toggle spewage of raw gpsd data. */ - case 's': - silent_flag = !silent_flag; - break; - - /* Clear the spewage area. */ - case 'c': - (void)werase(messages); - break; - - default: - break; - } + update_gps_panel(&gpsdata, message); + } + } + + /* Check for user input. */ + c = wgetch(datawin); + + switch (c) { + /* Quit */ + case 'q': + die(CGPS_QUIT); + break; + + /* Toggle spewage of raw gpsd data. */ + case 's': + silent_flag = !silent_flag; + break; + + /* Clear the spewage area. */ + case 'c': + (void)werase(messages); + break; + + default: + break; + } } } -- cgit v1.2.1