]> sigrok.org Git - libsigrok.git/blobdiff - output/ols.c
Replace 'probe' with 'channel' in most places.
[libsigrok.git] / output / ols.c
index a77dc6277b35e17e122d4c20839f3777489daa08..b59931624921ba0565e88d76cf82eb3d082d237c 100644 (file)
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 
-/* Message logging helpers with driver-specific prefix string. */
-#define DRIVER_LOG_DOMAIN "output/ols: "
-#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)
+#define LOG_PREFIX "output/ols"
 
 struct context {
-    uint64_t samplerate;
+       uint64_t samplerate;
        uint64_t num_samples;
 };
 
@@ -55,7 +48,7 @@ static int init(struct sr_output *o)
        }
        o->internal = ctx;
 
-    ctx->samplerate = 0;
+       ctx->samplerate = 0;
        ctx->num_samples = 0;
 
        return SR_OK;
@@ -63,28 +56,31 @@ static int init(struct sr_output *o)
 
 static GString *gen_header(const struct sr_dev_inst *sdi, struct context *ctx)
 {
-       struct sr_probe *probe;
+       struct sr_channel *ch;
        GSList *l;
        GString *s;
        GVariant *gvar;
-       int num_enabled_probes;
+       int num_enabled_channels;
 
-    if (!ctx->samplerate && sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
-                       &gvar, sdi) == SR_OK) {
+       if (!ctx->samplerate && sr_config_get(sdi->driver, sdi, NULL,
+                       SR_CONF_SAMPLERATE, &gvar) == SR_OK) {
                ctx->samplerate = g_variant_get_uint64(gvar);
                g_variant_unref(gvar);
        }
 
-       num_enabled_probes = 0;
-       for (l = sdi->probes; l; l = l->next) {
-               probe = l->data;
-               if (probe->enabled)
-                       num_enabled_probes++;
+       num_enabled_channels = 0;
+       for (l = sdi->channels; l; l = l->next) {
+               ch = l->data;
+               if (ch->type != SR_PROBE_LOGIC)
+                       continue;
+               if (!ch->enabled)
+                       continue;
+               num_enabled_channels++;
        }
 
        s = g_string_sized_new(512);
        g_string_append_printf(s, ";Rate: %"PRIu64"\n", ctx->samplerate);
-       g_string_append_printf(s, ";Channels: %d\n", num_enabled_probes);
+       g_string_append_printf(s, ";Channels: %d\n", num_enabled_channels);
        g_string_append_printf(s, ";EnabledChannels: -1\n");
        g_string_append_printf(s, ";Compressed: true\n");
        g_string_append_printf(s, ";CursorEnabled: false\n");
@@ -92,51 +88,50 @@ static GString *gen_header(const struct sr_dev_inst *sdi, struct context *ctx)
        return s;
 }
 
-static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi,
-               const struct sr_datafeed_packet *packet)
+static int receive(struct sr_output *o, const struct sr_dev_inst *sdi,
+               const struct sr_datafeed_packet *packet, GString **out)
 {
        struct context *ctx;
        const struct sr_datafeed_meta *meta;
        const struct sr_datafeed_logic *logic;
        const struct sr_config *src;
        GSList *l;
-       GString *out;
        unsigned int i, j;
        uint8_t c;
 
+       *out = NULL;
        if (!o || !o->sdi)
-               return NULL;
+               return SR_ERR_ARG;
        ctx = o->internal;
 
-       out = NULL;
        switch (packet->type) {
-    case SR_DF_META:
+       case SR_DF_META:
                meta = packet->payload;
                for (l = meta->config; l; l = l->next) {
                        src = l->data;
                        if (src->key == SR_CONF_SAMPLERATE)
                                ctx->samplerate = g_variant_get_uint64(src->data);
                }
-        break;
-    case SR_DF_LOGIC:
+               break;
+       case SR_DF_LOGIC:
                logic = packet->payload;
                if (ctx->num_samples == 0) {
                        /* First logic packet in the feed. */
-                       out = gen_header(sdi, ctx);
+                       *out = gen_header(sdi, ctx);
                } else
-                       out = g_string_sized_new(512);
+                       *out = g_string_sized_new(512);
                for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
                        for (j = 0; j < logic->unitsize; j++) {
                                /* The OLS format wants the samples presented MSB first. */
                                c = *((uint8_t *)logic->data + i + logic->unitsize - 1 - j);
-                               g_string_append_printf(out, "%02x", c);
+                               g_string_append_printf(*out, "%02x", c);
                        }
-                       g_string_append_printf(out, "@%"PRIu64"\n", ctx->num_samples++);
+                       g_string_append_printf(*out, "@%"PRIu64"\n", ctx->num_samples++);
                }
                break;
        }
 
-    return out;
+       return SR_OK;
 }
 
 static int cleanup(struct sr_output *o)
@@ -147,8 +142,8 @@ static int cleanup(struct sr_output *o)
                return SR_ERR_ARG;
 
        ctx = o->internal;
-    g_free(ctx);
-    o->internal = NULL;
+       g_free(ctx);
+       o->internal = NULL;
 
        return SR_OK;
 }
@@ -158,6 +153,6 @@ SR_PRIV struct sr_output_format output_ols = {
        .description = "OpenBench Logic Sniffer",
        .df_type = SR_DF_LOGIC,
        .init = init,
-       .recv = receive,
+       .receive = receive,
        .cleanup = cleanup
 };