From: Gerhard Sittig Date: Sun, 9 Jul 2017 11:56:45 +0000 (+0200) Subject: decode: Optionally print sample numbers with protocol decoder annotations X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=commitdiff_plain;h=08e9378bf68ad8fa0ce10dcb1973f819e10c5d1a decode: Optionally print sample numbers with protocol decoder annotations Introduce the "--protocol-decoder-samplenum" command line option (no short form available), which emits sample numbers with textual output from protocol decoder annotations, regardless of a log level value. This shall increase usability of sigrok-cli output with external postprocessors, as the option exclusively adds sample numbers to the output but does not affect the presence or layout of any other line. This commit prepends "text" and "meta" annotations with sample number information. It does not change "binary" output. --- diff --git a/decode.c b/decode.c index 24c7001..38b58ad 100644 --- a/decode.c +++ b/decode.c @@ -452,8 +452,8 @@ void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data) return; /* - * Determine the annotation's layout from the verbosity of the - * log level: + * Determine which fields of the annotation to display. Inspect + * user specified options as well as the verbosity of the log level: * - Optionally show the sample numbers for the annotation's span. * - Always show the protocol decoder ID. * - Optionally show the annotation's class description. @@ -464,7 +464,7 @@ void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data) * recipients might have to deal with a set of text variants. */ show_snum = show_class = show_quotes = show_abbrev = FALSE; - if (opt_loglevel > SR_LOG_WARN) { + if (opt_pd_samplenum || opt_loglevel > SR_LOG_WARN) { show_snum = TRUE; } if (opt_loglevel > SR_LOG_WARN) { @@ -509,7 +509,7 @@ void show_pd_meta(struct srd_proto_data *pdata, void *cb_data) /* Not in the list of PDs whose meta output we're showing. */ return; - if (opt_loglevel > SR_LOG_WARN) + if (opt_pd_samplenum || opt_loglevel > SR_LOG_WARN) printf("%"PRIu64"-%"PRIu64" ", pdata->start_sample, pdata->end_sample); printf("%s: ", pdata->pdo->proto_id); printf("%s: %s", pdata->pdo->meta_name, g_variant_print(pdata->data, FALSE)); diff --git a/options.c b/options.c index ca16e4c..49e3edf 100644 --- a/options.c +++ b/options.c @@ -38,6 +38,7 @@ gchar **opt_pds = NULL; gchar *opt_pd_annotations = NULL; gchar *opt_pd_meta = NULL; gchar *opt_pd_binary = NULL; +gboolean opt_pd_samplenum = FALSE; #endif gchar *opt_input_format = NULL; gchar *opt_output_format = NULL; @@ -134,6 +135,8 @@ static const GOptionEntry optargs[] = { "Protocol decoder meta output to show", NULL}, {"protocol-decoder-binary", 'B', 0, G_OPTION_ARG_CALLBACK, &check_opt_pd_binary, "Protocol decoder binary output to show", NULL}, + {"protocol-decoder-samplenum", 0, 0, G_OPTION_ARG_NONE, &opt_pd_samplenum, + "Show sample numbers in protocol decoder output", NULL}, #endif {"scan", 0, 0, G_OPTION_ARG_NONE, &opt_scan_devs, "Scan for devices", NULL}, diff --git a/sigrok-cli.h b/sigrok-cli.h index 96d8128..80b7417 100644 --- a/sigrok-cli.h +++ b/sigrok-cli.h @@ -116,6 +116,7 @@ extern gchar **opt_pds; extern gchar *opt_pd_annotations; extern gchar *opt_pd_meta; extern gchar *opt_pd_binary; +extern gboolean opt_pd_samplenum; #endif extern gchar *opt_input_format; extern gchar *opt_output_format;