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