]>
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 BV |
455 | printf("\n"); |
456 | continue; | |
457 | } | |
458 | ||
459 | stropts = g_variant_get_strv(gvar, &num_elements); | |
460 | for (i = 0; i < num_elements; i++) { | |
461 | if (i) | |
462 | printf(", "); | |
463 | printf("%s", stropts[i]); | |
464 | if (tmp_str && !strcmp(tmp_str, stropts[i])) | |
465 | printf(" (current)"); | |
466 | } | |
467 | printf("\n"); | |
468 | g_free(stropts); | |
469 | g_free(tmp_str); | |
470 | g_variant_unref(gvar); | |
471 | ||
472 | } else if (srci->datatype == SR_T_UINT64_RANGE) { | |
473 | printf(" %s: ", srci->id); | |
23cbb498 | 474 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
475 | &gvar_list) != SR_OK) { |
476 | printf("\n"); | |
477 | continue; | |
478 | } | |
479 | ||
23cbb498 | 480 | if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) { |
2be182e6 BV |
481 | g_variant_get(gvar, "(tt)", &cur_low, &cur_high); |
482 | g_variant_unref(gvar); | |
483 | } else { | |
484 | cur_low = 0; | |
485 | cur_high = 0; | |
486 | } | |
487 | ||
488 | num_elements = g_variant_n_children(gvar_list); | |
489 | for (i = 0; i < num_elements; i++) { | |
490 | gvar = g_variant_get_child_value(gvar_list, i); | |
491 | g_variant_get(gvar, "(tt)", &low, &high); | |
492 | g_variant_unref(gvar); | |
493 | if (i) | |
494 | printf(", "); | |
495 | printf("%"PRIu64"-%"PRIu64, low, high); | |
496 | if (low == cur_low && high == cur_high) | |
497 | printf(" (current)"); | |
498 | } | |
499 | printf("\n"); | |
500 | g_variant_unref(gvar_list); | |
501 | ||
502 | } else if (srci->datatype == SR_T_BOOL) { | |
503 | printf(" %s: ", srci->id); | |
23cbb498 | 504 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
505 | &gvar) == SR_OK) { |
506 | if (g_variant_get_boolean(gvar)) | |
507 | printf("on (current), off\n"); | |
508 | else | |
509 | printf("on, off (current)\n"); | |
510 | g_variant_unref(gvar); | |
511 | } else | |
512 | printf("on, off\n"); | |
513 | ||
426d0cda BV |
514 | } else if (srci->datatype == SR_T_DOUBLE_RANGE) { |
515 | printf(" %s: ", srci->id); | |
23cbb498 | 516 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
426d0cda BV |
517 | &gvar_list) != SR_OK) { |
518 | printf("\n"); | |
519 | continue; | |
520 | } | |
521 | ||
23cbb498 | 522 | if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) { |
426d0cda BV |
523 | g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high); |
524 | g_variant_unref(gvar); | |
525 | } else { | |
526 | dcur_low = 0; | |
527 | dcur_high = 0; | |
528 | } | |
529 | ||
530 | num_elements = g_variant_n_children(gvar_list); | |
531 | for (i = 0; i < num_elements; i++) { | |
532 | gvar = g_variant_get_child_value(gvar_list, i); | |
533 | g_variant_get(gvar, "(dd)", &dlow, &dhigh); | |
534 | g_variant_unref(gvar); | |
535 | if (i) | |
536 | printf(", "); | |
537 | printf("%.1f-%.1f", dlow, dhigh); | |
538 | if (dlow == dcur_low && dhigh == dcur_high) | |
539 | printf(" (current)"); | |
540 | } | |
541 | printf("\n"); | |
542 | g_variant_unref(gvar_list); | |
543 | ||
dcb420e7 BV |
544 | } else if (srci->datatype == SR_T_FLOAT) { |
545 | printf(" %s: ", srci->id); | |
23cbb498 | 546 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
dcb420e7 BV |
547 | &gvar) == SR_OK) { |
548 | printf("%f\n", g_variant_get_double(gvar)); | |
549 | g_variant_unref(gvar); | |
550 | } else | |
551 | printf("on, off\n"); | |
552 | ||
2be182e6 BV |
553 | } else { |
554 | ||
555 | /* Everything else */ | |
556 | printf(" %s\n", srci->id); | |
557 | } | |
558 | } | |
559 | g_variant_unref(gvar_opts); | |
560 | ||
561 | sr_dev_close(sdi); | |
2be182e6 BV |
562 | |
563 | } | |
564 | ||
565 | #ifdef HAVE_SRD | |
566 | void show_pd_detail(void) | |
567 | { | |
2be182e6 BV |
568 | struct srd_decoder *dec; |
569 | struct srd_decoder_option *o; | |
3dfbfbc8 | 570 | struct srd_channel *pdch; |
1eb46be8 | 571 | struct srd_decoder_annotation_row *r; |
3d7bf979 BV |
572 | GSList *l, *ll, *ol; |
573 | int idx; | |
574 | char **pdtokens, **pdtok, *optsep, **ann, *val, *doc; | |
2be182e6 BV |
575 | |
576 | pdtokens = g_strsplit(opt_pds, ",", -1); | |
577 | for (pdtok = pdtokens; *pdtok; pdtok++) { | |
578 | /* Strip options. */ | |
579 | if ((optsep = strchr(*pdtok, ':'))) | |
580 | *optsep = '\0'; | |
581 | if (!(dec = srd_decoder_get_by_id(*pdtok))) { | |
582 | g_critical("Protocol decoder %s not found.", *pdtok); | |
583 | return; | |
584 | } | |
585 | printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n", | |
586 | dec->id, dec->name, dec->longname, dec->desc); | |
587 | printf("License: %s\n", dec->license); | |
b39f3a1a | 588 | printf("Annotation classes:\n"); |
2be182e6 BV |
589 | if (dec->annotations) { |
590 | for (l = dec->annotations; l; l = l->next) { | |
591 | ann = l->data; | |
b39f3a1a | 592 | printf("- %s: %s\n", ann[0], ann[1]); |
2be182e6 BV |
593 | } |
594 | } else { | |
595 | printf("None.\n"); | |
596 | } | |
1eb46be8 UH |
597 | printf("Annotation rows:\n"); |
598 | if (dec->annotation_rows) { | |
599 | for (l = dec->annotation_rows; l; l = l->next) { | |
600 | r = l->data; | |
b39f3a1a | 601 | printf("- %s (%s): ", r->id, r->desc); |
3d7bf979 BV |
602 | for (ll = r->ann_classes; ll; ll = ll->next) { |
603 | idx = GPOINTER_TO_INT(ll->data); | |
604 | ann = g_slist_nth_data(dec->annotations, idx); | |
605 | printf("%s", ann[0]); | |
606 | if (ll->next) | |
607 | printf(", "); | |
608 | } | |
1eb46be8 UH |
609 | printf("\n"); |
610 | } | |
611 | } else { | |
612 | printf("None.\n"); | |
613 | } | |
3dfbfbc8 UH |
614 | printf("Required channels:\n"); |
615 | if (dec->channels) { | |
616 | for (l = dec->channels; l; l = l->next) { | |
617 | pdch = l->data; | |
2be182e6 | 618 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 619 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
620 | } |
621 | } else { | |
622 | printf("None.\n"); | |
623 | } | |
3dfbfbc8 UH |
624 | printf("Optional channels:\n"); |
625 | if (dec->opt_channels) { | |
626 | for (l = dec->opt_channels; l; l = l->next) { | |
627 | pdch = l->data; | |
2be182e6 | 628 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 629 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
630 | } |
631 | } else { | |
632 | printf("None.\n"); | |
633 | } | |
1eb46be8 | 634 | printf("Options:\n"); |
2be182e6 | 635 | if (dec->options) { |
2be182e6 BV |
636 | for (l = dec->options; l; l = l->next) { |
637 | o = l->data; | |
f2e82732 BV |
638 | printf("- %s: %s (", o->id, o->desc); |
639 | for (ol = o->values; ol; ol = ol->next) { | |
640 | val = g_variant_print(ol->data, FALSE); | |
641 | printf("%s, ", val); | |
642 | g_free(val); | |
643 | } | |
2be182e6 | 644 | val = g_variant_print(o->def, FALSE); |
f2e82732 | 645 | printf("default %s)\n", val); |
2be182e6 BV |
646 | g_free(val); |
647 | } | |
1eb46be8 UH |
648 | } else { |
649 | printf("None.\n"); | |
2be182e6 BV |
650 | } |
651 | if ((doc = srd_decoder_doc_get(dec))) { | |
652 | printf("Documentation:\n%s\n", | |
653 | doc[0] == '\n' ? doc + 1 : doc); | |
654 | g_free(doc); | |
655 | } | |
656 | } | |
657 | ||
658 | g_strfreev(pdtokens); | |
659 | } | |
660 | #endif | |
661 | ||
a8b4041a BV |
662 | void show_input(void) |
663 | { | |
664 | const struct sr_input_module *imod; | |
665 | const struct sr_option **opts; | |
666 | GSList *l; | |
667 | int i; | |
668 | char *s, **tok; | |
669 | ||
670 | tok = g_strsplit(opt_input_format, ":", 0); | |
671 | if (!tok[0] || !(imod = sr_input_find(tok[0]))) | |
672 | g_critical("Input module '%s' not found.", opt_input_format); | |
673 | ||
674 | printf("ID: %s\nName: %s\n", sr_input_id_get(imod), | |
675 | sr_input_name_get(imod)); | |
676 | printf("Description: %s\n", sr_input_description_get(imod)); | |
677 | if ((opts = sr_input_options_get(imod))) { | |
678 | printf("Options:\n"); | |
679 | for (i = 0; opts[i]; i++) { | |
680 | printf(" %s: %s", opts[i]->id, opts[i]->desc); | |
681 | if (opts[i]->def) { | |
682 | s = g_variant_print(opts[i]->def, FALSE); | |
683 | printf(" (default %s", s); | |
684 | g_free(s); | |
685 | if (opts[i]->values) { | |
686 | printf(", possible values "); | |
687 | for (l = opts[i]->values; l; l = l->next) { | |
688 | s = g_variant_print((GVariant *)l->data, FALSE); | |
689 | printf("%s%s", s, l->next ? ", " : ""); | |
690 | g_free(s); | |
691 | } | |
692 | } | |
693 | printf(")"); | |
694 | } | |
695 | printf("\n"); | |
696 | } | |
697 | sr_input_options_free(opts); | |
698 | } | |
699 | g_strfreev(tok); | |
700 | } | |
701 | ||
ad6520c4 BV |
702 | void show_output(void) |
703 | { | |
704 | const struct sr_output_module *omod; | |
7c6a0420 | 705 | const struct sr_option **opts; |
ad6520c4 | 706 | GSList *l; |
7c6a0420 | 707 | int i; |
e786e625 | 708 | char *s, **tok; |
ad6520c4 | 709 | |
e786e625 BV |
710 | tok = g_strsplit(opt_output_format, ":", 0); |
711 | if (!tok[0] || !(omod = sr_output_find(tok[0]))) | |
ad6520c4 BV |
712 | g_critical("Output module '%s' not found.", opt_output_format); |
713 | ||
714 | printf("ID: %s\nName: %s\n", sr_output_id_get(omod), | |
715 | sr_output_name_get(omod)); | |
716 | printf("Description: %s\n", sr_output_description_get(omod)); | |
b61a8850 | 717 | if ((opts = sr_output_options_get(omod))) { |
ad6520c4 | 718 | printf("Options:\n"); |
7c6a0420 BV |
719 | for (i = 0; opts[i]; i++) { |
720 | printf(" %s: %s", opts[i]->id, opts[i]->desc); | |
721 | if (opts[i]->def) { | |
722 | s = g_variant_print(opts[i]->def, FALSE); | |
ad6520c4 BV |
723 | printf(" (default %s", s); |
724 | g_free(s); | |
7c6a0420 | 725 | if (opts[i]->values) { |
ad6520c4 | 726 | printf(", possible values "); |
7c6a0420 | 727 | for (l = opts[i]->values; l; l = l->next) { |
ad6520c4 BV |
728 | s = g_variant_print((GVariant *)l->data, FALSE); |
729 | printf("%s%s", s, l->next ? ", " : ""); | |
730 | g_free(s); | |
731 | } | |
732 | } | |
733 | printf(")"); | |
734 | } | |
735 | printf("\n"); | |
ad6520c4 | 736 | } |
b61a8850 | 737 | sr_output_options_free(opts); |
ad6520c4 | 738 | } |
e786e625 | 739 | g_strfreev(tok); |
ad6520c4 BV |
740 | } |
741 |