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(" -c, --config=PATH config file path\n");
19 pr_info(" -h, --help show this help\n");
24 static void set_default_options(struct plotter_options *opts)
26 bzero(opts, sizeof(*opts));
28 opts->baud_rate = 128000;
29 opts->device_path = "/dev/ttyUSB0";
32 int read_args(int argc, char *argv[], struct plotter_options *opts)
34 int option_index = 0, c;
35 static struct option long_options[] = {
36 { .val = 'd', .name = "device", .has_arg = 1, },
37 { .val = 'o', .name = "output", .has_arg = 1 },
38 { .val = 'b', .name = "baud", .has_arg = 1 },
39 { .val = 'v', .name = "verbose", .has_arg = 2 },
40 { .val = 'q', .name = "quiet", },
41 { .val = 'c', .name = "config", .has_arg = 1 },
42 { .val = 'h', .name = "help", },
44 char short_options[] = "d:o:b:vqc:h";
46 set_default_options(opts);
49 c = getopt_long(argc, argv, short_options, long_options,
57 opts->device_path = optarg;
60 opts->output_path = optarg;
63 opts->baud_rate = atoi(optarg);
67 pr_debug("Increased trace level to %d\n", trace_level);
71 pr_debug("Degreased trace level to %d\n", trace_level);
74 opts->config_file_path = optarg;
77 print_help_and_die(argv[0]);
84 while (optind < argc) {
85 /* The rest of the options, ignored */