]> sigrok.org Git - libsigrok.git/blobdiff - input/vcd.c
GPL headers: Use correct project name.
[libsigrok.git] / input / vcd.c
index 138aa3c1526bbebee085de5d4289f8bcda865b3d..130e2eff6e9bb1daeeeefad7e8e176c03edb142f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2012 Petteri Aimonen <jpa@sr.mail.kapsi.fi>
  *
@@ -211,6 +211,7 @@ static void remove_empty_parts(gchar **parts)
  */
 static gboolean parse_header(FILE *file, struct context *ctx)
 {
+       uint64_t p, q;
        gchar *name = NULL, *contents = NULL;
        gboolean status = FALSE;
 
@@ -227,15 +228,14 @@ static gboolean parse_header(FILE *file, struct context *ctx)
                {
                        /* The standard allows for values 1, 10 or 100
                         * and units s, ms, us, ns, ps and fs. */
-                       struct sr_rational period;
-                       if (sr_parse_period(contents, &period) == SR_OK)
+                       if (sr_parse_period(contents, &p, &q) == SR_OK)
                        {
-                               ctx->samplerate = period.q / period.p;
-                               if (period.q % period.p != 0)
+                               ctx->samplerate = q / p;
+                               if (q % p != 0)
                                {
                                        /* Does not happen unless time value is non-standard */
                                        sr_warn("Inexact rounding of samplerate, %" PRIu64 " / %" PRIu64 " to %" PRIu64 " Hz.",
-                                               period.q, period.p, ctx->samplerate);
+                                               q, p, ctx->samplerate);
                                }
                                
                                sr_dbg("Samplerate: %" PRIu64, ctx->samplerate);
@@ -311,7 +311,7 @@ static int format_match(const char *filename)
        return status;
 }
 
-static int init(struct sr_input *in)
+static int init(struct sr_input *in, const char *filename)
 {
        struct sr_probe *probe;
        int num_probes, i;
@@ -319,6 +319,8 @@ static int init(struct sr_input *in)
        char *param;
        struct context *ctx;
 
+       (void)filename;
+
        if (!(ctx = g_try_malloc0(sizeof(*ctx)))) {
                sr_err("Input format context malloc failed.");
                return SR_ERR_MALLOC;
@@ -543,11 +545,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;
 
@@ -562,18 +565,16 @@ 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_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
+       meta.config = g_slist_append(NULL, src);
        sr_session_send(in->sdi, &packet);
+       sr_config_free(src);
 
        /* Parse the contents of the VCD file */
        parse_contents(file, in->sdi, ctx);