output/csv: use longer names for iteration variables

The process_analog() logic is rather complex, dealing with the total
list of channels in the device (which can be of different types), and a
number of submitted samples for a specified list of channels. Replace
the rather short variable names for i, j, c (and num_channels) with
something longer that hopefully increases readability of the complex
loop bodies.

Note that this change merely renames identifiers, and does not change
behaviour.
This commit is contained in:
Gerhard Sittig 2018-03-04 18:19:38 +01:00 committed by Uwe Hermann
parent b078dddb84
commit a551cb0927
1 changed files with 15 additions and 13 deletions

View File

@ -310,7 +310,8 @@ static void process_analog(struct context *ctx,
const struct sr_datafeed_analog *analog) const struct sr_datafeed_analog *analog)
{ {
int ret; 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;
struct sr_analog_meaning *meaning; struct sr_analog_meaning *meaning;
GSList *l; GSList *l;
float *fdata = NULL; float *fdata = NULL;
@ -327,29 +328,30 @@ static void process_analog(struct context *ctx,
ctx->num_samples, analog->num_samples); ctx->num_samples, analog->num_samples);
meaning = analog->meaning; meaning = analog->meaning;
num_channels = g_slist_length(meaning->channels); num_rcvd_ch = g_slist_length(meaning->channels);
ctx->channels_seen += num_channels; ctx->channels_seen += num_rcvd_ch;
sr_dbg("Processing packet of %u analog channels", num_channels); sr_dbg("Processing packet of %zu analog channels", num_rcvd_ch);
fdata = g_malloc(analog->num_samples * num_channels * sizeof(float)); fdata = g_malloc(analog->num_samples * num_rcvd_ch * sizeof(float));
if ((ret = sr_analog_to_float(analog, fdata)) != SR_OK) if ((ret = sr_analog_to_float(analog, fdata)) != SR_OK)
sr_warn("Problems converting data to floating point values."); sr_warn("Problems converting data to floating point values.");
for (i = 0; i < ctx->num_analog_channels + ctx->num_logic_channels; i++) { num_have_ch = ctx->num_analog_channels + ctx->num_logic_channels;
if (ctx->channels[i].ch->type != SR_CHANNEL_ANALOG) for (idx_have = 0; idx_have < num_have_ch; idx_have++) {
if (ctx->channels[idx_have].ch->type != SR_CHANNEL_ANALOG)
continue; continue;
sr_dbg("Looking for channel %s", sr_dbg("Looking for channel %s",
ctx->channels[i].ch->name); ctx->channels[idx_have].ch->name);
for (l = meaning->channels, c = 0; l; l = l->next, c++) { for (l = meaning->channels, idx_rcvd = 0; l; l = l->next, idx_rcvd++) {
ch = l->data; ch = l->data;
sr_dbg("Checking %s", ch->name); sr_dbg("Checking %s", ch->name);
if (ctx->channels[i].ch != l->data) if (ctx->channels[idx_have].ch != ch)
continue; continue;
if (ctx->label_do && !ctx->label_names) { if (ctx->label_do && !ctx->label_names) {
sr_analog_unit_to_string(analog, sr_analog_unit_to_string(analog,
&ctx->channels[i].label); &ctx->channels[idx_have].label);
} }
for (j = 0; j < analog->num_samples; j++) for (idx_smpl = 0; idx_smpl < analog->num_samples; idx_smpl++)
ctx->analog_samples[j * ctx->num_analog_channels + i] = fdata[j * num_channels + c]; ctx->analog_samples[idx_smpl * ctx->num_analog_channels + idx_have] = fdata[idx_smpl * num_rcvd_ch + idx_rcvd];
break; break;
} }
} }