X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Fcsv.c;h=28eedd6eadc02b55da4cec2cbfa6af0a28bf54cc;hb=016e72f30e21fbec6a1097318ab36877b2c140af;hp=f097024ed7c3e912f03162ec78eb7c7f8eca8d08;hpb=4829d37d6ad74c9368784b3cf3cae6f1a0a651c4;p=libsigrok.git diff --git a/output/csv.c b/output/csv.c index f097024e..28eedd6e 100644 --- a/output/csv.c +++ b/output/csv.c @@ -98,7 +98,7 @@ static int init(struct sr_output *o) ctx->samplerate); /* Columns / channels */ - g_string_append_printf(ctx->header, "; Channels (%d/%d): ", + g_string_append_printf(ctx->header, "; Channels (%d/%d):", ctx->num_enabled_probes, num_probes); for (l = o->sdi->probes; l; l = l->next) { probe = l->data; @@ -106,8 +106,11 @@ static int init(struct sr_output *o) continue; if (!probe->enabled) continue; - g_string_append_printf(ctx->header, "%s, ", probe->name); + g_string_append_printf(ctx->header, " %s,", probe->name); } + if (o->sdi->probes) + /* Drop last separator. */ + g_string_truncate(ctx->header, ctx->header->len - 1); g_string_append_printf(ctx->header, "\n"); return SR_OK; @@ -118,7 +121,8 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi, { const struct sr_datafeed_logic *logic; struct context *ctx; - uint64_t sample, i, j; + uint64_t i, j; + gchar *p, c; (void)sdi; @@ -143,11 +147,15 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi, } for (i = 0; i <= logic->length - ctx->unitsize; i += ctx->unitsize) { - memcpy(&sample, logic->data + i, ctx->unitsize); for (j = 0; j < ctx->num_enabled_probes; j++) { - g_string_append_printf(*out, "%d%c", - (int)((sample & (1 << j)) >> j), - ctx->separator); + p = logic->data + i + j / 8; + c = *p & (1 << (j % 8)); + g_string_append_c(*out, c ? '1' : '0'); + g_string_append_c(*out, ctx->separator); + } + if (j) { + /* Drop last separator. */ + g_string_truncate(*out, (*out)->len - 1); } g_string_append_printf(*out, "\n"); }