]> sigrok.org Git - sigrok-cli.git/commitdiff
Support SR_T_MQLIST.
authorBert Vermeulen <redacted>
Sun, 23 Aug 2015 21:21:14 +0000 (23:21 +0200)
committerBert Vermeulen <redacted>
Sun, 23 Aug 2015 21:21:14 +0000 (23:21 +0200)
session.c
show.c

index b36072cf7e0289f29cdc5f8a585a4a04ca2a090e..6e101784606dc4d168a824be891f48413ceffb33 100644 (file)
--- a/session.c
+++ b/session.c
@@ -354,14 +354,15 @@ void datafeed_in(const struct sr_dev_inst *sdi,
 
 int opt_to_gvar(char *key, char *value, struct sr_config *src)
 {
-       const struct sr_key_info *srci;
+       const struct sr_key_info *srci, *srmqi;
        double tmp_double, dlow, dhigh;
-       uint64_t tmp_u64, p, q, low, high;
-       GVariant *rational[2], *range[2];
+       uint64_t tmp_u64, p, q, low, high, mqflags;
+       uint32_t mq;
+       GVariant *rational[2], *range[2], *gvar, *gtup[2];
        GVariantBuilder *vbl;
        gboolean tmp_bool;
        gchar **keyval;
-       int ret;
+       int ret, i;
 
        if (!(srci = sr_key_info_name_get(SR_KEY_CONFIG, key))) {
                g_critical("Unknown device option '%s'.", (char *) key);
@@ -452,6 +453,36 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src)
                        g_strfreev(keyval);
                }
                break;
+       case SR_T_MQLIST:
+               /*
+                 Argument is MQ id e.g. ("voltage") optionally followed by one
+                 or more /<mqflag> e.g. "/ac".
+                */
+               keyval = g_strsplit(value, "/", 0);
+               if (!keyval[0] || !(srmqi = sr_key_info_name_get(SR_KEY_MQ, keyval[0]))) {
+                       g_strfreev(keyval);
+                       ret = -1;
+                       break;
+               }
+               mq = srmqi->key;
+               mqflags = 0;
+               for (i = 1; keyval[i]; i++) {
+                       if (!(srmqi = sr_key_info_name_get(SR_KEY_MQFLAGS, keyval[i]))) {
+                               ret = -1;
+                               break;
+                       }
+                       mqflags |= srmqi->key;
+               }
+               g_strfreev(keyval);
+               if (ret != -1) {
+                       vbl = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+                       gtup[0] = g_variant_new_uint32(mq);
+                       gtup[1] = g_variant_new_uint64(mqflags);
+                       gvar = g_variant_new_tuple(gtup, 2);
+                       g_variant_builder_add_value(vbl, gvar);
+                       src->data = g_variant_builder_end(vbl);
+               }
+               break;
        default:
                g_critical("Unknown data type specified for option '%s' "
                           "(driver implementation bug?).", key);
diff --git a/show.c b/show.c
index e81110a5eb5ec9f8ebbeb7774dc4bae6d738b3ec..957560f333a48637ce85f2306afbf7f7b6a8a801 100644 (file)
--- a/show.c
+++ b/show.c
@@ -263,19 +263,20 @@ void show_dev_detail(void)
 {
        struct sr_dev_driver *driver_from_opt, *driver;
        struct sr_dev_inst *sdi;
-       const struct sr_config_info *srci;
+       const struct sr_key_info *srci, *srmqi, *srmqfi;
        struct sr_channel *ch;
        struct sr_channel_group *channel_group, *cg;
        GSList *devices, *cgl, *chl, *channel_groups;
-       GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
+       GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar, *element;
        gsize num_opts, num_elements;
        double dlow, dhigh, dcur_low, dcur_high;
        const uint64_t *uint64, p, q, low, high;
-       uint64_t tmp_uint64, cur_low, cur_high, cur_p, cur_q;
+       uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q;
        const uint32_t *opts;
        const int32_t *int32;
-       uint32_t key, o;
-       unsigned int num_devices, i;
+       uint32_t key, o, cur_mq, mq;
+       uint64_t cur_mqflags, mqflags;
+       unsigned int num_devices, i, j;
        char *tmp_str, *s, c;
        const char **stropts;
 
@@ -625,6 +626,48 @@ void show_dev_detail(void)
                        }
                        g_variant_unref(gvar_list);
 
+               } else if (srci->datatype == SR_T_MQLIST) {
+                       printf("    %s: ", srci->id);
+                       if (maybe_config_get(driver, sdi, channel_group, key,
+                                       &gvar) == SR_OK
+                                       && g_variant_is_of_type(gvar, G_VARIANT_TYPE_ARRAY)
+                                       && g_variant_n_children(gvar) == 1) {
+                               element = g_variant_get_child_value(gvar, 0);
+                               g_variant_get(element, "(ut)", &cur_mq, &cur_mqflags);
+                               g_variant_unref(element);
+                               g_variant_unref(gvar);
+                       } else
+                               cur_mq = cur_mqflags = 0;
+
+                       if (maybe_config_list(driver, sdi, channel_group,
+                                       key, &gvar_list) != SR_OK) {
+                               printf("\n");
+                               continue;
+                       }
+                       printf(" - supported measurements:\n");
+                       num_elements = g_variant_n_children(gvar_list);
+                       for (i = 0; i < num_elements; i++) {
+                               printf("      ");
+                               gvar = g_variant_get_child_value(gvar_list, i);
+                               g_variant_get(gvar, "(ut)", &mq, &mqflags);
+                               if ((srmqi = sr_key_info_get(SR_KEY_MQ, mq)))
+                                       printf("%s", srmqi->id);
+                               else
+                                       printf("%d", mq);
+                               for (j = 0, mask = 1; j < 32; j++, mask <<= 1) {
+                                       if (!(mqflags & mask))
+                                               continue;
+                                       if ((srmqfi = sr_key_info_get(SR_KEY_MQFLAGS, mqflags & mask)))
+                                               printf("/%s", srmqfi->id);
+                                       else
+                                               printf("/%ld", mqflags & mask);
+                               }
+                               if (mq == cur_mq && mqflags == cur_mqflags)
+                                       printf(" (current)");
+                               printf("\n");
+                       }
+                       g_variant_unref(gvar_list);
+
                } else {
 
                        /* Everything else */