9 void print_help_and_die(const char *exec_name)
11 pr_info("Usage: %s [option]\n", exec_name);
12 pr_info(" -d, --device=DEVICE path to the serial device\n");
13 pr_info(" default: /dev/ttyUSB0\n");
14 pr_info(" -b, --baud=BAUD device baud rate, default 128000\n");
15 pr_info(" -o, --output logfile path, stdout only if omited\n");
16 pr_info(" -v, --verbose increase verbosity\n");
17 pr_info(" -q, --quiet decrease verbosity\n");
18 pr_info(" -h, --help show this help\n");
23 static void set_default_options(struct plotter_options *opts)
25 bzero(opts, sizeof(*opts));
27 opts->baud_rate = 128000;
28 opts->device_path = "/dev/ttyUSB0";
31 int read_args(int argc, char *argv[], struct plotter_options *opts)
33 int option_index = 0, c;
34 static struct option long_options[] = {
35 { .val = 'd', .name = "device", .has_arg = 1, },
36 { .val = 'o', .name = "output", .has_arg = 1 },
37 { .val = 'b', .name = "baud", .has_arg = 1 },
38 { .val = 'v', .name = "verbose", .has_arg = 2 },
39 { .val = 'q', .name = "quiet", },
40 { .val = 'h', .name = "help", },
42 char short_options[] = "d:o:b:vqh";
44 set_default_options(opts);
47 c = getopt_long(argc, argv, short_options, long_options,
55 opts->device_path = optarg;
58 opts->output_path = optarg;
61 opts->baud_rate = atoi(optarg);
65 pr_debug("Increased trace level to %d\n", trace_level);
69 pr_debug("Degreased trace level to %d\n", trace_level);
72 print_help_and_die(argv[0]);
79 while (optind < argc) {
80 /* The rest of the options, ignored */