]>
Commit | Line | Data |
---|---|---|
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 |
24 | static 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 | ||
30 | static 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 | ||
36 | static 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 |
44 | static 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 |
52 | void 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 | 131 | static 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 |
138 | static void print_dev_line(const struct sr_dev_inst *sdi) |
139 | { | |
029d73fe | 140 | struct sr_channel *ch; |
dd2f206a | 141 | GSList *sl, *l; |
2be182e6 BV |
142 | GString *s; |
143 | GVariant *gvar; | |
144 | ||
145 | s = g_string_sized_new(128); | |
146 | g_string_assign(s, sdi->driver->name); | |
147 | if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) { | |
148 | g_string_append(s, ":conn="); | |
149 | g_string_append(s, g_variant_get_string(gvar, NULL)); | |
150 | g_variant_unref(gvar); | |
151 | } | |
152 | g_string_append(s, " - "); | |
153 | if (sdi->vendor && sdi->vendor[0]) | |
154 | g_string_append_printf(s, "%s ", sdi->vendor); | |
155 | if (sdi->model && sdi->model[0]) | |
156 | g_string_append_printf(s, "%s ", sdi->model); | |
157 | if (sdi->version && sdi->version[0]) | |
158 | g_string_append_printf(s, "%s ", sdi->version); | |
029d73fe UH |
159 | if (sdi->channels) { |
160 | if (g_slist_length(sdi->channels) == 1) { | |
161 | ch = sdi->channels->data; | |
162 | g_string_append_printf(s, "with 1 channel: %s", ch->name); | |
2be182e6 | 163 | } else { |
029d73fe UH |
164 | sl = g_slist_sort(g_slist_copy(sdi->channels), sort_channels); |
165 | g_string_append_printf(s, "with %d channels:", g_slist_length(sl)); | |
dd2f206a | 166 | for (l = sl; l; l = l->next) { |
029d73fe UH |
167 | ch = l->data; |
168 | g_string_append_printf(s, " %s", ch->name); | |
2be182e6 | 169 | } |
dd2f206a | 170 | g_slist_free(sl); |
2be182e6 BV |
171 | } |
172 | } | |
173 | g_string_append_printf(s, "\n"); | |
174 | printf("%s", s->str); | |
175 | g_string_free(s, TRUE); | |
176 | ||
177 | } | |
178 | ||
179 | void show_dev_list(void) | |
180 | { | |
181 | struct sr_dev_inst *sdi; | |
182 | GSList *devices, *l; | |
183 | ||
184 | if (!(devices = device_scan())) | |
185 | return; | |
186 | ||
187 | printf("The following devices were found:\n"); | |
188 | for (l = devices; l; l = l->next) { | |
189 | sdi = l->data; | |
190 | print_dev_line(sdi); | |
191 | } | |
192 | g_slist_free(devices); | |
193 | ||
194 | } | |
195 | ||
196 | void show_dev_detail(void) | |
197 | { | |
198 | struct sr_dev_inst *sdi; | |
199 | const struct sr_config_info *srci; | |
029d73fe | 200 | struct sr_channel *ch; |
ca50f4b3 | 201 | struct sr_channel_group *channel_group, *cg; |
029d73fe | 202 | GSList *devices, *cgl, *chl; |
2be182e6 BV |
203 | GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar; |
204 | gsize num_opts, num_elements; | |
426d0cda | 205 | double dlow, dhigh, dcur_low, dcur_high; |
2be182e6 BV |
206 | const uint64_t *uint64, p, q, low, high; |
207 | uint64_t cur_low, cur_high; | |
23cbb498 BV |
208 | const uint32_t *opts; |
209 | const int32_t *int32; | |
131ae8d0 BV |
210 | uint32_t key, o; |
211 | unsigned int num_devices, i; | |
23cbb498 | 212 | char *tmp_str, *s, c; |
6b27bde4 | 213 | const char **stropts; |
2be182e6 BV |
214 | |
215 | if (!(devices = device_scan())) { | |
216 | g_critical("No devices found."); | |
217 | return; | |
218 | } | |
219 | ||
220 | num_devices = g_slist_length(devices); | |
221 | if (num_devices > 1) { | |
222 | g_critical("%d devices found. Use --scan to show them, " | |
223 | "and select one to show.", num_devices); | |
224 | return; | |
225 | } | |
226 | ||
227 | sdi = devices->data; | |
b4eece7c | 228 | g_slist_free(devices); |
2be182e6 BV |
229 | print_dev_line(sdi); |
230 | ||
231 | if (sr_dev_open(sdi) != SR_OK) { | |
232 | g_critical("Failed to open device."); | |
233 | return; | |
234 | } | |
235 | ||
236 | if ((sr_config_list(sdi->driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, | |
237 | &gvar_opts) == SR_OK)) { | |
238 | opts = g_variant_get_fixed_array(gvar_opts, &num_elements, | |
239 | sizeof(int32_t)); | |
240 | printf("Supported driver options:\n"); | |
241 | for (i = 0; i < num_elements; i++) { | |
242 | if (!(srci = sr_config_info_get(opts[i]))) | |
243 | continue; | |
244 | printf(" %s\n", srci->id); | |
245 | } | |
246 | g_variant_unref(gvar_opts); | |
247 | } | |
248 | ||
ca50f4b3 | 249 | /* Selected channels and channel group may affect which options are |
02c65935 | 250 | * returned, or which values for them. */ |
029d73fe | 251 | select_channels(sdi); |
ca50f4b3 | 252 | channel_group = select_channel_group(sdi); |
02c65935 | 253 | |
ca50f4b3 | 254 | if ((sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS, |
2be182e6 BV |
255 | &gvar_opts)) != SR_OK) |
256 | /* Driver supports no device instance options. */ | |
257 | return; | |
258 | ||
ca50f4b3 UH |
259 | if (sdi->channel_groups) { |
260 | printf("Channel groups:\n"); | |
261 | for (cgl = sdi->channel_groups; cgl; cgl = cgl->next) { | |
262 | cg = cgl->data; | |
263 | printf(" %s: channel%s", cg->name, | |
264 | g_slist_length(cg->channels) > 1 ? "s" : ""); | |
029d73fe UH |
265 | for (chl = cg->channels; chl; chl = chl->next) { |
266 | ch = chl->data; | |
267 | printf(" %s", ch->name); | |
2be182e6 BV |
268 | } |
269 | printf("\n"); | |
270 | } | |
271 | } | |
272 | ||
273 | printf("Supported configuration options"); | |
ca50f4b3 UH |
274 | if (sdi->channel_groups) { |
275 | if (!channel_group) | |
276 | printf(" across all channel groups"); | |
2be182e6 | 277 | else |
ca50f4b3 | 278 | printf(" on channel group %s", channel_group->name); |
2be182e6 BV |
279 | } |
280 | printf(":\n"); | |
131ae8d0 | 281 | opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t)); |
2be182e6 | 282 | for (o = 0; o < num_opts; o++) { |
23cbb498 BV |
283 | key = opts[o] & SR_CONF_MASK; |
284 | if (!(srci = sr_config_info_get(key))) | |
2be182e6 BV |
285 | continue; |
286 | ||
23cbb498 BV |
287 | if (key == SR_CONF_TRIGGER_MATCH) { |
288 | if (sr_config_list(sdi->driver, sdi, channel_group, key, | |
6b27bde4 | 289 | &gvar_list) != SR_OK) { |
2be182e6 BV |
290 | printf("\n"); |
291 | continue; | |
292 | } | |
6b27bde4 BV |
293 | int32 = g_variant_get_fixed_array(gvar_list, |
294 | &num_elements, sizeof(int32_t)); | |
2be182e6 | 295 | printf(" Supported triggers: "); |
6b27bde4 BV |
296 | for (i = 0; i < num_elements; i++) { |
297 | switch(int32[i]) { | |
298 | case SR_TRIGGER_ZERO: | |
299 | c = '0'; | |
300 | break; | |
301 | case SR_TRIGGER_ONE: | |
302 | c = '1'; | |
303 | break; | |
304 | case SR_TRIGGER_RISING: | |
305 | c = 'r'; | |
306 | break; | |
307 | case SR_TRIGGER_FALLING: | |
308 | c = 'f'; | |
309 | break; | |
310 | case SR_TRIGGER_EDGE: | |
311 | c = 'e'; | |
312 | break; | |
313 | case SR_TRIGGER_OVER: | |
314 | c = 'o'; | |
315 | break; | |
316 | case SR_TRIGGER_UNDER: | |
317 | c = 'u'; | |
318 | break; | |
50c641aa AJ |
319 | default: |
320 | c = 0; | |
321 | break; | |
6b27bde4 | 322 | } |
50c641aa AJ |
323 | if (c) |
324 | printf("%c ", c); | |
2be182e6 BV |
325 | } |
326 | printf("\n"); | |
6b27bde4 | 327 | g_variant_unref(gvar_list); |
2be182e6 | 328 | |
23cbb498 | 329 | } else if (key == SR_CONF_LIMIT_SAMPLES) { |
02c65935 BV |
330 | /* If implemented in config_list(), this denotes the |
331 | * maximum number of samples a device can send. This | |
332 | * really applies only to logic analyzers, and then | |
333 | * only to those that don't support compression, or | |
334 | * have it turned off by default. The values returned | |
335 | * are the low/high limits. */ | |
23cbb498 | 336 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
02c65935 BV |
337 | &gvar) != SR_OK) { |
338 | continue; | |
339 | } | |
340 | g_variant_get(gvar, "(tt)", &low, &high); | |
341 | g_variant_unref(gvar); | |
342 | printf(" Maximum number of samples: %"PRIu64"\n", high); | |
343 | ||
23cbb498 | 344 | } else if (key == SR_CONF_SAMPLERATE) { |
2be182e6 BV |
345 | /* Supported samplerates */ |
346 | printf(" %s", srci->id); | |
ca50f4b3 | 347 | if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_SAMPLERATE, |
2be182e6 BV |
348 | &gvar_dict) != SR_OK) { |
349 | printf("\n"); | |
350 | continue; | |
351 | } | |
352 | if ((gvar_list = g_variant_lookup_value(gvar_dict, | |
353 | "samplerates", G_VARIANT_TYPE("at")))) { | |
354 | uint64 = g_variant_get_fixed_array(gvar_list, | |
355 | &num_elements, sizeof(uint64_t)); | |
356 | printf(" - supported samplerates:\n"); | |
357 | for (i = 0; i < num_elements; i++) { | |
358 | if (!(s = sr_samplerate_string(uint64[i]))) | |
359 | continue; | |
360 | printf(" %s\n", s); | |
361 | g_free(s); | |
362 | } | |
363 | g_variant_unref(gvar_list); | |
364 | } else if ((gvar_list = g_variant_lookup_value(gvar_dict, | |
365 | "samplerate-steps", G_VARIANT_TYPE("at")))) { | |
366 | uint64 = g_variant_get_fixed_array(gvar_list, | |
367 | &num_elements, sizeof(uint64_t)); | |
368 | /* low */ | |
369 | if (!(s = sr_samplerate_string(uint64[0]))) | |
370 | continue; | |
371 | printf(" (%s", s); | |
372 | g_free(s); | |
373 | /* high */ | |
374 | if (!(s = sr_samplerate_string(uint64[1]))) | |
375 | continue; | |
376 | printf(" - %s", s); | |
377 | g_free(s); | |
378 | /* step */ | |
379 | if (!(s = sr_samplerate_string(uint64[2]))) | |
380 | continue; | |
381 | printf(" in steps of %s)\n", s); | |
382 | g_free(s); | |
383 | g_variant_unref(gvar_list); | |
384 | } | |
385 | g_variant_unref(gvar_dict); | |
386 | ||
23cbb498 | 387 | } else if (key == SR_CONF_BUFFERSIZE) { |
2be182e6 BV |
388 | /* Supported buffer sizes */ |
389 | printf(" %s", srci->id); | |
ca50f4b3 | 390 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 BV |
391 | SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) { |
392 | printf("\n"); | |
393 | continue; | |
394 | } | |
395 | uint64 = g_variant_get_fixed_array(gvar_list, | |
396 | &num_elements, sizeof(uint64_t)); | |
397 | printf(" - supported buffer sizes:\n"); | |
398 | for (i = 0; i < num_elements; i++) | |
399 | printf(" %"PRIu64"\n", uint64[i]); | |
400 | g_variant_unref(gvar_list); | |
401 | ||
23cbb498 | 402 | } else if (key == SR_CONF_TIMEBASE) { |
2be182e6 BV |
403 | /* Supported time bases */ |
404 | printf(" %s", srci->id); | |
ca50f4b3 | 405 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 BV |
406 | SR_CONF_TIMEBASE, &gvar_list) != SR_OK) { |
407 | printf("\n"); | |
408 | continue; | |
409 | } | |
410 | printf(" - supported time bases:\n"); | |
411 | num_elements = g_variant_n_children(gvar_list); | |
412 | for (i = 0; i < num_elements; i++) { | |
413 | gvar = g_variant_get_child_value(gvar_list, i); | |
414 | g_variant_get(gvar, "(tt)", &p, &q); | |
415 | s = sr_period_string(p * q); | |
416 | printf(" %s\n", s); | |
417 | g_free(s); | |
418 | } | |
419 | g_variant_unref(gvar_list); | |
420 | ||
23cbb498 | 421 | } else if (key == SR_CONF_VDIV) { |
2be182e6 BV |
422 | /* Supported volts/div values */ |
423 | printf(" %s", srci->id); | |
ca50f4b3 | 424 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 BV |
425 | SR_CONF_VDIV, &gvar_list) != SR_OK) { |
426 | printf("\n"); | |
427 | continue; | |
428 | } | |
429 | printf(" - supported volts/div:\n"); | |
430 | num_elements = g_variant_n_children(gvar_list); | |
431 | for (i = 0; i < num_elements; i++) { | |
432 | gvar = g_variant_get_child_value(gvar_list, i); | |
433 | g_variant_get(gvar, "(tt)", &p, &q); | |
434 | s = sr_voltage_string(p, q); | |
435 | printf(" %s\n", s); | |
436 | g_free(s); | |
437 | } | |
438 | g_variant_unref(gvar_list); | |
439 | ||
9db40e9f | 440 | } else if (srci->datatype == SR_T_STRING) { |
2be182e6 | 441 | printf(" %s: ", srci->id); |
23cbb498 | 442 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
443 | &gvar) == SR_OK) { |
444 | tmp_str = g_strdup(g_variant_get_string(gvar, NULL)); | |
445 | g_variant_unref(gvar); | |
446 | } else | |
447 | tmp_str = NULL; | |
448 | ||
23cbb498 | 449 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
2be182e6 | 450 | &gvar) != SR_OK) { |
dcb420e7 BV |
451 | if (tmp_str) { |
452 | /* Can't list it, but we have a value to show. */ | |
453 | printf("%s (current)", tmp_str); | |
454 | } | |
2be182e6 | 455 | printf("\n"); |
55bc3776 | 456 | g_free(tmp_str); |
2be182e6 BV |
457 | continue; |
458 | } | |
459 | ||
460 | stropts = g_variant_get_strv(gvar, &num_elements); | |
461 | for (i = 0; i < num_elements; i++) { | |
462 | if (i) | |
463 | printf(", "); | |
464 | printf("%s", stropts[i]); | |
465 | if (tmp_str && !strcmp(tmp_str, stropts[i])) | |
466 | printf(" (current)"); | |
467 | } | |
468 | printf("\n"); | |
469 | g_free(stropts); | |
470 | g_free(tmp_str); | |
471 | g_variant_unref(gvar); | |
472 | ||
473 | } else if (srci->datatype == SR_T_UINT64_RANGE) { | |
474 | printf(" %s: ", srci->id); | |
23cbb498 | 475 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
476 | &gvar_list) != SR_OK) { |
477 | printf("\n"); | |
478 | continue; | |
479 | } | |
480 | ||
23cbb498 | 481 | if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) { |
2be182e6 BV |
482 | g_variant_get(gvar, "(tt)", &cur_low, &cur_high); |
483 | g_variant_unref(gvar); | |
484 | } else { | |
485 | cur_low = 0; | |
486 | cur_high = 0; | |
487 | } | |
488 | ||
489 | num_elements = g_variant_n_children(gvar_list); | |
490 | for (i = 0; i < num_elements; i++) { | |
491 | gvar = g_variant_get_child_value(gvar_list, i); | |
492 | g_variant_get(gvar, "(tt)", &low, &high); | |
493 | g_variant_unref(gvar); | |
494 | if (i) | |
495 | printf(", "); | |
496 | printf("%"PRIu64"-%"PRIu64, low, high); | |
497 | if (low == cur_low && high == cur_high) | |
498 | printf(" (current)"); | |
499 | } | |
500 | printf("\n"); | |
501 | g_variant_unref(gvar_list); | |
502 | ||
503 | } else if (srci->datatype == SR_T_BOOL) { | |
504 | printf(" %s: ", srci->id); | |
23cbb498 | 505 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
506 | &gvar) == SR_OK) { |
507 | if (g_variant_get_boolean(gvar)) | |
508 | printf("on (current), off\n"); | |
509 | else | |
510 | printf("on, off (current)\n"); | |
511 | g_variant_unref(gvar); | |
512 | } else | |
513 | printf("on, off\n"); | |
514 | ||
426d0cda BV |
515 | } else if (srci->datatype == SR_T_DOUBLE_RANGE) { |
516 | printf(" %s: ", srci->id); | |
23cbb498 | 517 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
426d0cda BV |
518 | &gvar_list) != SR_OK) { |
519 | printf("\n"); | |
520 | continue; | |
521 | } | |
522 | ||
23cbb498 | 523 | if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) { |
426d0cda BV |
524 | g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high); |
525 | g_variant_unref(gvar); | |
526 | } else { | |
527 | dcur_low = 0; | |
528 | dcur_high = 0; | |
529 | } | |
530 | ||
531 | num_elements = g_variant_n_children(gvar_list); | |
532 | for (i = 0; i < num_elements; i++) { | |
533 | gvar = g_variant_get_child_value(gvar_list, i); | |
534 | g_variant_get(gvar, "(dd)", &dlow, &dhigh); | |
535 | g_variant_unref(gvar); | |
536 | if (i) | |
537 | printf(", "); | |
538 | printf("%.1f-%.1f", dlow, dhigh); | |
539 | if (dlow == dcur_low && dhigh == dcur_high) | |
540 | printf(" (current)"); | |
541 | } | |
542 | printf("\n"); | |
543 | g_variant_unref(gvar_list); | |
544 | ||
dcb420e7 BV |
545 | } else if (srci->datatype == SR_T_FLOAT) { |
546 | printf(" %s: ", srci->id); | |
23cbb498 | 547 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
dcb420e7 BV |
548 | &gvar) == SR_OK) { |
549 | printf("%f\n", g_variant_get_double(gvar)); | |
550 | g_variant_unref(gvar); | |
551 | } else | |
552 | printf("on, off\n"); | |
553 | ||
2be182e6 BV |
554 | } else { |
555 | ||
556 | /* Everything else */ | |
557 | printf(" %s\n", srci->id); | |
558 | } | |
559 | } | |
560 | g_variant_unref(gvar_opts); | |
561 | ||
562 | sr_dev_close(sdi); | |
2be182e6 BV |
563 | |
564 | } | |
565 | ||
566 | #ifdef HAVE_SRD | |
567 | void show_pd_detail(void) | |
568 | { | |
2be182e6 BV |
569 | struct srd_decoder *dec; |
570 | struct srd_decoder_option *o; | |
3dfbfbc8 | 571 | struct srd_channel *pdch; |
1eb46be8 | 572 | struct srd_decoder_annotation_row *r; |
3d7bf979 BV |
573 | GSList *l, *ll, *ol; |
574 | int idx; | |
575 | char **pdtokens, **pdtok, *optsep, **ann, *val, *doc; | |
2be182e6 BV |
576 | |
577 | pdtokens = g_strsplit(opt_pds, ",", -1); | |
578 | for (pdtok = pdtokens; *pdtok; pdtok++) { | |
579 | /* Strip options. */ | |
580 | if ((optsep = strchr(*pdtok, ':'))) | |
581 | *optsep = '\0'; | |
582 | if (!(dec = srd_decoder_get_by_id(*pdtok))) { | |
583 | g_critical("Protocol decoder %s not found.", *pdtok); | |
584 | return; | |
585 | } | |
586 | printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n", | |
587 | dec->id, dec->name, dec->longname, dec->desc); | |
588 | printf("License: %s\n", dec->license); | |
b39f3a1a | 589 | printf("Annotation classes:\n"); |
2be182e6 BV |
590 | if (dec->annotations) { |
591 | for (l = dec->annotations; l; l = l->next) { | |
592 | ann = l->data; | |
b39f3a1a | 593 | printf("- %s: %s\n", ann[0], ann[1]); |
2be182e6 BV |
594 | } |
595 | } else { | |
596 | printf("None.\n"); | |
597 | } | |
1eb46be8 UH |
598 | printf("Annotation rows:\n"); |
599 | if (dec->annotation_rows) { | |
600 | for (l = dec->annotation_rows; l; l = l->next) { | |
601 | r = l->data; | |
b39f3a1a | 602 | printf("- %s (%s): ", r->id, r->desc); |
3d7bf979 BV |
603 | for (ll = r->ann_classes; ll; ll = ll->next) { |
604 | idx = GPOINTER_TO_INT(ll->data); | |
605 | ann = g_slist_nth_data(dec->annotations, idx); | |
606 | printf("%s", ann[0]); | |
607 | if (ll->next) | |
608 | printf(", "); | |
609 | } | |
1eb46be8 UH |
610 | printf("\n"); |
611 | } | |
612 | } else { | |
613 | printf("None.\n"); | |
614 | } | |
3dfbfbc8 UH |
615 | printf("Required channels:\n"); |
616 | if (dec->channels) { | |
617 | for (l = dec->channels; l; l = l->next) { | |
618 | pdch = l->data; | |
2be182e6 | 619 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 620 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
621 | } |
622 | } else { | |
623 | printf("None.\n"); | |
624 | } | |
3dfbfbc8 UH |
625 | printf("Optional channels:\n"); |
626 | if (dec->opt_channels) { | |
627 | for (l = dec->opt_channels; l; l = l->next) { | |
628 | pdch = l->data; | |
2be182e6 | 629 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 630 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
631 | } |
632 | } else { | |
633 | printf("None.\n"); | |
634 | } | |
1eb46be8 | 635 | printf("Options:\n"); |
2be182e6 | 636 | if (dec->options) { |
2be182e6 BV |
637 | for (l = dec->options; l; l = l->next) { |
638 | o = l->data; | |
f2e82732 BV |
639 | printf("- %s: %s (", o->id, o->desc); |
640 | for (ol = o->values; ol; ol = ol->next) { | |
641 | val = g_variant_print(ol->data, FALSE); | |
642 | printf("%s, ", val); | |
643 | g_free(val); | |
644 | } | |
2be182e6 | 645 | val = g_variant_print(o->def, FALSE); |
f2e82732 | 646 | printf("default %s)\n", val); |
2be182e6 BV |
647 | g_free(val); |
648 | } | |
1eb46be8 UH |
649 | } else { |
650 | printf("None.\n"); | |
2be182e6 BV |
651 | } |
652 | if ((doc = srd_decoder_doc_get(dec))) { | |
653 | printf("Documentation:\n%s\n", | |
654 | doc[0] == '\n' ? doc + 1 : doc); | |
655 | g_free(doc); | |
656 | } | |
657 | } | |
658 | ||
659 | g_strfreev(pdtokens); | |
660 | } | |
661 | #endif | |
662 | ||
a8b4041a BV |
663 | void show_input(void) |
664 | { | |
665 | const struct sr_input_module *imod; | |
666 | const struct sr_option **opts; | |
667 | GSList *l; | |
668 | int i; | |
669 | char *s, **tok; | |
670 | ||
671 | tok = g_strsplit(opt_input_format, ":", 0); | |
672 | if (!tok[0] || !(imod = sr_input_find(tok[0]))) | |
673 | g_critical("Input module '%s' not found.", opt_input_format); | |
674 | ||
675 | printf("ID: %s\nName: %s\n", sr_input_id_get(imod), | |
676 | sr_input_name_get(imod)); | |
677 | printf("Description: %s\n", sr_input_description_get(imod)); | |
678 | if ((opts = sr_input_options_get(imod))) { | |
679 | printf("Options:\n"); | |
680 | for (i = 0; opts[i]; i++) { | |
681 | printf(" %s: %s", opts[i]->id, opts[i]->desc); | |
682 | if (opts[i]->def) { | |
683 | s = g_variant_print(opts[i]->def, FALSE); | |
684 | printf(" (default %s", s); | |
685 | g_free(s); | |
686 | if (opts[i]->values) { | |
687 | printf(", possible values "); | |
688 | for (l = opts[i]->values; l; l = l->next) { | |
689 | s = g_variant_print((GVariant *)l->data, FALSE); | |
690 | printf("%s%s", s, l->next ? ", " : ""); | |
691 | g_free(s); | |
692 | } | |
693 | } | |
694 | printf(")"); | |
695 | } | |
696 | printf("\n"); | |
697 | } | |
698 | sr_input_options_free(opts); | |
699 | } | |
700 | g_strfreev(tok); | |
701 | } | |
702 | ||
ad6520c4 BV |
703 | void show_output(void) |
704 | { | |
705 | const struct sr_output_module *omod; | |
7c6a0420 | 706 | const struct sr_option **opts; |
ad6520c4 | 707 | GSList *l; |
7c6a0420 | 708 | int i; |
e786e625 | 709 | char *s, **tok; |
ad6520c4 | 710 | |
e786e625 BV |
711 | tok = g_strsplit(opt_output_format, ":", 0); |
712 | if (!tok[0] || !(omod = sr_output_find(tok[0]))) | |
ad6520c4 BV |
713 | g_critical("Output module '%s' not found.", opt_output_format); |
714 | ||
715 | printf("ID: %s\nName: %s\n", sr_output_id_get(omod), | |
716 | sr_output_name_get(omod)); | |
717 | printf("Description: %s\n", sr_output_description_get(omod)); | |
b61a8850 | 718 | if ((opts = sr_output_options_get(omod))) { |
ad6520c4 | 719 | printf("Options:\n"); |
7c6a0420 BV |
720 | for (i = 0; opts[i]; i++) { |
721 | printf(" %s: %s", opts[i]->id, opts[i]->desc); | |
722 | if (opts[i]->def) { | |
723 | s = g_variant_print(opts[i]->def, FALSE); | |
ad6520c4 BV |
724 | printf(" (default %s", s); |
725 | g_free(s); | |
7c6a0420 | 726 | if (opts[i]->values) { |
ad6520c4 | 727 | printf(", possible values "); |
7c6a0420 | 728 | for (l = opts[i]->values; l; l = l->next) { |
ad6520c4 BV |
729 | s = g_variant_print((GVariant *)l->data, FALSE); |
730 | printf("%s%s", s, l->next ? ", " : ""); | |
731 | g_free(s); | |
732 | } | |
733 | } | |
734 | printf(")"); | |
735 | } | |
736 | printf("\n"); | |
ad6520c4 | 737 | } |
b61a8850 | 738 | sr_output_options_free(opts); |
ad6520c4 | 739 | } |
e786e625 | 740 | g_strfreev(tok); |
ad6520c4 BV |
741 | } |
742 |