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