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