X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=7f7de8c8c9eaf0db50d962ff0d2e8ac9ff94e131;hp=2ae593f27ac789ee6e2c647e876f7629a488d2c7;hb=7c4a2b15df1bddbe2f4a73d2a519e15a36d64929;hpb=96e0e4500717f3e09e6c9bae3f1f10967c8d6535 diff --git a/sigrok-cli.c b/sigrok-cli.c index 2ae593f..7f7de8c 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -60,6 +60,7 @@ static gchar *opt_output_file = NULL; static gchar *opt_drv = NULL; static gchar *opt_config = NULL; static gchar *opt_probes = NULL; +static gchar *opt_probe_group = NULL; static gchar *opt_triggers = NULL; static gchar *opt_pds = NULL; #ifdef HAVE_SRD @@ -94,6 +95,8 @@ static GOptionEntry optargs[] = { "Output format", NULL}, {"probes", 'p', 0, G_OPTION_ARG_STRING, &opt_probes, "Probes to use", NULL}, + {"probe-group", 'g', 0, G_OPTION_ARG_STRING, &opt_probe_group, + "Probe groups", NULL}, {"triggers", 't', 0, G_OPTION_ARG_STRING, &opt_triggers, "Trigger configuration", NULL}, {"wait-trigger", 'w', 0, G_OPTION_ARG_NONE, &opt_wait_trigger, @@ -151,6 +154,29 @@ static GSList *hash_to_hwopt(GHashTable *hash) return opts; } +static struct sr_probe_group *select_probe_group(struct sr_dev_inst *sdi) +{ + struct sr_probe_group *pg; + GSList *l; + + if (!opt_probe_group) + return NULL; + + if (!sdi->probe_groups) { + g_critical("This device does not have any probe groups."); + return NULL; + } + + for (l = sdi->probe_groups; l; l = l->next) { + pg = l->data; + if (!strcasecmp(opt_probe_group, pg->name)) { + return pg; + } + } + + return NULL; +} + static void free_drvopts(struct sr_config *src) { g_variant_unref(src->data); @@ -337,7 +363,7 @@ static void show_dev_detail(void) struct sr_dev_inst *sdi; const struct sr_config_info *srci; struct sr_probe *probe; - struct sr_probe_group *probe_group; + struct sr_probe_group *probe_group, *pg; GSList *devices, *pgl, *prl; GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar; gsize num_opts, num_elements; @@ -382,17 +408,19 @@ static void show_dev_detail(void) g_variant_unref(gvar_opts); } - if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, - &gvar_opts) != SR_OK)) + probe_group = select_probe_group(sdi); + if ((sr_config_list(sdi->driver, sdi, probe_group, SR_CONF_DEVICE_OPTIONS, + &gvar_opts)) != SR_OK) /* Driver supports no device instance options. */ return; if (sdi->probe_groups) { printf("Probe groups:\n"); for (pgl = sdi->probe_groups; pgl; pgl = pgl->next) { - probe_group = pgl->data; - printf(" %s:", probe_group->name); - for (prl = probe_group->probes; prl; prl = prl->next) { + pg = pgl->data; + printf(" %s: channel%s", pg->name, + g_slist_length(pg->probes) > 1 ? "s" : ""); + for (prl = pg->probes; prl; prl = prl->next) { probe = prl->data; printf(" %s", probe->name); } @@ -400,14 +428,21 @@ static void show_dev_detail(void) } } - printf("Supported configuration options:\n"); + printf("Supported configuration options"); + if (sdi->probe_groups) { + if (!probe_group) + printf(" across all probe groups"); + else + printf(" on probe group %s", probe_group->name); + } + printf(":\n"); opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(int32_t)); for (o = 0; o < num_opts; o++) { if (!(srci = sr_config_info_get(opts[o]))) continue; if (srci->key == SR_CONF_TRIGGER_TYPE) { - if (sr_config_list(sdi->driver, sdi, NULL, srci->key, + if (sr_config_list(sdi->driver, sdi, probe_group, srci->key, &gvar) != SR_OK) { printf("\n"); continue; @@ -424,7 +459,7 @@ static void show_dev_detail(void) } else if (srci->key == SR_CONF_PATTERN_MODE) { /* Pattern generator modes */ printf(" %s", srci->id); - if (sr_config_list(sdi->driver, sdi, NULL, srci->key, + if (sr_config_list(sdi->driver, sdi, probe_group, srci->key, &gvar) == SR_OK) { printf(" - supported patterns:\n"); stropts = g_variant_get_strv(gvar, &num_elements); @@ -438,7 +473,7 @@ static void show_dev_detail(void) } else if (srci->key == SR_CONF_SAMPLERATE) { /* Supported samplerates */ printf(" %s", srci->id); - if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE, + if (sr_config_list(sdi->driver, sdi, probe_group, SR_CONF_SAMPLERATE, &gvar_dict) != SR_OK) { printf("\n"); continue; @@ -481,7 +516,7 @@ static void show_dev_detail(void) } else if (srci->key == SR_CONF_BUFFERSIZE) { /* Supported buffer sizes */ printf(" %s", srci->id); - if (sr_config_list(sdi->driver, sdi, NULL, + if (sr_config_list(sdi->driver, sdi, probe_group, SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) { printf("\n"); continue; @@ -496,7 +531,7 @@ static void show_dev_detail(void) } else if (srci->key == SR_CONF_TIMEBASE) { /* Supported time bases */ printf(" %s", srci->id); - if (sr_config_list(sdi->driver, sdi, NULL, + if (sr_config_list(sdi->driver, sdi, probe_group, SR_CONF_TIMEBASE, &gvar_list) != SR_OK) { printf("\n"); continue; @@ -515,7 +550,7 @@ static void show_dev_detail(void) } else if (srci->key == SR_CONF_VDIV) { /* Supported volts/div values */ printf(" %s", srci->id); - if (sr_config_list(sdi->driver, sdi, NULL, + if (sr_config_list(sdi->driver, sdi, probe_group, SR_CONF_VDIV, &gvar_list) != SR_OK) { printf("\n"); continue; @@ -533,14 +568,14 @@ static void show_dev_detail(void) } else if (srci->datatype == SR_T_CHAR) { printf(" %s: ", srci->id); - if (sr_config_get(sdi->driver, sdi, NULL, srci->key, + if (sr_config_get(sdi->driver, sdi, probe_group, srci->key, &gvar) == SR_OK) { tmp_str = g_strdup(g_variant_get_string(gvar, NULL)); g_variant_unref(gvar); } else tmp_str = NULL; - if (sr_config_list(sdi->driver, sdi, NULL, srci->key, + if (sr_config_list(sdi->driver, sdi, probe_group, srci->key, &gvar) != SR_OK) { printf("\n"); continue; @@ -561,7 +596,7 @@ static void show_dev_detail(void) } else if (srci->datatype == SR_T_UINT64_RANGE) { printf(" %s: ", srci->id); - if (sr_config_list(sdi->driver, sdi, NULL, srci->key, + if (sr_config_list(sdi->driver, sdi, probe_group, srci->key, &gvar_list) != SR_OK) { printf("\n"); continue; @@ -1510,6 +1545,7 @@ static void load_input_file(void) static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args) { const struct sr_config_info *srci; + struct sr_probe_group *pg; GHashTableIter iter; gpointer key, value; int ret; @@ -1579,8 +1615,10 @@ static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args) default: ret = SR_ERR; } - if (val) - ret = sr_config_set(sdi, NULL, srci->key, val); + if (val) { + pg = select_probe_group(sdi); + ret = sr_config_set(sdi, pg, srci->key, val); + } if (ret != SR_OK) { g_critical("Failed to set device option '%s'.", (char *)key); return ret;