]> sigrok.org Git - libsigrok.git/commitdiff
input/csv: move samplerate meta packet to logic data feed submission
authorGerhard Sittig <redacted>
Sun, 13 Oct 2019 15:51:35 +0000 (17:51 +0200)
committerGerhard Sittig <redacted>
Sat, 21 Dec 2019 17:20:04 +0000 (18:20 +0100)
Move the communication of the samplerate meta packet to the very spot
where logic sample data gets sent. This allows to optionally determine
late the samplerate, potentially from input data instead of user specs.

src/input/csv.c

index c53ca426aa8863301638c6ebf5da086d5f5ee3a6..8471462b4e512e9aee3a4df00446a18aaa0a4b85 100644 (file)
@@ -116,6 +116,7 @@ struct context {
 
        /* Current selected samplerate. */
        uint64_t samplerate;
+       gboolean samplerate_sent;
 
        /* Number of channels. */
        size_t num_channels;
@@ -213,6 +214,9 @@ static int flush_logic_samples(const struct sr_input *in)
 {
        struct context *inc;
        struct sr_datafeed_packet packet;
+       struct sr_datafeed_meta meta;
+       struct sr_config *src;
+       uint64_t samplerate;
        struct sr_datafeed_logic logic;
        int rc;
 
@@ -220,6 +224,18 @@ static int flush_logic_samples(const struct sr_input *in)
        if (!inc->datafeed_buf_fill)
                return SR_OK;
 
+       if (inc->samplerate && !inc->samplerate_sent) {
+               packet.type = SR_DF_META;
+               packet.payload = &meta;
+               samplerate = inc->samplerate;
+               src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
+               meta.config = g_slist_append(NULL, src);
+               sr_session_send(in->sdi, &packet);
+               g_slist_free(meta.config);
+               sr_config_free(src);
+               inc->samplerate_sent = TRUE;
+       }
+
        memset(&packet, 0, sizeof(packet));
        memset(&logic, 0, sizeof(logic));
        packet.type = SR_DF_LOGIC;
@@ -814,12 +830,8 @@ static int initial_receive(const struct sr_input *in)
 
 static int process_buffer(struct sr_input *in, gboolean is_eof)
 {
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_meta meta;
-       struct sr_config *src;
        struct context *inc;
        gsize num_columns;
-       uint64_t samplerate;
        size_t max_columns, l;
        int ret;
        char *p, **lines, *line, **columns;
@@ -827,18 +839,6 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
        inc = in->priv;
        if (!inc->started) {
                std_session_send_df_header(in->sdi);
-
-               if (inc->samplerate) {
-                       packet.type = SR_DF_META;
-                       packet.payload = &meta;
-                       samplerate = inc->samplerate;
-                       src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
-                       meta.config = g_slist_append(NULL, src);
-                       sr_session_send(in->sdi, &packet);
-                       g_slist_free(meta.config);
-                       sr_config_free(src);
-               }
-
                inc->started = TRUE;
        }