]>
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 | ||
2be182e6 | 20 | #include <glib.h> |
55de58a2 | 21 | #include <string.h> |
662a1e27 | 22 | #include "sigrok-cli.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 | ||
6f7b4c5d UH |
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 | ||
37e4fcd4 BV |
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 | ||
628197af | 49 | #ifdef HAVE_SRD |
37e4fcd4 BV |
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 | } | |
628197af | 56 | #endif |
37e4fcd4 | 57 | |
2be182e6 BV |
58 | void show_version(void) |
59 | { | |
37e4fcd4 | 60 | struct sr_dev_driver **drivers, *driver; |
a8b4041a | 61 | const struct sr_input_module **inputs, *input; |
ad6520c4 | 62 | const struct sr_output_module **outputs, *output; |
6f7b4c5d | 63 | const struct sr_transform_module **transforms, *transform; |
37e4fcd4 BV |
64 | const GSList *l; |
65 | GSList *sl; | |
2be182e6 BV |
66 | int i; |
67 | #ifdef HAVE_SRD | |
68 | struct srd_decoder *dec; | |
2be182e6 BV |
69 | #endif |
70 | ||
9d642270 | 71 | printf("sigrok-cli %s\n\n", SC_PACKAGE_VERSION_STRING); |
2be182e6 BV |
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"); | |
59e421bb | 81 | drivers = sr_driver_list(sr_ctx); |
37e4fcd4 BV |
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); | |
2be182e6 BV |
88 | } |
89 | printf("\n"); | |
37e4fcd4 | 90 | g_slist_free(sl); |
2be182e6 BV |
91 | |
92 | printf("Supported input formats:\n"); | |
93 | inputs = sr_input_list(); | |
37e4fcd4 | 94 | for (sl = NULL, i = 0; inputs[i]; i++) |
a8b4041a | 95 | sl = g_slist_append(sl, (gpointer)inputs[i]); |
37e4fcd4 BV |
96 | sl = g_slist_sort(sl, sort_inputs); |
97 | for (l = sl; l; l = l->next) { | |
98 | input = l->data; | |
a8b4041a BV |
99 | printf(" %-20s %s\n", sr_input_id_get(input), |
100 | sr_input_description_get(input)); | |
37e4fcd4 | 101 | } |
2be182e6 | 102 | printf("\n"); |
37e4fcd4 | 103 | g_slist_free(sl); |
2be182e6 BV |
104 | |
105 | printf("Supported output formats:\n"); | |
106 | outputs = sr_output_list(); | |
37e4fcd4 | 107 | for (sl = NULL, i = 0; outputs[i]; i++) |
ad6520c4 | 108 | sl = g_slist_append(sl, (gpointer)outputs[i]); |
37e4fcd4 BV |
109 | sl = g_slist_sort(sl, sort_outputs); |
110 | for (l = sl; l; l = l->next) { | |
111 | output = l->data; | |
ad6520c4 BV |
112 | printf(" %-20s %s\n", sr_output_id_get(output), |
113 | sr_output_description_get(output)); | |
37e4fcd4 | 114 | } |
2be182e6 | 115 | printf("\n"); |
37e4fcd4 | 116 | g_slist_free(sl); |
2be182e6 | 117 | |
6f7b4c5d UH |
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 | ||
2be182e6 BV |
131 | #ifdef HAVE_SRD |
132 | if (srd_init(NULL) == SRD_OK) { | |
133 | printf("Supported protocol decoders:\n"); | |
134 | srd_decoder_load_all(); | |
37e4fcd4 BV |
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) { | |
2be182e6 BV |
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 | } | |
37e4fcd4 | 144 | g_slist_free(sl); |
2be182e6 BV |
145 | srd_exit(); |
146 | } | |
147 | printf("\n"); | |
148 | #endif | |
149 | } | |
150 | ||
029d73fe | 151 | static gint sort_channels(gconstpointer a, gconstpointer b) |
dd2f206a | 152 | { |
029d73fe | 153 | const struct sr_channel *pa = a, *pb = b; |
dd2f206a BV |
154 | |
155 | return pa->index - pb->index; | |
156 | } | |
157 | ||
2be182e6 BV |
158 | static void print_dev_line(const struct sr_dev_inst *sdi) |
159 | { | |
029d73fe | 160 | struct sr_channel *ch; |
c6fa2b2e | 161 | GSList *sl, *l, *channels; |
2be182e6 BV |
162 | GString *s; |
163 | GVariant *gvar; | |
c6fa2b2e UH |
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); | |
2be182e6 BV |
172 | |
173 | s = g_string_sized_new(128); | |
c6fa2b2e | 174 | g_string_assign(s, driver->name); |
24bd9719 | 175 | if (maybe_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) { |
2be182e6 BV |
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, " - "); | |
c6fa2b2e UH |
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; | |
029d73fe | 190 | g_string_append_printf(s, "with 1 channel: %s", ch->name); |
2be182e6 | 191 | } else { |
c6fa2b2e | 192 | sl = g_slist_sort(g_slist_copy(channels), sort_channels); |
029d73fe | 193 | g_string_append_printf(s, "with %d channels:", g_slist_length(sl)); |
dd2f206a | 194 | for (l = sl; l; l = l->next) { |
029d73fe UH |
195 | ch = l->data; |
196 | g_string_append_printf(s, " %s", ch->name); | |
2be182e6 | 197 | } |
dd2f206a | 198 | g_slist_free(sl); |
2be182e6 BV |
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 | ||
d75c8529 BV |
224 | void show_drv_detail(struct sr_dev_driver *driver) |
225 | { | |
e4e4b472 | 226 | const struct sr_key_info *srci; |
d75c8529 BV |
227 | GVariant *gvar_opts; |
228 | const uint32_t *opts; | |
229 | gsize num_elements, i; | |
230 | ||
783e263e BV |
231 | if (sr_config_list(driver, NULL, NULL, SR_CONF_DEVICE_OPTIONS, |
232 | &gvar_opts) == SR_OK) { | |
d75c8529 BV |
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++) { | |
e4e4b472 | 238 | if (!(srci = sr_key_info_get(SR_KEY_CONFIG, opts[i] & SR_CONF_MASK))) |
d75c8529 BV |
239 | continue; |
240 | printf(" %s\n", srci->name); | |
241 | } | |
242 | } | |
243 | g_variant_unref(gvar_opts); | |
244 | } | |
245 | ||
783e263e BV |
246 | if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, |
247 | &gvar_opts) == SR_OK) { | |
d75c8529 BV |
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++) { | |
e4e4b472 | 253 | if (!(srci = sr_key_info_get(SR_KEY_CONFIG, opts[i] & SR_CONF_MASK))) |
d75c8529 BV |
254 | continue; |
255 | printf(" %s\n", srci->id); | |
256 | } | |
257 | } | |
258 | g_variant_unref(gvar_opts); | |
259 | } | |
260 | } | |
261 | ||
2be182e6 BV |
262 | void show_dev_detail(void) |
263 | { | |
c6fa2b2e | 264 | struct sr_dev_driver *driver_from_opt, *driver; |
2be182e6 | 265 | struct sr_dev_inst *sdi; |
e9505599 | 266 | const struct sr_key_info *srci, *srmqi, *srmqfi; |
029d73fe | 267 | struct sr_channel *ch; |
ca50f4b3 | 268 | struct sr_channel_group *channel_group, *cg; |
c6fa2b2e | 269 | GSList *devices, *cgl, *chl, *channel_groups; |
84b39e3e | 270 | GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar; |
2be182e6 | 271 | gsize num_opts, num_elements; |
426d0cda | 272 | double dlow, dhigh, dcur_low, dcur_high; |
2be182e6 | 273 | const uint64_t *uint64, p, q, low, high; |
e9505599 | 274 | uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q; |
23cbb498 BV |
275 | const uint32_t *opts; |
276 | const int32_t *int32; | |
e9505599 BV |
277 | uint32_t key, o, cur_mq, mq; |
278 | uint64_t cur_mqflags, mqflags; | |
279 | unsigned int num_devices, i, j; | |
23cbb498 | 280 | char *tmp_str, *s, c; |
6b27bde4 | 281 | const char **stropts; |
2be182e6 | 282 | |
c6fa2b2e | 283 | if (parse_driver(opt_drv, &driver_from_opt, NULL)) { |
d75c8529 | 284 | /* A driver was specified, report driver-wide options now. */ |
c6fa2b2e | 285 | show_drv_detail(driver_from_opt); |
d75c8529 BV |
286 | } |
287 | ||
2be182e6 BV |
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; | |
b4eece7c | 301 | g_slist_free(devices); |
2be182e6 BV |
302 | print_dev_line(sdi); |
303 | ||
c6fa2b2e UH |
304 | driver = sr_dev_inst_driver_get(sdi); |
305 | channel_groups = sr_dev_inst_channel_groups_get(sdi); | |
306 | ||
2be182e6 BV |
307 | if (sr_dev_open(sdi) != SR_OK) { |
308 | g_critical("Failed to open device."); | |
309 | return; | |
310 | } | |
311 | ||
f0f54487 UH |
312 | /* |
313 | * Selected channels and channel group may affect which options are | |
314 | * returned, or which values for them. | |
315 | */ | |
029d73fe | 316 | select_channels(sdi); |
ca50f4b3 | 317 | channel_group = select_channel_group(sdi); |
02c65935 | 318 | |
783e263e BV |
319 | if (sr_config_list(driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS, |
320 | &gvar_opts) != SR_OK) | |
2be182e6 BV |
321 | /* Driver supports no device instance options. */ |
322 | return; | |
323 | ||
c6fa2b2e | 324 | if (channel_groups) { |
ca50f4b3 | 325 | printf("Channel groups:\n"); |
c6fa2b2e | 326 | for (cgl = channel_groups; cgl; cgl = cgl->next) { |
ca50f4b3 UH |
327 | cg = cgl->data; |
328 | printf(" %s: channel%s", cg->name, | |
329 | g_slist_length(cg->channels) > 1 ? "s" : ""); | |
029d73fe UH |
330 | for (chl = cg->channels; chl; chl = chl->next) { |
331 | ch = chl->data; | |
332 | printf(" %s", ch->name); | |
2be182e6 BV |
333 | } |
334 | printf("\n"); | |
335 | } | |
336 | } | |
337 | ||
338 | printf("Supported configuration options"); | |
c6fa2b2e | 339 | if (channel_groups) { |
ca50f4b3 UH |
340 | if (!channel_group) |
341 | printf(" across all channel groups"); | |
2be182e6 | 342 | else |
ca50f4b3 | 343 | printf(" on channel group %s", channel_group->name); |
2be182e6 BV |
344 | } |
345 | printf(":\n"); | |
131ae8d0 | 346 | opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t)); |
2be182e6 | 347 | for (o = 0; o < num_opts; o++) { |
23cbb498 | 348 | key = opts[o] & SR_CONF_MASK; |
e4e4b472 | 349 | if (!(srci = sr_key_info_get(SR_KEY_CONFIG, key))) |
2be182e6 BV |
350 | continue; |
351 | ||
23cbb498 | 352 | if (key == SR_CONF_TRIGGER_MATCH) { |
24bd9719 | 353 | if (maybe_config_list(driver, sdi, channel_group, key, |
6b27bde4 | 354 | &gvar_list) != SR_OK) { |
2be182e6 BV |
355 | printf("\n"); |
356 | continue; | |
357 | } | |
6b27bde4 BV |
358 | int32 = g_variant_get_fixed_array(gvar_list, |
359 | &num_elements, sizeof(int32_t)); | |
2be182e6 | 360 | printf(" Supported triggers: "); |
6b27bde4 | 361 | for (i = 0; i < num_elements; i++) { |
f0f54487 | 362 | switch (int32[i]) { |
6b27bde4 BV |
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; | |
50c641aa AJ |
384 | default: |
385 | c = 0; | |
386 | break; | |
6b27bde4 | 387 | } |
50c641aa AJ |
388 | if (c) |
389 | printf("%c ", c); | |
2be182e6 BV |
390 | } |
391 | printf("\n"); | |
6b27bde4 | 392 | g_variant_unref(gvar_list); |
2be182e6 | 393 | |
24bd9719 | 394 | } else if (key == SR_CONF_LIMIT_SAMPLES |
15db66c6 | 395 | && config_key_has_cap(driver, sdi, NULL, key, SR_CONF_LIST)) { |
f0f54487 UH |
396 | /* |
397 | * If implemented in config_list(), this denotes the | |
02c65935 BV |
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 | |
f0f54487 UH |
402 | * are the low/high limits. |
403 | */ | |
c6fa2b2e | 404 | if (sr_config_list(driver, sdi, channel_group, key, |
24bd9719 BV |
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); | |
02c65935 | 409 | } |
02c65935 | 410 | |
23cbb498 | 411 | } else if (key == SR_CONF_SAMPLERATE) { |
2be182e6 BV |
412 | /* Supported samplerates */ |
413 | printf(" %s", srci->id); | |
24bd9719 | 414 | if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE, |
2be182e6 BV |
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 | ||
5e78186b | 454 | } else if (srci->datatype == SR_T_UINT64) { |
24bd9719 | 455 | printf(" %s: ", srci->id); |
5e78186b | 456 | gvar = NULL; |
24bd9719 | 457 | if (maybe_config_get(driver, sdi, channel_group, key, |
5e78186b BV |
458 | &gvar) == SR_OK) { |
459 | tmp_uint64 = g_variant_get_uint64(gvar); | |
460 | g_variant_unref(gvar); | |
461 | } else | |
462 | tmp_uint64 = 0; | |
24bd9719 BV |
463 | if (maybe_config_list(driver, sdi, channel_group, |
464 | key, &gvar_list) != SR_OK) { | |
5e78186b BV |
465 | if (gvar) { |
466 | /* Can't list it, but we have a value to show. */ | |
467 | printf("%"PRIu64" (current)", tmp_uint64); | |
468 | } | |
2be182e6 BV |
469 | printf("\n"); |
470 | continue; | |
471 | } | |
472 | uint64 = g_variant_get_fixed_array(gvar_list, | |
473 | &num_elements, sizeof(uint64_t)); | |
5e78186b | 474 | printf(" - supported values:\n"); |
2be182e6 | 475 | for (i = 0; i < num_elements; i++) { |
5e78186b BV |
476 | printf(" %"PRIu64, uint64[i]); |
477 | if (gvar && tmp_uint64 == uint64[i]) | |
478 | printf(" (current)"); | |
2be182e6 | 479 | printf("\n"); |
2be182e6 BV |
480 | } |
481 | g_variant_unref(gvar_list); | |
482 | ||
9db40e9f | 483 | } else if (srci->datatype == SR_T_STRING) { |
2be182e6 | 484 | printf(" %s: ", srci->id); |
24bd9719 | 485 | if (maybe_config_get(driver, sdi, channel_group, key, |
2be182e6 BV |
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 | ||
24bd9719 | 492 | if (maybe_config_list(driver, sdi, channel_group, key, |
2be182e6 | 493 | &gvar) != SR_OK) { |
dcb420e7 BV |
494 | if (tmp_str) { |
495 | /* Can't list it, but we have a value to show. */ | |
496 | printf("%s (current)", tmp_str); | |
497 | } | |
2be182e6 | 498 | printf("\n"); |
55bc3776 | 499 | g_free(tmp_str); |
2be182e6 BV |
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); | |
24bd9719 | 518 | if (maybe_config_list(driver, sdi, channel_group, key, |
2be182e6 BV |
519 | &gvar_list) != SR_OK) { |
520 | printf("\n"); | |
521 | continue; | |
522 | } | |
523 | ||
24bd9719 | 524 | if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) { |
2be182e6 BV |
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); | |
24bd9719 | 548 | if (maybe_config_get(driver, sdi, channel_group, key, |
2be182e6 BV |
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 | ||
426d0cda BV |
558 | } else if (srci->datatype == SR_T_DOUBLE_RANGE) { |
559 | printf(" %s: ", srci->id); | |
24bd9719 | 560 | if (maybe_config_list(driver, sdi, channel_group, key, |
426d0cda BV |
561 | &gvar_list) != SR_OK) { |
562 | printf("\n"); | |
563 | continue; | |
564 | } | |
565 | ||
24bd9719 | 566 | if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) { |
426d0cda BV |
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 | ||
dcb420e7 BV |
588 | } else if (srci->datatype == SR_T_FLOAT) { |
589 | printf(" %s: ", srci->id); | |
24bd9719 | 590 | if (maybe_config_get(driver, sdi, channel_group, key, |
dcb420e7 BV |
591 | &gvar) == SR_OK) { |
592 | printf("%f\n", g_variant_get_double(gvar)); | |
593 | g_variant_unref(gvar); | |
594 | } else | |
5e78186b BV |
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); | |
24bd9719 | 600 | if (maybe_config_get(driver, sdi, channel_group, key, |
5e78186b BV |
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 | ||
24bd9719 | 607 | if (maybe_config_list(driver, sdi, channel_group, |
5e78186b BV |
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); | |
dcb420e7 | 628 | |
84b39e3e | 629 | } else if (srci->datatype == SR_T_MQ) { |
e9505599 BV |
630 | printf(" %s: ", srci->id); |
631 | if (maybe_config_get(driver, sdi, channel_group, key, | |
632 | &gvar) == SR_OK | |
84b39e3e BV |
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); | |
e9505599 BV |
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("/%ld", 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 | ||
2be182e6 BV |
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); | |
2be182e6 BV |
678 | |
679 | } | |
680 | ||
681 | #ifdef HAVE_SRD | |
682 | void show_pd_detail(void) | |
683 | { | |
2be182e6 BV |
684 | struct srd_decoder *dec; |
685 | struct srd_decoder_option *o; | |
3dfbfbc8 | 686 | struct srd_channel *pdch; |
1eb46be8 | 687 | struct srd_decoder_annotation_row *r; |
3d7bf979 BV |
688 | GSList *l, *ll, *ol; |
689 | int idx; | |
690 | char **pdtokens, **pdtok, *optsep, **ann, *val, *doc; | |
2be182e6 BV |
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); | |
b39f3a1a | 704 | printf("Annotation classes:\n"); |
2be182e6 BV |
705 | if (dec->annotations) { |
706 | for (l = dec->annotations; l; l = l->next) { | |
707 | ann = l->data; | |
b39f3a1a | 708 | printf("- %s: %s\n", ann[0], ann[1]); |
2be182e6 BV |
709 | } |
710 | } else { | |
711 | printf("None.\n"); | |
712 | } | |
1eb46be8 UH |
713 | printf("Annotation rows:\n"); |
714 | if (dec->annotation_rows) { | |
715 | for (l = dec->annotation_rows; l; l = l->next) { | |
716 | r = l->data; | |
b39f3a1a | 717 | printf("- %s (%s): ", r->id, r->desc); |
3d7bf979 BV |
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 | } | |
1eb46be8 UH |
725 | printf("\n"); |
726 | } | |
727 | } else { | |
728 | printf("None.\n"); | |
729 | } | |
3dfbfbc8 UH |
730 | printf("Required channels:\n"); |
731 | if (dec->channels) { | |
732 | for (l = dec->channels; l; l = l->next) { | |
733 | pdch = l->data; | |
2be182e6 | 734 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 735 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
736 | } |
737 | } else { | |
738 | printf("None.\n"); | |
739 | } | |
3dfbfbc8 UH |
740 | printf("Optional channels:\n"); |
741 | if (dec->opt_channels) { | |
742 | for (l = dec->opt_channels; l; l = l->next) { | |
743 | pdch = l->data; | |
2be182e6 | 744 | printf("- %s (%s): %s\n", |
3dfbfbc8 | 745 | pdch->id, pdch->name, pdch->desc); |
2be182e6 BV |
746 | } |
747 | } else { | |
748 | printf("None.\n"); | |
749 | } | |
1eb46be8 | 750 | printf("Options:\n"); |
2be182e6 | 751 | if (dec->options) { |
2be182e6 BV |
752 | for (l = dec->options; l; l = l->next) { |
753 | o = l->data; | |
f2e82732 BV |
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 | } | |
2be182e6 | 760 | val = g_variant_print(o->def, FALSE); |
f2e82732 | 761 | printf("default %s)\n", val); |
2be182e6 BV |
762 | g_free(val); |
763 | } | |
1eb46be8 UH |
764 | } else { |
765 | printf("None.\n"); | |
2be182e6 BV |
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 | ||
a8b4041a BV |
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 | ||
ad6520c4 BV |
818 | void show_output(void) |
819 | { | |
820 | const struct sr_output_module *omod; | |
7c6a0420 | 821 | const struct sr_option **opts; |
ad6520c4 | 822 | GSList *l; |
7c6a0420 | 823 | int i; |
e786e625 | 824 | char *s, **tok; |
ad6520c4 | 825 | |
e786e625 BV |
826 | tok = g_strsplit(opt_output_format, ":", 0); |
827 | if (!tok[0] || !(omod = sr_output_find(tok[0]))) | |
ad6520c4 BV |
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)); | |
b61a8850 | 833 | if ((opts = sr_output_options_get(omod))) { |
ad6520c4 | 834 | printf("Options:\n"); |
7c6a0420 BV |
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); | |
ad6520c4 BV |
839 | printf(" (default %s", s); |
840 | g_free(s); | |
7c6a0420 | 841 | if (opts[i]->values) { |
ad6520c4 | 842 | printf(", possible values "); |
7c6a0420 | 843 | for (l = opts[i]->values; l; l = l->next) { |
ad6520c4 BV |
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"); | |
ad6520c4 | 852 | } |
b61a8850 | 853 | sr_output_options_free(opts); |
ad6520c4 | 854 | } |
e786e625 | 855 | g_strfreev(tok); |
ad6520c4 BV |
856 | } |
857 | ||
6f7b4c5d UH |
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 | } |