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