]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
New --probe-group option
[sigrok-cli.git] / sigrok-cli.c
index 8f3d8e313d70bed817825945cd2991f193c5cbc7..aa3d17862c228afde75b00d2e557b593333a627c 100644 (file)
@@ -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,
@@ -336,7 +339,9 @@ static void show_dev_detail(void)
 {
        struct sr_dev_inst *sdi;
        const struct sr_config_info *srci;
-       GSList *devices;
+       struct sr_probe *probe;
+       struct sr_probe_group *probe_group;
+       GSList *devices, *pgl, *prl;
        GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
        gsize num_opts, num_elements;
        const uint64_t *uint64, p, q, low, high;
@@ -385,6 +390,19 @@ static void show_dev_detail(void)
                /* 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) {
+                               probe = prl->data;
+                               printf(" %s", probe->name);
+                       }
+                       printf("\n");
+               }
+       }
+
        printf("Supported configuration options:\n");
        opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(int32_t));
        for (o = 0; o < num_opts; o++) {
@@ -518,15 +536,15 @@ static void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_CHAR) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_get(sdi->driver, srci->key,
-                                       &gvar, sdi) == SR_OK) {
+                       if (sr_config_get(sdi->driver, sdi, NULL, 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, srci->key,
-                                       &gvar, sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL, srci->key,
+                                       &gvar) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -546,13 +564,13 @@ static void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_UINT64_RANGE) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_list(sdi->driver, srci->key,
-                                       &gvar_list, sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL, srci->key,
+                                       &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
                        }
 
-                       if (sr_config_get(sdi->driver, srci->key, &gvar, sdi) == SR_OK) {
+                       if (sr_config_get(sdi->driver, sdi, NULL, srci->key, &gvar) == SR_OK) {
                                g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
                                g_variant_unref(gvar);
                        } else {
@@ -576,8 +594,8 @@ static void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_BOOL) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_get(sdi->driver, srci->key,
-                                       &gvar, sdi) == SR_OK) {
+                       if (sr_config_get(sdi->driver, sdi, NULL, srci->key,
+                                       &gvar) == SR_OK) {
                                if (g_variant_get_boolean(gvar))
                                        printf("on (current), off\n");
                                else
@@ -757,7 +775,7 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                GVariant *gvar;
                if (opt_pds && logic_probelist->len) {
                        if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE,
-                                       &gvar, sdi) == SR_OK) {
+                                       &gvar) == SR_OK) {
                                samplerate = g_variant_get_uint64(gvar);
                                g_variant_unref(gvar);
                                if (srd_session_metadata_set(srd_sess, SRD_CONF_SAMPLERATE,
@@ -1356,6 +1374,29 @@ static int select_probes(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
+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;
+}
+
 /**
  * Return the input file format which the CLI tool should use.
  *
@@ -1495,6 +1536,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;
@@ -1564,8 +1606,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;