]> sigrok.org Git - sigrok-cli.git/commitdiff
Add --get option.
authorBert Vermeulen <redacted>
Wed, 10 Sep 2014 15:57:01 +0000 (17:57 +0200)
committerBert Vermeulen <redacted>
Wed, 10 Sep 2014 15:57:01 +0000 (17:57 +0200)
doc/sigrok-cli.1
main.c
options.c
sigrok-cli.h

index 2afbc7dfcab0f942def354873fad160c5667e8d0..5e5df36877cc6cd5671a20da170be30e99101336 100644 (file)
@@ -445,6 +445,11 @@ frames, then quit.
 .BR "\-\-continuous"
 Sample continuously until stopped. Not all devices support this.
 .TP
 .BR "\-\-continuous"
 Sample continuously until stopped. Not all devices support this.
 .TP
+.BR "\-\-get " <variable>
+Get the value of
+.B <variable>
+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.
 .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 19d146df7fe9560fcdcd396419694ee31ce8d1f2..a5749529e82859c00f38746a8d4d1cea9afaf597 100644 (file)
--- a/main.c
+++ b/main.c
@@ -71,6 +71,42 @@ int select_channels(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
        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;
 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();
                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)
        else if (opt_set)
                set_options();
        else if (opt_samples || opt_time || opt_frames || opt_continuous)
index c8b51ec1e353c2dfb2be035886ad6a58199adc60..179d892f4021239bda222ee4fdd84e9462e3c7b3 100644 (file)
--- 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_samples = NULL;
 gchar *opt_frames = NULL;
 gchar *opt_continuous = NULL;
+gchar *opt_get = NULL;
 gchar *opt_set = NULL;
 
 /* defines a callback function that generates
 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_time)
 CHECK_ONCE(opt_samples)
 CHECK_ONCE(opt_frames)
+CHECK_ONCE(opt_get)
 
 #undef CHECK_STR_ONCE
 
 
 #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},
                        "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}
 };
        {"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
        {NULL, 0, 0, 0, NULL, NULL, NULL}
 };
index cbf2a84f3bfcf76a705aaf6fdfbdb4c1d78809a7..8d0b624b786e8cd03595683eed0111f9065816ab 100644 (file)
@@ -109,6 +109,7 @@ extern gchar *opt_time;
 extern gchar *opt_samples;
 extern gchar *opt_frames;
 extern gchar *opt_continuous;
 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);
 extern gchar *opt_set;
 int parse_options(int argc, char **argv);
 void show_help(void);