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