]> sigrok.org Git - libsigrok.git/blobdiff - output/vcd.c
Deprecate SR_DI_CUR_SAMPLERATE.
[libsigrok.git] / output / vcd.c
index 7f7342795e139c670b89a5e57b16342a6913bcb8..39759d648f82be07de4c20ad167dd611ef60a5c8 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
-#include "config.h"
+#include "config.h" /* Needed for PACKAGE and others. */
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 
+/* Message logging helpers with driver-specific prefix string. */
+#define DRIVER_LOG_DOMAIN "output/vcd: "
+#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
+#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
+#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
+#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
+#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
+#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
+
 struct context {
        int num_enabled_probes;
        int unitsize;
@@ -45,33 +54,34 @@ static int init(struct sr_output *o)
        struct context *ctx;
        struct sr_probe *probe;
        GSList *l;
+       uint64_t *samplerate;
        int num_probes, i;
        char *samplerate_s, *frequency_s, *timestamp;
        time_t t;
 
        if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
-               sr_err("vcd out: %s: ctx malloc failed", __func__);
+               sr_err("%s: ctx malloc failed", __func__);
                return SR_ERR_MALLOC;
        }
 
        o->internal = ctx;
        ctx->num_enabled_probes = 0;
 
-       for (l = o->dev->probes; l; l = l->next) {
+       for (l = o->sdi->probes; l; l = l->next) {
                probe = l->data;
                if (!probe->enabled)
                        continue;
                ctx->probelist[ctx->num_enabled_probes++] = probe->name;
        }
        if (ctx->num_enabled_probes > 94) {
-               sr_err("vcd out: VCD only supports 94 probes.");
+               sr_err("VCD only supports 94 probes.");
                return SR_ERR;
        }
 
        ctx->probelist[ctx->num_enabled_probes] = 0;
        ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
        ctx->header = g_string_sized_new(512);
-       num_probes = g_slist_length(o->dev->probes);
+       num_probes = g_slist_length(o->sdi->probes);
 
        /* timestamp */
        t = time(NULL);
@@ -84,9 +94,10 @@ static int init(struct sr_output *o)
        g_string_append_printf(ctx->header, "$version %s %s $end\n",
                        PACKAGE, PACKAGE_VERSION);
 
-       if (o->dev->driver && sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
-               ctx->samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
-                               o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
+       if (o->sdi->driver && sr_dev_has_hwcap(o->sdi, SR_CONF_SAMPLERATE)) {
+               o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
+                               (const void **)&samplerate, o->sdi);
+               ctx->samplerate = *samplerate;
                if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) {
                        g_string_free(ctx->header, TRUE);
                        g_free(ctx);
@@ -128,7 +139,7 @@ static int init(struct sr_output *o)
        if (!(ctx->prevbits = g_try_malloc0(sizeof(int) * num_probes))) {
                g_string_free(ctx->header, TRUE);
                g_free(ctx);
-               sr_err("vcd out: %s: ctx->prevbits malloc failed", __func__);
+               sr_err("%s: ctx->prevbits malloc failed", __func__);
                return SR_ERR_MALLOC;
        }