]> sigrok.org Git - sigrok-cli.git/blob - show.c
e20705833a2d41a40bec65ddd45898c3e15e3665
[sigrok-cli.git] / show.c
1 /*
2  * This file is part of the sigrok-cli project.
3  *
4  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <config.h>
21 #include <glib.h>
22 #include <string.h>
23 #include "sigrok-cli.h"
24
25 static gint sort_inputs(gconstpointer a, gconstpointer b)
26 {
27         return strcmp(sr_input_id_get((struct sr_input_module *)a),
28                         sr_input_id_get((struct sr_input_module *)b));
29 }
30
31 static gint sort_outputs(gconstpointer a, gconstpointer b)
32 {
33         return strcmp(sr_output_id_get((struct sr_output_module *)a),
34                         sr_output_id_get((struct sr_output_module *)b));
35 }
36
37 static gint sort_transforms(gconstpointer a, gconstpointer b)
38 {
39         return strcmp(sr_transform_id_get((struct sr_transform_module *)a),
40                         sr_transform_id_get((struct sr_transform_module *)b));
41 }
42
43 static gint sort_drivers(gconstpointer a, gconstpointer b)
44 {
45         const struct sr_dev_driver *sdda = a, *sddb = b;
46
47         return strcmp(sdda->name, sddb->name);
48 }
49
50 #ifdef HAVE_SRD
51 static gint sort_pds(gconstpointer a, gconstpointer b)
52 {
53         const struct srd_decoder *sda = a, *sdb = b;
54
55         return strcmp(sda->id, sdb->id);
56 }
57 #endif
58
59 void show_version(void)
60 {
61         struct sr_dev_driver **drivers, *driver;
62         const struct sr_input_module **inputs, *input;
63         const struct sr_output_module **outputs, *output;
64         const struct sr_transform_module **transforms, *transform;
65         const GSList *l;
66         GSList *sl;
67         int i;
68 #ifdef HAVE_SRD
69         struct srd_decoder *dec;
70 #endif
71
72         printf("sigrok-cli %s\n\n", SC_PACKAGE_VERSION_STRING);
73
74         printf("Using libsigrok %s (lib version %s).\n",
75                sr_package_version_string_get(), sr_lib_version_string_get());
76 #ifdef HAVE_SRD
77         printf("Using libsigrokdecode %s (lib version %s).\n\n",
78                srd_package_version_string_get(), srd_lib_version_string_get());
79 #endif
80
81         printf("Supported hardware drivers:\n");
82         drivers = sr_driver_list(sr_ctx);
83         for (sl = NULL, i = 0; drivers[i]; i++)
84                 sl = g_slist_append(sl, drivers[i]);
85         sl = g_slist_sort(sl, sort_drivers);
86         for (l = sl; l; l = l->next) {
87                 driver = l->data;
88                 printf("  %-20s %s\n", driver->name, driver->longname);
89         }
90         printf("\n");
91         g_slist_free(sl);
92
93         printf("Supported input formats:\n");
94         inputs = sr_input_list();
95         for (sl = NULL, i = 0; inputs[i]; i++)
96                 sl = g_slist_append(sl, (gpointer)inputs[i]);
97         sl = g_slist_sort(sl, sort_inputs);
98         for (l = sl; l; l = l->next) {
99                 input = l->data;
100                 printf("  %-20s %s\n", sr_input_id_get(input),
101                                 sr_input_description_get(input));
102         }
103         printf("\n");
104         g_slist_free(sl);
105
106         printf("Supported output formats:\n");
107         outputs = sr_output_list();
108         for (sl = NULL, i = 0; outputs[i]; i++)
109                 sl = g_slist_append(sl, (gpointer)outputs[i]);
110         sl = g_slist_sort(sl, sort_outputs);
111         for (l = sl; l; l = l->next) {
112                 output = l->data;
113                 printf("  %-20s %s\n", sr_output_id_get(output),
114                                 sr_output_description_get(output));
115         }
116         printf("\n");
117         g_slist_free(sl);
118
119         printf("Supported transform modules:\n");
120         transforms = sr_transform_list();
121         for (sl = NULL, i = 0; transforms[i]; i++)
122                 sl = g_slist_append(sl, (gpointer)transforms[i]);
123         sl = g_slist_sort(sl, sort_transforms);
124         for (l = sl; l; l = l->next) {
125                 transform = l->data;
126                 printf("  %-20s %s\n", sr_transform_id_get(transform),
127                                 sr_transform_description_get(transform));
128         }
129         printf("\n");
130         g_slist_free(sl);
131
132 #ifdef HAVE_SRD
133         if (srd_init(NULL) == SRD_OK) {
134                 printf("Supported protocol decoders:\n");
135                 srd_decoder_load_all();
136                 sl = g_slist_copy((GSList *)srd_decoder_list());
137                 sl = g_slist_sort(sl, sort_pds);
138                 for (l = sl; l; l = l->next) {
139                         dec = l->data;
140                         printf("  %-20s %s\n", dec->id, dec->longname);
141                         /* Print protocol description upon "-l 3" or higher. */
142                         if (opt_loglevel >= SR_LOG_INFO)
143                                 printf("  %-20s %s\n", "", dec->desc);
144                 }
145                 g_slist_free(sl);
146                 srd_exit();
147         }
148         printf("\n");
149 #endif
150 }
151
152 static gint sort_channels(gconstpointer a, gconstpointer b)
153 {
154         const struct sr_channel *pa = a, *pb = b;
155
156         return pa->index - pb->index;
157 }
158
159 static void print_dev_line(const struct sr_dev_inst *sdi)
160 {
161         struct sr_channel *ch;
162         GSList *sl, *l, *channels;
163         GString *s;
164         GVariant *gvar;
165         struct sr_dev_driver *driver;
166         const char *vendor, *model, *version;
167
168         driver = sr_dev_inst_driver_get(sdi);
169         vendor = sr_dev_inst_vendor_get(sdi);
170         model = sr_dev_inst_model_get(sdi);
171         version = sr_dev_inst_version_get(sdi);
172         channels = sr_dev_inst_channels_get(sdi);
173
174         s = g_string_sized_new(128);
175         g_string_assign(s, driver->name);
176         if (maybe_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
177                 g_string_append(s, ":conn=");
178                 g_string_append(s, g_variant_get_string(gvar, NULL));
179                 g_variant_unref(gvar);
180         }
181         g_string_append(s, " - ");
182         if (vendor && vendor[0])
183                 g_string_append_printf(s, "%s ", vendor);
184         if (model && model[0])
185                 g_string_append_printf(s, "%s ", model);
186         if (version && version[0])
187                 g_string_append_printf(s, "%s ", version);
188         if (channels) {
189                 if (g_slist_length(channels) == 1) {
190                         ch = channels->data;
191                         g_string_append_printf(s, "with 1 channel: %s", ch->name);
192                 } else {
193                         sl = g_slist_sort(g_slist_copy(channels), sort_channels);
194                         g_string_append_printf(s, "with %d channels:", g_slist_length(sl));
195                         for (l = sl; l; l = l->next) {
196                                 ch = l->data;
197                                 g_string_append_printf(s, " %s", ch->name);
198                         }
199                         g_slist_free(sl);
200                 }
201         }
202         g_string_append_printf(s, "\n");
203         printf("%s", s->str);
204         g_string_free(s, TRUE);
205
206 }
207
208 void show_dev_list(void)
209 {
210         struct sr_dev_inst *sdi;
211         GSList *devices, *l;
212
213         if (!(devices = device_scan()))
214                 return;
215
216         printf("The following devices were found:\n");
217         for (l = devices; l; l = l->next) {
218                 sdi = l->data;
219                 print_dev_line(sdi);
220         }
221         g_slist_free(devices);
222
223 }
224
225 void show_drv_detail(struct sr_dev_driver *driver)
226 {
227         const struct sr_key_info *srci;
228         GVariant *gvar_opts;
229         const uint32_t *opts;
230         gsize num_elements, i;
231
232         if (sr_config_list(driver, NULL, NULL, SR_CONF_DEVICE_OPTIONS,
233                         &gvar_opts) == SR_OK) {
234                 opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
235                                 sizeof(uint32_t));
236                 if (num_elements) {
237                         printf("Driver functions:\n");
238                         for (i = 0; i < num_elements; i++) {
239                                 if (!(srci = sr_key_info_get(SR_KEY_CONFIG, opts[i] & SR_CONF_MASK)))
240                                         continue;
241                                 printf("    %s\n", srci->name);
242                         }
243                 }
244                 g_variant_unref(gvar_opts);
245         }
246
247         if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
248                         &gvar_opts) == SR_OK) {
249                 opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
250                                 sizeof(uint32_t));
251                 if (num_elements) {
252                         printf("Scan options:\n");
253                         for (i = 0; i < num_elements; i++) {
254                                 if (!(srci = sr_key_info_get(SR_KEY_CONFIG, opts[i] & SR_CONF_MASK)))
255                                         continue;
256                                 printf("    %s\n", srci->id);
257                         }
258                 }
259                 g_variant_unref(gvar_opts);
260         }
261 }
262
263 void show_dev_detail(void)
264 {
265         struct sr_dev_driver *driver_from_opt, *driver;
266         struct sr_dev_inst *sdi;
267         const struct sr_key_info *srci, *srmqi, *srmqfi;
268         struct sr_channel *ch;
269         struct sr_channel_group *channel_group, *cg;
270         GSList *devices, *cgl, *chl, *channel_groups;
271         GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
272         gsize num_opts, num_elements;
273         double dlow, dhigh, dcur_low, dcur_high;
274         const uint64_t *uint64, p, q, low, high;
275         uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q;
276         const uint32_t *opts;
277         const int32_t *int32;
278         uint32_t key, o, cur_mq, mq;
279         uint64_t cur_mqflags, mqflags;
280         unsigned int num_devices, i, j;
281         char *tmp_str, *s, c;
282         const char **stropts;
283
284         if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
285                 /* A driver was specified, report driver-wide options now. */
286                 show_drv_detail(driver_from_opt);
287         }
288
289         if (!(devices = device_scan())) {
290                 g_critical("No devices found.");
291                 return;
292         }
293
294         num_devices = g_slist_length(devices);
295         if (num_devices > 1) {
296                 g_critical("%d devices found. Use --scan to show them, "
297                                 "and select one to show.", num_devices);
298                 return;
299         }
300
301         sdi = devices->data;
302         g_slist_free(devices);
303         print_dev_line(sdi);
304
305         driver = sr_dev_inst_driver_get(sdi);
306         channel_groups = sr_dev_inst_channel_groups_get(sdi);
307
308         if (sr_dev_open(sdi) != SR_OK) {
309                 g_critical("Failed to open device.");
310                 return;
311         }
312
313         /*
314          * Selected channels and channel group may affect which options are
315          * returned, or which values for them.
316          */
317         select_channels(sdi);
318         channel_group = select_channel_group(sdi);
319
320         if (sr_config_list(driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS,
321                         &gvar_opts) != SR_OK)
322                 /* Driver supports no device instance options. */
323                 return;
324
325         if (channel_groups) {
326                 printf("Channel groups:\n");
327                 for (cgl = channel_groups; cgl; cgl = cgl->next) {
328                         cg = cgl->data;
329                         printf("    %s: channel%s", cg->name,
330                                         g_slist_length(cg->channels) > 1 ? "s" : "");
331                         for (chl = cg->channels; chl; chl = chl->next) {
332                                 ch = chl->data;
333                                 printf(" %s", ch->name);
334                         }
335                         printf("\n");
336                 }
337         }
338
339         printf("Supported configuration options");
340         if (channel_groups) {
341                 if (!channel_group)
342                         printf(" across all channel groups");
343                 else
344                         printf(" on channel group %s", channel_group->name);
345         }
346         printf(":\n");
347         opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
348         for (o = 0; o < num_opts; o++) {
349                 key = opts[o] & SR_CONF_MASK;
350                 if (!(srci = sr_key_info_get(SR_KEY_CONFIG, key)))
351                         continue;
352
353                 if (key == SR_CONF_TRIGGER_MATCH) {
354                         if (maybe_config_list(driver, sdi, channel_group, key,
355                                         &gvar_list) != SR_OK) {
356                                 printf("\n");
357                                 continue;
358                         }
359                         int32 = g_variant_get_fixed_array(gvar_list,
360                                         &num_elements, sizeof(int32_t));
361                         printf("    Supported triggers: ");
362                         for (i = 0; i < num_elements; i++) {
363                                 switch (int32[i]) {
364                                 case SR_TRIGGER_ZERO:
365                                         c = '0';
366                                         break;
367                                 case SR_TRIGGER_ONE:
368                                         c = '1';
369                                         break;
370                                 case SR_TRIGGER_RISING:
371                                         c = 'r';
372                                         break;
373                                 case SR_TRIGGER_FALLING:
374                                         c = 'f';
375                                         break;
376                                 case SR_TRIGGER_EDGE:
377                                         c = 'e';
378                                         break;
379                                 case SR_TRIGGER_OVER:
380                                         c = 'o';
381                                         break;
382                                 case SR_TRIGGER_UNDER:
383                                         c = 'u';
384                                         break;
385                                 default:
386                                         c = 0;
387                                         break;
388                                 }
389                                 if (c)
390                                         printf("%c ", c);
391                         }
392                         printf("\n");
393                         g_variant_unref(gvar_list);
394
395                 } else if (key == SR_CONF_LIMIT_SAMPLES
396                                 && config_key_has_cap(driver, sdi, NULL, key, SR_CONF_LIST)) {
397                         /*
398                          * If implemented in config_list(), this denotes the
399                          * maximum number of samples a device can send. This
400                          * really applies only to logic analyzers, and then
401                          * only to those that don't support compression, or
402                          * have it turned off by default. The values returned
403                          * are the low/high limits.
404                          */
405                         if (sr_config_list(driver, sdi, channel_group, key,
406                                         &gvar) == SR_OK) {
407                                 g_variant_get(gvar, "(tt)", &low, &high);
408                                 g_variant_unref(gvar);
409                                 printf("    Maximum number of samples: %"PRIu64"\n", high);
410                         }
411
412                 } else if (key == SR_CONF_SAMPLERATE) {
413                         /* Supported samplerates */
414                         printf("    %s", srci->id);
415                         if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
416                                         &gvar_dict) != SR_OK) {
417                                 printf("\n");
418                                 continue;
419                         }
420                         if ((gvar_list = g_variant_lookup_value(gvar_dict,
421                                         "samplerates", G_VARIANT_TYPE("at")))) {
422                                 uint64 = g_variant_get_fixed_array(gvar_list,
423                                                 &num_elements, sizeof(uint64_t));
424                                 printf(" - supported samplerates:\n");
425                                 for (i = 0; i < num_elements; i++) {
426                                         if (!(s = sr_samplerate_string(uint64[i])))
427                                                 continue;
428                                         printf("      %s\n", s);
429                                         g_free(s);
430                                 }
431                                 g_variant_unref(gvar_list);
432                         } else if ((gvar_list = g_variant_lookup_value(gvar_dict,
433                                         "samplerate-steps", G_VARIANT_TYPE("at")))) {
434                                 uint64 = g_variant_get_fixed_array(gvar_list,
435                                                 &num_elements, sizeof(uint64_t));
436                                 /* low */
437                                 if (!(s = sr_samplerate_string(uint64[0])))
438                                         continue;
439                                 printf(" (%s", s);
440                                 g_free(s);
441                                 /* high */
442                                 if (!(s = sr_samplerate_string(uint64[1])))
443                                         continue;
444                                 printf(" - %s", s);
445                                 g_free(s);
446                                 /* step */
447                                 if (!(s = sr_samplerate_string(uint64[2])))
448                                         continue;
449                                 printf(" in steps of %s)\n", s);
450                                 g_free(s);
451                                 g_variant_unref(gvar_list);
452                         }
453                         g_variant_unref(gvar_dict);
454
455                 } else if (srci->datatype == SR_T_UINT64) {
456                         printf("    %s: ", srci->id);
457                         gvar = NULL;
458                         if (maybe_config_get(driver, sdi, channel_group, key,
459                                         &gvar) == SR_OK) {
460                                 tmp_uint64 = g_variant_get_uint64(gvar);
461                                 g_variant_unref(gvar);
462                         } else
463                                 tmp_uint64 = 0;
464                         if (maybe_config_list(driver, sdi, channel_group,
465                                         key, &gvar_list) != SR_OK) {
466                                 if (gvar) {
467                                         /* Can't list it, but we have a value to show. */
468                                         printf("%"PRIu64" (current)", tmp_uint64);
469                                 }
470                                 printf("\n");
471                                 continue;
472                         }
473                         uint64 = g_variant_get_fixed_array(gvar_list,
474                                         &num_elements, sizeof(uint64_t));
475                         printf(" - supported values:\n");
476                         for (i = 0; i < num_elements; i++) {
477                                 printf("      %"PRIu64, uint64[i]);
478                                 if (gvar && tmp_uint64 == uint64[i])
479                                         printf(" (current)");
480                                 printf("\n");
481                         }
482                         g_variant_unref(gvar_list);
483
484                 } else if (srci->datatype == SR_T_STRING) {
485                         printf("    %s: ", srci->id);
486                         if (maybe_config_get(driver, sdi, channel_group, key,
487                                         &gvar) == SR_OK) {
488                                 tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
489                                 g_variant_unref(gvar);
490                         } else
491                                 tmp_str = NULL;
492
493                         if (maybe_config_list(driver, sdi, channel_group, key,
494                                         &gvar) != SR_OK) {
495                                 if (tmp_str) {
496                                         /* Can't list it, but we have a value to show. */
497                                         printf("%s (current)", tmp_str);
498                                 }
499                                 printf("\n");
500                                 g_free(tmp_str);
501                                 continue;
502                         }
503
504                         stropts = g_variant_get_strv(gvar, &num_elements);
505                         for (i = 0; i < num_elements; i++) {
506                                 if (i)
507                                         printf(", ");
508                                 printf("%s", stropts[i]);
509                                 if (tmp_str && !strcmp(tmp_str, stropts[i]))
510                                         printf(" (current)");
511                         }
512                         printf("\n");
513                         g_free(stropts);
514                         g_free(tmp_str);
515                         g_variant_unref(gvar);
516
517                 } else if (srci->datatype == SR_T_UINT64_RANGE) {
518                         printf("    %s: ", srci->id);
519                         if (maybe_config_list(driver, sdi, channel_group, key,
520                                         &gvar_list) != SR_OK) {
521                                 printf("\n");
522                                 continue;
523                         }
524
525                         if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
526                                 g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
527                                 g_variant_unref(gvar);
528                         } else {
529                                 cur_low = 0;
530                                 cur_high = 0;
531                         }
532
533                         num_elements = g_variant_n_children(gvar_list);
534                         for (i = 0; i < num_elements; i++) {
535                                 gvar = g_variant_get_child_value(gvar_list, i);
536                                 g_variant_get(gvar, "(tt)", &low, &high);
537                                 g_variant_unref(gvar);
538                                 if (i)
539                                         printf(", ");
540                                 printf("%"PRIu64"-%"PRIu64, low, high);
541                                 if (low == cur_low && high == cur_high)
542                                         printf(" (current)");
543                         }
544                         printf("\n");
545                         g_variant_unref(gvar_list);
546
547                 } else if (srci->datatype == SR_T_BOOL) {
548                         printf("    %s: ", srci->id);
549                         if (maybe_config_get(driver, sdi, channel_group, key,
550                                         &gvar) == SR_OK) {
551                                 if (g_variant_get_boolean(gvar))
552                                         printf("on (current), off\n");
553                                 else
554                                         printf("on, off (current)\n");
555                                 g_variant_unref(gvar);
556                         } else
557                                 printf("on, off\n");
558
559                 } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
560                         printf("    %s: ", srci->id);
561                         if (maybe_config_list(driver, sdi, channel_group, key,
562                                         &gvar_list) != SR_OK) {
563                                 printf("\n");
564                                 continue;
565                         }
566
567                         if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
568                                 g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
569                                 g_variant_unref(gvar);
570                         } else {
571                                 dcur_low = 0;
572                                 dcur_high = 0;
573                         }
574
575                         num_elements = g_variant_n_children(gvar_list);
576                         for (i = 0; i < num_elements; i++) {
577                                 gvar = g_variant_get_child_value(gvar_list, i);
578                                 g_variant_get(gvar, "(dd)", &dlow, &dhigh);
579                                 g_variant_unref(gvar);
580                                 if (i)
581                                         printf(", ");
582                                 printf("%.1f-%.1f", dlow, dhigh);
583                                 if (dlow == dcur_low && dhigh == dcur_high)
584                                         printf(" (current)");
585                         }
586                         printf("\n");
587                         g_variant_unref(gvar_list);
588
589                 } else if (srci->datatype == SR_T_FLOAT) {
590                         printf("    %s: ", srci->id);
591                         if (maybe_config_get(driver, sdi, channel_group, key,
592                                         &gvar) == SR_OK) {
593                                 printf("%f\n", g_variant_get_double(gvar));
594                                 g_variant_unref(gvar);
595                         } else
596                                 printf("\n");
597
598                 } else if (srci->datatype == SR_T_RATIONAL_PERIOD
599                                 || srci->datatype == SR_T_RATIONAL_VOLT) {
600                         printf("    %s", srci->id);
601                         if (maybe_config_get(driver, sdi, channel_group, key,
602                                         &gvar) == SR_OK) {
603                                 g_variant_get(gvar, "(tt)", &cur_p, &cur_q);
604                                 g_variant_unref(gvar);
605                         } else
606                                 cur_p = cur_q = 0;
607
608                         if (maybe_config_list(driver, sdi, channel_group,
609                                         key, &gvar_list) != SR_OK) {
610                                 printf("\n");
611                                 continue;
612                         }
613                         printf(" - supported values:\n");
614                         num_elements = g_variant_n_children(gvar_list);
615                         for (i = 0; i < num_elements; i++) {
616                                 gvar = g_variant_get_child_value(gvar_list, i);
617                                 g_variant_get(gvar, "(tt)", &p, &q);
618                                 if (srci->datatype == SR_T_RATIONAL_PERIOD)
619                                         s = sr_period_string(p * q);
620                                 else
621                                         s = sr_voltage_string(p, q);
622                                 printf("      %s", s);
623                                 g_free(s);
624                                 if (p == cur_p && q == cur_q)
625                                         printf(" (current)");
626                                 printf("\n");
627                         }
628                         g_variant_unref(gvar_list);
629
630                 } else if (srci->datatype == SR_T_MQ) {
631                         printf("    %s: ", srci->id);
632                         if (maybe_config_get(driver, sdi, channel_group, key,
633                                         &gvar) == SR_OK
634                                         && g_variant_is_of_type(gvar, G_VARIANT_TYPE_TUPLE)
635                                         && g_variant_n_children(gvar) == 2) {
636                                 g_variant_get(gvar, "(ut)", &cur_mq, &cur_mqflags);
637                                 g_variant_unref(gvar);
638                         } else
639                                 cur_mq = cur_mqflags = 0;
640
641                         if (maybe_config_list(driver, sdi, channel_group,
642                                         key, &gvar_list) != SR_OK) {
643                                 printf("\n");
644                                 continue;
645                         }
646                         printf(" - supported measurements:\n");
647                         num_elements = g_variant_n_children(gvar_list);
648                         for (i = 0; i < num_elements; i++) {
649                                 printf("      ");
650                                 gvar = g_variant_get_child_value(gvar_list, i);
651                                 g_variant_get(gvar, "(ut)", &mq, &mqflags);
652                                 if ((srmqi = sr_key_info_get(SR_KEY_MQ, mq)))
653                                         printf("%s", srmqi->id);
654                                 else
655                                         printf("%d", mq);
656                                 for (j = 0, mask = 1; j < 32; j++, mask <<= 1) {
657                                         if (!(mqflags & mask))
658                                                 continue;
659                                         if ((srmqfi = sr_key_info_get(SR_KEY_MQFLAGS, mqflags & mask)))
660                                                 printf("/%s", srmqfi->id);
661                                         else
662                                                 printf("/%" PRIu64, mqflags & mask);
663                                 }
664                                 if (mq == cur_mq && mqflags == cur_mqflags)
665                                         printf(" (current)");
666                                 printf("\n");
667                         }
668                         g_variant_unref(gvar_list);
669
670                 } else {
671
672                         /* Everything else */
673                         printf("    %s\n", srci->id);
674                 }
675         }
676         g_variant_unref(gvar_opts);
677
678         sr_dev_close(sdi);
679
680 }
681
682 #ifdef HAVE_SRD
683 void show_pd_detail(void)
684 {
685         struct srd_decoder *dec;
686         struct srd_decoder_option *o;
687         struct srd_channel *pdch;
688         struct srd_decoder_annotation_row *r;
689         GSList *l, *ll, *ol;
690         int idx;
691         char **pdtokens, **pdtok, *optsep, **ann, *val, *doc;
692
693         pdtokens = g_strsplit(opt_pds, ",", -1);
694         for (pdtok = pdtokens; *pdtok; pdtok++) {
695                 /* Strip options. */
696                 if ((optsep = strchr(*pdtok, ':')))
697                         *optsep = '\0';
698                 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
699                         g_critical("Protocol decoder %s not found.", *pdtok);
700                         return;
701                 }
702                 printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
703                                 dec->id, dec->name, dec->longname, dec->desc);
704                 printf("License: %s\n", dec->license);
705                 printf("Annotation classes:\n");
706                 if (dec->annotations) {
707                         for (l = dec->annotations; l; l = l->next) {
708                                 ann = l->data;
709                                 printf("- %s: %s\n", ann[0], ann[1]);
710                         }
711                 } else {
712                         printf("None.\n");
713                 }
714                 printf("Annotation rows:\n");
715                 if (dec->annotation_rows) {
716                         for (l = dec->annotation_rows; l; l = l->next) {
717                                 r = l->data;
718                                 printf("- %s (%s): ", r->id, r->desc);
719                                 for (ll = r->ann_classes; ll; ll = ll->next) {
720                                         idx = GPOINTER_TO_INT(ll->data);
721                                         ann = g_slist_nth_data(dec->annotations, idx);
722                                         printf("%s", ann[0]);
723                                         if (ll->next)
724                                                 printf(", ");
725                                 }
726                                 printf("\n");
727                         }
728                 } else {
729                         printf("None.\n");
730                 }
731                 printf("Required channels:\n");
732                 if (dec->channels) {
733                         for (l = dec->channels; l; l = l->next) {
734                                 pdch = l->data;
735                                 printf("- %s (%s): %s\n",
736                                        pdch->id, pdch->name, pdch->desc);
737                         }
738                 } else {
739                         printf("None.\n");
740                 }
741                 printf("Optional channels:\n");
742                 if (dec->opt_channels) {
743                         for (l = dec->opt_channels; l; l = l->next) {
744                                 pdch = l->data;
745                                 printf("- %s (%s): %s\n",
746                                        pdch->id, pdch->name, pdch->desc);
747                         }
748                 } else {
749                         printf("None.\n");
750                 }
751                 printf("Options:\n");
752                 if (dec->options) {
753                         for (l = dec->options; l; l = l->next) {
754                                 o = l->data;
755                                 printf("- %s: %s (", o->id, o->desc);
756                                 for (ol = o->values; ol; ol = ol->next) {
757                                         val = g_variant_print(ol->data, FALSE);
758                                         printf("%s, ", val);
759                                         g_free(val);
760                                 }
761                                 val = g_variant_print(o->def, FALSE);
762                                 printf("default %s)\n", val);
763                                 g_free(val);
764                         }
765                 } else {
766                         printf("None.\n");
767                 }
768                 if ((doc = srd_decoder_doc_get(dec))) {
769                         printf("Documentation:\n%s\n",
770                                doc[0] == '\n' ? doc + 1 : doc);
771                         g_free(doc);
772                 }
773         }
774
775         g_strfreev(pdtokens);
776 }
777 #endif
778
779 void show_input(void)
780 {
781         const struct sr_input_module *imod;
782         const struct sr_option **opts;
783         GSList *l;
784         int i;
785         char *s, **tok;
786
787         tok = g_strsplit(opt_input_format, ":", 0);
788         if (!tok[0] || !(imod = sr_input_find(tok[0])))
789                 g_critical("Input module '%s' not found.", opt_input_format);
790
791         printf("ID: %s\nName: %s\n", sr_input_id_get(imod),
792                         sr_input_name_get(imod));
793         printf("Description: %s\n", sr_input_description_get(imod));
794         if ((opts = sr_input_options_get(imod))) {
795                 printf("Options:\n");
796                 for (i = 0; opts[i]; i++) {
797                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
798                         if (opts[i]->def) {
799                                 s = g_variant_print(opts[i]->def, FALSE);
800                                 printf(" (default %s", s);
801                                 g_free(s);
802                                 if (opts[i]->values) {
803                                         printf(", possible values ");
804                                         for (l = opts[i]->values; l; l = l->next) {
805                                                 s = g_variant_print((GVariant *)l->data, FALSE);
806                                                 printf("%s%s", s, l->next ? ", " : "");
807                                                 g_free(s);
808                                         }
809                                 }
810                                 printf(")");
811                         }
812                         printf("\n");
813                 }
814                 sr_input_options_free(opts);
815         }
816         g_strfreev(tok);
817 }
818
819 void show_output(void)
820 {
821         const struct sr_output_module *omod;
822         const struct sr_option **opts;
823         GSList *l;
824         int i;
825         char *s, **tok;
826
827         tok = g_strsplit(opt_output_format, ":", 0);
828         if (!tok[0] || !(omod = sr_output_find(tok[0])))
829                 g_critical("Output module '%s' not found.", opt_output_format);
830
831         printf("ID: %s\nName: %s\n", sr_output_id_get(omod),
832                         sr_output_name_get(omod));
833         printf("Description: %s\n", sr_output_description_get(omod));
834         if ((opts = sr_output_options_get(omod))) {
835                 printf("Options:\n");
836                 for (i = 0; opts[i]; i++) {
837                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
838                         if (opts[i]->def) {
839                                 s = g_variant_print(opts[i]->def, FALSE);
840                                 printf(" (default %s", s);
841                                 g_free(s);
842                                 if (opts[i]->values) {
843                                         printf(", possible values ");
844                                         for (l = opts[i]->values; l; l = l->next) {
845                                                 s = g_variant_print((GVariant *)l->data, FALSE);
846                                                 printf("%s%s", s, l->next ? ", " : "");
847                                                 g_free(s);
848                                         }
849                                 }
850                                 printf(")");
851                         }
852                         printf("\n");
853                 }
854                 sr_output_options_free(opts);
855         }
856         g_strfreev(tok);
857 }
858
859 void show_transform(void)
860 {
861         const struct sr_transform_module *tmod;
862         const struct sr_option **opts;
863         GSList *l;
864         int i;
865         char *s, **tok;
866
867         tok = g_strsplit(opt_transform_module, ":", 0);
868         if (!tok[0] || !(tmod = sr_transform_find(tok[0])))
869                 g_critical("Transform module '%s' not found.", opt_transform_module);
870
871         printf("ID: %s\nName: %s\n", sr_transform_id_get(tmod),
872                         sr_transform_name_get(tmod));
873         printf("Description: %s\n", sr_transform_description_get(tmod));
874         if ((opts = sr_transform_options_get(tmod))) {
875                 printf("Options:\n");
876                 for (i = 0; opts[i]; i++) {
877                         printf("  %s: %s", opts[i]->id, opts[i]->desc);
878                         if (opts[i]->def) {
879                                 s = g_variant_print(opts[i]->def, FALSE);
880                                 printf(" (default %s", s);
881                                 g_free(s);
882                                 if (opts[i]->values) {
883                                         printf(", possible values ");
884                                         for (l = opts[i]->values; l; l = l->next) {
885                                                 s = g_variant_print((GVariant *)l->data, FALSE);
886                                                 printf("%s%s", s, l->next ? ", " : "");
887                                                 g_free(s);
888                                         }
889                                 }
890                                 printf(")");
891                         }
892                         printf("\n");
893                 }
894                 sr_transform_options_free(opts);
895         }
896         g_strfreev(tok);
897 }