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