diff options
author | Dario Lombardo <dario.lombardo@libero.it> | 2011-03-09 16:27:20 +0000 |
---|---|---|
committer | Andreas.Eversberg <jolly@eversberg.eu> | 2011-03-09 16:27:20 +0000 |
commit | aa2f2fdfa1a7839b03fbb555e3d7ecfd4ac026e4 (patch) | |
tree | c36c0c0fc7e781a10a47d44c2e55e204756fc78f /src/host/layer23/src/misc | |
parent | cde3f7d2c6f29eecb433c29ca7425b949d0b4777 (diff) |
[PATCH] Added runtime selection of gps device.
Diffstat (limited to 'src/host/layer23/src/misc')
-rw-r--r-- | src/host/layer23/src/misc/app_cell_log.c | 76 | ||||
-rw-r--r-- | src/host/layer23/src/misc/cell_log.c | 28 |
2 files changed, 58 insertions, 46 deletions
diff --git a/src/host/layer23/src/misc/app_cell_log.c b/src/host/layer23/src/misc/app_cell_log.c index 7a2c67a8..fdecc638 100644 --- a/src/host/layer23/src/misc/app_cell_log.c +++ b/src/host/layer23/src/misc/app_cell_log.c @@ -92,13 +92,12 @@ static int l23_getopt_options(struct option **options) {"logfile", 1, 0, 'l'}, {"rach", 1, 0, 'r'}, {"no-rach", 1, 0, 'n'}, -#ifdef _USE_GPSD +#ifdef _HAVE_GPSD {"gpsd-host", 1, 0, 'g'}, - {"gpsd-port", 1, 0, 'p'} -#else + {"gpsd-port", 1, 0, 'p'}, +#endif {"gps", 1, 0, 'g'}, {"baud", 1, 0, 'b'} -#endif }; *options = opts; @@ -109,15 +108,13 @@ static int l23_cfg_print_help() { printf("\nApplication specific\n"); printf(" -l --logfile LOGFILE Logfile for the cell log.\n"); - printf(" -r --rach RACH Nr. of RACH bursts to send.\n"); - printf(" -n --no-rach Send no rach bursts.\n"); -#ifdef _USE_GPSD + printf(" -r --rach RACH Nr. of RACH bursts to send.\n"); + printf(" -n --no-rach Send no rach bursts.\n"); printf(" -g --gpsd-host HOST 127.0.0.1. gpsd host.\n"); - printf(" -p --port PORT 2947. gpsd port\n"); -#else - printf(" -g --gps DEVICE /dev/ttyACM0. GPS device.\n"); - printf(" -b --baud BAUDRAT The baud rate of the GPS device\n"); -#endif + printf(" -p --port PORT 2947. gpsd port\n"); + printf(" -f --gps DEVICE /dev/ttyACM0. GPS serial device.\n"); + printf(" -b --baud BAUDRAT The baud rate of the GPS device\n"); + return 0; } @@ -133,42 +130,57 @@ static int l23_cfg_handle(int c, const char *optarg) case 'n': RACH_MAX = 0; break; -#ifdef _USE_GPSD case 'g': - snprintf(gps.gpsd_host, ARRAY_SIZE(gps.gpsd_host), "%s", optarg); +#ifdef _HAVE_GPSD + snprintf(g.gpsd_host, ARRAY_SIZE(g.gpsd_host), "%s", optarg); /* force string terminator */ - gps.gpsd_host[ARRAY_SIZE(gps.gpsd_host) - 1] = '\0'; - LOGP(DGPS, LOGL_INFO, "Using gpsd host %s\n", gps.gpsd_host); + g.gpsd_host[ARRAY_SIZE(g.gpsd_host) - 1] = '\0'; + if (g.gps_type != GPS_TYPE_UNDEF) + goto cmd_line_error; + g.gps_type = GPS_TYPE_GPSD; + LOGP(DGPS, LOGL_INFO, "Using gpsd host %s\n", g.gpsd_host); +#else + printf("Gpsd support not compiled.\n"); + exit(1); +#endif break; case 'p': - snprintf(gps.gpsd_port, ARRAY_SIZE(gps.gpsd_port), "%s", optarg); +#ifdef _HAVE_GPSD + snprintf(g.gpsd_port, ARRAY_SIZE(g.gpsd_port), "%s", optarg); /* force string terminator */ - gps.gpsd_port[ARRAY_SIZE(gps.gpsd_port) - 1] = '\0'; - LOGP(DGPS, LOGL_INFO, "Using gpsd port %s\n", gps.gpsd_port); - break; + g.gpsd_port[ARRAY_SIZE(g.gpsd_port) - 1] = '\0'; + g.gps_type = GPS_TYPE_GPSD; + LOGP(DGPS, LOGL_INFO, "Using gpsd port %s\n", g.gpsd_port); #else - case 'g': - snprintf(gps.device, ARRAY_SIZE(gps.device), "%s", optarg); + printf("Gpsd support not compiled.\n"); + exit(1); +#endif + break; + case 'f': + snprintf(g.device, ARRAY_SIZE(g.device), "%s", optarg); /* force string terminator */ - gps.device[ARRAY_SIZE(gps.device) - 1] = '\0'; - LOGP(DGPS, LOGL_INFO, "Using GPS device %s\n", gps.device); + g.device[ARRAY_SIZE(g.device) - 1] = '\0'; + if (g.gps_type != GPS_TYPE_UNDEF) + goto cmd_line_error; + g.gps_type = GPS_TYPE_SERIAL; + LOGP(DGPS, LOGL_INFO, "Using GPS serial device %s\n", g.device); break; case 'b': - gps.baud = atoi(optarg); - LOGP(DGPS, LOGL_INFO, "Setting GPS baudrate to %u\n", gps.baud); + g.baud = atoi(optarg); + g.gps_type = GPS_TYPE_SERIAL; + LOGP(DGPS, LOGL_INFO, "Setting GPS baudrate to %u\n", g.baud); break; -#endif } return 0; + +cmd_line_error: + printf("\nYou can't specify both gpsd and serial gps!!\n\n"); + exit(1); } static struct l23_app_info info = { .copyright = "Copyright (C) 2010 Andreas Eversberg\n", -#ifdef _USE_GPSD - .getopt_string = "l:r:ng:p:", -#else - .getopt_string = "l:r:ng:b:", -#endif + .getopt_string = "g:p:l:r:nf:b:", .cfg_supported = l23_cfg_supported, .cfg_getopt_opt = l23_getopt_options, .cfg_handle_opt = l23_cfg_handle, diff --git a/src/host/layer23/src/misc/cell_log.c b/src/host/layer23/src/misc/cell_log.c index a0f97698..7de2c400 100644 --- a/src/host/layer23/src/misc/cell_log.c +++ b/src/host/layer23/src/misc/cell_log.c @@ -119,17 +119,17 @@ static void start_pm(void); static void log_gps(void) { - if (!gps.enable || !gps.valid) + if (!g.enable || !g.valid) return; - LOGFILE("position %.8f %.8f\n", gps.longitude, gps.latitude); + LOGFILE("position %.8f %.8f\n", g.longitude, g.latitude); } static void log_time(void) { time_t now; - if (gps.enable && gps.valid) - now = gps.gmt; + if (g.enable && g.valid) + now = g.gmt; else time(&now); LOGFILE("time %lu\n", now); @@ -317,15 +317,15 @@ static void start_sync(void) } } /* if GPS becomes valid, like after exitting a tunnel */ - if (!pm_gps_valid && gps.valid) { + if (!pm_gps_valid && g.valid) { pm_gps_valid = 1; - geo2space(&pm_gps_x, &pm_gps_y, &pm_gps_z, gps.longitude, - gps.latitude); + geo2space(&pm_gps_x, &pm_gps_y, &pm_gps_z, g.longitude, + g.latitude); } - if (pm_gps_valid && gps.valid) { + if (pm_gps_valid && g.valid) { double x, y, z; - geo2space(&x, &y, &z, gps.longitude, gps.latitude); + geo2space(&x, &y, &z, g.longitude, g.latitude); dist = distinspace(pm_gps_x, pm_gps_y, pm_gps_z, x, y, z); sprintf(dist_str, " dist %d", (int)dist); } @@ -357,10 +357,10 @@ static void start_pm(void) if (from == 0 && to == 0) { LOGP(DSUM, LOGL_INFO, "Measurement done\n"); - pm_gps_valid = gps.enable && gps.valid; + pm_gps_valid = g.enable && g.valid; if (pm_gps_valid) geo2space(&pm_gps_x, &pm_gps_y, &pm_gps_z, - gps.longitude, gps.latitude); + g.longitude, g.latitude); log_pm(); start_sync(); return; @@ -786,10 +786,10 @@ int scan_init(struct osmocom_ms *_ms) register_signal_handler(SS_L1CTL, &signal_cb, NULL); memset(&timer, 0, sizeof(timer)); osmol2_register_handler(ms, &rcv_rsl); - gps.enable = 1; + g.enable = 1; osmo_gps_init(); if (osmo_gps_open()) - gps.enable = 0; + g.enable = 0; if (!strcmp(logname, "-")) logfp = stdout; @@ -808,7 +808,7 @@ int scan_init(struct osmocom_ms *_ms) int scan_exit(void) { LOGP(DSUM, LOGL_INFO, "Scanner exit\n"); - if (gps.valid) + if (g.valid) osmo_gps_close(); if (logfp) fclose(logfp); |