]>
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 | { | |
26 | const struct sr_input_format *ia = a, *ib = b; | |
27 | ||
28 | return strcmp(ia->id, ib->id); | |
29 | } | |
30 | ||
31 | static gint sort_outputs(gconstpointer a, gconstpointer b) | |
32 | { | |
33 | const struct sr_output_format *oa = a, *ob = b; | |
34 | ||
35 | return strcmp(oa->id, ob->id); | |
36 | } | |
37 | ||
38 | static gint sort_drivers(gconstpointer a, gconstpointer b) | |
39 | { | |
40 | const struct sr_dev_driver *sdda = a, *sddb = b; | |
41 | ||
42 | return strcmp(sdda->name, sddb->name); | |
43 | } | |
44 | ||
628197af | 45 | #ifdef HAVE_SRD |
37e4fcd4 BV |
46 | static gint sort_pds(gconstpointer a, gconstpointer b) |
47 | { | |
48 | const struct srd_decoder *sda = a, *sdb = b; | |
49 | ||
50 | return strcmp(sda->id, sdb->id); | |
51 | } | |
628197af | 52 | #endif |
37e4fcd4 | 53 | |
2be182e6 BV |
54 | void show_version(void) |
55 | { | |
37e4fcd4 BV |
56 | struct sr_dev_driver **drivers, *driver; |
57 | struct sr_input_format **inputs, *input; | |
58 | struct sr_output_format **outputs, *output; | |
59 | const GSList *l; | |
60 | GSList *sl; | |
2be182e6 BV |
61 | int i; |
62 | #ifdef HAVE_SRD | |
63 | struct srd_decoder *dec; | |
2be182e6 BV |
64 | #endif |
65 | ||
66 | printf("sigrok-cli %s\n\n", VERSION); | |
67 | ||
68 | printf("Using libsigrok %s (lib version %s).\n", | |
69 | sr_package_version_string_get(), sr_lib_version_string_get()); | |
70 | #ifdef HAVE_SRD | |
71 | printf("Using libsigrokdecode %s (lib version %s).\n\n", | |
72 | srd_package_version_string_get(), srd_lib_version_string_get()); | |
73 | #endif | |
74 | ||
75 | printf("Supported hardware drivers:\n"); | |
76 | drivers = sr_driver_list(); | |
37e4fcd4 BV |
77 | for (sl = NULL, i = 0; drivers[i]; i++) |
78 | sl = g_slist_append(sl, drivers[i]); | |
79 | sl = g_slist_sort(sl, sort_drivers); | |
80 | for (l = sl; l; l = l->next) { | |
81 | driver = l->data; | |
82 | printf(" %-20s %s\n", driver->name, driver->longname); | |
2be182e6 BV |
83 | } |
84 | printf("\n"); | |
37e4fcd4 | 85 | g_slist_free(sl); |
2be182e6 BV |
86 | |
87 | printf("Supported input formats:\n"); | |
88 | inputs = sr_input_list(); | |
37e4fcd4 BV |
89 | for (sl = NULL, i = 0; inputs[i]; i++) |
90 | sl = g_slist_append(sl, inputs[i]); | |
91 | sl = g_slist_sort(sl, sort_inputs); | |
92 | for (l = sl; l; l = l->next) { | |
93 | input = l->data; | |
94 | printf(" %-20s %s\n", input->id, input->description); | |
95 | } | |
2be182e6 | 96 | printf("\n"); |
37e4fcd4 | 97 | g_slist_free(sl); |
2be182e6 BV |
98 | |
99 | printf("Supported output formats:\n"); | |
100 | outputs = sr_output_list(); | |
37e4fcd4 BV |
101 | for (sl = NULL, i = 0; outputs[i]; i++) |
102 | sl = g_slist_append(sl, outputs[i]); | |
103 | sl = g_slist_sort(sl, sort_outputs); | |
104 | for (l = sl; l; l = l->next) { | |
105 | output = l->data; | |
106 | printf(" %-20s %s\n", output->id, output->description); | |
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; | |
6b27bde4 | 208 | const int32_t *int32, *opts; |
2be182e6 BV |
209 | unsigned int num_devices, o, i; |
210 | char *tmp_str; | |
6b27bde4 BV |
211 | char *s, c; |
212 | const char **stropts; | |
2be182e6 BV |
213 | |
214 | if (!(devices = device_scan())) { | |
215 | g_critical("No devices found."); | |
216 | return; | |
217 | } | |
218 | ||
219 | num_devices = g_slist_length(devices); | |
220 | if (num_devices > 1) { | |
221 | g_critical("%d devices found. Use --scan to show them, " | |
222 | "and select one to show.", num_devices); | |
223 | return; | |
224 | } | |
225 | ||
226 | sdi = devices->data; | |
227 | print_dev_line(sdi); | |
228 | ||
229 | if (sr_dev_open(sdi) != SR_OK) { | |
230 | g_critical("Failed to open device."); | |
231 | return; | |
232 | } | |
233 | ||
234 | if ((sr_config_list(sdi->driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, | |
235 | &gvar_opts) == SR_OK)) { | |
236 | opts = g_variant_get_fixed_array(gvar_opts, &num_elements, | |
237 | sizeof(int32_t)); | |
238 | printf("Supported driver options:\n"); | |
239 | for (i = 0; i < num_elements; i++) { | |
240 | if (!(srci = sr_config_info_get(opts[i]))) | |
241 | continue; | |
242 | printf(" %s\n", srci->id); | |
243 | } | |
244 | g_variant_unref(gvar_opts); | |
245 | } | |
246 | ||
ca50f4b3 | 247 | /* Selected channels and channel group may affect which options are |
02c65935 | 248 | * returned, or which values for them. */ |
029d73fe | 249 | select_channels(sdi); |
ca50f4b3 | 250 | channel_group = select_channel_group(sdi); |
02c65935 | 251 | |
ca50f4b3 | 252 | if ((sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS, |
2be182e6 BV |
253 | &gvar_opts)) != SR_OK) |
254 | /* Driver supports no device instance options. */ | |
255 | return; | |
256 | ||
ca50f4b3 UH |
257 | if (sdi->channel_groups) { |
258 | printf("Channel groups:\n"); | |
259 | for (cgl = sdi->channel_groups; cgl; cgl = cgl->next) { | |
260 | cg = cgl->data; | |
261 | printf(" %s: channel%s", cg->name, | |
262 | g_slist_length(cg->channels) > 1 ? "s" : ""); | |
029d73fe UH |
263 | for (chl = cg->channels; chl; chl = chl->next) { |
264 | ch = chl->data; | |
265 | printf(" %s", ch->name); | |
2be182e6 BV |
266 | } |
267 | printf("\n"); | |
268 | } | |
269 | } | |
270 | ||
271 | printf("Supported configuration options"); | |
ca50f4b3 UH |
272 | if (sdi->channel_groups) { |
273 | if (!channel_group) | |
274 | printf(" across all channel groups"); | |
2be182e6 | 275 | else |
ca50f4b3 | 276 | printf(" on channel group %s", channel_group->name); |
2be182e6 BV |
277 | } |
278 | printf(":\n"); | |
279 | opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(int32_t)); | |
280 | for (o = 0; o < num_opts; o++) { | |
281 | if (!(srci = sr_config_info_get(opts[o]))) | |
282 | continue; | |
283 | ||
6b27bde4 | 284 | if (srci->key == SR_CONF_TRIGGER_MATCH) { |
ca50f4b3 | 285 | if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, |
6b27bde4 | 286 | &gvar_list) != SR_OK) { |
2be182e6 BV |
287 | printf("\n"); |
288 | continue; | |
289 | } | |
6b27bde4 BV |
290 | int32 = g_variant_get_fixed_array(gvar_list, |
291 | &num_elements, sizeof(int32_t)); | |
2be182e6 | 292 | printf(" Supported triggers: "); |
6b27bde4 BV |
293 | for (i = 0; i < num_elements; i++) { |
294 | switch(int32[i]) { | |
295 | case SR_TRIGGER_ZERO: | |
296 | c = '0'; | |
297 | break; | |
298 | case SR_TRIGGER_ONE: | |
299 | c = '1'; | |
300 | break; | |
301 | case SR_TRIGGER_RISING: | |
302 | c = 'r'; | |
303 | break; | |
304 | case SR_TRIGGER_FALLING: | |
305 | c = 'f'; | |
306 | break; | |
307 | case SR_TRIGGER_EDGE: | |
308 | c = 'e'; | |
309 | break; | |
310 | case SR_TRIGGER_OVER: | |
311 | c = 'o'; | |
312 | break; | |
313 | case SR_TRIGGER_UNDER: | |
314 | c = 'u'; | |
315 | break; | |
50c641aa AJ |
316 | default: |
317 | c = 0; | |
318 | break; | |
6b27bde4 | 319 | } |
50c641aa AJ |
320 | if (c) |
321 | printf("%c ", c); | |
2be182e6 BV |
322 | } |
323 | printf("\n"); | |
6b27bde4 | 324 | g_variant_unref(gvar_list); |
2be182e6 | 325 | |
02c65935 BV |
326 | } else if (srci->key == SR_CONF_LIMIT_SAMPLES) { |
327 | /* If implemented in config_list(), this denotes the | |
328 | * maximum number of samples a device can send. This | |
329 | * really applies only to logic analyzers, and then | |
330 | * only to those that don't support compression, or | |
331 | * have it turned off by default. The values returned | |
332 | * are the low/high limits. */ | |
ca50f4b3 | 333 | if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, |
02c65935 BV |
334 | &gvar) != SR_OK) { |
335 | continue; | |
336 | } | |
337 | g_variant_get(gvar, "(tt)", &low, &high); | |
338 | g_variant_unref(gvar); | |
339 | printf(" Maximum number of samples: %"PRIu64"\n", high); | |
340 | ||
2be182e6 BV |
341 | } else if (srci->key == SR_CONF_SAMPLERATE) { |
342 | /* Supported samplerates */ | |
343 | printf(" %s", srci->id); | |
ca50f4b3 | 344 | if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_SAMPLERATE, |
2be182e6 BV |
345 | &gvar_dict) != SR_OK) { |
346 | printf("\n"); | |
347 | continue; | |
348 | } | |
349 | if ((gvar_list = g_variant_lookup_value(gvar_dict, | |
350 | "samplerates", G_VARIANT_TYPE("at")))) { | |
351 | uint64 = g_variant_get_fixed_array(gvar_list, | |
352 | &num_elements, sizeof(uint64_t)); | |
353 | printf(" - supported samplerates:\n"); | |
354 | for (i = 0; i < num_elements; i++) { | |
355 | if (!(s = sr_samplerate_string(uint64[i]))) | |
356 | continue; | |
357 | printf(" %s\n", s); | |
358 | g_free(s); | |
359 | } | |
360 | g_variant_unref(gvar_list); | |
361 | } else if ((gvar_list = g_variant_lookup_value(gvar_dict, | |
362 | "samplerate-steps", G_VARIANT_TYPE("at")))) { | |
363 | uint64 = g_variant_get_fixed_array(gvar_list, | |
364 | &num_elements, sizeof(uint64_t)); | |
365 | /* low */ | |
366 | if (!(s = sr_samplerate_string(uint64[0]))) | |
367 | continue; | |
368 | printf(" (%s", s); | |
369 | g_free(s); | |
370 | /* high */ | |
371 | if (!(s = sr_samplerate_string(uint64[1]))) | |
372 | continue; | |
373 | printf(" - %s", s); | |
374 | g_free(s); | |
375 | /* step */ | |
376 | if (!(s = sr_samplerate_string(uint64[2]))) | |
377 | continue; | |
378 | printf(" in steps of %s)\n", s); | |
379 | g_free(s); | |
380 | g_variant_unref(gvar_list); | |
381 | } | |
382 | g_variant_unref(gvar_dict); | |
383 | ||
384 | } else if (srci->key == SR_CONF_BUFFERSIZE) { | |
385 | /* Supported buffer sizes */ | |
386 | printf(" %s", srci->id); | |
ca50f4b3 | 387 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 BV |
388 | SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) { |
389 | printf("\n"); | |
390 | continue; | |
391 | } | |
392 | uint64 = g_variant_get_fixed_array(gvar_list, | |
393 | &num_elements, sizeof(uint64_t)); | |
394 | printf(" - supported buffer sizes:\n"); | |
395 | for (i = 0; i < num_elements; i++) | |
396 | printf(" %"PRIu64"\n", uint64[i]); | |
397 | g_variant_unref(gvar_list); | |
398 | ||
399 | } else if (srci->key == SR_CONF_TIMEBASE) { | |
400 | /* Supported time bases */ | |
401 | printf(" %s", srci->id); | |
ca50f4b3 | 402 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 BV |
403 | SR_CONF_TIMEBASE, &gvar_list) != SR_OK) { |
404 | printf("\n"); | |
405 | continue; | |
406 | } | |
407 | printf(" - supported time bases:\n"); | |
408 | num_elements = g_variant_n_children(gvar_list); | |
409 | for (i = 0; i < num_elements; i++) { | |
410 | gvar = g_variant_get_child_value(gvar_list, i); | |
411 | g_variant_get(gvar, "(tt)", &p, &q); | |
412 | s = sr_period_string(p * q); | |
413 | printf(" %s\n", s); | |
414 | g_free(s); | |
415 | } | |
416 | g_variant_unref(gvar_list); | |
417 | ||
418 | } else if (srci->key == SR_CONF_VDIV) { | |
419 | /* Supported volts/div values */ | |
420 | printf(" %s", srci->id); | |
ca50f4b3 | 421 | if (sr_config_list(sdi->driver, sdi, channel_group, |
2be182e6 BV |
422 | SR_CONF_VDIV, &gvar_list) != SR_OK) { |
423 | printf("\n"); | |
424 | continue; | |
425 | } | |
426 | printf(" - supported volts/div:\n"); | |
427 | num_elements = g_variant_n_children(gvar_list); | |
428 | for (i = 0; i < num_elements; i++) { | |
429 | gvar = g_variant_get_child_value(gvar_list, i); | |
430 | g_variant_get(gvar, "(tt)", &p, &q); | |
431 | s = sr_voltage_string(p, q); | |
432 | printf(" %s\n", s); | |
433 | g_free(s); | |
434 | } | |
435 | g_variant_unref(gvar_list); | |
436 | ||
9db40e9f | 437 | } else if (srci->datatype == SR_T_STRING) { |
2be182e6 | 438 | printf(" %s: ", srci->id); |
ca50f4b3 | 439 | if (sr_config_get(sdi->driver, sdi, channel_group, srci->key, |
2be182e6 BV |
440 | &gvar) == SR_OK) { |
441 | tmp_str = g_strdup(g_variant_get_string(gvar, NULL)); | |
442 | g_variant_unref(gvar); | |
443 | } else | |
444 | tmp_str = NULL; | |
445 | ||
ca50f4b3 | 446 | if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, |
2be182e6 BV |
447 | &gvar) != SR_OK) { |
448 | printf("\n"); | |
449 | continue; | |
450 | } | |
451 | ||
452 | stropts = g_variant_get_strv(gvar, &num_elements); | |
453 | for (i = 0; i < num_elements; i++) { | |
454 | if (i) | |
455 | printf(", "); | |
456 | printf("%s", stropts[i]); | |
457 | if (tmp_str && !strcmp(tmp_str, stropts[i])) | |
458 | printf(" (current)"); | |
459 | } | |
460 | printf("\n"); | |
461 | g_free(stropts); | |
462 | g_free(tmp_str); | |
463 | g_variant_unref(gvar); | |
464 | ||
465 | } else if (srci->datatype == SR_T_UINT64_RANGE) { | |
466 | printf(" %s: ", srci->id); | |
ca50f4b3 | 467 | if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, |
2be182e6 BV |
468 | &gvar_list) != SR_OK) { |
469 | printf("\n"); | |
470 | continue; | |
471 | } | |
472 | ||
473 | if (sr_config_get(sdi->driver, sdi, NULL, srci->key, &gvar) == SR_OK) { | |
474 | g_variant_get(gvar, "(tt)", &cur_low, &cur_high); | |
475 | g_variant_unref(gvar); | |
476 | } else { | |
477 | cur_low = 0; | |
478 | cur_high = 0; | |
479 | } | |
480 | ||
481 | num_elements = g_variant_n_children(gvar_list); | |
482 | for (i = 0; i < num_elements; i++) { | |
483 | gvar = g_variant_get_child_value(gvar_list, i); | |
484 | g_variant_get(gvar, "(tt)", &low, &high); | |
485 | g_variant_unref(gvar); | |
486 | if (i) | |
487 | printf(", "); | |
488 | printf("%"PRIu64"-%"PRIu64, low, high); | |
489 | if (low == cur_low && high == cur_high) | |
490 | printf(" (current)"); | |
491 | } | |
492 | printf("\n"); | |
493 | g_variant_unref(gvar_list); | |
494 | ||
495 | } else if (srci->datatype == SR_T_BOOL) { | |
496 | printf(" %s: ", srci->id); | |
497 | if (sr_config_get(sdi->driver, sdi, NULL, srci->key, | |
498 | &gvar) == SR_OK) { | |
499 | if (g_variant_get_boolean(gvar)) | |
500 | printf("on (current), off\n"); | |
501 | else | |
502 | printf("on, off (current)\n"); | |
503 | g_variant_unref(gvar); | |
504 | } else | |
505 | printf("on, off\n"); | |
506 | ||
426d0cda BV |
507 | } else if (srci->datatype == SR_T_DOUBLE_RANGE) { |
508 | printf(" %s: ", srci->id); | |
029d73fe | 509 | if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, |
426d0cda BV |
510 | &gvar_list) != SR_OK) { |
511 | printf("\n"); | |
512 | continue; | |
513 | } | |
514 | ||
515 | if (sr_config_get(sdi->driver, sdi, NULL, srci->key, &gvar) == SR_OK) { | |
516 | g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high); | |
517 | g_variant_unref(gvar); | |
518 | } else { | |
519 | dcur_low = 0; | |
520 | dcur_high = 0; | |
521 | } | |
522 | ||
523 | num_elements = g_variant_n_children(gvar_list); | |
524 | for (i = 0; i < num_elements; i++) { | |
525 | gvar = g_variant_get_child_value(gvar_list, i); | |
526 | g_variant_get(gvar, "(dd)", &dlow, &dhigh); | |
527 | g_variant_unref(gvar); | |
528 | if (i) | |
529 | printf(", "); | |
530 | printf("%.1f-%.1f", dlow, dhigh); | |
531 | if (dlow == dcur_low && dhigh == dcur_high) | |
532 | printf(" (current)"); | |
533 | } | |
534 | printf("\n"); | |
535 | g_variant_unref(gvar_list); | |
536 | ||
2be182e6 BV |
537 | } else { |
538 | ||
539 | /* Everything else */ | |
540 | printf(" %s\n", srci->id); | |
541 | } | |
542 | } | |
543 | g_variant_unref(gvar_opts); | |
544 | ||
545 | sr_dev_close(sdi); | |
546 | g_slist_free(devices); | |
547 | ||
548 | } | |
549 | ||
550 | #ifdef HAVE_SRD | |
551 | void show_pd_detail(void) | |
552 | { | |
f2e82732 | 553 | GSList *l, *ll, *ol; |
2be182e6 BV |
554 | struct srd_decoder *dec; |
555 | struct srd_decoder_option *o; | |
556 | char **pdtokens, **pdtok, *optsep, **ann, *val, *doc; | |
3dfbfbc8 | 557 | struct srd_channel *pdch; |
1eb46be8 | 558 | struct srd_decoder_annotation_row *r; |
2be182e6 BV |
559 | |
560 | pdtokens = g_strsplit(opt_pds, ",", -1); | |
561 | for (pdtok = pdtokens; *pdtok; pdtok++) { | |
562 | /* Strip options. */ | |
563 | if ((optsep = strchr(*pdtok, ':'))) | |
564 | *optsep = '\0'; | |
565 | if (!(dec = srd_decoder_get_by_id(*pdtok))) { | |
566 | g_critical("Protocol decoder %s not found.", *pdtok); | |
567 | return; | |
568 | } | |
569 | printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n", | |
570 | dec->id, dec->name, dec->longname, dec->desc); | |
571 | printf("License: %s\n", dec->license); | |
b39f3a1a | 572 | printf("Annotation classes:\n"); |
2be182e6 BV |
573 | if (dec->annotations) { |
574 | for (l = dec->annotations; l; l = l->next) { | |
575 | ann = l->data; | |
b39f3a1a | 576 | printf("- %s: %s\n", ann[0], ann[1]); |
2be182e6 BV |
577 | } |
578 | } else { | |
579 | printf("None.\n"); | |
580 | } | |
1eb46be8 UH |
581 | printf("Annotation rows:\n"); |
582 | if (dec->annotation_rows) { | |
583 | for (l = dec->annotation_rows; l; l = l->next) { | |
584 | r = l->data; | |
b39f3a1a | 585 | printf("- %s (%s): ", r->id, r->desc); |
1eb46be8 UH |
586 | for (ll = r->ann_classes; ll; ll = ll->next) |
587 | printf("%d ", GPOINTER_TO_INT(ll->data)); | |
588 | printf("\n"); | |
589 | } | |
590 | } else { | |
591 | printf("None.\n"); | |
592 | } | |
3dfbfbc8 UH |
593 | printf("Required channels:\n"); |
594 | if (dec->channels) { | |
595 | for (l = dec->channels; l; l = l->next) { | |
596 | pdch = l->data; | |
2be182e6 | 597 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 598 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
599 | } |
600 | } else { | |
601 | printf("None.\n"); | |
602 | } | |
3dfbfbc8 UH |
603 | printf("Optional channels:\n"); |
604 | if (dec->opt_channels) { | |
605 | for (l = dec->opt_channels; l; l = l->next) { | |
606 | pdch = l->data; | |
2be182e6 | 607 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 608 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
609 | } |
610 | } else { | |
611 | printf("None.\n"); | |
612 | } | |
1eb46be8 | 613 | printf("Options:\n"); |
2be182e6 | 614 | if (dec->options) { |
2be182e6 BV |
615 | for (l = dec->options; l; l = l->next) { |
616 | o = l->data; | |
f2e82732 BV |
617 | printf("- %s: %s (", o->id, o->desc); |
618 | for (ol = o->values; ol; ol = ol->next) { | |
619 | val = g_variant_print(ol->data, FALSE); | |
620 | printf("%s, ", val); | |
621 | g_free(val); | |
622 | } | |
2be182e6 | 623 | val = g_variant_print(o->def, FALSE); |
f2e82732 | 624 | printf("default %s)\n", val); |
2be182e6 BV |
625 | g_free(val); |
626 | } | |
1eb46be8 UH |
627 | } else { |
628 | printf("None.\n"); | |
2be182e6 BV |
629 | } |
630 | if ((doc = srd_decoder_doc_get(dec))) { | |
631 | printf("Documentation:\n%s\n", | |
632 | doc[0] == '\n' ? doc + 1 : doc); | |
633 | g_free(doc); | |
634 | } | |
635 | } | |
636 | ||
637 | g_strfreev(pdtokens); | |
638 | } | |
639 | #endif | |
640 |