output/csv: Use the logic stream's unitsize.
This also fixes the channel index, instead of counting on the logic data being arranged according to enabled channels only.
This commit is contained in:
parent
2b78ffea54
commit
2a035e539a
26
output/csv.c
26
output/csv.c
|
@ -29,10 +29,10 @@
|
||||||
|
|
||||||
struct context {
|
struct context {
|
||||||
unsigned int num_enabled_channels;
|
unsigned int num_enabled_channels;
|
||||||
unsigned int unitsize;
|
|
||||||
uint64_t samplerate;
|
uint64_t samplerate;
|
||||||
GString *header;
|
GString *header;
|
||||||
char separator;
|
char separator;
|
||||||
|
int *channel_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -53,7 +53,7 @@ static int init(struct sr_output *o)
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
GVariant *gvar;
|
GVariant *gvar;
|
||||||
int num_channels;
|
int num_channels, i, j;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
if (!o)
|
if (!o)
|
||||||
|
@ -62,7 +62,7 @@ static int init(struct sr_output *o)
|
||||||
if (!o->sdi)
|
if (!o->sdi)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
|
||||||
ctx = g_try_malloc0(sizeof(struct context));
|
ctx = g_malloc0(sizeof(struct context));
|
||||||
o->internal = ctx;
|
o->internal = ctx;
|
||||||
|
|
||||||
/* Get the number of channels, and the unitsize. */
|
/* Get the number of channels, and the unitsize. */
|
||||||
|
@ -74,8 +74,7 @@ static int init(struct sr_output *o)
|
||||||
continue;
|
continue;
|
||||||
ctx->num_enabled_channels++;
|
ctx->num_enabled_channels++;
|
||||||
}
|
}
|
||||||
|
ctx->channel_index = g_malloc(sizeof(int) * ctx->num_enabled_channels);
|
||||||
ctx->unitsize = (ctx->num_enabled_channels + 7) / 8;
|
|
||||||
|
|
||||||
num_channels = g_slist_length(o->sdi->channels);
|
num_channels = g_slist_length(o->sdi->channels);
|
||||||
|
|
||||||
|
@ -100,13 +99,15 @@ static int init(struct sr_output *o)
|
||||||
/* Columns / channels */
|
/* Columns / channels */
|
||||||
g_string_append_printf(ctx->header, "; Channels (%d/%d):",
|
g_string_append_printf(ctx->header, "; Channels (%d/%d):",
|
||||||
ctx->num_enabled_channels, num_channels);
|
ctx->num_enabled_channels, num_channels);
|
||||||
for (l = o->sdi->channels; l; l = l->next) {
|
for (i = 0, j = 0, l = o->sdi->channels; l; l = l->next, i++) {
|
||||||
ch = l->data;
|
ch = l->data;
|
||||||
if (ch->type != SR_CHANNEL_LOGIC)
|
if (ch->type != SR_CHANNEL_LOGIC)
|
||||||
continue;
|
continue;
|
||||||
if (!ch->enabled)
|
if (!ch->enabled)
|
||||||
continue;
|
continue;
|
||||||
g_string_append_printf(ctx->header, " %s,", ch->name);
|
g_string_append_printf(ctx->header, " %s,", ch->name);
|
||||||
|
/* Remember the enabled channel's index while we're at it. */
|
||||||
|
ctx->channel_index[j++] = i;
|
||||||
}
|
}
|
||||||
if (o->sdi->channels)
|
if (o->sdi->channels)
|
||||||
/* Drop last separator. */
|
/* Drop last separator. */
|
||||||
|
@ -121,6 +122,7 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi,
|
||||||
{
|
{
|
||||||
const struct sr_datafeed_logic *logic;
|
const struct sr_datafeed_logic *logic;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
|
int idx;
|
||||||
uint64_t i, j;
|
uint64_t i, j;
|
||||||
gchar *p, c;
|
gchar *p, c;
|
||||||
|
|
||||||
|
@ -146,10 +148,11 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi,
|
||||||
*out = g_string_sized_new(512);
|
*out = g_string_sized_new(512);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i <= logic->length - ctx->unitsize; i += ctx->unitsize) {
|
for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
|
||||||
for (j = 0; j < ctx->num_enabled_channels; j++) {
|
for (j = 0; j < ctx->num_enabled_channels; j++) {
|
||||||
p = logic->data + i + j / 8;
|
idx = ctx->channel_index[j];
|
||||||
c = *p & (1 << (j % 8));
|
p = logic->data + i + idx / 8;
|
||||||
|
c = *p & (1 << (idx % 8));
|
||||||
g_string_append_c(*out, c ? '1' : '0');
|
g_string_append_c(*out, c ? '1' : '0');
|
||||||
g_string_append_c(*out, ctx->separator);
|
g_string_append_c(*out, ctx->separator);
|
||||||
}
|
}
|
||||||
|
@ -160,10 +163,6 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi,
|
||||||
g_string_append_printf(*out, "\n");
|
g_string_append_printf(*out, "\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SR_DF_END:
|
|
||||||
g_free(o->internal);
|
|
||||||
o->internal = NULL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -180,6 +179,7 @@ static int cleanup(struct sr_output *o)
|
||||||
ctx = o->internal;
|
ctx = o->internal;
|
||||||
if (ctx->header)
|
if (ctx->header)
|
||||||
g_string_free(ctx->header, TRUE);
|
g_string_free(ctx->header, TRUE);
|
||||||
|
g_free(ctx->channel_index);
|
||||||
g_free(o->internal);
|
g_free(o->internal);
|
||||||
o->internal = NULL;
|
o->internal = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue