+ // Default arguments;
+ opt_tty = "/dev/ttyACM0";
+ opt_device = 1;
+ opt_world = (ntime_t){ts.tv_sec, ts.tv_nsec};
+ opt_start = (ntime_t){0, 0};
+ opt_period = (ntime_t){1, 0};
+
+ // Long options
+ struct option long_options[] = {
+ {"device", required_argument },
+ {"world", required_argument },
+ {"start", required_argument },
+ {"period", required_argument },
+ {"relay", no_argument },
+ {"sync", no_argument },
+ {"pretend", no_argument },
+ {"verbose", no_argument },
+ {"help", no_argument },
+ {0, 0 },
+ };
+
+ // Run parser
+ while (1) {
+ int opt = getopt_long(argc, argv, "d:w:s:p:rynvh", long_options, 0);
+ if (opt == -1)
+ break;
+ switch (opt) {
+ case 'd': opt_device = atoi(optarg); break;
+ case 'w': opt_world = gettime(optarg); break;
+ case 's': opt_start = gettime(optarg); break;
+ case 'p': opt_period = gettime(optarg); break;
+ case 'r': opt_relay = 1; break;
+ case 'y': opt_sync = 1; break;
+ case 'n': opt_pretend = 1; break;
+ case 'v': opt_verbose++; break;
+ case 'h': usage(); exit(0); break;
+ default: usage(); exit(1); break;
+ }
+ }
+ if (optind < argc)
+ opt_tty = argv[optind];
+}
+
+// Main
+int main(int argc, char **argv)
+{
+ // Lookup current wall-clock time
+ parse(argc, argv);
+
+ // Debug output
+ if (opt_verbose) {
+ printf("options:\n");
+ printf(" tty = %s\n", opt_tty);
+ printf(" device = %d\n", opt_device);
+ printf(" world = %d.%09u\n", opt_world.seconds, opt_world.nanosec);
+ printf(" start = %d.%09u\n", opt_start.seconds, opt_start.nanosec);
+ printf(" period = %d.%09u\n", opt_period.seconds, opt_period.nanosec);
+ printf(" relay = %s\n", opt_relay ? "true" : "false");
+ printf(" sync = %s\n", opt_sync ? "true" : "false");
+ printf(" pretend = %s\n", opt_pretend ? "true" : "false");
+ printf(" verbose = %s\n", opt_verbose ? "true" : "false");
+ }
+