2 * This file is part of the sigrok-cli project.
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
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.
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.
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/>.
23 #include "sigrok-cli.h"
25 static gint sort_inputs(gconstpointer a, gconstpointer b)
27 return strcmp(sr_input_id_get((struct sr_input_module *)a),
28 sr_input_id_get((struct sr_input_module *)b));
31 static gint sort_outputs(gconstpointer a, gconstpointer b)
33 return strcmp(sr_output_id_get((struct sr_output_module *)a),
34 sr_output_id_get((struct sr_output_module *)b));
37 static gint sort_transforms(gconstpointer a, gconstpointer b)
39 return strcmp(sr_transform_id_get((struct sr_transform_module *)a),
40 sr_transform_id_get((struct sr_transform_module *)b));
43 static gint sort_drivers(gconstpointer a, gconstpointer b)
45 const struct sr_dev_driver *sdda = a, *sddb = b;
47 return strcmp(sdda->name, sddb->name);
51 static gint sort_pds(gconstpointer a, gconstpointer b)
53 const struct srd_decoder *sda = a, *sdb = b;
55 return strcmp(sda->id, sdb->id);
59 void show_version(void)
62 GSList *l, *l_orig, *m;
64 const char *lib, *version;
66 printf("sigrok-cli %s\n\n", SC_PACKAGE_VERSION_STRING);
68 printf("Libraries and features:\n");
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());
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) {
80 version = m->next->data;
81 g_string_append_printf(s, " - %s %s\n", lib, version);
82 g_slist_free_full(m, g_free);
85 s->str[s->len - 1] = '\0';
86 printf("%s\n", s->str);
87 g_string_free(s, TRUE);
89 str = sr_buildinfo_host_get();
90 printf(" - Host: %s.\n", str);
93 str = sr_buildinfo_scpi_backends_get();
94 printf(" - SCPI backends: %s.\n", str);
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());
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) {
108 version = m->next->data;
109 g_string_append_printf(s, " - %s %s\n", lib, version);
110 g_slist_free_full(m, g_free);
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);
117 str = srd_buildinfo_host_get();
118 printf(" - Host: %s.\n", str);
123 void show_supported(void)
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;
133 struct srd_decoder *dec;
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) {
143 printf(" %-20s %s\n", driver->name, driver->longname);
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) {
155 printf(" %-20s %s\n", sr_input_id_get(input),
156 sr_input_description_get(input));
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) {
168 printf(" %-20s %s\n", sr_output_id_get(output),
169 sr_output_description_get(output));
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) {
181 printf(" %-20s %s\n", sr_transform_id_get(transform),
182 sr_transform_description_get(transform));
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) {
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);
207 void show_supported_wiki(void)
210 printf("Error, libsigrokdecode support not compiled in.");
214 struct srd_decoder *dec;
216 if (srd_init(NULL) != SRD_OK)
219 srd_decoder_load_all();
220 sl = g_slist_copy((GSList *)srd_decoder_list());
221 sl = g_slist_sort(sl, sort_pds);
223 printf("== Supported protocol decoders ==\n\n");
225 printf("<!-- Generated via sigrok-cli --list-supported-wiki. -->\n\n");
227 printf("Number of currently supported protocol decoders: "
228 "'''%d'''.\n\n", g_slist_length(sl));
230 printf("{| border=\"0\" style=\"font-size: smaller\" "
231 "class=\"alternategrey sortable sigroktable\"\n"
232 "|-\n!Protocol\n!Tags\n!Input IDs\n!Output IDs\n!Status\n"
233 "!Full name\n!Description\n\n");
235 for (l = sl; l; l = l->next) {
238 GString *tags = g_string_new(NULL);
239 for (GSList *t = dec->tags; t; t = t->next)
240 g_string_append_printf(tags, "%s, ", (char *)t->data);
242 g_string_truncate(tags, tags->len - 2);
244 GString *in = g_string_new(NULL);
245 for (GSList *t = dec->inputs; t; t = t->next)
246 g_string_append_printf(in, "%s, ", (char *)t->data);
248 g_string_append_printf(in, "—");
250 g_string_truncate(in, in->len - 2);
252 GString *out = g_string_new(NULL);
253 for (GSList *t = dec->outputs; t; t = t->next)
254 g_string_append_printf(out, "%s, ", (char *)t->data);
256 g_string_append_printf(out, "—");
258 g_string_truncate(out, out->len - 2);
260 printf("{{pd|%s|%s|%s|%s|%s|%s|%s|supported}}\n",
261 dec->id, dec->name, dec->longname, dec->desc,
262 tags->str, in->str, out->str);
264 g_string_free(tags, TRUE);
265 g_string_free(in, TRUE);
266 g_string_free(out, TRUE);
275 static gint sort_channels(gconstpointer a, gconstpointer b)
277 const struct sr_channel *pa = a, *pb = b;
279 return pa->index - pb->index;
282 static void print_dev_line(const struct sr_dev_inst *sdi)
284 struct sr_channel *ch;
285 GSList *sl, *l, *channels;
288 struct sr_dev_driver *driver;
289 const char *vendor, *model, *version;
291 driver = sr_dev_inst_driver_get(sdi);
292 vendor = sr_dev_inst_vendor_get(sdi);
293 model = sr_dev_inst_model_get(sdi);
294 version = sr_dev_inst_version_get(sdi);
295 channels = sr_dev_inst_channels_get(sdi);
297 s = g_string_sized_new(128);
298 g_string_assign(s, driver->name);
299 if (maybe_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
300 g_string_append(s, ":conn=");
301 g_string_append(s, g_variant_get_string(gvar, NULL));
302 g_variant_unref(gvar);
304 g_string_append(s, " - ");
305 if (vendor && vendor[0])
306 g_string_append_printf(s, "%s ", vendor);
307 if (model && model[0])
308 g_string_append_printf(s, "%s ", model);
309 if (version && version[0])
310 g_string_append_printf(s, "%s ", version);
312 if (g_slist_length(channels) == 1) {
314 g_string_append_printf(s, "with 1 channel: %s", ch->name);
316 sl = g_slist_sort(g_slist_copy(channels), sort_channels);
317 g_string_append_printf(s, "with %d channels:", g_slist_length(sl));
318 for (l = sl; l; l = l->next) {
320 g_string_append_printf(s, " %s", ch->name);
325 g_string_append_printf(s, "\n");
326 printf("%s", s->str);
327 g_string_free(s, TRUE);
331 void show_dev_list(void)
333 struct sr_dev_inst *sdi;
336 if (!(devices = device_scan()))
339 printf("The following devices were found:\n");
340 for (l = devices; l; l = l->next) {
344 g_slist_free(devices);
348 void show_drv_detail(struct sr_dev_driver *driver)
350 const struct sr_key_info *srci;
354 if ((opts = sr_dev_options(driver, NULL, NULL))) {
356 printf("Driver functions:\n");
357 for (i = 0; i < opts->len; i++) {
358 if (!(srci = sr_key_info_get(SR_KEY_CONFIG,
359 g_array_index(opts, uint32_t, i))))
361 printf(" %s\n", srci->name);
364 g_array_free(opts, TRUE);
367 if ((opts = sr_driver_scan_options_list(driver))) {
369 printf("Scan options:\n");
370 for (i = 0; i < opts->len; i++) {
371 if (!(srci = sr_key_info_get(SR_KEY_CONFIG,
372 g_array_index(opts, uint32_t, i))))
374 printf(" %s\n", srci->id);
377 g_array_free(opts, TRUE);
381 void show_dev_detail(void)
383 struct sr_dev_driver *driver_from_opt, *driver;
384 struct sr_dev_inst *sdi;
385 const struct sr_key_info *srci, *srmqi, *srmqfi;
386 struct sr_channel *ch;
387 struct sr_channel_group *channel_group, *cg;
388 GSList *devices, *cgl, *chl, *channel_groups;
389 GVariant *gvar_dict, *gvar_list, *gvar;
391 double dlow, dhigh, dcur_low, dcur_high;
392 const uint64_t *uint64;
393 uint64_t p = 0, q = 0, low = 0, high = 0;
394 uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q;
396 const int32_t *int32;
397 uint32_t key, o, cur_mq, mq;
398 uint64_t cur_mqflags, mqflags;
399 unsigned int num_devices, i, j;
400 char *tmp_str, *s, c;
401 const char **stropts;
403 const double *fltopts;
405 if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
406 /* A driver was specified, report driver-wide options now. */
407 show_drv_detail(driver_from_opt);
410 if (!(devices = device_scan())) {
411 g_critical("No devices found.");
415 num_devices = g_slist_length(devices);
416 if (num_devices > 1) {
417 g_critical("%d devices found. Use --scan to show them, "
418 "and select one to show.", num_devices);
423 g_slist_free(devices);
426 driver = sr_dev_inst_driver_get(sdi);
427 channel_groups = sr_dev_inst_channel_groups_get(sdi);
429 if (sr_dev_open(sdi) != SR_OK) {
430 g_critical("Failed to open device.");
435 * Selected channels and channel group may affect which options are
436 * returned, or which values for them.
438 select_channels(sdi);
439 channel_group = select_channel_group(sdi);
441 if (!(opts = sr_dev_options(driver, sdi, channel_group)))
442 /* Driver supports no device instance options. */
445 if (channel_groups) {
446 printf("Channel groups:\n");
447 for (cgl = channel_groups; cgl; cgl = cgl->next) {
449 printf(" %s: channel%s", cg->name,
450 g_slist_length(cg->channels) > 1 ? "s" : "");
451 for (chl = cg->channels; chl; chl = chl->next) {
453 printf(" %s", ch->name);
459 printf("Supported configuration options");
460 if (channel_groups) {
462 printf(" across all channel groups");
464 printf(" on channel group %s", channel_group->name);
467 for (o = 0; o < opts->len; o++) {
468 key = g_array_index(opts, uint32_t, o);
469 if (!(srci = sr_key_info_get(SR_KEY_CONFIG, key)))
472 if (key == SR_CONF_TRIGGER_MATCH) {
473 if (maybe_config_list(driver, sdi, channel_group, key,
474 &gvar_list) != SR_OK) {
478 int32 = g_variant_get_fixed_array(gvar_list,
479 &num_elements, sizeof(int32_t));
480 printf(" Supported triggers: ");
481 for (i = 0; i < num_elements; i++) {
483 case SR_TRIGGER_ZERO:
489 case SR_TRIGGER_RISING:
492 case SR_TRIGGER_FALLING:
495 case SR_TRIGGER_EDGE:
498 case SR_TRIGGER_OVER:
501 case SR_TRIGGER_UNDER:
512 g_variant_unref(gvar_list);
514 } else if (key == SR_CONF_LIMIT_SAMPLES
515 && (sr_dev_config_capabilities_list(sdi, NULL, key)
518 * If implemented in config_list(), this denotes the
519 * maximum number of samples a device can send. This
520 * really applies only to logic analyzers, and then
521 * only to those that don't support compression, or
522 * have it turned off by default. The values returned
523 * are the low/high limits.
525 if (sr_config_list(driver, sdi, channel_group, key,
527 g_variant_get(gvar, "(tt)", &low, &high);
528 g_variant_unref(gvar);
529 printf(" Maximum number of samples: %"PRIu64"\n", high);
532 } else if (key == SR_CONF_SAMPLERATE) {
533 /* Supported samplerates */
534 printf(" %s", srci->id);
535 if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
536 &gvar_dict) != SR_OK) {
540 if ((gvar_list = g_variant_lookup_value(gvar_dict,
541 "samplerates", G_VARIANT_TYPE("at")))) {
542 uint64 = g_variant_get_fixed_array(gvar_list,
543 &num_elements, sizeof(uint64_t));
544 printf(" - supported samplerates:\n");
545 for (i = 0; i < num_elements; i++) {
546 if (!(s = sr_samplerate_string(uint64[i])))
551 g_variant_unref(gvar_list);
552 } else if ((gvar_list = g_variant_lookup_value(gvar_dict,
553 "samplerate-steps", G_VARIANT_TYPE("at")))) {
554 uint64 = g_variant_get_fixed_array(gvar_list,
555 &num_elements, sizeof(uint64_t));
557 if (!(s = sr_samplerate_string(uint64[0])))
562 if (!(s = sr_samplerate_string(uint64[1])))
567 if (!(s = sr_samplerate_string(uint64[2])))
569 printf(" in steps of %s)\n", s);
571 g_variant_unref(gvar_list);
573 g_variant_unref(gvar_dict);
575 } else if (srci->datatype == SR_T_UINT64) {
576 printf(" %s: ", srci->id);
578 if (maybe_config_get(driver, sdi, channel_group, key,
580 tmp_uint64 = g_variant_get_uint64(gvar);
581 g_variant_unref(gvar);
584 if (maybe_config_list(driver, sdi, channel_group,
585 key, &gvar_list) != SR_OK) {
587 /* Can't list it, but we have a value to show. */
588 printf("%"PRIu64" (current)", tmp_uint64);
593 uint64 = g_variant_get_fixed_array(gvar_list,
594 &num_elements, sizeof(uint64_t));
595 printf(" - supported values:\n");
596 for (i = 0; i < num_elements; i++) {
597 printf(" %"PRIu64, uint64[i]);
598 if (gvar && tmp_uint64 == uint64[i])
599 printf(" (current)");
602 g_variant_unref(gvar_list);
604 } else if (srci->datatype == SR_T_STRING) {
605 printf(" %s: ", srci->id);
606 if (maybe_config_get(driver, sdi, channel_group, key,
608 tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
609 g_variant_unref(gvar);
613 if (maybe_config_list(driver, sdi, channel_group, key,
616 /* Can't list it, but we have a value to show. */
617 printf("%s (current)", tmp_str);
624 stropts = g_variant_get_strv(gvar, &num_elements);
625 for (i = 0; i < num_elements; i++) {
628 printf("%s", stropts[i]);
629 if (tmp_str && !strcmp(tmp_str, stropts[i]))
630 printf(" (current)");
635 g_variant_unref(gvar);
637 } else if (srci->datatype == SR_T_UINT64_RANGE) {
638 printf(" %s: ", srci->id);
639 if (maybe_config_list(driver, sdi, channel_group, key,
640 &gvar_list) != SR_OK) {
645 if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
646 g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
647 g_variant_unref(gvar);
653 num_elements = g_variant_n_children(gvar_list);
654 for (i = 0; i < num_elements; i++) {
655 gvar = g_variant_get_child_value(gvar_list, i);
656 g_variant_get(gvar, "(tt)", &low, &high);
657 g_variant_unref(gvar);
660 printf("%"PRIu64"-%"PRIu64, low, high);
661 if (low == cur_low && high == cur_high)
662 printf(" (current)");
665 g_variant_unref(gvar_list);
667 } else if (srci->datatype == SR_T_BOOL) {
668 printf(" %s: ", srci->id);
669 if (maybe_config_get(driver, sdi, channel_group, key,
671 if (g_variant_get_boolean(gvar))
672 printf("on (current), off\n");
674 printf("on, off (current)\n");
675 g_variant_unref(gvar);
679 } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
680 printf(" %s: ", srci->id);
681 if (maybe_config_list(driver, sdi, channel_group, key,
682 &gvar_list) != SR_OK) {
687 if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
688 g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
689 g_variant_unref(gvar);
695 num_elements = g_variant_n_children(gvar_list);
696 for (i = 0; i < num_elements; i++) {
697 gvar = g_variant_get_child_value(gvar_list, i);
698 g_variant_get(gvar, "(dd)", &dlow, &dhigh);
699 g_variant_unref(gvar);
702 printf("%.1f-%.1f", dlow, dhigh);
703 if (dlow == dcur_low && dhigh == dcur_high)
704 printf(" (current)");
707 g_variant_unref(gvar_list);
709 } else if (srci->datatype == SR_T_FLOAT) {
710 printf(" %s: ", srci->id);
712 if (maybe_config_get(driver, sdi, channel_group, key,
714 tmp_flt = g_variant_get_double(gvar);
715 g_variant_unref(gvar);
717 if (maybe_config_list(driver, sdi, channel_group, key,
720 /* Can't list, but got a value to show. */
721 printf("%f (current)", tmp_flt);
726 fltopts = g_variant_get_fixed_array(gvar,
727 &num_elements, sizeof(tmp_flt));
728 for (i = 0; i < num_elements; i++) {
731 printf("%f", fltopts[i]);
732 if (tmp_flt && fltopts[i] == tmp_flt)
733 printf(" (current)");
736 g_variant_unref(gvar);
738 } else if (srci->datatype == SR_T_RATIONAL_PERIOD
739 || srci->datatype == SR_T_RATIONAL_VOLT) {
740 printf(" %s", srci->id);
741 if (maybe_config_get(driver, sdi, channel_group, key,
743 g_variant_get(gvar, "(tt)", &cur_p, &cur_q);
744 g_variant_unref(gvar);
748 if (maybe_config_list(driver, sdi, channel_group,
749 key, &gvar_list) != SR_OK) {
753 printf(" - supported values:\n");
754 num_elements = g_variant_n_children(gvar_list);
755 for (i = 0; i < num_elements; i++) {
756 gvar = g_variant_get_child_value(gvar_list, i);
757 g_variant_get(gvar, "(tt)", &p, &q);
758 if (srci->datatype == SR_T_RATIONAL_PERIOD)
759 s = sr_period_string(p, q);
761 s = sr_voltage_string(p, q);
764 if (p == cur_p && q == cur_q)
765 printf(" (current)");
768 g_variant_unref(gvar_list);
770 } else if (srci->datatype == SR_T_MQ) {
771 printf(" %s: ", srci->id);
772 if (maybe_config_get(driver, sdi, channel_group, key,
774 && g_variant_is_of_type(gvar, G_VARIANT_TYPE_TUPLE)
775 && g_variant_n_children(gvar) == 2) {
776 g_variant_get(gvar, "(ut)", &cur_mq, &cur_mqflags);
777 g_variant_unref(gvar);
779 cur_mq = cur_mqflags = 0;
781 if (maybe_config_list(driver, sdi, channel_group,
782 key, &gvar_list) != SR_OK) {
786 printf(" - supported measurements:\n");
787 num_elements = g_variant_n_children(gvar_list);
788 for (i = 0; i < num_elements; i++) {
790 gvar = g_variant_get_child_value(gvar_list, i);
791 g_variant_get(gvar, "(ut)", &mq, &mqflags);
792 if ((srmqi = sr_key_info_get(SR_KEY_MQ, mq)))
793 printf("%s", srmqi->id);
796 for (j = 0, mask = 1; j < 32; j++, mask <<= 1) {
797 if (!(mqflags & mask))
799 if ((srmqfi = sr_key_info_get(SR_KEY_MQFLAGS, mqflags & mask)))
800 printf("/%s", srmqfi->id);
802 printf("/%" PRIu64, mqflags & mask);
804 if (mq == cur_mq && mqflags == cur_mqflags)
805 printf(" (current)");
808 g_variant_unref(gvar_list);
812 /* Everything else */
813 printf(" %s\n", srci->id);
816 g_array_free(opts, TRUE);
823 static void show_pd_detail_single(const char *pd)
825 struct srd_decoder *dec;
826 struct srd_decoder_option *o;
827 struct srd_channel *pdch;
828 struct srd_decoder_annotation_row *r;
831 char **pdtokens, **pdtok, *optsep, **ann, **bin, *val, *doc, *str;
833 pdtokens = g_strsplit(pd, ",", -1);
834 for (pdtok = pdtokens; *pdtok; pdtok++) {
836 if ((optsep = strchr(*pdtok, ':')))
838 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
839 g_critical("Protocol decoder %s not found.", *pdtok);
842 printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
843 dec->id, dec->name, dec->longname, dec->desc);
844 printf("License: %s\n", dec->license);
845 printf("Possible decoder input IDs:\n");
847 for (l = dec->inputs; l; l = l->next) {
849 printf("- %s\n", str);
854 printf("Possible decoder output IDs:\n");
856 for (l = dec->outputs; l; l = l->next) {
858 printf("- %s\n", str);
863 printf("Decoder tags:\n");
865 for (l = dec->tags; l; l = l->next) {
867 printf("- %s\n", str);
872 printf("Annotation classes:\n");
873 if (dec->annotations) {
874 for (l = dec->annotations; l; l = l->next) {
876 printf("- %s: %s\n", ann[0], ann[1]);
881 printf("Annotation rows:\n");
882 if (dec->annotation_rows) {
883 for (l = dec->annotation_rows; l; l = l->next) {
885 printf("- %s (%s): ", r->id, r->desc);
886 for (ll = r->ann_classes; ll; ll = ll->next) {
887 idx = GPOINTER_TO_INT(ll->data);
888 ann = g_slist_nth_data(dec->annotations, idx);
889 printf("%s", ann[0]);
898 printf("Binary classes:\n");
900 for (l = dec->binary; l; l = l->next) {
902 printf("- %s: %s\n", bin[0], bin[1]);
907 printf("Required channels:\n");
909 for (l = dec->channels; l; l = l->next) {
911 printf("- %s (%s): %s\n",
912 pdch->id, pdch->name, pdch->desc);
917 printf("Optional channels:\n");
918 if (dec->opt_channels) {
919 for (l = dec->opt_channels; l; l = l->next) {
921 printf("- %s (%s): %s\n",
922 pdch->id, pdch->name, pdch->desc);
927 printf("Options:\n");
929 for (l = dec->options; l; l = l->next) {
931 printf("- %s: %s (", o->id, o->desc);
932 for (ol = o->values; ol; ol = ol->next) {
933 val = g_variant_print(ol->data, FALSE);
937 val = g_variant_print(o->def, FALSE);
938 printf("default %s)\n", val);
944 if ((doc = srd_decoder_doc_get(dec))) {
945 printf("Documentation:\n%s\n",
946 doc[0] == '\n' ? doc + 1 : doc);
951 g_strfreev(pdtokens);
954 void show_pd_detail(void)
956 for (int i = 0; opt_pds[i]; i++)
957 show_pd_detail_single(opt_pds[i]);
961 void show_input(void)
963 const struct sr_input_module *imod;
964 const struct sr_option **opts;
969 tok = g_strsplit(opt_input_format, ":", 0);
970 if (!tok[0] || !(imod = sr_input_find(tok[0])))
971 g_critical("Input module '%s' not found.", opt_input_format);
973 printf("ID: %s\nName: %s\n", sr_input_id_get(imod),
974 sr_input_name_get(imod));
975 printf("Description: %s\n", sr_input_description_get(imod));
976 if ((opts = sr_input_options_get(imod))) {
977 printf("Options:\n");
978 for (i = 0; opts[i]; i++) {
979 printf(" %s: %s", opts[i]->id, opts[i]->desc);
981 s = g_variant_print(opts[i]->def, FALSE);
982 printf(" (default %s", s);
984 if (opts[i]->values) {
985 printf(", possible values ");
986 for (l = opts[i]->values; l; l = l->next) {
987 s = g_variant_print((GVariant *)l->data, FALSE);
988 printf("%s%s", s, l->next ? ", " : "");
996 sr_input_options_free(opts);
1001 void show_output(void)
1003 const struct sr_output_module *omod;
1004 const struct sr_option **opts;
1009 tok = g_strsplit(opt_output_format, ":", 0);
1010 if (!tok[0] || !(omod = sr_output_find(tok[0])))
1011 g_critical("Output module '%s' not found.", opt_output_format);
1013 printf("ID: %s\nName: %s\n", sr_output_id_get(omod),
1014 sr_output_name_get(omod));
1015 printf("Description: %s\n", sr_output_description_get(omod));
1016 if ((opts = sr_output_options_get(omod))) {
1017 printf("Options:\n");
1018 for (i = 0; opts[i]; i++) {
1019 printf(" %s: %s", opts[i]->id, opts[i]->desc);
1021 s = g_variant_print(opts[i]->def, FALSE);
1022 printf(" (default %s", s);
1024 if (opts[i]->values) {
1025 printf(", possible values ");
1026 for (l = opts[i]->values; l; l = l->next) {
1027 s = g_variant_print((GVariant *)l->data, FALSE);
1028 printf("%s%s", s, l->next ? ", " : "");
1036 sr_output_options_free(opts);
1041 void show_transform(void)
1043 const struct sr_transform_module *tmod;
1044 const struct sr_option **opts;
1049 tok = g_strsplit(opt_transform_module, ":", 0);
1050 if (!tok[0] || !(tmod = sr_transform_find(tok[0])))
1051 g_critical("Transform module '%s' not found.", opt_transform_module);
1053 printf("ID: %s\nName: %s\n", sr_transform_id_get(tmod),
1054 sr_transform_name_get(tmod));
1055 printf("Description: %s\n", sr_transform_description_get(tmod));
1056 if ((opts = sr_transform_options_get(tmod))) {
1057 printf("Options:\n");
1058 for (i = 0; opts[i]; i++) {
1059 printf(" %s: %s", opts[i]->id, opts[i]->desc);
1061 s = g_variant_print(opts[i]->def, FALSE);
1062 printf(" (default %s", s);
1064 if (opts[i]->values) {
1065 printf(", possible values ");
1066 for (l = opts[i]->values; l; l = l->next) {
1067 s = g_variant_print((GVariant *)l->data, FALSE);
1068 printf("%s%s", s, l->next ? ", " : "");
1076 sr_transform_options_free(opts);
1081 static void print_serial_port(gpointer data, gpointer user_data)
1083 struct sr_serial_port *port;
1085 port = (void *)data;
1087 printf("\t%s\t%s\n", port->name, port->description);
1090 void show_serial_ports(void)
1092 GSList *serial_ports;
1094 serial_ports = sr_serial_list(NULL);
1098 printf("Available serial/HID/BT/BLE ports:\n");
1099 g_slist_foreach(serial_ports, print_serial_port, NULL);
1100 g_slist_free_full(serial_ports, (GDestroyNotify)sr_serial_free);