X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fcsv.c;h=f892311205869ba0f65b4f9fa041a671b4e8b2a9;hb=0f523f2b45e84114add85cec5a97aed3f85f95e6;hp=f6502fb8a9b6e6588f669e893e7f686307641e43;hpb=b078dddb849829be05093bbce5a7056fa2fc0eb7;p=libsigrok.git diff --git a/src/output/csv.c b/src/output/csv.c index f6502fb8..f8923112 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -310,7 +310,9 @@ static void process_analog(struct context *ctx, const struct sr_datafeed_analog *analog) { int ret; - unsigned int i, j, c, num_channels; + size_t num_rcvd_ch, num_have_ch; + size_t idx_have, idx_smpl, idx_rcvd; + size_t idx_send; struct sr_analog_meaning *meaning; GSList *l; float *fdata = NULL; @@ -327,31 +329,34 @@ static void process_analog(struct context *ctx, ctx->num_samples, analog->num_samples); meaning = analog->meaning; - num_channels = g_slist_length(meaning->channels); - ctx->channels_seen += num_channels; - sr_dbg("Processing packet of %u analog channels", num_channels); - fdata = g_malloc(analog->num_samples * num_channels * sizeof(float)); + num_rcvd_ch = g_slist_length(meaning->channels); + ctx->channels_seen += num_rcvd_ch; + sr_dbg("Processing packet of %zu analog channels", num_rcvd_ch); + fdata = g_malloc(analog->num_samples * num_rcvd_ch * sizeof(float)); if ((ret = sr_analog_to_float(analog, fdata)) != SR_OK) sr_warn("Problems converting data to floating point values."); - for (i = 0; i < ctx->num_analog_channels + ctx->num_logic_channels; i++) { - if (ctx->channels[i].ch->type != SR_CHANNEL_ANALOG) + num_have_ch = ctx->num_analog_channels + ctx->num_logic_channels; + idx_send = 0; + for (idx_have = 0; idx_have < num_have_ch; idx_have++) { + if (ctx->channels[idx_have].ch->type != SR_CHANNEL_ANALOG) continue; sr_dbg("Looking for channel %s", - ctx->channels[i].ch->name); - for (l = meaning->channels, c = 0; l; l = l->next, c++) { + ctx->channels[idx_have].ch->name); + for (l = meaning->channels, idx_rcvd = 0; l; l = l->next, idx_rcvd++) { ch = l->data; sr_dbg("Checking %s", ch->name); - if (ctx->channels[i].ch != l->data) + if (ctx->channels[idx_have].ch != ch) continue; if (ctx->label_do && !ctx->label_names) { sr_analog_unit_to_string(analog, - &ctx->channels[i].label); + &ctx->channels[idx_have].label); } - for (j = 0; j < analog->num_samples; j++) - ctx->analog_samples[j * ctx->num_analog_channels + i] = fdata[j * num_channels + c]; + for (idx_smpl = 0; idx_smpl < analog->num_samples; idx_smpl++) + ctx->analog_samples[idx_smpl * ctx->num_analog_channels + idx_send] = fdata[idx_smpl * num_rcvd_ch + idx_rcvd]; break; } + idx_send++; } g_free(fdata); } @@ -638,6 +643,8 @@ static struct sr_option options[] = { static const struct sr_option *get_options(void) { + GSList *l = NULL; + if (!options[0].def) { options[0].def = g_variant_ref_sink(g_variant_new_string("")); options[1].def = g_variant_ref_sink(g_variant_new_boolean(TRUE)); @@ -647,6 +654,10 @@ static const struct sr_option *get_options(void) options[5].def = g_variant_ref_sink(g_variant_new_string(";")); options[6].def = g_variant_ref_sink(g_variant_new_boolean(TRUE)); options[7].def = g_variant_ref_sink(g_variant_new_string("units")); + l = g_slist_append(l, g_variant_ref_sink(g_variant_new_string("units"))); + l = g_slist_append(l, g_variant_ref_sink(g_variant_new_string("channel"))); + l = g_slist_append(l, g_variant_ref_sink(g_variant_new_string("off"))); + options[7].values = l; options[8].def = g_variant_ref_sink(g_variant_new_boolean(TRUE)); options[9].def = g_variant_ref_sink(g_variant_new_boolean(FALSE)); options[10].def = g_variant_ref_sink(g_variant_new_boolean(TRUE));