]> sigrok.org Git - sigrok-cli.git/blobdiff - session.c
doc: update sigrok-cli(1) for channel assignment to decoder inputs
[sigrok-cli.git] / session.c
index 65352bbd841481b31219c0d20111f65d3fb9d3b6..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,17 +101,25 @@ 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) {
-               if (!sr_output_test_flag(omod, SR_OUTPUT_INTERNAL_IO_HANDLING))
+               if (!sr_output_test_flag(omod, SR_OUTPUT_INTERNAL_IO_HANDLING)) {
                        *outfile = g_fopen(opt_output_file, "wb");
-               else
+                       if (!*outfile) {
+                               g_critical("Cannot write to output file '%s'.",
+                                       opt_output_file);
+                       }
+               } else {
                        *outfile = NULL;
+               }
        } else {
+               setup_binary_stdout();
                *outfile = stdout;
        }
 
@@ -130,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.");
@@ -139,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);
@@ -318,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.");
@@ -346,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;
@@ -473,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);
@@ -642,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.",
@@ -670,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;
@@ -753,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) {