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