]> sigrok.org Git - libsigrok.git/blobdiff - input/vcd.c
Add and use std_session_send_df_header().
[libsigrok.git] / input / vcd.c
index 3aad3bd89b3c655308723abcce4d993846e73277..a9963f7e7682dc136575f785f9471f2e439b7d61 100644 (file)
  * downsample:  Divide the samplerate by the given factor.
  *              This can speed up analyzing of long captures.
  *
+ * compress:    Compress idle periods longer than this value.
+ *              This can speed up analyzing of long captures.
+ *              Default 0 = don't compress.
+ *
  * Based on Verilog standard IEEE Std 1364-2001 Version C
  *
  * Supported features:
@@ -167,6 +171,7 @@ struct context
        int maxprobes;
        int probecount;
        int downsample;
+       unsigned compress;
        int64_t skip;
        struct probe probes[SR_MAX_NUM_PROBES];
 };
@@ -344,6 +349,11 @@ static int init(struct sr_input *in)
                        }
                }
                
+               param = g_hash_table_lookup(in->param, "compress");
+               if (param) {
+                       ctx->compress = strtoul(param, NULL, 10);
+               }
+               
                param = g_hash_table_lookup(in->param, "skip");
                if (param) {
                        ctx->skip = strtoul(param, NULL, 10) / ctx->downsample;
@@ -447,6 +457,12 @@ static void parse_contents(FILE *file, const struct sr_dev_inst *sdi, struct con
                        }
                        else
                        {
+                               if (ctx->compress != 0 && timestamp - prev_timestamp > ctx->compress)
+                               {
+                                       /* Compress long idle periods */
+                                       prev_timestamp = timestamp - ctx->compress;
+                               }
+                       
                                sr_dbg("New timestamp: %" PRIu64, timestamp);
                        
                                /* Generate samples from prev_timestamp up to timestamp - 1. */
@@ -527,11 +543,12 @@ static void parse_contents(FILE *file, const struct sr_dev_inst *sdi, struct con
 
 static int loadfile(struct sr_input *in, const char *filename)
 {
-       struct sr_datafeed_header header;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_meta_logic meta;
+       struct sr_datafeed_meta meta;
+       struct sr_config *src;
        FILE *file;
        struct context *ctx;
+       uint64_t samplerate;
 
        ctx = in->internal;
 
@@ -546,17 +563,14 @@ static int loadfile(struct sr_input *in, const char *filename)
        }
 
        /* Send header packet to the session bus. */
-       header.feed_version = 1;
-       gettimeofday(&header.starttime, NULL);
-       packet.type = SR_DF_HEADER;
-       packet.payload = &header;
-       sr_session_send(in->sdi, &packet);
+       std_session_send_df_header(in->sdi, DRIVER_LOG_DOMAIN);
 
        /* Send metadata about the SR_DF_LOGIC packets to come. */
-       packet.type = SR_DF_META_LOGIC;
+       packet.type = SR_DF_META;
        packet.payload = &meta;
-       meta.samplerate = ctx->samplerate / ctx->downsample;
-       meta.num_probes = ctx->probecount;
+       samplerate = ctx->samplerate / ctx->downsample;
+       src = sr_config_make(SR_CONF_SAMPLERATE, (const void *)&samplerate);
+       meta.config = g_slist_append(NULL, src);
        sr_session_send(in->sdi, &packet);
 
        /* Parse the contents of the VCD file */