X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fugps.git;a=blobdiff_plain;f=main.c;fp=main.c;h=87d069be02112ecd1e1d75884bf9bbc713ce85a4;hp=29b341b2dcc696102a9cf2d3f765a7d38cdfee83;hb=24df9761cc0f819847bfdb850ca6c07a2fc62893;hpb=ab92ba862353cc1d76cd769b8f095e197c75538a diff --git a/main.c b/main.c index 29b341b..87d069b 100644 --- a/main.c +++ b/main.c @@ -27,9 +27,11 @@ #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 }; void @@ -89,22 +91,58 @@ ubus_connect_handler(struct ubus_context *ctx) } static int -usage(void) +usage(const char *prog) { - LOG("ugps \n"); + fprintf(stderr, "Usage: %s [options] \n" + "Options:\n" + " -s Path to ubus socket\n" + " -d 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, "d:D:s:S")) != -1) { + switch (ch) { + 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);