From 346822c38d5952b8f4910a862d53807d133474d3 Mon Sep 17 00:00:00 2001 From: Martin Mueller Date: Wed, 25 Nov 2009 21:18:59 +0000 Subject: [PATCH] Add command line options to ublox gps config. --- conf/gps/ublox_conf.c | 70 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/conf/gps/ublox_conf.c b/conf/gps/ublox_conf.c index 1d23e3a47e..e2e95e10de 100644 --- a/conf/gps/ublox_conf.c +++ b/conf/gps/ublox_conf.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include /* *********************** change this to your needs *********************** */ @@ -47,7 +49,7 @@ /* **************** no user servicable part below this line **************** */ - + #define SYNC_CHAR_1 0xB5 #define SYNC_CHAR_2 0x62 #define BLANK_CHAR ' ' @@ -192,10 +194,10 @@ int wait_for_ack( unsigned char* data, int serial_fd ) } -int main (void) +int main (int argc, char **argv) { - char in_file_name[80] = IN_FILE_NAME; - char out_file_name[80] = OUT_FILE_NAME; + char *in_file_name = NULL; + char *out_file_name = OUT_FILE_NAME; struct termios orig_termios, cur_termios; @@ -215,10 +217,61 @@ int main (void) int count, i; int br; int baud; + int save_perm = SAVE_PERMANENT; + int baudrate = DEFAULT_BAUDRATE; + int ublox_port = UBLOX_PORT; - if ((br = int_to_baud(DEFAULT_BAUDRATE)) < 0 ) + while ((i=getopt(argc, argv, "p:b:s:d:")) != -1) { - printf("invalid baudrate %d\n", DEFAULT_BAUDRATE); + switch(i) + { + case'p': + ublox_port = strtoul(optarg, 0, 0); + break; + case'b': + baudrate = strtoul(optarg, 0, 0); + break; + case's': + save_perm = strtoul(optarg, 0, 0); + break; + case'd': + out_file_name = optarg; + break; + } + } + + if (optind == argc - 1) + { + in_file_name = argv[ optind ]; + ++optind; + } + + if (in_file_name == NULL) + { +// fprintf(stderr, usage_str); + fprintf(stderr, + "ublox_conf\nConfigures u-blox GPS receivers\n"); + fprintf(stderr, + " : configuration file name (example: %s)\n", + IN_FILE_NAME); + fprintf(stderr, + " -d : GPS device name (default: %s)\n", + OUT_FILE_NAME); + fprintf(stderr, + " -b : initial GPS receiver baud rate (default: %d)\n", + DEFAULT_BAUDRATE); + fprintf(stderr, + " -s <0|1> : save config to Flash/battery backed RAM (default: %d)\n", + SAVE_PERMANENT); + fprintf(stderr, + " -p : internal u-blox receiver port (default: %d)\n", + UBLOX_PORT); + exit(2); + } + + if ((br = int_to_baud(baudrate)) < 0 ) + { + printf("invalid baudrate %d\n", baudrate); return( -1 ); } @@ -385,7 +438,7 @@ int main (void) (data[6+10] << 16) + (data[6+11] << 24); - if (data[6] == UBLOX_PORT) + if (data[6] == ublox_port) { sleep(1); printf("port in use, "); @@ -439,7 +492,7 @@ int main (void) } /* save it forever? */ - if (SAVE_PERMANENT != 0) + if (save_perm != 0) { printf("CFG-CFG writing config to permanent memory "); count = CFG_CFG_LENGTH-2; @@ -460,3 +513,4 @@ int main (void) return(0); } +