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