]> sigrok.org Git - sigrok-cli.git/commitdiff
doc: update sigrok-cli(1) for channel assignment to decoder inputs master github/master
authorGerhard Sittig <redacted>
Fri, 7 Apr 2023 16:54:14 +0000 (18:54 +0200)
committerGerhard Sittig <redacted>
Sun, 9 Apr 2023 22:19:38 +0000 (00:19 +0200)
Extend the sigrok-cli manpage section which discusses the -P option.
Mention the assignment of logic channels to decoder inputs by index
or by name.

Automatic assignment by position in the absence of user specs seems
to not have been recent implementations' default behaviour. Remove
that outdated or incorrect comment.

16 files changed:
HACKING
Makefile.am
README
configure.ac
contrib/sigrok-cli_cross.nsi.in
decode.c
device.c
doc/sigrok-cli.1
input.c
main.c
options.c
output.c [new file with mode: 0644]
parsers.c
session.c
show.c
sigrok-cli.h

diff --git a/HACKING b/HACKING
index c9b876b1df7dc57a1df85cfe0aaaec6c815337e3..36c6756faaccd9228019d84a17f5aee8eeec9f0b 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -29,18 +29,27 @@ Contributions
 Random notes
 ------------
 
- - Consistently use g_try_malloc() / g_try_malloc0(). Do not use standard
+ - Don't do variable declarations in compound statements, only at the
+   beginning of a function.
+
+ - Generally avoid assigning values to variables at declaration time,
+   especially so for complex and/or run-time dependent values.
+
+ - Consistently use g_*malloc() / g_*malloc0(). Do not use standard
    malloc()/calloc() if it can be avoided (sometimes other libs such
    as libftdi can return malloc()'d memory, for example).
 
  - Always properly match allocations with the proper *free() functions. If
-   glib's g_try_malloc()/g_try_malloc0() was used, use g_free() to free the
+   glib's g_*malloc()/g_*malloc0() was used, use g_free() to free the
    memory. Otherwise use standard free(). Never use the wrong function!
 
- - Never use g_malloc() or g_malloc0(). These functions do not return NULL
-   if not enough memory is available but rather lead to an exit() or segfault
-   instead. This behaviour is not acceptable.
-   Use g_try_malloc()/g_try_malloc0() instead and check the return value.
+ - We assume that "small" memory allocations (< 1MB) will always succeed.
+   Thus, it's fine to use g_malloc() or g_malloc0() for allocations of
+   simple/small structs and such (instead of using g_try_malloc()), and
+   there's no need to check the return value.
+
+   Do use g_try_malloc() or g_try_malloc0() for large (>= 1MB) allocations
+   and check the return value.
 
  - You should never print any messages (neither to stdout nor stderr nor
    elsewhere) "manually" via e.g. printf() or g_log() or similar functions.
index 84f94b49afbad809ecb58de3b60dacd7766b7d47..d5cc780c49c2609a3da5737b9322dde9f5850206 100644 (file)
@@ -30,6 +30,7 @@ sigrok_cli_SOURCES = \
        device.c \
        session.c \
        input.c \
+       output.c \
        decode.c \
        sigrok-cli.h \
        parsers.c \
diff --git a/README b/README
index d33597a511daa4ed6a1bea925591ac1b99a73505..234b0efd336e42fef8bddd27f0edd910d69fe50c 100644 (file)
--- a/README
+++ b/README
@@ -29,7 +29,7 @@ Requirements
  - pkg-config >= 0.22
  - libglib >= 2.32.0
  - libsigrok >= 0.5.0
- - libsigrokdecode >= 0.6.0
+ - libsigrokdecode >= 0.5.0
 
 
 Building and installing
@@ -74,7 +74,7 @@ Mailing list
 IRC
 ---
 
-You can find the sigrok developers in the #sigrok IRC channel on Freenode.
+You can find the sigrok developers in the #sigrok IRC channel on Libera.Chat.
 
 
 Website
index ef0ea0b2ce34dff2379c742785d9d0b95f2e5654..f7e689be976b5516c9b15f73e207e5f5d3b7d721 100644 (file)
@@ -91,6 +91,15 @@ AC_SYS_LARGEFILE
 PKG_CHECK_MODULES([SIGROK_CLI],
        [glib-2.0 >= 2.32.0 libsigrok >= 0.5.0 $SC_PKGLIBS])
 
+# Check for version dependent availability of functions.
+srd_save_cflags=$CFLAGS
+srd_save_libs=$LIBS
+CFLAGS="$SIGROK_CLI_CFLAGS $CFLAGS"
+LIBS="$SIGROK_CLI_LIBS $LIBS"
+AC_CHECK_FUNCS([srd_session_send_eof])
+CFLAGS=$srd_save_cflags
+LIBS=$srd_save_libs
+
 sc_glib_version=`$PKG_CONFIG --modversion glib-2.0 2>&AS_MESSAGE_LOG_FD`
 sc_libsigrok_version=`$PKG_CONFIG --modversion libsigrok 2>&AS_MESSAGE_LOG_FD`
 
index 196a10740a599eed437c71484d23f801ca673118..6f60540fa19cfd31969dbacff3b624403cf3b4a6 100644 (file)
@@ -1,7 +1,7 @@
 ##
 ## This file is part of the sigrok-cli project.
 ##
-## Copyright (C) 2011-2014 Uwe Hermann <uwe@hermann-uwe.de>
+## Copyright (C) 2011-2020 Uwe Hermann <uwe@hermann-uwe.de>
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -40,7 +40,11 @@ Name "@PACKAGE_NAME@"
 OutFile "@PACKAGE_NAME@-@SC_PACKAGE_VERSION@-installer.exe"
 
 # Where to install the application.
-InstallDir "$PROGRAMFILES\sigrok\@PACKAGE_NAME@"
+!ifdef PE64
+       InstallDir "$PROGRAMFILES64\sigrok\@PACKAGE_NAME@"
+!else
+       InstallDir "$PROGRAMFILES\sigrok\@PACKAGE_NAME@"
+!endif
 
 # Request admin privileges for Windows Vista and Windows 7.
 # http://nsis.sourceforge.net/Docs/Chapter4.html
@@ -129,6 +133,7 @@ Section "@PACKAGE_NAME@ (required)" Section1
        # Python
        File "${CROSS}/python34.dll"
        File "${CROSS}/python34.zip"
+       File "${CROSS}/*.pyd"
 
        SetOutPath "$INSTDIR\share"
 
@@ -236,6 +241,7 @@ Section "Uninstall"
        Delete "$INSTDIR\zadig_xp.exe"
        Delete "$INSTDIR\python34.dll"
        Delete "$INSTDIR\python34.zip"
+       Delete "$INSTDIR\*.pyd"
 
        # Delete all decoders and everything else in libsigrokdecode/.
        # There could be *.pyc files or __pycache__ subdirs and so on.
index 225162a45e4cde1238da788ec4e5c8754bd91f93..12083a1707f5d0171096b188db6e87176f6c1dd5 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -29,8 +29,14 @@ static GHashTable *pd_meta_visible = NULL;
 static GHashTable *pd_binary_visible = NULL;
 static GHashTable *pd_channel_maps = NULL;
 
+uint64_t pd_samplerate = 0;
+
 extern struct srd_session *srd_sess;
 
+static const char *keyword_assign = "assign_channels";
+static const char *assign_by_index = "auto_index";
+static const char *assign_by_name = "auto_names";
+
 static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash,
                GHashTable **options)
 {
@@ -87,7 +93,7 @@ static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash,
        return ret;
 }
 
-static int move_hash_element(GHashTable *src, GHashTable *dest, void *key)
+static int move_hash_element(GHashTable *src, GHashTable *dest, const void *key)
 {
        void *orig_key, *value;
 
@@ -109,6 +115,7 @@ static GHashTable *extract_channel_map(struct srd_decoder *dec, GHashTable *hash
        channel_map = g_hash_table_new_full(g_str_hash, g_str_equal,
                                          g_free, g_free);
 
+       move_hash_element(hash, channel_map, keyword_assign);
        for (l = dec->channels; l; l = l->next) {
                pdch = l->data;
                move_hash_element(hash, channel_map, pdch->id);
@@ -137,7 +144,7 @@ static int register_pd(char *opt_pds, char *opt_pd_annotations)
 
        pdtokens = g_strsplit(opt_pds, ",", 0);
        for (pdtok = pdtokens; *pdtok; pdtok++) {
-               if (!(pd_opthash = parse_generic_arg(*pdtok, TRUE))) {
+               if (!(pd_opthash = parse_generic_arg(*pdtok, TRUE, NULL))) {
                        g_critical("Invalid protocol decoder option '%s'.", *pdtok);
                        break;
                }
@@ -251,11 +258,21 @@ static void map_pd_inst_channels(void *key, void *value, void *user_data)
        GHashTable *channel_indices;
        GSList *channel_list;
        struct srd_decoder_inst *di;
+       struct srd_decoder *pd;
        GVariant *var;
        void *channel_id;
        void *channel_target;
        struct sr_channel *ch;
        GHashTableIter iter;
+       enum assign_t {
+               ASSIGN_UNKNOWN,
+               ASSIGN_USER_SPEC,
+               ASSIGN_BY_INDEX,
+               ASSIGN_BY_NAMES,
+       } assign;
+       const char *keyword;
+       GSList *l_pd, *l_pdo, *l_ch;
+       struct srd_channel *pdch;
 
        channel_map = value;
        channel_list = user_data;
@@ -269,9 +286,108 @@ static void map_pd_inst_channels(void *key, void *value, void *user_data)
        channel_indices = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
                                              (GDestroyNotify)g_variant_unref);
 
+       /*
+        * The typical mode of operation is to apply a user specified
+        * mapping of sigrok channels to decoder inputs. Lack of mapping
+        * specs will assign no signals (compatible behaviour to earlier
+        * implementations).
+        *
+        * Alternatively we can assign sigrok logic channels to decoder
+        * inputs in the strict order of channel indices, or when their
+        * names match. Users need to request this automatic assignment
+        * though, because this behaviour differs from earlier versions.
+        *
+        * Even more sophisticated heuristics of mapping sigrok channels
+        * to decoder inputs are not implemented here. Later versions
+        * could translate the Pulseview approach to the C language, but
+        * it's better to stabilize that logic first before porting it.
+        */
+       assign = ASSIGN_USER_SPEC;
+       keyword = g_hash_table_lookup(channel_map, keyword_assign);
+       if (g_hash_table_size(channel_map) != 1) {
+               assign = ASSIGN_USER_SPEC;
+       } else if (!keyword) {
+               assign = ASSIGN_USER_SPEC;
+       } else if (strcmp(keyword, assign_by_index) == 0) {
+               assign = ASSIGN_BY_INDEX;
+       } else if (strcmp(keyword, assign_by_name) == 0) {
+               assign = ASSIGN_BY_NAMES;
+       } else {
+               g_critical("Unknown type of decoder channel assignment: %s.",
+                       keyword);
+               return;
+       }
+
+       pd = di->decoder;
+       if (assign == ASSIGN_BY_INDEX) {
+               /*
+                * Iterate the protocol decoder's list of input signals
+                * (mandatory and optional, never more than the decoder's
+                * total channels count). Assign sigrok logic channels
+                * until either is exhausted. Use sigrok channels in the
+                * very order of their declaration in the input stream.
+                */
+               l_ch = channel_list;
+               l_pd = pd->channels;
+               while (l_ch && l_pd) {
+                       ch = l_ch->data;
+                       l_ch = l_ch->next;
+                       if (ch->type != SR_CHANNEL_LOGIC)
+                               break;
+                       if (ch->index >= di->dec_num_channels)
+                               break;
+                       pdch = l_pd->data;
+                       l_pd = l_pd->next;
+                       if (!l_pd)
+                               l_pd = pd->opt_channels;
+                       /* TODO Emit an INFO message. */
+                       g_hash_table_insert(channel_map,
+                               g_strdup(pdch->id), g_strdup(ch->name));
+               }
+       } else if (assign == ASSIGN_BY_NAMES) {
+               /*
+                * Iterate the protocol decoder's list of input signals.
+                * Search for sigrok logic channels that have matching
+                * names (case insensitive comparison). Not finding a
+                * sigrok channel of a given name is non-fatal (could be
+                * an optional channel, the decoder will check later for
+                * all mandatory channels to be assigned).
+                */
+               l_pd = pd->channels;
+               l_pdo = pd->opt_channels;
+               while (l_pd) {
+                       pdch = l_pd->data;
+                       l_pd = l_pd->next;
+                       if (!l_pd) {
+                               l_pd = l_pdo;
+                               l_pdo = NULL;
+                       }
+                       ch = find_channel(channel_list, pdch->id, FALSE);
+                       if (!ch) {
+                               /* TODO Emit a WARN message. */
+                               /* if (l_pdo) ...; */
+                               continue;
+                       }
+                       if (ch->type != SR_CHANNEL_LOGIC) {
+                               /* TODO Emit a WARN message. */
+                               continue;
+                       }
+                       /* TODO Emit an INFO message. */
+                       g_hash_table_insert(channel_map,
+                               g_strdup(pdch->id), g_strdup(ch->name));
+               }
+       }
+
        g_hash_table_iter_init(&iter, channel_map);
        while (g_hash_table_iter_next(&iter, &channel_id, &channel_target)) {
-               ch = find_channel(channel_list, channel_target);
+               if (strcmp(channel_id, keyword_assign) == 0)
+                       continue;
+               if (!channel_target) {
+                       g_printerr("cli: Channel name for \"%s\" missing.\n",
+                                  (char *)channel_id);
+                       continue;
+               }
+               ch = find_channel(channel_list, channel_target, TRUE);
                if (!ch) {
                        g_printerr("cli: No channel with name \"%s\" found.\n",
                                   (char *)channel_target);
@@ -473,6 +589,147 @@ int setup_pd_binary(char *opt_pd_binary)
        return 0;
 }
 
+/*
+ * Balance JSON object and array parentheses, and separate array items.
+ * Somewhat convoluted API to re-use the routine for individual items as
+ * well as the surrounding array and object, including deferred start of
+ * the output and late flush (and to keep the state strictly local to the
+ * routine). Some additional complexity due to JSON's inability to handle
+ * a trailing comma at the last item. Code phrased such that text literals
+ * are kept in their order of appearance in the output (where possible).
+ */
+static void jsontrace_open_close(gboolean is_close_req,
+       gboolean open_item, gboolean close_item)
+{
+       static gboolean is_file_open;
+       static gboolean is_item_open;
+
+       if (is_close_req && is_item_open)
+               close_item = TRUE;
+
+       /* Automatic file header, and array item separation. */
+       if (open_item) {
+               if (!is_file_open)
+                       printf("{\"traceEvents\": [\n");
+               if (is_item_open) {
+                       printf("}");
+                       is_item_open = FALSE;
+               }
+               if (is_file_open) {
+                       printf(",\n");
+               }
+               is_file_open = TRUE;
+       }
+
+       /* Array item open/append/close. */
+       if (open_item) {
+               printf("{");
+               is_item_open = TRUE;
+       }
+       if (!open_item && !close_item && !is_close_req) {
+               printf(", ");
+               is_item_open = TRUE;
+       }
+       if (close_item) {
+               printf("}");
+               is_item_open = FALSE;
+       }
+
+       /* Automatic file footer on shutdown. */
+       if (is_close_req && is_file_open) {
+               printf("\n");
+               printf("]}\n");
+       }
+       if (is_close_req)
+               is_file_open = FALSE;
+
+       /* Flush at end of lines, or end of file. */
+       if (close_item || is_close_req)
+               fflush(stdout);
+}
+
+/* Convert uint64 sample number to double timestamp in microseconds. */
+static double jsontrace_ts_usec(uint64_t snum)
+{
+       double ts_usec;
+
+       ts_usec = snum;
+       ts_usec *= 1e6;
+       ts_usec /= pd_samplerate;
+       return ts_usec;
+}
+
+/* Emit two Google Trace Events (JSON) for one PD annotation (ss, es). */
+static void jsontrace_annotation(struct srd_decoder *dec,
+       struct srd_proto_data_annotation *pda, struct srd_proto_data *pdata)
+{
+       char *row_text;
+       GSList *lrow, *lcls;
+       struct srd_decoder_annotation_row *row;
+       int cls;
+       char **ann_descr;
+
+       /*
+        * Search for an annotation row for this index, or use the
+        * annotation's descriptor.
+        */
+       row_text = NULL;
+       if (dec->annotation_rows) {
+               for (lrow = dec->annotation_rows; lrow; lrow = lrow->next) {
+                       row = lrow->data;
+                       for (lcls = row->ann_classes; lcls; lcls = lcls->next) {
+                               cls = GPOINTER_TO_INT(lcls->data);
+                               if (cls == pda->ann_class) {
+                                       row_text = row->desc;
+                                       break;
+                               }
+                       }
+                       if (row_text)
+                               break;
+               }
+       }
+       if (!row_text) {
+               ann_descr = g_slist_nth_data(dec->annotations, pda->ann_class);
+               row_text = ann_descr[0];
+       }
+
+       /*
+        * Emit two Google Trace Events for the start and end times.
+        * Set the 'pid' (process ID) to the decoder name to group a
+        * decoder's annotations. Set the 'tid' (thread ID) to the
+        * annotation row's description. The 'ts' (timestamp) is in
+        * microseconds. Set 'name' to the longest annotation text.
+        *
+        * BEWARE of the unfortunate JSON format limitation, which
+        * clutters data output calls with format helper calls.
+        * TODO Want to introduce a cJSON dependency to delegate the
+        * construction of output text?
+        */
+       jsontrace_open_close(FALSE, TRUE, FALSE);
+       printf("\"%s\": \"%s\"", "ph", "B");
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": %lf", "ts", jsontrace_ts_usec(pdata->start_sample));
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": \"%s\"", "pid", pdata->pdo->proto_id);
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": \"%s\"", "tid", row_text);
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": \"%s\"", "name", pda->ann_text[0]);
+
+       jsontrace_open_close(FALSE, TRUE, FALSE);
+       printf("\"%s\": \"%s\"", "ph", "E");
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": %lf", "ts", jsontrace_ts_usec(pdata->end_sample));
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": \"%s\"", "pid", pdata->pdo->proto_id);
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": \"%s\"", "tid", row_text);
+       jsontrace_open_close(FALSE, FALSE, FALSE);
+       printf("\"%s\": \"%s\"", "name", pda->ann_text[0]);
+
+       jsontrace_open_close(FALSE, FALSE, TRUE);
+}
+
 void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data)
 {
        struct srd_decoder *dec;
@@ -507,6 +764,12 @@ void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data)
        if (!show_ann)
                return;
 
+       /* Google Trace Events are rather special. Use a separate code path. */
+       if (opt_pd_jsontrace) {
+               jsontrace_annotation(dec, pda, pdata);
+               return;
+       }
+
        /*
         * Determine which fields of the annotation to display. Inspect
         * user specified options as well as the verbosity of the log level:
@@ -530,6 +793,8 @@ void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data)
                show_class = TRUE;
                show_abbrev = TRUE;
        }
+       if (opt_pd_ann_class)
+               show_class = TRUE;
 
        /*
         * Display the annotation's fields after the layout was
@@ -594,4 +859,16 @@ void show_pd_binary(struct srd_proto_data *pdata, void *cb_data)
        fwrite(pdb->data, pdb->size, 1, stdout);
        fflush(stdout);
 }
+
+void show_pd_prepare(void)
+{
+       if (opt_pd_jsontrace)
+               jsontrace_open_close(TRUE, FALSE, FALSE);
+}
+
+void show_pd_close(void)
+{
+       if (opt_pd_jsontrace)
+               jsontrace_open_close(TRUE, FALSE, FALSE);
+}
 #endif
index 19192ecbb0b69b404529df45d374be955d1962c9..7da744431154c134b5bee897bc24f817cc774e46 100644 (file)
--- a/device.c
+++ b/device.c
@@ -63,16 +63,37 @@ GSList *device_scan(void)
        return devices;
 }
 
-struct sr_channel_group *select_channel_group(struct sr_dev_inst *sdi)
+/**
+ * Lookup a channel group from its name.
+ *
+ * Uses the caller specified channel group name, or a previously stored
+ * option value as a fallback. Returns a reference to the channel group
+ * when the lookup succeeded, or #NULL after lookup failure, as well as
+ * #NULL for the global channel group (the device).
+ *
+ * Accepts either #NULL pointer, or an empty string, or the "global"
+ * literal to address the global channel group (the device). Emits an
+ * error message when the lookup failed while a name was specified.
+ *
+ * @param[in] sdi Device instance.
+ * @param[in] cg_name Caller provided channel group name.
+ *
+ * @returns The channel group, or #NULL for failed lookup.
+ */
+struct sr_channel_group *lookup_channel_group(struct sr_dev_inst *sdi,
+       const char *cg_name)
 {
        struct sr_channel_group *cg;
        GSList *l, *channel_groups;
 
-       if (!opt_channel_group)
+       if (!cg_name)
+               cg_name = opt_channel_group;
+       if (cg_name && g_ascii_strcasecmp(cg_name, "global") == 0)
+               cg_name = NULL;
+       if (!cg_name || !*cg_name)
                return NULL;
 
        channel_groups = sr_dev_inst_channel_groups_get(sdi);
-
        if (!channel_groups) {
                g_critical("This device does not have any channel groups.");
                return NULL;
@@ -80,11 +101,11 @@ struct sr_channel_group *select_channel_group(struct sr_dev_inst *sdi)
 
        for (l = channel_groups; l; l = l->next) {
                cg = l->data;
-               if (!g_ascii_strcasecmp(opt_channel_group, cg->name)) {
-                       return cg;
-               }
+               if (g_ascii_strcasecmp(cg_name, cg->name) != 0)
+                       continue;
+               return cg;
        }
-       g_critical("Invalid channel group '%s'", opt_channel_group);
+       g_critical("Invalid channel group '%s'", cg_name);
 
        return NULL;
 }
index 3ec6768e57484a43d3e9d252a348cda99594f7f2..33174cdbe4a6ec545e48a370bb4efd7cb52d0ee5 100644 (file)
@@ -1,4 +1,4 @@
-.TH SIGROK\-CLI 1 "March 28, 2019"
+.TH SIGROK\-CLI 1 "April 07, 2023"
 .SH "NAME"
 sigrok\-cli \- Command-line client for the sigrok software
 .SH "SYNOPSIS"
@@ -72,6 +72,17 @@ specification.
 .BR "\-c, \-\-config " <deviceoption>
 A colon-separated list of device options, where each option takes the form
 .BR key=value .
+Multiple occurances of the
+.B \-\-config
+option are supported.
+The first item in the list of options can take the form
+.B channel_group=<name>
+which would override the
+.B \-\-channel\-group
+specification for this list of options. Other option lists in other
+.B \-\-config
+occurances are not affected by this list's channel group name.
+.sp
 For example, to set the samplerate to 1MHz on a device supported by the
 fx2lafw driver, you might specify
 .sp
@@ -86,6 +97,15 @@ The following are all equivalent:
 .RB "  $ " "sigrok\-cli \-d fx2lafw \-\-config samplerate=1m" " [...]"
 .sp
 .RB "  $ " "sigrok\-cli \-d fx2lafw \-\-config \(dqsamplerate=1 MHz\(dq" " [...]"
+.sp
+These examples specify options within a channel group.
+The first two are equivalent.
+.sp
+.RB "  $ " "sigrok\-cli \-d demo \-\-channel\-group Logic \-\-config pattern=random [...]"
+.sp
+.RB "  $ " "sigrok\-cli \-d demo \-\-config channel_group=Logic:pattern=random [...]"
+.sp
+.RB "  $ " "sigrok\-cli \-d demo \-\-config samplerate=1m \-\-config channel_group=Logic:pattern=random [...]"
 .TP
 .BR "\-i, \-\-input\-file " <filename>
 Load input from a file instead of a hardware device. You can specify
@@ -211,6 +231,17 @@ Examples:
 .RB "  $ " "sigrok\-cli \-g CH1" " [...]"
 .sp
 .RB "  $ " "sigrok\-cli \-d demo \-g Logic \-c pattern=graycode" " [...]"
+.sp
+Channel group specifications in
+.B \-\-get
+or
+.B \-\-config
+options take precedence over channel group names in
+.B \-\-channel\-group
+so that a single
+.B sigrok\-cli
+invocation can support the query or manipulation of multiple device options
+which reside in different channel groups.
 .TP
 .BR "\-t, \-\-triggers " <triggerlist>
 A comma-separated list of triggers to use, of the form
@@ -261,7 +292,7 @@ Example:
  $
 .B "sigrok\-cli \-i <file.sr> "
 .br
-.B "              \-P uart:baudrate=115200:parity_type=odd"
+.B "              \-P uart:baudrate=115200:parity=odd"
 .sp
 The list of supported options depends entirely on the protocol decoder. Every
 protocol decoder has different options it supports.
@@ -280,15 +311,27 @@ In this example,
 .B wordsize
 is an option supported by the
 .B spi
-protocol decoder. Additionally, the user tells sigrok to decode the SPI
+protocol decoder. Additionally, the user requests sigrok to decode the SPI
 protocol using channel 1 as MISO signal for SPI, channel 5 as MOSI, channel 3
 as CLK, and channel 0 as CS# signal.
 .sp
-Notice that the
+The
 .B sigrok\-cli
-application does not support "name matching". Instead it's assumed that the
-traces in the input stream match the order of the decoder's input signals,
-or that users explicitly specify the input channel to decoder signal mapping.
+application can automatically assign logic channels to decoder inputs
+in their strict channel index order (by means of the
+.B auto_index
+keyword), or can automatically assign logic channels to decoder inputs
+when their names match (case insensitive match,
+.B auto_names
+keyword). Users need to explicitly request this assignment, the default
+behaviour is to not automatically assign any signals.
+.sp
+Example:
+.sp
+ $
+.B "sigrok\-cli \-i <file.sr>"
+.br
+.B "              \-P ieee488:assign_channels=auto_names"
 .br
 .sp
 When multiple decoders are specified in the same
@@ -395,6 +438,13 @@ Not every decoder generates binary output.
 When given, decoder annotations will include sample numbers, too.
 This allows consumers to receive machine readable timing information.
 .TP
+.BR "\-\-protocol\-decoder\-ann\-class
+When given, decoder annotations will include annotation class names.
+.TP
+.BR "\-\-protocol\-decoder\-jsontrace
+When given, decoder output uses the Google Trace Event format (JSON).
+Which can be inspected in web browsers or other viewers.
+.TP
 .BR "\-l, \-\-loglevel " <level>
 Set the libsigrok and libsigrokdecode loglevel. At the moment \fBsigrok\-cli\fP
 doesn't support setting the two loglevels independently. The higher the
@@ -503,6 +553,20 @@ Sample continuously until stopped. Not all devices support this.
 Get the value of
 .B <variable>
 from the specified device and print it.
+Multiple variable names can be specified and get separated by colon.
+The list of variable names optionally can be preceeded by
+.B "channel_group=<name>"
+which would override the
+.B \-\-channel\-group
+specification.
+Multiple
+.B \-\-get
+occurances are supported in a single
+.B sigrok\-cli
+invocation.
+.sp
+ $
+.B sigrok\-cli \-d demo \-\-get samplerate:averaging \-\-get channel_group=Logic:pattern
 .TP
 .BR "\-\-set"
 Set one or more variables specified with the \fB\-\-config\fP option, without
@@ -536,6 +600,25 @@ To turn on internal logging on a Lascar EL-USB series device:
 .SH "EXIT STATUS"
 .B sigrok\-cli
 exits with 0 on success, 1 on most failures.
+.SH "ENVIRONMENT"
+.TP
+.B SIGROK_FIRMWARE_DIR
+A single path where to search for firmware images, in addition to a
+builtin list of locations.
+.TP
+.B SIGROK_FIRMWARE_PATH
+Multiple path entries where to search for firmware images, in addition
+to builtin locations.
+.TP
+When decoder support was enabled in the application's configuration:
+.TP
+.B SIGROKDECODE_DIR
+A single path where to search for protocol decoders, in addition to
+a builtin list of locations.
+.TP
+.B SIGROKDECODE_PATH
+Multiple path entries where to search for protocol decoders, in addition
+to builtin locations.
 .SH "SEE ALSO"
 \fBpulseview\fP(1)
 .SH "BUGS"
diff --git a/input.c b/input.c
index 7d3396fc744503cdad7e348d2eb319a98e584556..cce0d9ff916b9a159f0f3400d80bd5d96df263eb 100644 (file)
--- a/input.c
+++ b/input.c
@@ -44,6 +44,7 @@ static void load_input_file_module(struct df_arg_desc *df_arg)
        ssize_t len;
        char *mod_id;
        gboolean is_stdin;
+       gboolean push_scan_data;
 
        if (!sr_input_list())
                g_critical("No supported input formats available.");
@@ -51,11 +52,12 @@ static void load_input_file_module(struct df_arg_desc *df_arg)
        mod_id = NULL;
        mod_args = NULL;
        if (opt_input_format) {
-               mod_args = parse_generic_arg(opt_input_format, TRUE);
+               mod_args = parse_generic_arg(opt_input_format, TRUE, NULL);
                mod_id = g_hash_table_lookup(mod_args, "sigrok_key");
        }
 
        is_stdin = strcmp(opt_input_file, "-") == 0;
+       push_scan_data = FALSE;
        fd = 0;
        buf = g_string_sized_new(CHUNK_SIZE);
        if (mod_id) {
@@ -65,9 +67,11 @@ static void load_input_file_module(struct df_arg_desc *df_arg)
                g_hash_table_remove(mod_args, "sigrok_key");
                if ((options = sr_input_options_get(imod))) {
                        mod_opts = generic_arg_to_opt(options, mod_args);
-                       sr_output_options_free(options);
-               } else
+                       (void)warn_unknown_keys(options, mod_args, NULL);
+                       sr_input_options_free(options);
+               } else {
                        mod_opts = NULL;
+               }
                if (!(in = sr_input_new(imod, mod_opts)))
                        g_critical("Error: failed to initialize input module.");
                if (mod_opts)
@@ -101,11 +105,12 @@ static void load_input_file_module(struct df_arg_desc *df_arg)
                                        g_critical("Failed to load %s: %s.", opt_input_file,
                                                        g_strerror(errno));
                        }
-                       if ((len = read(fd, buf->str, CHUNK_SIZE)) < 1)
+                       if ((len = read(fd, buf->str, buf->allocated_len)) < 1)
                                g_critical("Failed to read %s: %s.", opt_input_file,
                                                g_strerror(errno));
                        buf->len = len;
                        sr_input_scan_buffer(buf, &in);
+                       push_scan_data = TRUE;
                }
                if (!in)
                        g_critical("Error: no input module found for this file.");
@@ -114,24 +119,46 @@ static void load_input_file_module(struct df_arg_desc *df_arg)
        df_arg->session = session;
        sr_session_datafeed_callback_add(session, datafeed_in, df_arg);
 
+       /*
+        * Implementation detail: The combination of reading from stdin
+        * and automatic file format detection may have pushed the first
+        * chunk of input data into the input module's data accumulator,
+        * _bypassing_ the .receive() callback. It is essential to call
+        * .receive() before calling .end() for files of size smaller than
+        * CHUNK_SIZE (which is a typical case). So that sdi becomes ready.
+        * Fortunately all input modules accept .receive() calls with
+        * a zero length, and inspect whatever was accumulated so far.
+        *
+        * After that optional initial push of data which was queued
+        * above during format detection, continue reading remaining
+        * chunks from the input file until EOF is seen.
+        */
        got_sdi = FALSE;
        while (TRUE) {
                g_string_truncate(buf, 0);
-               len = read(fd, buf->str, CHUNK_SIZE);
+               if (push_scan_data)
+                       len = 0;
+               else
+                       len = read(fd, buf->str, buf->allocated_len);
                if (len < 0)
                        g_critical("Read failed: %s", g_strerror(errno));
-               if (len == 0)
+               if (len == 0 && !push_scan_data)
                        /* End of file or stream. */
                        break;
+               push_scan_data = FALSE;
                buf->len = len;
-               if (sr_input_send(in, buf) != SR_OK)
+               if (sr_input_send(in, buf) != SR_OK) {
+                       g_critical("File import failed (read)");
                        break;
+               }
 
                sdi = sr_input_dev_inst_get(in);
                if (!got_sdi && sdi) {
                        /* First time we got a valid sdi. */
-                       if (select_channels(sdi) != SR_OK)
+                       if (select_channels(sdi) != SR_OK) {
+                               g_critical("File import failed (channels)");
                                return;
+                       }
                        if (sr_session_dev_add(session, sdi) != SR_OK) {
                                g_critical("Failed to use device.");
                                sr_session_destroy(session);
@@ -143,10 +170,10 @@ static void load_input_file_module(struct df_arg_desc *df_arg)
        sr_input_end(in);
        sr_input_free(in);
        g_string_free(buf, TRUE);
+       close(fd);
 
        df_arg->session = NULL;
        sr_session_destroy(session);
-
 }
 
 void load_input_file(gboolean do_props)
diff --git a/main.c b/main.c
index 829492f5704aa8b3b0f4d5f2a1c48a1d4b61709a..b128c8800e2fca733db67aa77a5769338ba56f4c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -106,47 +106,29 @@ int maybe_config_list(struct sr_dev_driver *driver,
        return SR_ERR_NA;
 }
 
-static void get_option(void)
+static void get_option(struct sr_dev_inst *sdi,
+       struct sr_channel_group *cg, const char *opt)
 {
-       struct sr_dev_inst *sdi;
-       struct sr_channel_group *cg;
+       struct sr_dev_driver *driver;
        const struct sr_key_info *ci;
-       GSList *devices;
-       GVariant *gvar;
-       GHashTable *devargs;
        int ret;
-       char *s;
-       struct sr_dev_driver *driver;
+       GVariant *gvar;
        const struct sr_key_info *srci, *srmqi, *srmqfi;
        uint32_t mq;
        uint64_t mask, mqflags;
        unsigned int j;
-
-       if (!(devices = device_scan())) {
-               g_critical("No devices found.");
-               return;
-       }
-       sdi = devices->data;
-       g_slist_free(devices);
+       char *s;
 
        driver = sr_dev_inst_driver_get(sdi);
 
-       if (sr_dev_open(sdi) != SR_OK) {
-               g_critical("Failed to open device.");
-               return;
-       }
+       ci = sr_key_info_name_get(SR_KEY_CONFIG, opt);
+       if (!ci)
+               g_critical("Unknown option '%s'", opt);
 
-       cg = select_channel_group(sdi);
-       if (!(ci = sr_key_info_name_get(SR_KEY_CONFIG, opt_get)))
-               g_critical("Unknown option '%s'", opt_get);
+       ret = maybe_config_get(driver, sdi, cg, ci->key, &gvar);
+       if (ret != SR_OK)
+               g_critical("Failed to get '%s': %s", opt, sr_strerror(ret));
 
-       if ((devargs = parse_generic_arg(opt_config, FALSE)))
-               set_dev_options(sdi, devargs);
-       else
-               devargs = NULL;
-
-       if ((ret = maybe_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK)
-               g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret));
        srci = sr_key_info_get(SR_KEY_CONFIG, ci->key);
        if (srci && srci->datatype == SR_T_MQ) {
                g_variant_get(gvar, "(ut)", &mq, &mqflags);
@@ -170,25 +152,65 @@ static void get_option(void)
        }
 
        g_variant_unref(gvar);
+}
+
+static void get_options(void)
+{
+       GSList *devices;
+       struct sr_dev_inst *sdi;
+       size_t get_idx;
+       char *get_text, *cg_name;
+       GHashTable *args;
+       GHashTableIter iter;
+       gpointer key, value;
+       struct sr_channel_group *cg;
+
+       /* Lookup and open the device. */
+       devices = device_scan();
+       if (!devices) {
+               g_critical("No devices found.");
+               return;
+       }
+       sdi = devices->data;
+       g_slist_free(devices);
+
+       if (sr_dev_open(sdi) != SR_OK) {
+               g_critical("Failed to open device.");
+               return;
+       }
+
+       /* Set configuration values when -c was specified. */
+       set_dev_options_array(sdi, opt_configs);
+
+       /* Get configuration values which were specified by --get. */
+       for (get_idx = 0; (get_text = opt_gets[get_idx]); get_idx++) {
+               args = parse_generic_arg(get_text, FALSE, "channel_group");
+               if (!args)
+                       continue;
+               cg_name = g_hash_table_lookup(args, "sigrok_key");
+               cg = lookup_channel_group(sdi, cg_name);
+               g_hash_table_iter_init(&iter, args);
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       if (g_ascii_strcasecmp(key, "sigrok_key") == 0)
+                               continue;
+                       get_option(sdi, cg, key);
+               }
+       }
+
+       /* Close the device. */
        sr_dev_close(sdi);
-       if (devargs)
-               g_hash_table_destroy(devargs);
 }
 
 static void set_options(void)
 {
        struct sr_dev_inst *sdi;
        GSList *devices;
-       GHashTable *devargs;
 
-       if (!opt_config) {
+       if (!opt_configs) {
                g_critical("No setting specified.");
                return;
        }
 
-       if (!(devargs = parse_generic_arg(opt_config, FALSE)))
-               return;
-
        if (!(devices = device_scan())) {
                g_critical("No devices found.");
                return;
@@ -201,11 +223,9 @@ static void set_options(void)
                return;
        }
 
-       set_dev_options(sdi, devargs);
+       set_dev_options_array(sdi, opt_configs);
 
        sr_dev_close(sdi);
-       g_hash_table_destroy(devargs);
-
 }
 
 int main(int argc, char **argv)
@@ -224,6 +244,11 @@ int main(int argc, char **argv)
                goto done;
 
 #ifdef HAVE_SRD
+       if (opt_pd_binary && !opt_pds) {
+               g_critical("Option -B will not take effect in the absence of -P.");
+               goto done;
+       }
+
        /* Set the loglevel (amount of messages to output) for libsigrokdecode. */
        if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
                goto done;
@@ -242,6 +267,8 @@ int main(int argc, char **argv)
                if (opt_pd_binary) {
                        if (setup_pd_binary(opt_pd_binary) != 0)
                                goto done;
+                       if (setup_binary_stdout() != 0)
+                               goto done;
                        if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_BINARY,
                                        show_pd_binary, NULL) != SRD_OK)
                                goto done;
@@ -259,6 +286,7 @@ int main(int argc, char **argv)
                                        show_pd_annotations, NULL) != SRD_OK)
                                goto done;
                }
+               show_pd_prepare();
        }
 #endif
 
@@ -286,8 +314,8 @@ int main(int argc, char **argv)
                show_dev_detail();
        else if (opt_input_file)
                load_input_file(FALSE);
-       else if (opt_get)
-               get_option();
+       else if (opt_gets)
+               get_options();
        else if (opt_set)
                set_options();
        else if (opt_samples || opt_time || opt_frames || opt_continuous)
@@ -298,6 +326,8 @@ int main(int argc, char **argv)
                show_help();
 
 #ifdef HAVE_SRD
+       if (opt_pds)
+               show_pd_close();
        if (opt_pds)
                srd_exit();
 #endif
index 5a6f9487769f640bd4e04a71c61832bcf6f0191e..e47b6804e96eb7635f9874b3090cb02110526dae 100644 (file)
--- a/options.c
+++ b/options.c
@@ -31,7 +31,7 @@ gboolean opt_wait_trigger = FALSE;
 gchar *opt_input_file = NULL;
 gchar *opt_output_file = NULL;
 gchar *opt_drv = NULL;
-gchar *opt_config = NULL;
+gchar **opt_configs = NULL;
 gchar *opt_channels = NULL;
 gchar *opt_channel_group = NULL;
 gchar *opt_triggers = NULL;
@@ -40,7 +40,9 @@ gchar **opt_pds = NULL;
 gchar *opt_pd_annotations = NULL;
 gchar *opt_pd_meta = NULL;
 gchar *opt_pd_binary = NULL;
+gboolean opt_pd_ann_class = FALSE;
 gboolean opt_pd_samplenum = FALSE;
+gboolean opt_pd_jsontrace = FALSE;
 #endif
 gchar *opt_input_format = NULL;
 gchar *opt_output_format = NULL;
@@ -50,7 +52,7 @@ gchar *opt_time = NULL;
 gchar *opt_samples = NULL;
 gchar *opt_frames = NULL;
 gboolean opt_continuous = FALSE;
-gchar *opt_get = NULL;
+gchar **opt_gets = NULL;
 gboolean opt_set = FALSE;
 gboolean opt_list_serial = FALSE;
 
@@ -78,7 +80,6 @@ static gboolean check_ ## option                                          \
 }
 
 CHECK_ONCE(opt_drv)
-CHECK_ONCE(opt_config)
 CHECK_ONCE(opt_input_format)
 CHECK_ONCE(opt_output_format)
 CHECK_ONCE(opt_transform_module)
@@ -93,7 +94,6 @@ CHECK_ONCE(opt_pd_binary)
 CHECK_ONCE(opt_time)
 CHECK_ONCE(opt_samples)
 CHECK_ONCE(opt_frames)
-CHECK_ONCE(opt_get)
 
 #undef CHECK_STR_ONCE
 
@@ -111,7 +111,7 @@ static const GOptionEntry optargs[] = {
                        "Set loglevel (5 is most verbose)", NULL},
        {"driver", 'd', 0, G_OPTION_ARG_CALLBACK, &check_opt_drv,
                        "The driver to use", NULL},
-       {"config", 'c', 0, G_OPTION_ARG_CALLBACK, &check_opt_config,
+       {"config", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &opt_configs,
                        "Specify device configuration options", NULL},
        {"input-file", 'i', 0, G_OPTION_ARG_FILENAME_ARRAY, &input_file_array,
                        "Load input from file", NULL},
@@ -140,8 +140,12 @@ 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-ann-class", 0, 0, G_OPTION_ARG_NONE, &opt_pd_ann_class,
+                       "Show annotation class in decoder output", NULL},
        {"protocol-decoder-samplenum", 0, 0, G_OPTION_ARG_NONE, &opt_pd_samplenum,
                        "Show sample numbers in decoder output", NULL},
+       {"protocol-decoder-jsontrace", 0, 0, G_OPTION_ARG_NONE, &opt_pd_jsontrace,
+                       "Output in Google Trace Event format (JSON)", NULL},
 #endif
        {"scan", 0, 0, G_OPTION_ARG_NONE, &opt_scan_devs,
                        "Scan for devices", NULL},
@@ -157,7 +161,8 @@ static const GOptionEntry optargs[] = {
                        "Number of frames to acquire", NULL},
        {"continuous", 0, 0, G_OPTION_ARG_NONE, &opt_continuous,
                        "Sample continuously", NULL},
-       {"get", 0, 0, G_OPTION_ARG_CALLBACK, &check_opt_get, "Get device options only", NULL},
+       {"get", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gets,
+                       "Get device options only", NULL},
        {"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
        {"list-serial", 0, 0, G_OPTION_ARG_NONE, &opt_list_serial, "List available serial/HID/BT/BLE ports", NULL},
        {NULL, 0, 0, 0, NULL, NULL, NULL}
diff --git a/output.c b/output.c
new file mode 100644 (file)
index 0000000..051ec8b
--- /dev/null
+++ b/output.c
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the sigrok-cli project.
+ *
+ * Copyright (C) 2019 Devan Lai <devan.lai@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#ifdef _WIN32
+#include <io.h>
+#include <fcntl.h>
+#endif
+
+#include <glib.h>
+#include "sigrok-cli.h"
+
+/* Disable newline translation on stdout when outputting binary data. */
+int setup_binary_stdout(void)
+{
+#ifdef _WIN32
+       int oldmode = _setmode(_fileno(stdout), _O_BINARY);
+       if (oldmode == -1) {
+               g_critical("Failed to set binary stdout mode: errno=%d", errno);
+               return -1;
+       }
+#endif
+       return 0;
+}
index 5ec655f78ad3dce8a05f01186a2a7ec61febb437..2aacefb089f184eeb18dfb8d5be8855dc5623811 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -25,7 +25,8 @@
 #include <glib.h>
 #include "sigrok-cli.h"
 
-struct sr_channel *find_channel(GSList *channellist, const char *channelname)
+struct sr_channel *find_channel(GSList *channellist, const char *channelname,
+       gboolean exact_case)
 {
        struct sr_channel *ch;
        GSList *l;
@@ -33,8 +34,13 @@ struct sr_channel *find_channel(GSList *channellist, const char *channelname)
        ch = NULL;
        for (l = channellist; l; l = l->next) {
                ch = l->data;
-               if (!strcmp(ch->name, channelname))
-                       break;
+               if (exact_case) {
+                       if (strcmp(ch->name, channelname) == 0)
+                               break;
+               } else {
+                       if (g_ascii_strcasecmp(ch->name, channelname) == 0)
+                               break;
+               }
        }
        ch = l ? l->data : NULL;
 
@@ -105,7 +111,7 @@ GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring)
                                        ret = SR_ERR;
                                        break;
                                }
-                               ch = find_channel(channels, str);
+                               ch = find_channel(channels, str, TRUE);
                                if (!ch) {
                                        g_critical("unknown channel '%d'.", b);
                                        ret = SR_ERR;
@@ -130,7 +136,7 @@ range_fail:
                                break;
                        }
 
-                       ch = find_channel(channels, names[0]);
+                       ch = find_channel(channels, names[0], TRUE);
                        if (!ch) {
                                g_critical("unknown channel '%s'.", names[0]);
                                g_strfreev(names);
@@ -139,8 +145,7 @@ range_fail:
                        }
                        if (names[1]) {
                                /* Rename channel. */
-                               g_free(ch->name);
-                               ch->name = g_strdup(names[1]);
+                               sr_dev_channel_name_set(ch, names[1]);
                        }
                        channellist = g_slist_append(channellist, ch);
 
@@ -267,36 +272,167 @@ int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
        return !error;
 }
 
-GHashTable *parse_generic_arg(const char *arg, gboolean sep_first)
+/**
+ * Split an input text into a key and value respectively ('=' separator).
+ *
+ * @param[in] text Writeable copy of the input text, gets modified.
+ * @param[out] key Position of the keyword.
+ * @param[out] val Position of the value.
+ *
+ * TODO In theory the returned key/value locations could be const pointers.
+ * Which even would be preferrable. Unfortunately most call sites deal with
+ * glib hashes, and their insert API seriously lacks the const attribute.
+ * So we drop it here as well to avoid clutter at callers'.
+ */
+static void split_key_value(char *text, char **key, char **val)
+{
+       char *k, *v;
+       char *pos;
+
+       if (key)
+               *key = NULL;
+       if (val)
+               *val = NULL;
+       if (!text || !*text)
+               return;
+
+       k = text;
+       v = NULL;
+       pos = strchr(k, '=');
+       if (pos) {
+               *pos = '\0';
+               v = ++pos;
+       }
+       if (key)
+               *key = k;
+       if (val)
+               *val = v;
+}
+
+/**
+ * Create hash table from colon separated key-value pairs input text.
+ *
+ * Accepts input text as it was specified by users. Splits the colon
+ * separated key-value pairs and creates a hash table from these items.
+ * Optionally supports special forms which are useful for different CLI
+ * features.
+ *
+ * Typical form: <key>=<val>[:<key>=<val>]*
+ * Generic list of key-value pairs, all items being equal. Mere set.
+ *
+ * ID form: <id>[:<key>=<val>]*
+ * First item is not a key-value pair, instead it's an identifier. Used
+ * to specify a protocol decoder, or a device driver, or an input/output
+ * file format, optionally followed by more parameters' values. The ID
+ * part of the input spec is not optional.
+ *
+ * Optional ID: [<sel>=<id>][:<key>=<val>]*
+ * All items are key-value pairs. The first item _may_ be an identifier,
+ * if its key matches a caller specified key name. Otherwise the input
+ * text is the above typical form, a mere list of key-value pairs while
+ * none of them is special.
+ *
+ * @param[in] arg Input text.
+ * @param[in] sep_first Boolean, whether ID form is required.
+ * @param[in] key_first Keyword name if optional ID is applicable.
+ *
+ * @returns A hash table which contains the key/value pairs, or #NULL
+ *   when the input is invalid.
+ */
+GHashTable *parse_generic_arg(const char *arg,
+       gboolean sep_first, const char *key_first)
 {
        GHashTable *hash;
+       char **elements;
        int i;
-       char **elements, *e;
+       char *k, *v;
 
        if (!arg || !arg[0])
                return NULL;
+       if (key_first && !key_first[0])
+               key_first = NULL;
 
-       i = 0;
-       hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-                       g_free, g_free);
+       hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
        elements = g_strsplit(arg, ":", 0);
-       if (sep_first)
-               g_hash_table_insert(hash, g_strdup("sigrok_key"),
-                               g_strdup(elements[i++]));
-       for (; elements[i]; i++) {
-               e = strchr(elements[i], '=');
-               if (!e)
-                       g_hash_table_insert(hash, g_strdup(elements[i]), NULL);
-               else {
-                       *e++ = '\0';
-                       g_hash_table_insert(hash, g_strdup(elements[i]), g_strdup(e));
+       i = 0;
+       if (sep_first) {
+               k = g_strdup("sigrok_key");
+               v = g_strdup(elements[i++]);
+               g_hash_table_insert(hash, k, v);
+       } else if (key_first) {
+               split_key_value(elements[i], &k, &v);
+               if (g_ascii_strcasecmp(k, key_first) == 0) {
+                       k = "sigrok_key";
                }
+               k = g_strdup(k);
+               v = g_strdup(v);
+               g_hash_table_insert(hash, k, v);
+               i++;
+       }
+       for (; elements[i]; i++) {
+               if (!elements[i][0])
+                       continue;
+               split_key_value(elements[i], &k, &v);
+               k = g_strdup(k);
+               v = v ? g_strdup(v) : NULL;
+               g_hash_table_insert(hash, k, v);
        }
        g_strfreev(elements);
 
        return hash;
 }
 
+GSList *check_unknown_keys(const struct sr_option **avail, GHashTable *used)
+{
+       GSList *unknown;
+       GHashTableIter iter;
+       void *key;
+       const char *used_id;
+       size_t avail_idx;
+       const char *avail_id, *found_id;
+
+       /* Collect a list of used but not available keywords. */
+       unknown = NULL;
+       g_hash_table_iter_init(&iter, used);
+       while (g_hash_table_iter_next(&iter, &key, NULL)) {
+               used_id = key;
+               found_id = NULL;
+               for (avail_idx = 0; avail[avail_idx] && avail[avail_idx]->id; avail_idx++) {
+                       avail_id = avail[avail_idx]->id;
+                       if (strcmp(avail_id, used_id) == 0) {
+                               found_id = avail_id;
+                               break;
+                       }
+               }
+               if (!found_id)
+                       unknown = g_slist_append(unknown, g_strdup(used_id));
+       }
+
+       /* Return the list of unknown keywords, or NULL if empty. */
+       return unknown;
+}
+
+gboolean warn_unknown_keys(const struct sr_option **avail, GHashTable *used,
+       const char *caption)
+{
+       GSList *unknown, *l;
+       gboolean had_unknown;
+       const char *s;
+
+       if (!caption || !*caption)
+               caption = "Unknown keyword";
+
+       unknown = check_unknown_keys(avail, used);
+       had_unknown = unknown != NULL;
+       for (l = unknown; l; l = l->next) {
+               s = l->data;
+               g_warning("%s: %s.", caption, s);
+       }
+       g_slist_free_full(unknown, g_free);
+
+       return had_unknown;
+}
+
 GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genargs)
 {
        GHashTable *hash;
@@ -315,11 +451,11 @@ GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genarg
                        g_hash_table_insert(hash, g_strdup(opts[i]->id),
                                        g_variant_ref_sink(gvar));
                } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_INT32)) {
-                       gvar = g_variant_new_int32(strtoul(s, NULL, 10));
+                       gvar = g_variant_new_int32(strtol(s, NULL, 10));
                        g_hash_table_insert(hash, g_strdup(opts[i]->id),
                                        g_variant_ref_sink(gvar));
                } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_UINT64)) {
-                       gvar = g_variant_new_uint64(strtoul(s, NULL, 10));
+                       gvar = g_variant_new_uint64(strtoull(s, NULL, 10));
                        g_hash_table_insert(hash, g_strdup(opts[i]->id),
                                        g_variant_ref_sink(gvar));
                } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_DOUBLE)) {
@@ -412,7 +548,7 @@ int parse_driver(char *arg, struct sr_dev_driver **driver, GSList **drvopts)
        if (!arg)
                return FALSE;
 
-       drvargs = parse_generic_arg(arg, TRUE);
+       drvargs = parse_generic_arg(arg, TRUE, NULL);
 
        drvname = g_strdup(g_hash_table_lookup(drvargs, "sigrok_key"));
        g_hash_table_remove(drvargs, "sigrok_key");
index 3b3e962d3706ad46c28132f1fece9068d42ac405..5f5ca8f01f7030cef93874d04047f0ee9692f75b 100644 (file)
--- a/session.c
+++ b/session.c
@@ -92,7 +92,7 @@ const struct sr_output *setup_output_format(const struct sr_dev_inst *sdi, FILE
                }
        }
 
-       fmtargs = parse_generic_arg(opt_output_format, TRUE);
+       fmtargs = parse_generic_arg(opt_output_format, TRUE, NULL);
        fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key");
        if (!fmtspec)
                g_critical("Invalid output format.");
@@ -101,9 +101,11 @@ const struct sr_output *setup_output_format(const struct sr_dev_inst *sdi, FILE
        g_hash_table_remove(fmtargs, "sigrok_key");
        if ((options = sr_output_options_get(omod))) {
                fmtopts = generic_arg_to_opt(options, fmtargs);
+               (void)warn_unknown_keys(options, fmtargs, NULL);
                sr_output_options_free(options);
-       } else
+       } else {
                fmtopts = NULL;
+       }
        o = sr_output_new(omod, fmtopts, sdi, opt_output_file);
 
        if (opt_output_file) {
@@ -117,6 +119,7 @@ const struct sr_output *setup_output_format(const struct sr_dev_inst *sdi, FILE
                        *outfile = NULL;
                }
        } else {
+               setup_binary_stdout();
                *outfile = stdout;
        }
 
@@ -135,7 +138,7 @@ const struct sr_transform *setup_transform_module(const struct sr_dev_inst *sdi)
        GHashTable *fmtargs, *fmtopts;
        char *fmtspec;
 
-       fmtargs = parse_generic_arg(opt_transform_module, TRUE);
+       fmtargs = parse_generic_arg(opt_transform_module, TRUE, NULL);
        fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key");
        if (!fmtspec)
                g_critical("Invalid transform module.");
@@ -144,9 +147,11 @@ const struct sr_transform *setup_transform_module(const struct sr_dev_inst *sdi)
        g_hash_table_remove(fmtargs, "sigrok_key");
        if ((options = sr_transform_options_get(tmod))) {
                fmtopts = generic_arg_to_opt(options, fmtargs);
+               (void)warn_unknown_keys(options, fmtargs, NULL);
                sr_transform_options_free(options);
-       } else
+       } else {
                fmtopts = NULL;
+       }
        t = sr_transform_new(tmod, fmtopts, sdi);
        if (fmtopts)
                g_hash_table_destroy(fmtopts);
@@ -323,6 +328,7 @@ void datafeed_in(const struct sr_dev_inst *sdi,
                                        g_critical("Failed to configure decode session.");
                                        break;
                                }
+                               pd_samplerate = samplerate;
                        }
                        if (srd_session_start(srd_sess) != SRD_OK) {
                                g_critical("Failed to start decode session.");
@@ -351,6 +357,7 @@ void datafeed_in(const struct sr_dev_inst *sdi,
                                                        g_variant_new_uint64(samplerate)) != SRD_OK) {
                                                g_critical("Failed to pass samplerate to decoder.");
                                        }
+                                       pd_samplerate = samplerate;
                                }
 #endif
                                break;
@@ -478,6 +485,10 @@ void datafeed_in(const struct sr_dev_inst *sdi,
        if (packet->type == SR_DF_END) {
                g_debug("cli: Received SR_DF_END.");
 
+#if defined HAVE_SRD_SESSION_SEND_EOF && HAVE_SRD_SESSION_SEND_EOF
+               (void)srd_session_send_eof(srd_sess);
+#endif
+
                if (do_props) {
                        props_dump_details(df_arg);
                        props_cleanup(df_arg);
@@ -647,19 +658,51 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src)
        return ret;
 }
 
+int set_dev_options_array(struct sr_dev_inst *sdi, char **opts)
+{
+       size_t opt_idx;
+       const char *opt_text;
+       GHashTable *args;
+       int ret;
+
+       for (opt_idx = 0; opts && opts[opt_idx]; opt_idx++) {
+               opt_text = opts[opt_idx];
+               args = parse_generic_arg(opt_text, FALSE, "channel_group");
+               if (!args)
+                       continue;
+               ret = set_dev_options(sdi, args);
+               g_hash_table_destroy(args);
+               if (ret != SR_OK)
+                       return ret;
+       }
+
+       return SR_OK;
+}
+
 int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args)
 {
        struct sr_config src;
+       const char *cg_name;
        struct sr_channel_group *cg;
        GHashTableIter iter;
        gpointer key, value;
        int ret;
 
+       /*
+        * Not finding the 'sigrok_key' key (optional user specified
+        * channel group name) in the current options group's hash table
+        * is perfectly fine. In that case the -g selection is used,
+        * which defaults to "the device" (global parameters).
+        */
+       cg_name = g_hash_table_lookup(args, "sigrok_key");
+       cg = lookup_channel_group(sdi, cg_name);
+
        g_hash_table_iter_init(&iter, args);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
+               if (g_ascii_strcasecmp(key, "sigrok_key") == 0)
+                       continue;
                if ((ret = opt_to_gvar(key, value, &src)) != 0)
                        return ret;
-               cg = select_channel_group(sdi);
                if ((ret = maybe_config_set(sr_dev_inst_driver_get(sdi), sdi, cg,
                                src.key, src.data)) != SR_OK) {
                        g_critical("Failed to set device option '%s': %s.",
@@ -675,7 +718,6 @@ void run_session(void)
 {
        struct df_arg_desc df_arg;
        GSList *devices, *real_devices, *sd;
-       GHashTable *devargs;
        GVariant *gvar;
        struct sr_session *session;
        struct sr_trigger *trigger;
@@ -758,12 +800,9 @@ void run_session(void)
                return;
        }
 
-       if (opt_config) {
-               if ((devargs = parse_generic_arg(opt_config, FALSE))) {
-                       if (set_dev_options(sdi, devargs) != SR_OK)
-                               return;
-                       g_hash_table_destroy(devargs);
-               }
+       if (opt_configs) {
+               if (set_dev_options_array(sdi, opt_configs) != SR_OK)
+                       return;
        }
 
        if (select_channels(sdi) != SR_OK) {
diff --git a/show.c b/show.c
index 650936031b9a5c8ecfb022dbedbfee4917f7674c..85b440989212f04d2480f68bb242c155117c5b0f 100644 (file)
--- a/show.c
+++ b/show.c
 #include <string.h>
 #include "sigrok-cli.h"
 
+#define DECODERS_HAVE_TAGS \
+       ((SRD_PACKAGE_VERSION_MAJOR > 0) || \
+        (SRD_PACKAGE_VERSION_MAJOR == 0) && (SRD_PACKAGE_VERSION_MINOR > 5))
+
 static gint sort_inputs(gconstpointer a, gconstpointer b)
 {
        return strcmp(sr_input_id_get((struct sr_input_module *)a),
@@ -235,11 +239,13 @@ void show_supported_wiki(void)
        for (l = sl; l; l = l->next) {
                dec = l->data;
 
+#if DECODERS_HAVE_TAGS
                GString *tags = g_string_new(NULL);
                for (GSList *t = dec->tags; t; t = t->next)
                        g_string_append_printf(tags, "%s, ", (char *)t->data);
                if (tags->len != 0)
                        g_string_truncate(tags, tags->len - 2);
+#endif
 
                GString *in = g_string_new(NULL);
                for (GSList *t = dec->inputs; t; t = t->next)
@@ -257,11 +263,19 @@ void show_supported_wiki(void)
                else
                        g_string_truncate(out, out->len - 2);
 
+#if DECODERS_HAVE_TAGS
                printf("{{pd|%s|%s|%s|%s|%s|%s|%s|supported}}\n",
                        dec->id, dec->name, dec->longname, dec->desc,
                        tags->str, in->str, out->str);
+#else
+               printf("{{pd|%s|%s|%s|%s|%s|%s|supported}}\n",
+                       dec->id, dec->name, dec->longname, dec->desc,
+                       in->str, out->str);
+#endif
 
+#if DECODERS_HAVE_TAGS
                g_string_free(tags, TRUE);
+#endif
                g_string_free(in, TRUE);
                g_string_free(out, TRUE);
        }
@@ -286,12 +300,13 @@ static void print_dev_line(const struct sr_dev_inst *sdi)
        GString *s;
        GVariant *gvar;
        struct sr_dev_driver *driver;
-       const char *vendor, *model, *version;
+       const char *vendor, *model, *version, *sernum;
 
        driver = sr_dev_inst_driver_get(sdi);
        vendor = sr_dev_inst_vendor_get(sdi);
        model = sr_dev_inst_model_get(sdi);
        version = sr_dev_inst_version_get(sdi);
+       sernum = sr_dev_inst_sernum_get(sdi);
        channels = sr_dev_inst_channels_get(sdi);
 
        s = g_string_sized_new(128);
@@ -308,6 +323,8 @@ static void print_dev_line(const struct sr_dev_inst *sdi)
                g_string_append_printf(s, "%s ", model);
        if (version && version[0])
                g_string_append_printf(s, "%s ", version);
+       if (sernum && sernum[0])
+               g_string_append_printf(s, "[S/N: %s] ", sernum);
        if (channels) {
                if (g_slist_length(channels) == 1) {
                        ch = channels->data;
@@ -390,6 +407,7 @@ void show_dev_detail(void)
        gsize num_elements;
        double dlow, dhigh, dcur_low, dcur_high;
        const uint64_t *uint64;
+       uint64_t cur_rate, rate;
        uint64_t p = 0, q = 0, low = 0, high = 0;
        uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q;
        GArray *opts;
@@ -400,6 +418,7 @@ void show_dev_detail(void)
        char *tmp_str, *s, c;
        const char **stropts;
        double tmp_flt;
+       gboolean have_tmp_flt, have_curr;
        const double *fltopts;
 
        if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
@@ -436,7 +455,7 @@ void show_dev_detail(void)
         * returned, or which values for them.
         */
        select_channels(sdi);
-       channel_group = select_channel_group(sdi);
+       channel_group = lookup_channel_group(sdi, NULL);
 
        if (!(opts = sr_dev_options(driver, sdi, channel_group)))
                /* Driver supports no device instance options. */
@@ -446,8 +465,11 @@ void show_dev_detail(void)
                printf("Channel groups:\n");
                for (cgl = channel_groups; cgl; cgl = cgl->next) {
                        cg = cgl->data;
-                       printf("    %s: channel%s", cg->name,
-                                       g_slist_length(cg->channels) > 1 ? "s" : "");
+                       printf("    %s: ", cg->name);
+                       if (g_slist_length(cg->channels) == 0)
+                               printf("No channels");
+                       else
+                               printf("channel%s", g_slist_length(cg->channels) > 1 ? "s" : "");
                        for (chl = cg->channels; chl; chl = chl->next) {
                                ch = chl->data;
                                printf(" %s", ch->name);
@@ -532,6 +554,13 @@ void show_dev_detail(void)
                } else if (key == SR_CONF_SAMPLERATE) {
                        /* Supported samplerates */
                        printf("    %s", srci->id);
+                       cur_rate = ~0ull;
+                       if (maybe_config_get(driver, sdi, channel_group,
+                               SR_CONF_SAMPLERATE, &gvar) == SR_OK) {
+                               if (g_variant_is_of_type(gvar, G_VARIANT_TYPE_UINT64))
+                                       cur_rate = g_variant_get_uint64(gvar);
+                               g_variant_unref(gvar);
+                       }
                        if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
                                        &gvar_dict) != SR_OK) {
                                printf("\n");
@@ -543,9 +572,14 @@ void show_dev_detail(void)
                                                &num_elements, sizeof(uint64_t));
                                printf(" - supported samplerates:\n");
                                for (i = 0; i < num_elements; i++) {
-                                       if (!(s = sr_samplerate_string(uint64[i])))
+                                       rate = uint64[i];
+                                       s = sr_samplerate_string(rate);
+                                       if (!s)
                                                continue;
-                                       printf("      %s\n", s);
+                                       printf("      %s", s);
+                                       if (rate == cur_rate)
+                                               printf(" (current)");
+                                       printf("\n");
                                        g_free(s);
                                }
                                g_variant_unref(gvar_list);
@@ -684,12 +718,11 @@ void show_dev_detail(void)
                                continue;
                        }
 
+                       have_curr = FALSE;
                        if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
                                g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
                                g_variant_unref(gvar);
-                       } else {
-                               dcur_low = 0;
-                               dcur_high = 0;
+                               have_curr = TRUE;
                        }
 
                        num_elements = g_variant_n_children(gvar_list);
@@ -700,6 +733,8 @@ void show_dev_detail(void)
                                if (i)
                                        printf(", ");
                                printf("%.1f-%.1f", dlow, dhigh);
+                               if (!have_curr)
+                                       continue;
                                if (dlow == dcur_low && dhigh == dcur_high)
                                        printf(" (current)");
                        }
@@ -709,14 +744,16 @@ void show_dev_detail(void)
                } else if (srci->datatype == SR_T_FLOAT) {
                        printf("    %s: ", srci->id);
                        tmp_flt = 0.0;
+                       have_tmp_flt = FALSE;
                        if (maybe_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                tmp_flt = g_variant_get_double(gvar);
+                               have_tmp_flt = TRUE;
                                g_variant_unref(gvar);
                        }
                        if (maybe_config_list(driver, sdi, channel_group, key,
                                        &gvar) != SR_OK) {
-                               if (tmp_flt) {
+                               if (have_tmp_flt) {
                                        /* Can't list, but got a value to show. */
                                        printf("%f (current)", tmp_flt);
                                }
@@ -729,7 +766,7 @@ void show_dev_detail(void)
                                if (i)
                                        printf(", ");
                                printf("%f", fltopts[i]);
-                               if (tmp_flt && fltopts[i] == tmp_flt)
+                               if (have_tmp_flt && fltopts[i] == tmp_flt)
                                        printf(" (current)");
                        }
                        printf("\n");
@@ -861,6 +898,7 @@ static void show_pd_detail_single(const char *pd)
                        printf("None.\n");
                }
                printf("Decoder tags:\n");
+#if DECODERS_HAVE_TAGS
                if (dec->tags) {
                        for (l = dec->tags; l; l = l->next) {
                                str = l->data;
@@ -869,6 +907,7 @@ static void show_pd_detail_single(const char *pd)
                } else {
                        printf("None.\n");
                }
+#endif
                printf("Annotation classes:\n");
                if (dec->annotations) {
                        for (l = dec->annotations; l; l = l->next) {
@@ -1084,7 +1123,7 @@ static void print_serial_port(gpointer data, gpointer user_data)
 
        port = (void *)data;
        (void)user_data;
-       printf("\t%s\t%s\n", port->name, port->description);
+       printf("  %s\t%s\n", port->name, port->description);
 }
 
 void show_serial_ports(void)
index 7def7412fd62cbc8dd3bb4885da4c02f30d46173..b33b076bd1f82824d284395ed7ca4267fd3b516c 100644 (file)
@@ -56,7 +56,8 @@ void show_serial_ports(void);
 
 /* device.c */
 GSList *device_scan(void);
-struct sr_channel_group *select_channel_group(struct sr_dev_inst *sdi);
+struct sr_channel_group *lookup_channel_group(struct sr_dev_inst *sdi,
+       const char *cg_name);
 
 /* session.c */
 struct df_arg_desc {
@@ -76,14 +77,19 @@ struct df_arg_desc {
 void datafeed_in(const struct sr_dev_inst *sdi,
                const struct sr_datafeed_packet *packet, void *cb_data);
 int opt_to_gvar(char *key, char *value, struct sr_config *src);
+int set_dev_options_array(struct sr_dev_inst *sdi, char **opts);
 int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args);
 void run_session(void);
 
 /* input.c */
 void load_input_file(gboolean do_props);
 
+/* output.c */
+int setup_binary_stdout(void);
+
 /* decode.c */
 #ifdef HAVE_SRD
+extern uint64_t pd_samplerate;
 int register_pds(gchar **all_pds, char *opt_pd_annotations);
 int setup_pd_annotations(char *opt_pd_annotations);
 int setup_pd_meta(char *opt_pd_meta);
@@ -91,16 +97,23 @@ int setup_pd_binary(char *opt_pd_binary);
 void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data);
 void show_pd_meta(struct srd_proto_data *pdata, void *cb_data);
 void show_pd_binary(struct srd_proto_data *pdata, void *cb_data);
+void show_pd_prepare(void);
+void show_pd_close(void);
 void map_pd_channels(struct sr_dev_inst *sdi);
 #endif
 
 /* parsers.c */
-struct sr_channel *find_channel(GSList *channellist, const char *channelname);
+struct sr_channel *find_channel(GSList *channellist, const char *channelname,
+       gboolean exact_case);
 GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring);
 int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
                struct sr_trigger **trigger);
-GHashTable *parse_generic_arg(const char *arg, gboolean sep_first);
+GHashTable *parse_generic_arg(const char *arg,
+               gboolean sep_first, const char *key_first);
 GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genargs);
+GSList *check_unknown_keys(const struct sr_option **avail, GHashTable *used);
+gboolean warn_unknown_keys(const struct sr_option **avail, GHashTable *used,
+               const char *caption);
 int canon_cmp(const char *str1, const char *str2);
 int parse_driver(char *arg, struct sr_dev_driver **driver, GSList **drvopts);
 
@@ -119,7 +132,7 @@ extern gboolean opt_wait_trigger;
 extern gchar *opt_input_file;
 extern gchar *opt_output_file;
 extern gchar *opt_drv;
-extern gchar *opt_config;
+extern gchar **opt_configs;
 extern gchar *opt_channels;
 extern gchar *opt_channel_group;
 extern gchar *opt_triggers;
@@ -128,7 +141,9 @@ extern gchar **opt_pds;
 extern gchar *opt_pd_annotations;
 extern gchar *opt_pd_meta;
 extern gchar *opt_pd_binary;
+extern gboolean opt_pd_ann_class;
 extern gboolean opt_pd_samplenum;
+extern gboolean opt_pd_jsontrace;
 #endif
 extern gchar *opt_input_format;
 extern gchar *opt_output_format;
@@ -138,7 +153,7 @@ extern gchar *opt_time;
 extern gchar *opt_samples;
 extern gchar *opt_frames;
 extern gboolean opt_continuous;
-extern gchar *opt_get;
+extern gchar **opt_gets;
 extern gboolean opt_set;
 extern gboolean opt_list_serial;
 int parse_options(int argc, char **argv);