remove deprication warning
[project/ugps.git] / main.c
diff --git a/main.c b/main.c
index 29b341b..7696cbc 100644 (file)
--- a/main.c
+++ b/main.c
 #include "log.h"
 #include "nmea.h"
 
+unsigned int debug;
 static struct ustream_fd stream;
 static struct ubus_auto_conn conn;
 static struct blob_buf b;
+static char *ubus_socket;
 struct timespec stamp = { 0 };
+unsigned int adjust_clock = 0;
 
 void
 gps_timestamp(void)
@@ -55,7 +58,7 @@ gps_info(struct ubus_context *ctx, struct ubus_object *obj,
                blobmsg_add_u32(&b, "age", now.tv_sec - stamp.tv_sec);
                blobmsg_add_string(&b, "latitude", latitude);
                blobmsg_add_string(&b, "longitude", longitude);
-               blobmsg_add_string(&b, "elivation", elivation);
+               blobmsg_add_string(&b, "elevation", elevation);
                blobmsg_add_string(&b, "course", course);
                blobmsg_add_string(&b, "speed", speed);
        }
@@ -89,25 +92,68 @@ ubus_connect_handler(struct ubus_context *ctx)
 }
 
 static int
-usage(void)
+usage(const char *prog)
 {
-       LOG("ugps <device>\n");
+       fprintf(stderr, "Usage: %s [options] <device>\n"
+               "Options:\n"
+               "       -a              Adjust system clock from gps\n"
+               "       -s <path>       Path to ubus socket\n"
+               "       -d <level>      Enable debug messages\n"
+               "       -S              Print messages to stdout\n"
+               "\n", prog);
        return -1;
 }
 
 int
 main(int argc, char ** argv)
 {
+       int ch;
+       char *device = NULL;
+       char *dbglvl = getenv("DBGLVL");
+       int ulog_channels = ULOG_KMSG;
 
        signal(SIGPIPE, SIG_IGN);
 
-       if (argc != 2)
-               return usage();
+       if (dbglvl) {
+               debug = atoi(dbglvl);
+               unsetenv("DBGLVL");
+       }
+
+       while ((ch = getopt(argc, argv, "ad:s:S")) != -1) {
+               switch (ch) {
+               case 'a':
+                       adjust_clock = -1;
+                       break;
+               case 's':
+                       ubus_socket = optarg;
+                       break;
+               case 'd':
+                       debug = atoi(optarg);
+                       break;
+               case 'S':
+                       ulog_channels = ULOG_STDIO;
+                       break;
+               default:
+                       return usage(argv[0]);
+               }
+       }
+
+       if (argc - optind < 1) {
+               fprintf(stderr, "ERROR: missing device parameter\n");
+               return usage(argv[0]);
+       }
+
+       device = argv[optind];
+       ulog_open(ulog_channels, LOG_DAEMON, "ugps");
 
        uloop_init();
+       conn.path = ubus_socket;
        conn.cb = ubus_connect_handler;
        ubus_auto_connect(&conn);
-       nmea_open(argv[1], &stream, B4800);
+
+       if (nmea_open(device, &stream, B4800) < 0)
+               return -1;
+
        uloop_run();
        uloop_done();