]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
Use new probe_groups API
[sigrok-cli.git] / sigrok-cli.c
index 7f5cb5817e6428678cc2338f893e371d2b3a52fe..8f3d8e313d70bed817825945cd2991f193c5cbc7 100644 (file)
@@ -178,11 +178,14 @@ static GSList *device_scan(void)
                }
                if (!driver) {
                        g_critical("Driver %s not found.", drvname);
+                       g_hash_table_destroy(drvargs);
+                       g_free(drvname);
                        return NULL;
                }
                g_free(drvname);
                if (sr_driver_init(sr_ctx, driver) != SR_OK) {
                        g_critical("Failed to initialize driver.");
+                       g_hash_table_destroy(drvargs);
                        return NULL;
                }
                drvopts = NULL;
@@ -193,7 +196,7 @@ static GSList *device_scan(void)
                                return NULL;
                        }
                }
-               g_hash_table_destroy(drvargs); 
+               g_hash_table_destroy(drvargs);
                devices = sr_driver_scan(driver, drvopts);
                g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
        } else {
@@ -282,7 +285,7 @@ static void print_dev_line(const struct sr_dev_inst *sdi)
 
        s = g_string_sized_new(128);
        g_string_assign(s, sdi->driver->name);
-       if (sr_config_get(sdi->driver, SR_CONF_CONN, &gvar, sdi) == SR_OK) {
+       if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
                g_string_append(s, ":conn=");
                g_string_append(s, g_variant_get_string(gvar, NULL));
                g_variant_unref(gvar);
@@ -364,8 +367,8 @@ static void show_dev_detail(void)
                return;
        }
 
-       if ((sr_config_list(sdi->driver, SR_CONF_SCAN_OPTIONS, &gvar_opts,
-                       NULL) == SR_OK)) {
+       if ((sr_config_list(sdi->driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
+                       &gvar_opts) == SR_OK)) {
                opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
                                sizeof(int32_t));
                printf("Supported driver options:\n");
@@ -377,8 +380,8 @@ static void show_dev_detail(void)
                g_variant_unref(gvar_opts);
        }
 
-       if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_OPTIONS, &gvar_opts,
-                       sdi) != SR_OK))
+       if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS,
+                       &gvar_opts) != SR_OK))
                /* Driver supports no device instance options. */
                return;
 
@@ -389,8 +392,8 @@ static void show_dev_detail(void)
                        continue;
 
                if (srci->key == SR_CONF_TRIGGER_TYPE) {
-                       if (sr_config_list(sdi->driver, srci->key, &gvar,
-                                       sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL, srci->key,
+                                       &gvar) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -406,8 +409,8 @@ static void show_dev_detail(void)
                } else if (srci->key == SR_CONF_PATTERN_MODE) {
                        /* Pattern generator modes */
                        printf("    %s", srci->id);
-                       if (sr_config_list(sdi->driver, srci->key, &gvar,
-                                       sdi) == SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL, srci->key,
+                                       &gvar) == SR_OK) {
                                printf(" - supported patterns:\n");
                                stropts = g_variant_get_strv(gvar, &num_elements);
                                for (i = 0; i < num_elements; i++)
@@ -420,8 +423,8 @@ static void show_dev_detail(void)
                } else if (srci->key == SR_CONF_SAMPLERATE) {
                        /* Supported samplerates */
                        printf("    %s", srci->id);
-                       if (sr_config_list(sdi->driver, SR_CONF_SAMPLERATE,
-                                       &gvar_dict, sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE,
+                                       &gvar_dict) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -463,8 +466,8 @@ static void show_dev_detail(void)
                } else if (srci->key == SR_CONF_BUFFERSIZE) {
                        /* Supported buffer sizes */
                        printf("    %s", srci->id);
-                       if (sr_config_list(sdi->driver, SR_CONF_BUFFERSIZE,
-                                       &gvar_list, sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL,
+                                       SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -478,8 +481,8 @@ static void show_dev_detail(void)
                } else if (srci->key == SR_CONF_TIMEBASE) {
                        /* Supported time bases */
                        printf("    %s", srci->id);
-                       if (sr_config_list(sdi->driver, SR_CONF_TIMEBASE,
-                                       &gvar_list, sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL,
+                                       SR_CONF_TIMEBASE, &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -497,8 +500,8 @@ static void show_dev_detail(void)
                } else if (srci->key == SR_CONF_VDIV) {
                        /* Supported volts/div values */
                        printf("    %s", srci->id);
-                       if (sr_config_list(sdi->driver, SR_CONF_VDIV,
-                                       &gvar_list, sdi) != SR_OK) {
+                       if (sr_config_list(sdi->driver, sdi, NULL,
+                                       SR_CONF_VDIV, &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -701,7 +704,7 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
        GSList *l;
        GString *out;
        int sample_size, ret;
-       uint64_t samplerate, output_len, filter_out_len;
+       uint64_t samplerate, output_len, filter_out_len, end_sample;
        uint8_t *output_buf, *filter_out;
 
        (void) cb_data;
@@ -753,28 +756,15 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
 #ifdef HAVE_SRD
                GVariant *gvar;
                if (opt_pds && logic_probelist->len) {
-                       if (sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
-                                       &gvar, sdi) != SR_OK) {
-                               g_critical("Unable to initialize protocol "
-                                               "decoders: no samplerate found.");
-                               break;
-                       }
-                       samplerate = g_variant_get_uint64(gvar);
-                       g_variant_unref(gvar);
-                       if (srd_session_config_set(srd_sess, SRD_CONF_NUM_PROBES,
-                                               g_variant_new_uint64(logic_probelist->len)) != SRD_OK) {
-                               g_critical("Failed to configure decode session.");
-                               break;
-                       }
-                       if (srd_session_config_set(srd_sess, SRD_CONF_UNITSIZE,
-                                               g_variant_new_uint64(unitsize)) != SRD_OK) {
-                               g_critical("Failed to configure decode session.");
-                               break;
-                       }
-                       if (srd_session_config_set(srd_sess, SRD_CONF_SAMPLERATE,
+                       if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE,
+                                       &gvar, sdi) == SR_OK) {
+                               samplerate = g_variant_get_uint64(gvar);
+                               g_variant_unref(gvar);
+                               if (srd_session_metadata_set(srd_sess, SRD_CONF_SAMPLERATE,
                                                g_variant_new_uint64(samplerate)) != SRD_OK) {
-                               g_critical("Failed to configure decode session.");
-                               break;
+                                       g_critical("Failed to configure decode session.");
+                                       break;
+                               }
                        }
                        if (srd_session_start(srd_sess) != SRD_OK) {
                                g_critical("Failed to start decode session.");
@@ -793,6 +783,14 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                        case SR_CONF_SAMPLERATE:
                                samplerate = g_variant_get_uint64(src->data);
                                g_debug("cli: got samplerate %"PRIu64" Hz", samplerate);
+#ifdef HAVE_SRD
+                               if (opt_pds) {
+                                       if (srd_session_metadata_set(srd_sess, SRD_CONF_SAMPLERATE,
+                                                       g_variant_new_uint64(samplerate)) != SRD_OK) {
+                                               g_critical("Failed to pass samplerate to decoder.");
+                                       }
+                               }
+#endif
                                break;
                        case SR_CONF_SAMPLE_INTERVAL:
                                samplerate = g_variant_get_uint64(src->data);
@@ -833,9 +831,10 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                if (ret != SR_OK)
                        break;
 
-               /* What comes out of the filter is guaranteed to be packed into the
+               /*
+                * What comes out of the filter is guaranteed to be packed into the
                 * minimum size needed to support the number of samples at this sample
-                * size. however, the driver may have submitted too much -- cut off
+                * size. however, the driver may have submitted too much. Cut off
                 * the buffer of the last packet according to the sample limit.
                 */
                if (limit_samples && (received_samples + logic->length / sample_size >
@@ -848,7 +847,8 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                } else {
                        if (opt_pds) {
 #ifdef HAVE_SRD
-                               if (srd_session_send(srd_sess, received_samples,
+                               end_sample = received_samples + filter_out_len / unitsize;
+                               if (srd_session_send(srd_sess, received_samples, end_sample,
                                                (uint8_t*)filter_out, filter_out_len) != SRD_OK)
                                        sr_session_stop();
 #endif
@@ -1565,7 +1565,7 @@ static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args)
                        ret = SR_ERR;
                }
                if (val)
-                       ret = sr_config_set(sdi, srci->key, val);
+                       ret = sr_config_set(sdi, NULL, srci->key, val);
                if (ret != SR_OK) {
                        g_critical("Failed to set device option '%s'.", (char *)key);
                        return ret;
@@ -1621,13 +1621,13 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
 
        if (sr_dev_has_option(sdi, SR_CONF_LIMIT_MSEC)) {
                gvar = g_variant_new_uint64(time_msec);
-               if (sr_config_set(sdi, SR_CONF_LIMIT_MSEC, gvar) != SR_OK) {
+               if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_MSEC, gvar) != SR_OK) {
                        g_critical("Failed to configure time limit.");
                        return SR_ERR;
                }
        } else if (sr_dev_has_option(sdi, SR_CONF_SAMPLERATE)) {
                /* Convert to samples based on the samplerate.  */
-               sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, &gvar, sdi);
+               sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar);
                samplerate = g_variant_get_uint64(gvar);
                g_variant_unref(gvar);
                limit_samples = (samplerate) * time_msec / (uint64_t)1000;
@@ -1636,7 +1636,7 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
                        return SR_ERR;
                }
                gvar = g_variant_new_uint64(limit_samples);
-               if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
+               if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
                        g_critical("Failed to configure time-based sample limit.");
                        return SR_ERR;
                }
@@ -1733,7 +1733,7 @@ static void run_session(void)
                        return;
                }
                gvar = g_variant_new_uint64(limit_samples);
-               if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
+               if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
                        g_critical("Failed to configure sample limit.");
                        sr_session_destroy();
                        return;
@@ -1747,7 +1747,7 @@ static void run_session(void)
                        return;
                }
                gvar = g_variant_new_uint64(limit_frames);
-               if (sr_config_set(sdi, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
+               if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
                        g_critical("Failed to configure frame limit.");
                        sr_session_destroy();
                        return;