From: Bert Vermeulen Date: Wed, 10 Sep 2014 15:57:01 +0000 (+0200) Subject: Add --get option. X-Git-Tag: sigrok-cli-0.6.0~67 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=62a64762ea3532d12853d431622b8cd05adbcc8c;p=sigrok-cli.git Add --get option. --- diff --git a/doc/sigrok-cli.1 b/doc/sigrok-cli.1 index 2afbc7d..5e5df36 100644 --- a/doc/sigrok-cli.1 +++ b/doc/sigrok-cli.1 @@ -445,6 +445,11 @@ frames, then quit. .BR "\-\-continuous" Sample continuously until stopped. Not all devices support this. .TP +.BR "\-\-get " +Get the value of +.B +from the specified device and print it. +.TP .BR "\-\-set" Set one or more variables specified with the \fB\-\-config\fP option, without doing any acquisition. diff --git a/main.c b/main.c index 19d146d..a574952 100644 --- a/main.c +++ b/main.c @@ -71,6 +71,42 @@ int select_channels(struct sr_dev_inst *sdi) return SR_OK; } +static void get_option(void) +{ + struct sr_dev_inst *sdi; + struct sr_channel_group *cg; + const struct sr_config_info *ci; + GSList *devices; + GVariant *gvar; + int ret; + char *s; + + if (!(devices = device_scan())) { + g_critical("No devices found."); + return; + } + sdi = devices->data; + g_slist_free(devices); + + if (sr_dev_open(sdi) != SR_OK) { + g_critical("Failed to open device."); + return; + } + + cg = select_channel_group(sdi); + if (!(ci = sr_config_info_name_get(opt_get))) + g_critical("Unknown option '%s'", opt_get); + + if ((ret = sr_config_get(sdi->driver, sdi, cg, ci->key, &gvar)) != SR_OK) + g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret)); + s = g_variant_print(gvar, FALSE); + printf("%s\n", s); + g_free(s); + + g_variant_unref(gvar); + sr_dev_close(sdi); +} + static void set_options(void) { struct sr_dev_inst *sdi; @@ -176,6 +212,8 @@ int main(int argc, char **argv) show_dev_detail(); else if (opt_input_file) load_input_file(); + else if (opt_get) + get_option(); else if (opt_set) set_options(); else if (opt_samples || opt_time || opt_frames || opt_continuous) diff --git a/options.c b/options.c index c8b51ec..179d892 100644 --- a/options.c +++ b/options.c @@ -45,6 +45,7 @@ gchar *opt_time = NULL; gchar *opt_samples = NULL; gchar *opt_frames = NULL; gchar *opt_continuous = NULL; +gchar *opt_get = NULL; gchar *opt_set = NULL; /* defines a callback function that generates @@ -85,6 +86,7 @@ CHECK_ONCE(opt_pd_binary) CHECK_ONCE(opt_time) CHECK_ONCE(opt_samples) CHECK_ONCE(opt_frames) +CHECK_ONCE(opt_get) #undef CHECK_STR_ONCE @@ -140,6 +142,7 @@ static const GOptionEntry optargs[] = { "Number of frames to acquire", NULL}, {"continuous", 0, 0, G_OPTION_ARG_NONE, &opt_continuous, "Sample continuously", NULL}, + {"get", 0, 0, G_OPTION_ARG_CALLBACK, &check_opt_get, "Get device option only", NULL}, {"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL}, {NULL, 0, 0, 0, NULL, NULL, NULL} }; diff --git a/sigrok-cli.h b/sigrok-cli.h index cbf2a84..8d0b624 100644 --- a/sigrok-cli.h +++ b/sigrok-cli.h @@ -109,6 +109,7 @@ extern gchar *opt_time; extern gchar *opt_samples; extern gchar *opt_frames; extern gchar *opt_continuous; +extern gchar *opt_get; extern gchar *opt_set; int parse_options(int argc, char **argv); void show_help(void);