On Sun, Sep 25, 2016 at 3:46 PM Mike Meyer <[email protected]> wrote:
> On Sat, Sep 24, 2016 at 5:03 AM Uwe Hermann <[email protected]> wrote:
>
>> Btw, I'm seeing a segfault when doing this (not sure if related to this
>> specific patch or not):
>>
>> sigrok-cli -d demo --samples 2 -O csv
>>
>> Can you reproduce that, and if yes, any idea why it happens?
>>
>
> Yes, I can reproduce it. Very odd - works fine for 1 and 3 samples, but
> breaks for 2.
>
> This is almost certainly a bug in the way I'm storing values for later
> display. I can comment out that one line, and it goes away. I'm having
> trouble finding time to look into it, though. I hope to get to it today or
> tomorrow.
>
Ok, here's a fix. It was a bit more complicated than expected, but is now
done.
On the subject of tabs - that's not normally something I pay attention to,
using the emacs config that the project recommends. I noticed that patch
had some differences, and tried to fix some of them. This code is sort of a
mismash, as it has indentation from multiple sources, but I tried to fix
them all as well. Do you have a recommended emacs config? If not, let me
know if this one is wrong, as it means the config I'm using is still wrong.
diff --git a/src/output/csv.c b/src/output/csv.c
index a6e835a..32188a1 100644
--- a/src/output/csv.c
+++ b/src/output/csv.c
@@ -309,21 +309,11 @@ static void process_analog(struct context *ctx,
const struct sr_datafeed_analog *analog)
{
int ret;
- unsigned int i, j, c, num_channels;
+ unsigned int i, j, c, ch, num_channels;
struct sr_analog_meaning *meaning;
GSList *l;
float *fdata = NULL;
- if (!ctx->analog_samples) {
- ctx->analog_samples = g_malloc(analog->num_samples
- * sizeof(float) * ctx->num_analog_channels);
- if (!ctx->num_samples)
- ctx->num_samples = analog->num_samples;
- }
- if (ctx->num_samples != analog->num_samples)
- sr_warn("Expecting %u analog samples, got %u.",
- ctx->num_samples, analog->num_samples);
-
meaning = analog->meaning;
num_channels = g_slist_length(meaning->channels);
ctx->channels_seen += num_channels;
@@ -332,23 +322,35 @@ static void process_analog(struct context *ctx,
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) {
- sr_dbg("Looking for channel %s",
- ctx->channels[i].ch->name);
+ if (!ctx->analog_samples) {
+ ctx->analog_samples = g_malloc(sizeof(float) * analog->num_samples
+ * ctx->num_analog_channels);
+ if (!ctx->num_samples)
+ ctx->num_samples = analog->num_samples;
+ }
+ if (ctx->num_samples != analog->num_samples)
+ sr_warn("Expecting %u analog samples, got %u.",
+ ctx->num_samples, analog->num_samples);
+
+ for (j = ch = 0; ch < ctx->num_analog_channels; j++) {
+ if (ctx->channels[j].ch->type == SR_CHANNEL_ANALOG) {
+ sr_dbg("Looking for channel %s",
+ ctx->channels[j].ch->name);
for (l = meaning->channels, c = 0; l; l = l->next, c++) {
- struct sr_channel *ch = l->data;
- sr_dbg("Checking %s", ch->name);
- if (ctx->channels[i].ch == l->data) {
+ sr_dbg("Checking %s",
+ ((struct sr_channel *) l->data)->name);
+ if (ctx->channels[j].ch == l->data) {
if (ctx->label_do && !ctx->label_names) {
- sr_analog_unit_to_string(analog,
- &ctx->channels[i].label);
+ sr_analog_unit_to_string(
+ analog,
+ &ctx->channels[j].label);
}
- for (j = 0; j < analog->num_samples; j++)
- ctx->analog_samples[j * ctx->num_analog_channels + i] = fdata[j * num_channels + c];
+ for (i = 0; i < analog->num_samples; i++)
+ ctx->analog_samples[i * ctx->num_analog_channels + ch] = fdata[i * num_channels + c];
break;
}
}
+ ch++;
}
}
g_free(fdata);
@@ -393,7 +395,7 @@ static void process_logic(struct context *ctx,
static void dump_saved_values(struct context *ctx, GString **out)
{
- unsigned int i, j, analog_size, num_channels;
+ unsigned int i, ch, analog_size, num_channels;
float *analog_sample, value;
uint8_t *logic_sample;
@@ -436,12 +438,12 @@ static void dump_saved_values(struct context *ctx, GString **out)
for (i = 0; i < ctx->num_samples; i++) {
ctx->sample_time += ctx->period;
- analog_sample =
- &ctx->analog_samples[i * ctx->num_analog_channels];
- logic_sample =
- &ctx->logic_samples[i * ctx->num_logic_channels];
-
if (ctx->dedup) {
+ analog_sample = &ctx->analog_samples[
+ i * ctx->num_analog_channels];
+ logic_sample = &ctx->logic_samples[
+ i * ctx->num_logic_channels];
+
if (i > 0 && i < ctx->num_samples - 1 &&
!memcmp(logic_sample, ctx->previous_sample,
ctx->num_logic_channels) &&
@@ -461,21 +463,21 @@ static void dump_saved_values(struct context *ctx, GString **out)
g_string_append_printf(*out, "%lu%s",
ctx->sample_time, ctx->value);
- for (j = 0; j < num_channels; j++) {
- if (ctx->channels[j].ch->type == SR_CHANNEL_ANALOG) {
- value = ctx->analog_samples[i * ctx->num_analog_channels + j];
- ctx->channels[j].max =
- fmax(value, ctx->channels[j].max);
- ctx->channels[j].min =
- fmin(value, ctx->channels[j].min);
+ for (ch = 0; ch < num_channels; ch++) {
+ if (ctx->channels[ch].ch->type == SR_CHANNEL_ANALOG) {
+ value = ctx->analog_samples[i * ctx->num_analog_channels + ch];
+ ctx->channels[ch].max =
+ fmax(value, ctx->channels[ch].max);
+ ctx->channels[ch].min =
+ fmin(value, ctx->channels[ch].min);
g_string_append_printf(*out, "%g%s",
value, ctx->value);
- } else if (ctx->channels[j].ch->type == SR_CHANNEL_LOGIC) {
+ } else if (ctx->channels[ch].ch->type == SR_CHANNEL_LOGIC) {
g_string_append_printf(*out, "%c%s",
- ctx->logic_samples[i * ctx->num_logic_channels + j] ? '1' : '0', ctx->value);
+ ctx->logic_samples[i * ctx->num_logic_channels + ch] ? '1' : '0', ctx->value);
} else {
sr_warn("Unexpected channel type: %d",
- ctx->channels[i].ch->type);
+ ctx->channels[ch].ch->type);
}
}
------------------------------------------------------------------------------
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel