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