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