]> sigrok.org Git - sigrok-cli.git/blame - decode.c
show: do print floating point results even if value is zero
[sigrok-cli.git] / decode.c
CommitLineData
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>
f0f54487
UH
21#include <stdlib.h>
22#include <string.h>
2be182e6 23#include <glib.h>
662a1e27 24#include "sigrok-cli.h"
2be182e6
BV
25
26#ifdef HAVE_SRD
27static GHashTable *pd_ann_visible = NULL;
28static GHashTable *pd_meta_visible = NULL;
29static GHashTable *pd_binary_visible = NULL;
3dfbfbc8 30static GHashTable *pd_channel_maps = NULL;
2be182e6
BV
31
32extern struct srd_session *srd_sess;
2be182e6
BV
33
34static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash,
35 GHashTable **options)
36{
37 struct srd_decoder_option *o;
38 GSList *optl;
39 GVariant *gvar;
40 gint64 val_int;
4c1a29f4 41 double val_dbl;
2be182e6
BV
42 int ret;
43 char *val_str, *conv;
44
45 ret = TRUE;
46 *options = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
47 (GDestroyNotify)g_variant_unref);
48
49 for (optl = dec->options; optl; optl = optl->next) {
50 o = optl->data;
51 if (!(val_str = g_hash_table_lookup(hash, o->id)))
52 /* Not specified. */
53 continue;
54 if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_STRING)) {
55 gvar = g_variant_new_string(val_str);
56 } else if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_INT64)) {
b5c8f3a1 57 conv = NULL;
2be182e6 58 val_int = strtoll(val_str, &conv, 0);
b5c8f3a1 59 if (!conv || conv == val_str || *conv) {
2be182e6
BV
60 g_critical("Protocol decoder '%s' option '%s' "
61 "requires a number.", dec->name, o->id);
62 ret = FALSE;
63 break;
64 }
65 gvar = g_variant_new_int64(val_int);
4c1a29f4
GS
66 } else if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_DOUBLE)) {
67 conv = NULL;
68 val_dbl = strtod(val_str, &conv);
69 if (!conv || conv == val_str || *conv) {
70 g_critical("Protocol decoder '%s' option '%s' requires a float number.",
71 dec->name, o->id);
72 ret = FALSE;
73 break;
74 }
75 gvar = g_variant_new_double(val_dbl);
2be182e6
BV
76 } else {
77 g_critical("Unsupported type for option '%s' (%s)",
78 o->id, g_variant_get_type_string(o->def));
79 ret = FALSE;
80 break;
81 }
82 g_variant_ref_sink(gvar);
83 g_hash_table_insert(*options, g_strdup(o->id), gvar);
84 g_hash_table_remove(hash, o->id);
85 }
86
87 return ret;
88}
89
39aedc34 90static int move_hash_element(GHashTable *src, GHashTable *dest, void *key)
2be182e6 91{
39aedc34
DE
92 void *orig_key, *value;
93
94 if (!g_hash_table_lookup_extended(src, key, &orig_key, &value))
95 /* Not specified. */
96 return FALSE;
97 g_hash_table_steal(src, orig_key);
98 g_hash_table_insert(dest, orig_key, value);
99
100 return TRUE;
101}
102
3dfbfbc8 103static GHashTable *extract_channel_map(struct srd_decoder *dec, GHashTable *hash)
39aedc34 104{
3dfbfbc8
UH
105 GHashTable *channel_map;
106 struct srd_channel *pdch;
39aedc34 107 GSList *l;
2be182e6 108
3dfbfbc8 109 channel_map = g_hash_table_new_full(g_str_hash, g_str_equal,
39aedc34 110 g_free, g_free);
2be182e6 111
3dfbfbc8
UH
112 for (l = dec->channels; l; l = l->next) {
113 pdch = l->data;
114 move_hash_element(hash, channel_map, pdch->id);
39aedc34 115 }
3dfbfbc8
UH
116 for (l = dec->opt_channels; l; l = l->next) {
117 pdch = l->data;
118 move_hash_element(hash, channel_map, pdch->id);
2be182e6 119 }
2be182e6 120
3dfbfbc8 121 return channel_map;
2be182e6
BV
122}
123
551f570c 124static int register_pd(char *opt_pds, char *opt_pd_annotations)
2be182e6 125{
551f570c 126 int ret;
2be182e6 127 struct srd_decoder *dec;
551f570c
KP
128 struct srd_decoder_inst *di, *di_prior;
129 char **pdtokens, **pdtok, *pd_name;
3dfbfbc8 130 GHashTable *pd_opthash, *options, *channels;
2be182e6 131 GList *leftover, *l;
2be182e6 132
2be182e6
BV
133 ret = 0;
134 pd_name = NULL;
551f570c
KP
135 di_prior = NULL;
136 pd_opthash = options = channels = NULL;
137
26c63758 138 pdtokens = g_strsplit(opt_pds, ",", 0);
2be182e6
BV
139 for (pdtok = pdtokens; *pdtok; pdtok++) {
140 if (!(pd_opthash = parse_generic_arg(*pdtok, TRUE))) {
141 g_critical("Invalid protocol decoder option '%s'.", *pdtok);
142 break;
143 }
144
145 pd_name = g_strdup(g_hash_table_lookup(pd_opthash, "sigrok_key"));
146 g_hash_table_remove(pd_opthash, "sigrok_key");
147 if (srd_decoder_load(pd_name) != SRD_OK) {
148 g_critical("Failed to load protocol decoder %s.", pd_name);
149 ret = 1;
150 break;
151 }
3a8ceb6a
BV
152 if (!(dec = srd_decoder_get_by_id(pd_name))) {
153 g_critical("Failed to get decoder %s by id.", pd_name);
154 ret = 1;
155 break;
156 }
2be182e6 157
3dfbfbc8 158 /* Convert decoder option and channel values to GVariant. */
2be182e6
BV
159 if (!opts_to_gvar(dec, pd_opthash, &options)) {
160 ret = 1;
161 break;
162 }
3dfbfbc8 163 channels = extract_channel_map(dec, pd_opthash);
39aedc34 164
2be182e6
BV
165 if (g_hash_table_size(pd_opthash) > 0) {
166 leftover = g_hash_table_get_keys(pd_opthash);
167 for (l = leftover; l; l = l->next)
3dfbfbc8 168 g_critical("Unknown option or channel '%s'", (char *)l->data);
2be182e6
BV
169 g_list_free(leftover);
170 break;
171 }
172
173 if (!(di = srd_inst_new(srd_sess, pd_name, options))) {
174 g_critical("Failed to instantiate protocol decoder %s.", pd_name);
175 ret = 1;
176 break;
177 }
178
09fea207 179 if (pdtok == pdtokens) {
3dfbfbc8
UH
180 /*
181 * Save the channel setup for later, but only on the
182 * first decoder (stacked decoders don't get channels).
183 */
3dfbfbc8
UH
184 g_hash_table_insert(pd_channel_maps, g_strdup(di->inst_id), channels);
185 channels = NULL;
09fea207 186 }
39aedc34 187
f0f54487
UH
188 /*
189 * If no annotation list was specified, add them all in now.
2be182e6
BV
190 * This will be pared down later to leave only the last PD
191 * in the stack.
192 */
551f570c 193 if (!opt_pd_annotations) {
10d4fc25 194 g_hash_table_insert(pd_ann_visible, g_strdup(di->decoder->id),
790b0261 195 g_slist_append(NULL, GINT_TO_POINTER(-1)));
551f570c
KP
196 }
197 if (di_prior) {
198 if (srd_inst_stack(srd_sess, di_prior, di) != SRD_OK) {
199 g_critical("Failed to stack %s -> %s.",
200 di_prior->inst_id, di->inst_id);
201 ret = 1;
202 break;
203 }
204 /* Remove annotations from prior levels. */
205 if (!opt_pd_annotations)
206 g_hash_table_remove(pd_ann_visible, di_prior->inst_id);
207 }
208 di_prior = di;
c5e0e72e
KP
209 g_free(pd_name);
210 g_hash_table_destroy(pd_opthash);
211 g_hash_table_destroy(options);
212 pd_opthash = options = NULL;
2be182e6
BV
213 }
214
2be182e6
BV
215 if (pd_opthash)
216 g_hash_table_destroy(pd_opthash);
217 if (options)
218 g_hash_table_destroy(options);
3dfbfbc8
UH
219 if (channels)
220 g_hash_table_destroy(channels);
551f570c
KP
221
222 g_strfreev(pdtokens);
2be182e6
BV
223
224 return ret;
225}
226
551f570c
KP
227/*
228 * Register all the PDs from all stacks.
229 *
230 * Each PD string is a single stack such as "uart:baudrate=19200,modbus".
231 */
232int register_pds(gchar **all_pds, char *opt_pd_annotations)
233{
234 int ret;
235
236 ret = 0;
237 pd_ann_visible = g_hash_table_new_full(g_str_hash, g_str_equal,
238 g_free, NULL);
239 pd_channel_maps = g_hash_table_new_full(g_str_hash,
240 g_str_equal, g_free, (GDestroyNotify)g_hash_table_destroy);
241
242 for (int i = 0; all_pds[i]; i++)
243 ret += register_pd(all_pds[i], opt_pd_annotations);
244
245 return ret;
246}
247
3dfbfbc8 248static void map_pd_inst_channels(void *key, void *value, void *user_data)
39aedc34 249{
3dfbfbc8
UH
250 GHashTable *channel_map;
251 GHashTable *channel_indices;
252 GSList *channel_list;
39aedc34
DE
253 struct srd_decoder_inst *di;
254 GVariant *var;
3dfbfbc8 255 void *channel_id;
029d73fe
UH
256 void *channel_target;
257 struct sr_channel *ch;
39aedc34 258 GHashTableIter iter;
39aedc34 259
3dfbfbc8
UH
260 channel_map = value;
261 channel_list = user_data;
39aedc34
DE
262
263 di = srd_inst_find_by_id(srd_sess, key);
264 if (!di) {
265 g_critical("Protocol decoder instance \"%s\" not found.",
266 (char *)key);
267 return;
268 }
3dfbfbc8 269 channel_indices = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
39aedc34
DE
270 (GDestroyNotify)g_variant_unref);
271
3dfbfbc8
UH
272 g_hash_table_iter_init(&iter, channel_map);
273 while (g_hash_table_iter_next(&iter, &channel_id, &channel_target)) {
172d2b30
WS
274 if (!channel_target) {
275 g_printerr("cli: Channel name for \"%s\" missing.\n",
276 (char *)channel_id);
277 continue;
278 }
3dfbfbc8 279 ch = find_channel(channel_list, channel_target);
029d73fe
UH
280 if (!ch) {
281 g_printerr("cli: No channel with name \"%s\" found.\n",
282 (char *)channel_target);
39aedc34
DE
283 continue;
284 }
029d73fe
UH
285 if (!ch->enabled)
286 g_printerr("cli: Target channel \"%s\" not enabled.\n",
287 (char *)channel_target);
39aedc34 288
029d73fe 289 var = g_variant_new_int32(ch->index);
39aedc34 290 g_variant_ref_sink(var);
3dfbfbc8 291 g_hash_table_insert(channel_indices, g_strdup(channel_id), var);
39aedc34
DE
292 }
293
ee639fb4 294 srd_inst_channel_set_all(di, channel_indices);
c5e0e72e 295 g_hash_table_destroy(channel_indices);
39aedc34
DE
296}
297
3dfbfbc8 298void map_pd_channels(struct sr_dev_inst *sdi)
39aedc34 299{
c6fa2b2e
UH
300 GSList *channels;
301
302 channels = sr_dev_inst_channels_get(sdi);
303
3dfbfbc8
UH
304 if (pd_channel_maps) {
305 g_hash_table_foreach(pd_channel_maps, &map_pd_inst_channels,
c6fa2b2e 306 channels);
3dfbfbc8
UH
307 g_hash_table_destroy(pd_channel_maps);
308 pd_channel_maps = NULL;
39aedc34
DE
309 }
310}
311
26c63758 312int setup_pd_annotations(char *opt_pd_annotations)
2be182e6 313{
790b0261 314 GSList *l, *l_ann;
2be182e6
BV
315 struct srd_decoder *dec;
316 int ann_class;
790b0261 317 char **pds, **pdtok, **keyval, **annlist, **ann, **ann_descr;
d6ebfaa8
GS
318 const char *dec_id;
319 const char *ann_txt;
320 const char *ann_id;
65cd80ad
GS
321 const struct srd_decoder_annotation_row *row_desc;
322 char **ann_diag;
2be182e6
BV
323
324 /* Set up custom list of PDs and annotations to show. */
325 pds = g_strsplit(opt_pd_annotations, ",", 0);
326 for (pdtok = pds; *pdtok && **pdtok; pdtok++) {
327 keyval = g_strsplit(*pdtok, "=", 0);
d6ebfaa8
GS
328 dec_id = keyval[0];
329 if (!(dec = srd_decoder_get_by_id(dec_id))) {
330 g_critical("Protocol decoder '%s' not found.", dec_id);
8f72edc3
GS
331 g_strfreev(keyval);
332 g_strfreev(pds);
2be182e6
BV
333 return 1;
334 }
335 if (!dec->annotations) {
d6ebfaa8 336 g_critical("Protocol decoder '%s' has no annotations.", dec_id);
8f72edc3
GS
337 g_strfreev(keyval);
338 g_strfreev(pds);
2be182e6
BV
339 return 1;
340 }
d6ebfaa8
GS
341 ann_txt = (g_strv_length(keyval) == 2) ? keyval[1] : NULL;
342 if (ann_txt && *ann_txt) {
343 annlist = g_strsplit(ann_txt, ":", 0);
790b0261 344 for (ann = annlist; *ann && **ann; ann++) {
d6ebfaa8 345 ann_id = *ann;
65cd80ad 346 g_debug("cli: Lookup decoder %s annotation %s.", dec_id, ann_id);
4171a0a0 347 /* Lookup annotation class. */
790b0261
BV
348 ann_class = 0;
349 for (l = dec->annotations; l; l = l->next, ann_class++) {
350 ann_descr = l->data;
d6ebfaa8 351 if (!canon_cmp(ann_descr[0], ann_id))
790b0261
BV
352 /* Found it. */
353 break;
354 }
4171a0a0
GS
355 if (l) {
356 l_ann = g_hash_table_lookup(pd_ann_visible, dec_id);
357 l_ann = g_slist_append(l_ann, GINT_TO_POINTER(ann_class));
358 g_hash_table_replace(pd_ann_visible, g_strdup(dec_id), l_ann);
359 g_debug("cli: Showing protocol decoder %s annotation "
360 "class %d (%s).", dec_id, ann_class, ann_descr[0]);
361 continue;
790b0261 362 }
65cd80ad
GS
363 /* Lookup annotation row. */
364 for (l = dec->annotation_rows; l; l = l->next) {
365 row_desc = l->data;
366 if (!canon_cmp(row_desc->id, ann_id))
367 break;
368 }
369 if (l) {
370 g_debug("cli: Showing decoder %s annotation row %s (%s).",
371 dec_id, row_desc->id, row_desc->desc);
372 l_ann = g_hash_table_lookup(pd_ann_visible, dec_id);
373 for (l = row_desc->ann_classes; l; l = l->next) {
374 /*
375 * This could just be:
376 * l_ann = g_slist_append(l_ann, l->data);
377 * But we are explicit for readability
378 * and to access details for diagnostics.
379 */
380 ann_class = GPOINTER_TO_INT(l->data);
381 l_ann = g_slist_append(l_ann, GINT_TO_POINTER(ann_class));
382 ann_diag = g_slist_nth_data(dec->annotations, ann_class);
383 g_debug("cli: Adding class %d/%s from row %s.",
384 ann_class, ann_diag[0], row_desc->id);
385 }
386 g_hash_table_replace(pd_ann_visible, g_strdup(dec_id), l_ann);
387 continue;
388 }
4171a0a0
GS
389 /* No match found. */
390 g_critical("Annotation '%s' not found "
391 "for protocol decoder '%s'.", ann_id, dec_id);
392 g_strfreev(keyval);
393 g_strfreev(pds);
394 return 1;
2be182e6 395 }
2be182e6
BV
396 } else {
397 /* No class specified: show all of them. */
11e554c2
GS
398 ann_class = -1;
399 l_ann = g_slist_append(NULL, GINT_TO_POINTER(ann_class));
400 g_hash_table_insert(pd_ann_visible, g_strdup(dec_id), l_ann);
2be182e6 401 g_debug("cli: Showing all annotation classes for protocol "
d6ebfaa8 402 "decoder %s.", dec_id);
2be182e6 403 }
2be182e6
BV
404 g_strfreev(keyval);
405 }
406 g_strfreev(pds);
407
408 return 0;
409}
410
26c63758 411int setup_pd_meta(char *opt_pd_meta)
2be182e6
BV
412{
413 struct srd_decoder *dec;
414 char **pds, **pdtok;
415
416 pd_meta_visible = g_hash_table_new_full(g_str_hash, g_int_equal,
417 g_free, NULL);
418 pds = g_strsplit(opt_pd_meta, ",", 0);
419 for (pdtok = pds; *pdtok && **pdtok; pdtok++) {
420 if (!(dec = srd_decoder_get_by_id(*pdtok))) {
421 g_critical("Protocol decoder '%s' not found.", *pdtok);
422 return 1;
423 }
424 g_debug("cli: Showing protocol decoder meta output from '%s'.", *pdtok);
425 g_hash_table_insert(pd_meta_visible, g_strdup(*pdtok), NULL);
426 }
427 g_strfreev(pds);
428
429 return 0;
430}
431
26c63758 432int setup_pd_binary(char *opt_pd_binary)
2be182e6
BV
433{
434 GSList *l;
435 struct srd_decoder *dec;
436 int bin_class;
5ff52594 437 char **pds, **pdtok, **keyval, **bin_name;
2be182e6
BV
438
439 pd_binary_visible = g_hash_table_new_full(g_str_hash, g_int_equal,
440 g_free, NULL);
441 pds = g_strsplit(opt_pd_binary, ",", 0);
442 for (pdtok = pds; *pdtok && **pdtok; pdtok++) {
443 keyval = g_strsplit(*pdtok, "=", 0);
444 if (!(dec = srd_decoder_get_by_id(keyval[0]))) {
445 g_critical("Protocol decoder '%s' not found.", keyval[0]);
446 return 1;
447 }
448 if (!dec->binary) {
449 g_critical("Protocol decoder '%s' has no binary output.", keyval[0]);
450 return 1;
451 }
452 bin_class = 0;
453 if (g_strv_length(keyval) == 2) {
454 for (l = dec->binary; l; l = l->next, bin_class++) {
455 bin_name = l->data;
5ff52594 456 if (!strcmp(bin_name[0], keyval[1]))
2be182e6
BV
457 /* Found it. */
458 break;
459 }
460 if (!l) {
461 g_critical("binary output '%s' not found "
462 "for protocol decoder '%s'.", keyval[1], keyval[0]);
463 return 1;
464 }
465 g_debug("cli: Showing protocol decoder %s binary class "
5ff52594 466 "%d (%s).", keyval[0], bin_class, bin_name[0]);
2be182e6
BV
467 } else {
468 /* No class specified: output all of them. */
469 bin_class = -1;
470 g_debug("cli: Showing all binary classes for protocol "
471 "decoder %s.", keyval[0]);
472 }
473 g_hash_table_insert(pd_binary_visible, g_strdup(keyval[0]), GINT_TO_POINTER(bin_class));
474 g_strfreev(keyval);
475 }
476 g_strfreev(pds);
477
478 return 0;
479}
480
481void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data)
482{
6fdcc67d 483 struct srd_decoder *dec;
2be182e6 484 struct srd_proto_data_annotation *pda;
790b0261
BV
485 GSList *ann_list, *l;
486 int i;
6fdcc67d 487 char **ann_descr;
241f9b13 488 gboolean show_ann, show_snum, show_class, show_quotes, show_abbrev;
e1a352d1 489 const char *quote;
2be182e6 490
2be182e6
BV
491 (void)cb_data;
492
493 if (!pd_ann_visible)
494 return;
495
10d4fc25
KP
496 if (!g_hash_table_lookup_extended(pd_ann_visible, pdata->pdo->di->decoder->id,
497 NULL, (void **)&ann_list)) {
2be182e6
BV
498 /* Not in the list of PDs whose annotations we're showing. */
499 return;
10d4fc25 500 }
2be182e6 501
6fdcc67d 502 dec = pdata->pdo->di->decoder;
2be182e6 503 pda = pdata->data;
241f9b13 504 show_ann = FALSE;
790b0261
BV
505 for (l = ann_list; l; l = l->next) {
506 if (GPOINTER_TO_INT(l->data) == -1
a23105b1 507 || GPOINTER_TO_INT(l->data) == pda->ann_class) {
241f9b13 508 show_ann = TRUE;
790b0261
BV
509 break;
510 }
511 }
241f9b13 512 if (!show_ann)
2be182e6
BV
513 return;
514
241f9b13 515 /*
08e9378b
GS
516 * Determine which fields of the annotation to display. Inspect
517 * user specified options as well as the verbosity of the log level:
241f9b13
GS
518 * - Optionally show the sample numbers for the annotation's span.
519 * - Always show the protocol decoder ID.
520 * - Optionally show the annotation's class description.
521 * - Always show the longest annotation text.
522 * - Optionally show alternative annotation text (abbreviations
523 * for different zoom levels).
524 * - Optionally put quote marks around annotation text, when
525 * recipients might have to deal with a set of text variants.
526 */
527 show_snum = show_class = show_quotes = show_abbrev = FALSE;
08e9378b 528 if (opt_pd_samplenum || opt_loglevel > SR_LOG_WARN) {
241f9b13
GS
529 show_snum = TRUE;
530 }
531 if (opt_loglevel > SR_LOG_WARN) {
532 show_quotes = TRUE;
533 }
534 if (opt_loglevel > SR_LOG_INFO) {
535 show_class = TRUE;
536 show_abbrev = TRUE;
537 }
241f9b13
GS
538
539 /*
540 * Display the annotation's fields after the layout was
541 * determined above.
542 */
e1a352d1
GS
543 if (show_snum) {
544 printf("%" PRIu64 "-%" PRIu64 " ",
545 pdata->start_sample, pdata->end_sample);
546 }
aa001713 547 printf("%s: ", pdata->pdo->proto_id);
e1a352d1
GS
548 if (show_class) {
549 ann_descr = g_slist_nth_data(dec->annotations, pda->ann_class);
550 printf("%s: ", ann_descr[0]);
551 }
552 quote = show_quotes ? "\"" : "";
553 printf("%s%s%s", quote, pda->ann_text[0], quote);
554 if (show_abbrev) {
555 for (i = 1; pda->ann_text[i]; i++)
556 printf(" %s%s%s", quote, pda->ann_text[i], quote);
6fdcc67d 557 }
2be182e6
BV
558 printf("\n");
559 fflush(stdout);
560}
561
562void show_pd_meta(struct srd_proto_data *pdata, void *cb_data)
563{
2be182e6
BV
564 (void)cb_data;
565
566 if (!g_hash_table_lookup_extended(pd_meta_visible,
567 pdata->pdo->di->decoder->id, NULL, NULL))
568 /* Not in the list of PDs whose meta output we're showing. */
569 return;
570
08e9378b 571 if (opt_pd_samplenum || opt_loglevel > SR_LOG_WARN)
2be182e6
BV
572 printf("%"PRIu64"-%"PRIu64" ", pdata->start_sample, pdata->end_sample);
573 printf("%s: ", pdata->pdo->proto_id);
574 printf("%s: %s", pdata->pdo->meta_name, g_variant_print(pdata->data, FALSE));
575 printf("\n");
576 fflush(stdout);
577}
578
579void show_pd_binary(struct srd_proto_data *pdata, void *cb_data)
580{
581 struct srd_proto_data_binary *pdb;
582 gpointer classp;
4ae9434a 583 int classi;
2be182e6 584
2be182e6
BV
585 (void)cb_data;
586
587 if (!g_hash_table_lookup_extended(pd_binary_visible,
588 pdata->pdo->di->decoder->id, NULL, (void **)&classp))
589 /* Not in the list of PDs whose meta output we're showing. */
590 return;
591
4ae9434a 592 classi = GPOINTER_TO_INT(classp);
2be182e6 593 pdb = pdata->data;
4ae9434a 594 if (classi != -1 && classi != pdb->bin_class)
2be182e6
BV
595 /* Not showing this binary class. */
596 return;
597
598 /* Just send the binary output to stdout, no embellishments. */
599 fwrite(pdb->data, pdb->size, 1, stdout);
600 fflush(stdout);
601}
602#endif