[PATCH] Added runtime selection of gps device.
authorDario Lombardo <dario.lombardo@libero.it>
Wed, 9 Mar 2011 16:27:20 +0000 (16:27 +0000)
committerAndreas.Eversberg <jolly@eversberg.eu>
Wed, 9 Mar 2011 16:27:20 +0000 (16:27 +0000)
src/host/layer23/configure.ac
src/host/layer23/include/osmocom/bb/common/gps.h
src/host/layer23/src/common/gps.c
src/host/layer23/src/misc/app_cell_log.c
src/host/layer23/src/misc/cell_log.c
src/host/layer23/src/mobile/vty_interface.c

index e1c718e..05c6d24 100644 (file)
@@ -15,7 +15,7 @@ AC_PROG_RANLIB
 dnl checks for libraries
 PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore)
 PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty)
-AC_CHECK_LIB(gps, gps_open, CFLAGS+=" -D_USE_GPSD" LDFLAGS+=" -lgps",,)
+AC_CHECK_LIB(gps, gps_waiting, CFLAGS+=" -D_HAVE_GPSD" LDFLAGS+=" -lgps",,)
 
 dnl checks for header files
 AC_HEADER_STDC
index b7500db..58c0c53 100644 (file)
  *
  */
 
+enum {
+       GPS_TYPE_UNDEF,
+       GPS_TYPE_GPSD,
+       GPS_TYPE_SERIAL
+};
+
 struct osmo_gps {
        /* GPS device */
        uint8_t         enable;
+       uint8_t         gps_type;
 
-#ifdef _USE_GPSD
+#ifdef _HAVE_GPSD
        char            gpsd_host[32];
        char            gpsd_port[6];
-#else
+#endif
+
        char            device[32];
        uint32_t        baud;
-#endif
 
        /* current data */
        uint8_t         valid; /* we have a fix */
@@ -37,7 +44,7 @@ struct osmo_gps {
        double          latitude, longitude;
 };
 
-extern struct osmo_gps gps;
+extern struct osmo_gps g;
 
 int osmo_gps_open(void);
 void osmo_gps_close(void);
index 55dd239..07bc460 100644 (file)
@@ -26,8 +26,9 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <time.h>
+#include <stdbool.h>
 
-#ifdef _USE_GPSD
+#ifdef _HAVE_GPSD
 #include <gps.h>
 #endif
 
 #include <osmocom/bb/common/logging.h>
 #include <osmocom/bb/common/gps.h>
 
-struct osmo_gps gps = {
+struct osmo_gps g = {
        0,
-#ifdef _USE_GPSD
+       GPS_TYPE_UNDEF,
+#ifdef _HAVE_GPSD
     "localhost",
        "2947",
-#else
+#endif
        "/dev/ttyACM0",
        0,
-#endif
        0,
        0,
        0,0
@@ -53,16 +54,16 @@ struct osmo_gps gps = {
 
 static struct bsc_fd gps_bfd;
 
-#ifdef _USE_GPSD
+#ifdef _HAVE_GPSD
 
 static struct gps_data_t* gdata;
 
-int osmo_gps_cb(struct bsc_fd *bfd, unsigned int what)
+int osmo_gpsd_cb(struct bsc_fd *bfd, unsigned int what)
 {
        struct tm *tm;
        unsigned diff = 0;
 
-       gps.valid = 0;
+       g.valid = 0;
 
        /* gps is offline */
        if (gdata->online)
@@ -78,21 +79,21 @@ int osmo_gps_cb(struct bsc_fd *bfd, unsigned int what)
 
        /* data are valid */
        if (gdata->set & LATLON_SET) {
-               gps.valid = 1;
-               gps.gmt = gdata->fix.time;
-               tm = localtime(&gps.gmt);
-               diff = time(NULL) - gps.gmt;
-               gps.latitude = gdata->fix.latitude;
-               gps.longitude = gdata->fix.longitude;
+               g.valid = 1;
+               g.gmt = gdata->fix.time;
+               tm = localtime(&g.gmt);
+               diff = time(NULL) - g.gmt;
+               g.latitude = gdata->fix.latitude;
+               g.longitude = gdata->fix.longitude;
 
                LOGP(DGPS, LOGL_INFO, " time=%02d:%02d:%02d %04d-%02d-%02d, "
                        "diff-to-host=%d, latitude=%do%.4f, longitude=%do%.4f\n",
                        tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_year + 1900,
                        tm->tm_mday, tm->tm_mon + 1, diff,
-                       (int)gps.latitude,
-                       (gps.latitude - ((int)gps.latitude)) * 60.0,
-                       (int)gps.longitude,
-                       (gps.longitude - ((int)gps.longitude)) * 60.0);
+                       (int)g.latitude,
+                       (g.latitude - ((int)g.latitude)) * 60.0,
+                       (int)g.longitude,
+                       (g.longitude - ((int)g.longitude)) * 60.0);
        }
 
        return 0;
@@ -102,15 +103,15 @@ gps_not_ready:
        return -1;
 }
 
-int osmo_gps_open(void)
+int osmo_gpsd_open(void)
 {
-       LOGP(DGPS, LOGL_INFO, "Connecting to gpsd at '%s:%s'\n", gps.gpsd_host, gps.gpsd_port);
+       LOGP(DGPS, LOGL_INFO, "Connecting to gpsd at '%s:%s'\n", g.gpsd_host, g.gpsd_port);
 
        gps_bfd.data = NULL;
        gps_bfd.when = BSC_FD_READ;
-       gps_bfd.cb = osmo_gps_cb;
+       gps_bfd.cb = osmo_gpsd_cb;
 
-       gdata = gps_open(gps.gpsd_host, gps.gpsd_port);
+       gdata = gps_open(g.gpsd_host, g.gpsd_port);
        if (gdata == NULL) {
                LOGP(DGPS, LOGL_ERROR, "Can't connect to gpsd\n");
                return -1;
@@ -129,7 +130,7 @@ int osmo_gps_open(void)
        return 0;
 }
 
-void osmo_gps_close(void)
+void osmo_gpsd_close(void)
 {
        if (gps_bfd.fd <= 0)
                return;
@@ -142,11 +143,11 @@ void osmo_gps_close(void)
        gps_bfd.fd = -1; /* -1 or 0 indicates: 'close' */
 }
 
-#else
+#endif
 
 static struct termios gps_termios, gps_old_termios;
 
-static int osmo_gps_line(char *line)
+static int osmo_serialgps_line(char *line)
 {
        time_t gps_now, host_now;
        struct tm *tm;
@@ -164,10 +165,10 @@ static int osmo_gps_line(char *line)
        /* valid position */
        if (line[36] != 'A') {
                LOGP(DGPS, LOGL_INFO, "%s (invalid)\n", line);
-               gps.valid = 0;
+               g.valid = 0;
                return 0;
        }
-       gps.valid = 1;
+       g.valid = 1;
 
        /* time stamp */
        gps_now = line[30] - '0';
@@ -185,7 +186,7 @@ static int osmo_gps_line(char *line)
                diff -= 86400;
        /* apply the "date" part to the GPS time */
        gps_now = host_now - diff;
-       gps.gmt = gps_now;
+       g.gmt = gps_now;
        tm = localtime(&gps_now);
 
        /* position */
@@ -199,7 +200,7 @@ static int osmo_gps_line(char *line)
        latitude += (double)(line[8] - '0') / 600000.0;
        if (line[10] == 'S')
                latitude = 0.0 - latitude;
-       gps.latitude = latitude;
+       g.latitude = latitude;
        longitude = (double)(line[12] - '0') * 100.0;
        longitude += (double)(line[13] - '0') * 10.0;
        longitude += (double)(line[14] - '0');
@@ -211,17 +212,17 @@ static int osmo_gps_line(char *line)
        longitude += (double)(line[21] - '0') / 600000.0;
        if (line[23] == 'W')
                longitude = 360.0 - longitude;
-       gps.longitude = longitude;
+       g.longitude = longitude;
        
        LOGP(DGPS, LOGL_DEBUG, "%s\n", line);
        LOGP(DGPS, LOGL_INFO, " time=%02d:%02d:%02d %04d-%02d-%02d, "
                "diff-to-host=%d, latitude=%do%.4f, longitude=%do%.4f\n",
                tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_year + 1900,
                tm->tm_mday, tm->tm_mon + 1, diff,
-               (int)gps.latitude,
-               (gps.latitude - ((int)gps.latitude)) * 60.0,
-               (int)gps.longitude,
-               (gps.longitude - ((int)gps.longitude)) * 60.0);
+               (int)g.latitude,
+               (g.latitude - ((int)g.latitude)) * 60.0,
+               (int)g.longitude,
+               (g.longitude - ((int)g.longitude)) * 60.0);
        return 0;
 }
 
@@ -241,7 +242,7 @@ static int nmea_checksum(char *line)
        return (strtoul(line+1, NULL, 16) == checksum);
 }
 
-int osmo_gps_cb(struct bsc_fd *bfd, unsigned int what)
+int osmo_serialgps_cb(struct bsc_fd *bfd, unsigned int what)
 {
        char buff[128];
        static char line[128];
@@ -265,7 +266,7 @@ int osmo_gps_cb(struct bsc_fd *bfd, unsigned int what)
                        if (!nmea_checksum(line))
                                fprintf(stderr, "NMEA checksum error\n");
                        else
-                               osmo_gps_line(line);
+                               osmo_serialgps_line(line);
                        continue;
                }
                line[lpos++] = buff[i++];
@@ -276,23 +277,23 @@ int osmo_gps_cb(struct bsc_fd *bfd, unsigned int what)
        return 0;
 }
 
-int osmo_gps_open(void)
+int osmo_serialgps_open(void)
 {
        int baud = 0;
 
        if (gps_bfd.fd > 0)
                return 0;
 
-       LOGP(DGPS, LOGL_INFO, "Open GPS device '%s'\n", gps.device);
+       LOGP(DGPS, LOGL_INFO, "Open GPS device '%s'\n", g.device);
 
        gps_bfd.data = NULL;
        gps_bfd.when = BSC_FD_READ;
-       gps_bfd.cb = osmo_gps_cb;
-       gps_bfd.fd = open(gps.device, O_RDONLY);
+       gps_bfd.cb = osmo_serialgps_cb;
+       gps_bfd.fd = open(g.device, O_RDONLY);
        if (gps_bfd.fd < 0)
                return gps_bfd.fd;
 
-       switch (gps.baud) {
+       switch (g.baud) {
        case   4800:
                baud = B4800;      break;
        case   9600:
@@ -327,7 +328,7 @@ int osmo_gps_open(void)
        return 0;
 }
 
-void osmo_gps_close(void)
+void osmo_serialgps_close(void)
 {
        if (gps_bfd.fd <= 0)
                return;
@@ -343,11 +344,38 @@ void osmo_gps_close(void)
        gps_bfd.fd = -1; /* -1 or 0 indicates: 'close' */
 }
 
-#endif
-
 void osmo_gps_init(void)
 {
        memset(&gps_bfd, 0, sizeof(gps_bfd));
 }
 
+int osmo_gps_open(void)
+{
+       switch (g.gps_type) {
+#ifdef _HAVE_GPSD
+               case GPS_TYPE_GPSD:
+                       return osmo_gpsd_open();
+#endif
+               case GPS_TYPE_SERIAL:
+                       return osmo_serialgps_open();
+
+               default:
+                       return 0;
+       }
+}
+
+void osmo_gps_close(void)
+{
+       switch (g.gps_type) {
+#ifdef _HAVE_GPSD
+               case GPS_TYPE_GPSD:
+                       return osmo_gpsd_close();
+#endif
+               case GPS_TYPE_SERIAL:
+                       return osmo_serialgps_close();
+
+               default:
+                       return;
+       }
+}
 
index 7a2c67a..fdecc63 100644 (file)
@@ -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,
index a0f9769..7de2c40 100644 (file)
@@ -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);
index 7888f01..b93248d 100644 (file)
@@ -836,11 +836,11 @@ DEFUN(cfg_gps_enable, cfg_gps_enable_cmd, "gps enable",
        "GPS receiver")
 {
        if (osmo_gps_open()) {
-               gps.enable = 1;
+               g.enable = 1;
                vty_out(vty, "Failed to open GPS device!%s", VTY_NEWLINE);
                return CMD_WARNING;
        }
-       gps.enable = 1;
+       g.enable = 1;
 
        return CMD_SUCCESS;
 }
@@ -848,31 +848,32 @@ DEFUN(cfg_gps_enable, cfg_gps_enable_cmd, "gps enable",
 DEFUN(cfg_no_gps_enable, cfg_no_gps_enable_cmd, "no gps enable",
        NO_STR "Disable GPS receiver")
 {
-       if (gps.enable)
+       if (g.enable)
                osmo_gps_close();
-       gps.enable = 0;
+       g.enable = 0;
 
        return CMD_SUCCESS;
 }
 
-#ifdef _USE_GPSD
+#ifdef _HAVE_GPSD
 DEFUN(cfg_gps_host, cfg_gps_host_cmd, "gps host HOST:PORT",
        "GPS receiver\nSelect gpsd host and port\n"
        "IP and port (optional) of the host running gpsd")
 {
        char* colon = strstr(argv[0], ":");
        if (colon != NULL) {
-               memcpy(gps.gpsd_host, argv[0], colon - argv[0] - 1);
-               gps.gpsd_host[colon - argv[0]] = '\0';
-               memcpy(gps.gpsd_port, colon, strlen(colon));
-               gps.gpsd_port[strlen(colon)] = '\0';
+               memcpy(g.gpsd_host, argv[0], colon - argv[0] - 1);
+               g.gpsd_host[colon - argv[0]] = '\0';
+               memcpy(g.gpsd_port, colon, strlen(colon));
+               g.gpsd_port[strlen(colon)] = '\0';
        } else {
-               snprintf(gps.gpsd_host, ARRAY_SIZE(gps.gpsd_host), "%s", argv[0]);
-               gps.gpsd_host[ARRAY_SIZE(gps.gpsd_host) - 1] = '\0';
-               snprintf(gps.gpsd_port, ARRAY_SIZE(gps.gpsd_port), "2947");
-               gps.gpsd_port[ARRAY_SIZE(gps.gpsd_port) - 1] = '\0';
+               snprintf(g.gpsd_host, ARRAY_SIZE(g.gpsd_host), "%s", argv[0]);
+               g.gpsd_host[ARRAY_SIZE(g.gpsd_host) - 1] = '\0';
+               snprintf(g.gpsd_port, ARRAY_SIZE(g.gpsd_port), "2947");
+               g.gpsd_port[ARRAY_SIZE(g.gpsd_port) - 1] = '\0';
        }
-       if (gps.enable) {
+       g.gps_type = GPS_TYPE_GPSD;
+       if (g.enable) {
                osmo_gps_close();
                if (osmo_gps_open()) {
                        vty_out(vty, "Failed to connect to gpsd host!%s",
@@ -883,14 +884,16 @@ DEFUN(cfg_gps_host, cfg_gps_host_cmd, "gps host HOST:PORT",
 
        return CMD_SUCCESS;
 }
-#else
+#endif
+
 DEFUN(cfg_gps_device, cfg_gps_device_cmd, "gps device DEVICE",
        "GPS receiver\nSelect serial device\n"
        "Full path of serial device including /dev/")
 {
-       strncpy(gps.device, argv[0], sizeof(gps.device));
-       gps.device[sizeof(gps.device) - 1] = '\0';
-       if (gps.enable) {
+       strncpy(g.device, argv[0], sizeof(g.device));
+       g.device[sizeof(g.device) - 1] = '\0';
+       g.gps_type = GPS_TYPE_SERIAL;
+       if (g.enable) {
                osmo_gps_close();
                if (osmo_gps_open()) {
                        vty_out(vty, "Failed to open GPS device!%s",
@@ -901,21 +904,19 @@ DEFUN(cfg_gps_device, cfg_gps_device_cmd, "gps device DEVICE",
 
        return CMD_SUCCESS;
 }
-#endif
 
-#ifndef _USE_GPSD
 DEFUN(cfg_gps_baud, cfg_gps_baud_cmd, "gps baudrate "
        "(default|4800|""9600|19200|38400|57600|115200)",
        "GPS receiver\nSelect baud rate\nDefault, don't modify\n\n\n\n\n\n")
 {
        if (argv[0][0] == 'd')
-               gps.baud = 0;
+               g.baud = 0;
        else
-               gps.baud = atoi(argv[0]);
-       if (gps.enable) {
+               g.baud = atoi(argv[0]);
+       if (g.enable) {
                osmo_gps_close();
                if (osmo_gps_open()) {
-                       gps.enable = 0;
+                       g.enable = 0;
                        vty_out(vty, "Failed to open GPS device!%s",
                                VTY_NEWLINE);
                        return CMD_WARNING;
@@ -924,7 +925,6 @@ DEFUN(cfg_gps_baud, cfg_gps_baud_cmd, "gps baudrate "
 
        return CMD_SUCCESS;
 }
-#endif
 
 /* per MS config */
 DEFUN(cfg_ms, cfg_ms_cmd, "ms MS_NAME",
@@ -1204,17 +1204,16 @@ static int config_write(struct vty *vty)
 {
        struct osmocom_ms *ms;
 
-#ifdef _USE_GPSD
-       vty_out(vty, "gpsd host %s%s", gps.gpsd_host, VTY_NEWLINE);
-       vty_out(vty, "gpsd port %s%s", gps.gpsd_port, VTY_NEWLINE);
-#else
-       vty_out(vty, "gps device %s%s", gps.device, VTY_NEWLINE);
-       if (gps.baud)
-               vty_out(vty, "gps baudrate %d%s", gps.baud, VTY_NEWLINE);
+#ifdef _HAVE_GPSD
+       vty_out(vty, "gpsd host %s%s", g.gpsd_host, VTY_NEWLINE);
+       vty_out(vty, "gpsd port %s%s", g.gpsd_port, VTY_NEWLINE);
+#endif
+       vty_out(vty, "gps device %s%s", g.device, VTY_NEWLINE);
+       if (g.baud)
+               vty_out(vty, "gps baudrate %d%s", g.baud, VTY_NEWLINE);
        else
                vty_out(vty, "gps baudrate default%s", VTY_NEWLINE);
-#endif
-       vty_out(vty, "%sgps enable%s", (gps.enable) ? "" : "no ", VTY_NEWLINE);
+       vty_out(vty, "%sgps enable%s", (g.enable) ? "" : "no ", VTY_NEWLINE);
        vty_out(vty, "!%s", VTY_NEWLINE);
 
        llist_for_each_entry(ms, &ms_list, entity)
@@ -2305,12 +2304,11 @@ int ms_vty_init(void)
        install_element(ENABLE_NODE, &call_retr_cmd);
        install_element(ENABLE_NODE, &call_dtmf_cmd);
 
-#ifdef _USE_GPSD
+#ifdef _HAVE_GPSD
        install_element(CONFIG_NODE, &cfg_gps_host_cmd);
-#else
+#endif
        install_element(CONFIG_NODE, &cfg_gps_device_cmd);
        install_element(CONFIG_NODE, &cfg_gps_baud_cmd);
-#endif
        install_element(CONFIG_NODE, &cfg_gps_enable_cmd);
        install_element(CONFIG_NODE, &cfg_no_gps_enable_cmd);