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