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