(receive): Use probe index for sample byte selection too, not just
for bit selection. Also simplify the indexing expressions a bit.
This fixes the problem of incorrect output for probes indices 8 to
31.
Also, use double rather than float in the timestamp calculation,
and format the result directly as floating point number rather than
converting it back to uint64_t.
Additionally, make sure that the state of all signals is written
for the very first sample in the stream. This fixes the problem
that signals would be displayed as indeterminate until the first
change.
(context.samplecount): Make the sample counter part of the context
struct, rather than keeping it as a global static.
uint8_t *prevsample;
int period;
uint64_t samplerate;
uint8_t *prevsample;
int period;
uint64_t samplerate;
unsigned int unitsize;
};
unsigned int unitsize;
};
unsigned int i;
int p, curbit, prevbit, index;
uint8_t *sample;
unsigned int i;
int p, curbit, prevbit, index;
uint8_t *sample;
- static uint64_t samplecount = 0;
/* The header is still here, this must be the first packet. */
*out = ctx->header;
ctx->header = NULL;
/* The header is still here, this must be the first packet. */
*out = ctx->header;
ctx->header = NULL;
} else {
*out = g_string_sized_new(512);
}
logic = packet->payload;
for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
} else {
*out = g_string_sized_new(512);
}
logic = packet->payload;
for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
sample = logic->data + i;
for (p = 0; p < ctx->num_enabled_probes; p++) {
index = g_array_index(ctx->probeindices, int, p);
sample = logic->data + i;
for (p = 0; p < ctx->num_enabled_probes; p++) {
index = g_array_index(ctx->probeindices, int, p);
- curbit = (sample[p / 8] & (((uint8_t) 1) << index)) >> index;
- prevbit = (ctx->prevsample[p / 8] & (((uint8_t) 1) << index)) >> index;
+ curbit = ((unsigned)sample[index / 8] >> (index % 8)) & 1;
+ prevbit = ((unsigned)ctx->prevsample[index / 8] >> (index % 8)) & 1;
/* VCD only contains deltas/changes of signals. */
/* VCD only contains deltas/changes of signals. */
+ if (prevbit == curbit && ctx->samplecount > 0)
continue;
/* Output which signal changed to which value. */
continue;
/* Output which signal changed to which value. */
- g_string_append_printf(*out, "#%" PRIu64 "\n%i%c\n",
- (uint64_t)(((float)samplecount / ctx->samplerate)
- * ctx->period), curbit, (char)('!' + p));
+ g_string_append_printf(*out, "#%.0f\n%i%c\n",
+ (double)ctx->samplecount / ctx->samplerate * ctx->period,
+ curbit, (char)('!' + p));
memcpy(ctx->prevsample, sample, ctx->unitsize);
}
memcpy(ctx->prevsample, sample, ctx->unitsize);
}