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