]>
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 | 206 | const uint64_t *uint64, p, q, low, high; |
5e78186b | 207 | uint64_t tmp_uint64, cur_low, cur_high, cur_p, cur_q; |
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 | ||
5e78186b | 387 | } else if (srci->datatype == SR_T_UINT64) { |
2be182e6 | 388 | printf(" %s", srci->id); |
5e78186b BV |
389 | gvar = NULL; |
390 | if (sr_config_get(sdi->driver, sdi, channel_group, key, | |
391 | &gvar) == SR_OK) { | |
392 | tmp_uint64 = g_variant_get_uint64(gvar); | |
393 | g_variant_unref(gvar); | |
394 | } else | |
395 | tmp_uint64 = 0; | |
ca50f4b3 | 396 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 | 397 | SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) { |
5e78186b BV |
398 | if (gvar) { |
399 | /* Can't list it, but we have a value to show. */ | |
400 | printf("%"PRIu64" (current)", tmp_uint64); | |
401 | } | |
2be182e6 BV |
402 | printf("\n"); |
403 | continue; | |
404 | } | |
405 | uint64 = g_variant_get_fixed_array(gvar_list, | |
406 | &num_elements, sizeof(uint64_t)); | |
5e78186b | 407 | printf(" - supported values:\n"); |
2be182e6 | 408 | for (i = 0; i < num_elements; i++) { |
5e78186b BV |
409 | printf(" %"PRIu64, uint64[i]); |
410 | if (gvar && tmp_uint64 == uint64[i]) | |
411 | printf(" (current)"); | |
2be182e6 | 412 | printf("\n"); |
2be182e6 BV |
413 | } |
414 | g_variant_unref(gvar_list); | |
415 | ||
9db40e9f | 416 | } else if (srci->datatype == SR_T_STRING) { |
2be182e6 | 417 | printf(" %s: ", srci->id); |
23cbb498 | 418 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
419 | &gvar) == SR_OK) { |
420 | tmp_str = g_strdup(g_variant_get_string(gvar, NULL)); | |
421 | g_variant_unref(gvar); | |
422 | } else | |
423 | tmp_str = NULL; | |
424 | ||
23cbb498 | 425 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
2be182e6 | 426 | &gvar) != SR_OK) { |
dcb420e7 BV |
427 | if (tmp_str) { |
428 | /* Can't list it, but we have a value to show. */ | |
429 | printf("%s (current)", tmp_str); | |
430 | } | |
2be182e6 | 431 | printf("\n"); |
55bc3776 | 432 | g_free(tmp_str); |
2be182e6 BV |
433 | continue; |
434 | } | |
435 | ||
436 | stropts = g_variant_get_strv(gvar, &num_elements); | |
437 | for (i = 0; i < num_elements; i++) { | |
438 | if (i) | |
439 | printf(", "); | |
440 | printf("%s", stropts[i]); | |
441 | if (tmp_str && !strcmp(tmp_str, stropts[i])) | |
442 | printf(" (current)"); | |
443 | } | |
444 | printf("\n"); | |
445 | g_free(stropts); | |
446 | g_free(tmp_str); | |
447 | g_variant_unref(gvar); | |
448 | ||
449 | } else if (srci->datatype == SR_T_UINT64_RANGE) { | |
450 | printf(" %s: ", srci->id); | |
23cbb498 | 451 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
452 | &gvar_list) != SR_OK) { |
453 | printf("\n"); | |
454 | continue; | |
455 | } | |
456 | ||
23cbb498 | 457 | if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) { |
2be182e6 BV |
458 | g_variant_get(gvar, "(tt)", &cur_low, &cur_high); |
459 | g_variant_unref(gvar); | |
460 | } else { | |
461 | cur_low = 0; | |
462 | cur_high = 0; | |
463 | } | |
464 | ||
465 | num_elements = g_variant_n_children(gvar_list); | |
466 | for (i = 0; i < num_elements; i++) { | |
467 | gvar = g_variant_get_child_value(gvar_list, i); | |
468 | g_variant_get(gvar, "(tt)", &low, &high); | |
469 | g_variant_unref(gvar); | |
470 | if (i) | |
471 | printf(", "); | |
472 | printf("%"PRIu64"-%"PRIu64, low, high); | |
473 | if (low == cur_low && high == cur_high) | |
474 | printf(" (current)"); | |
475 | } | |
476 | printf("\n"); | |
477 | g_variant_unref(gvar_list); | |
478 | ||
479 | } else if (srci->datatype == SR_T_BOOL) { | |
480 | printf(" %s: ", srci->id); | |
23cbb498 | 481 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
2be182e6 BV |
482 | &gvar) == SR_OK) { |
483 | if (g_variant_get_boolean(gvar)) | |
484 | printf("on (current), off\n"); | |
485 | else | |
486 | printf("on, off (current)\n"); | |
487 | g_variant_unref(gvar); | |
488 | } else | |
489 | printf("on, off\n"); | |
490 | ||
426d0cda BV |
491 | } else if (srci->datatype == SR_T_DOUBLE_RANGE) { |
492 | printf(" %s: ", srci->id); | |
23cbb498 | 493 | if (sr_config_list(sdi->driver, sdi, channel_group, key, |
426d0cda BV |
494 | &gvar_list) != SR_OK) { |
495 | printf("\n"); | |
496 | continue; | |
497 | } | |
498 | ||
23cbb498 | 499 | if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) { |
426d0cda BV |
500 | g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high); |
501 | g_variant_unref(gvar); | |
502 | } else { | |
503 | dcur_low = 0; | |
504 | dcur_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, "(dd)", &dlow, &dhigh); | |
511 | g_variant_unref(gvar); | |
512 | if (i) | |
513 | printf(", "); | |
514 | printf("%.1f-%.1f", dlow, dhigh); | |
515 | if (dlow == dcur_low && dhigh == dcur_high) | |
516 | printf(" (current)"); | |
517 | } | |
518 | printf("\n"); | |
519 | g_variant_unref(gvar_list); | |
520 | ||
dcb420e7 BV |
521 | } else if (srci->datatype == SR_T_FLOAT) { |
522 | printf(" %s: ", srci->id); | |
23cbb498 | 523 | if (sr_config_get(sdi->driver, sdi, channel_group, key, |
dcb420e7 BV |
524 | &gvar) == SR_OK) { |
525 | printf("%f\n", g_variant_get_double(gvar)); | |
526 | g_variant_unref(gvar); | |
527 | } else | |
5e78186b BV |
528 | printf("\n"); |
529 | ||
530 | } else if (srci->datatype == SR_T_RATIONAL_PERIOD | |
531 | || srci->datatype == SR_T_RATIONAL_VOLT) { | |
532 | printf(" %s", srci->id); | |
533 | if (sr_config_get(sdi->driver, sdi, channel_group, key, | |
534 | &gvar) == SR_OK) { | |
535 | g_variant_get(gvar, "(tt)", &cur_p, &cur_q); | |
536 | g_variant_unref(gvar); | |
537 | } else | |
538 | cur_p = cur_q = 0; | |
539 | ||
540 | if (sr_config_list(sdi->driver, sdi, channel_group, | |
541 | key, &gvar_list) != SR_OK) { | |
542 | printf("\n"); | |
543 | continue; | |
544 | } | |
545 | printf(" - supported values:\n"); | |
546 | num_elements = g_variant_n_children(gvar_list); | |
547 | for (i = 0; i < num_elements; i++) { | |
548 | gvar = g_variant_get_child_value(gvar_list, i); | |
549 | g_variant_get(gvar, "(tt)", &p, &q); | |
550 | if (srci->datatype == SR_T_RATIONAL_PERIOD) | |
551 | s = sr_period_string(p * q); | |
552 | else | |
553 | s = sr_voltage_string(p, q); | |
554 | printf(" %s", s); | |
555 | g_free(s); | |
556 | if (p == cur_p && q == cur_q) | |
557 | printf(" (current)"); | |
558 | printf("\n"); | |
559 | } | |
560 | g_variant_unref(gvar_list); | |
dcb420e7 | 561 | |
2be182e6 BV |
562 | } else { |
563 | ||
564 | /* Everything else */ | |
565 | printf(" %s\n", srci->id); | |
566 | } | |
567 | } | |
568 | g_variant_unref(gvar_opts); | |
569 | ||
570 | sr_dev_close(sdi); | |
2be182e6 BV |
571 | |
572 | } | |
573 | ||
574 | #ifdef HAVE_SRD | |
575 | void show_pd_detail(void) | |
576 | { | |
2be182e6 BV |
577 | struct srd_decoder *dec; |
578 | struct srd_decoder_option *o; | |
3dfbfbc8 | 579 | struct srd_channel *pdch; |
1eb46be8 | 580 | struct srd_decoder_annotation_row *r; |
3d7bf979 BV |
581 | GSList *l, *ll, *ol; |
582 | int idx; | |
583 | char **pdtokens, **pdtok, *optsep, **ann, *val, *doc; | |
2be182e6 BV |
584 | |
585 | pdtokens = g_strsplit(opt_pds, ",", -1); | |
586 | for (pdtok = pdtokens; *pdtok; pdtok++) { | |
587 | /* Strip options. */ | |
588 | if ((optsep = strchr(*pdtok, ':'))) | |
589 | *optsep = '\0'; | |
590 | if (!(dec = srd_decoder_get_by_id(*pdtok))) { | |
591 | g_critical("Protocol decoder %s not found.", *pdtok); | |
592 | return; | |
593 | } | |
594 | printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n", | |
595 | dec->id, dec->name, dec->longname, dec->desc); | |
596 | printf("License: %s\n", dec->license); | |
b39f3a1a | 597 | printf("Annotation classes:\n"); |
2be182e6 BV |
598 | if (dec->annotations) { |
599 | for (l = dec->annotations; l; l = l->next) { | |
600 | ann = l->data; | |
b39f3a1a | 601 | printf("- %s: %s\n", ann[0], ann[1]); |
2be182e6 BV |
602 | } |
603 | } else { | |
604 | printf("None.\n"); | |
605 | } | |
1eb46be8 UH |
606 | printf("Annotation rows:\n"); |
607 | if (dec->annotation_rows) { | |
608 | for (l = dec->annotation_rows; l; l = l->next) { | |
609 | r = l->data; | |
b39f3a1a | 610 | printf("- %s (%s): ", r->id, r->desc); |
3d7bf979 BV |
611 | for (ll = r->ann_classes; ll; ll = ll->next) { |
612 | idx = GPOINTER_TO_INT(ll->data); | |
613 | ann = g_slist_nth_data(dec->annotations, idx); | |
614 | printf("%s", ann[0]); | |
615 | if (ll->next) | |
616 | printf(", "); | |
617 | } | |
1eb46be8 UH |
618 | printf("\n"); |
619 | } | |
620 | } else { | |
621 | printf("None.\n"); | |
622 | } | |
3dfbfbc8 UH |
623 | printf("Required channels:\n"); |
624 | if (dec->channels) { | |
625 | for (l = dec->channels; l; l = l->next) { | |
626 | pdch = l->data; | |
2be182e6 | 627 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 628 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
629 | } |
630 | } else { | |
631 | printf("None.\n"); | |
632 | } | |
3dfbfbc8 UH |
633 | printf("Optional channels:\n"); |
634 | if (dec->opt_channels) { | |
635 | for (l = dec->opt_channels; l; l = l->next) { | |
636 | pdch = l->data; | |
2be182e6 | 637 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 638 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
639 | } |
640 | } else { | |
641 | printf("None.\n"); | |
642 | } | |
1eb46be8 | 643 | printf("Options:\n"); |
2be182e6 | 644 | if (dec->options) { |
2be182e6 BV |
645 | for (l = dec->options; l; l = l->next) { |
646 | o = l->data; | |
f2e82732 BV |
647 | printf("- %s: %s (", o->id, o->desc); |
648 | for (ol = o->values; ol; ol = ol->next) { | |
649 | val = g_variant_print(ol->data, FALSE); | |
650 | printf("%s, ", val); | |
651 | g_free(val); | |
652 | } | |
2be182e6 | 653 | val = g_variant_print(o->def, FALSE); |
f2e82732 | 654 | printf("default %s)\n", val); |
2be182e6 BV |
655 | g_free(val); |
656 | } | |
1eb46be8 UH |
657 | } else { |
658 | printf("None.\n"); | |
2be182e6 BV |
659 | } |
660 | if ((doc = srd_decoder_doc_get(dec))) { | |
661 | printf("Documentation:\n%s\n", | |
662 | doc[0] == '\n' ? doc + 1 : doc); | |
663 | g_free(doc); | |
664 | } | |
665 | } | |
666 | ||
667 | g_strfreev(pdtokens); | |
668 | } | |
669 | #endif | |
670 | ||
a8b4041a BV |
671 | void show_input(void) |
672 | { | |
673 | const struct sr_input_module *imod; | |
674 | const struct sr_option **opts; | |
675 | GSList *l; | |
676 | int i; | |
677 | char *s, **tok; | |
678 | ||
679 | tok = g_strsplit(opt_input_format, ":", 0); | |
680 | if (!tok[0] || !(imod = sr_input_find(tok[0]))) | |
681 | g_critical("Input module '%s' not found.", opt_input_format); | |
682 | ||
683 | printf("ID: %s\nName: %s\n", sr_input_id_get(imod), | |
684 | sr_input_name_get(imod)); | |
685 | printf("Description: %s\n", sr_input_description_get(imod)); | |
686 | if ((opts = sr_input_options_get(imod))) { | |
687 | printf("Options:\n"); | |
688 | for (i = 0; opts[i]; i++) { | |
689 | printf(" %s: %s", opts[i]->id, opts[i]->desc); | |
690 | if (opts[i]->def) { | |
691 | s = g_variant_print(opts[i]->def, FALSE); | |
692 | printf(" (default %s", s); | |
693 | g_free(s); | |
694 | if (opts[i]->values) { | |
695 | printf(", possible values "); | |
696 | for (l = opts[i]->values; l; l = l->next) { | |
697 | s = g_variant_print((GVariant *)l->data, FALSE); | |
698 | printf("%s%s", s, l->next ? ", " : ""); | |
699 | g_free(s); | |
700 | } | |
701 | } | |
702 | printf(")"); | |
703 | } | |
704 | printf("\n"); | |
705 | } | |
706 | sr_input_options_free(opts); | |
707 | } | |
708 | g_strfreev(tok); | |
709 | } | |
710 | ||
ad6520c4 BV |
711 | void show_output(void) |
712 | { | |
713 | const struct sr_output_module *omod; | |
7c6a0420 | 714 | const struct sr_option **opts; |
ad6520c4 | 715 | GSList *l; |
7c6a0420 | 716 | int i; |
e786e625 | 717 | char *s, **tok; |
ad6520c4 | 718 | |
e786e625 BV |
719 | tok = g_strsplit(opt_output_format, ":", 0); |
720 | if (!tok[0] || !(omod = sr_output_find(tok[0]))) | |
ad6520c4 BV |
721 | g_critical("Output module '%s' not found.", opt_output_format); |
722 | ||
723 | printf("ID: %s\nName: %s\n", sr_output_id_get(omod), | |
724 | sr_output_name_get(omod)); | |
725 | printf("Description: %s\n", sr_output_description_get(omod)); | |
b61a8850 | 726 | if ((opts = sr_output_options_get(omod))) { |
ad6520c4 | 727 | printf("Options:\n"); |
7c6a0420 BV |
728 | for (i = 0; opts[i]; i++) { |
729 | printf(" %s: %s", opts[i]->id, opts[i]->desc); | |
730 | if (opts[i]->def) { | |
731 | s = g_variant_print(opts[i]->def, FALSE); | |
ad6520c4 BV |
732 | printf(" (default %s", s); |
733 | g_free(s); | |
7c6a0420 | 734 | if (opts[i]->values) { |
ad6520c4 | 735 | printf(", possible values "); |
7c6a0420 | 736 | for (l = opts[i]->values; l; l = l->next) { |
ad6520c4 BV |
737 | s = g_variant_print((GVariant *)l->data, FALSE); |
738 | printf("%s%s", s, l->next ? ", " : ""); | |
739 | g_free(s); | |
740 | } | |
741 | } | |
742 | printf(")"); | |
743 | } | |
744 | printf("\n"); | |
ad6520c4 | 745 | } |
b61a8850 | 746 | sr_output_options_free(opts); |
ad6520c4 | 747 | } |
e786e625 | 748 | g_strfreev(tok); |
ad6520c4 BV |
749 | } |
750 |