GSList *l;
uint64_t samplerate;
int i, b, num_probes;
- char *c;
- char sbuf[10], wbuf[1000];
+ char *c, *samplerate_s;
+ char wbuf[1000];
ctx = malloc(sizeof(struct context));
if (ctx == NULL)
samplerate = *((uint64_t *) o->device->plugin->get_device_info(
o->device->plugin_index, DI_CUR_SAMPLERATE));
- /* Samplerate string */
- if (samplerate >= GHZ(1))
- snprintf(sbuf, 10, "%"PRIu64" GHz", samplerate / 1000000000);
- else if (samplerate >= MHZ(1))
- snprintf(sbuf, 10, "%"PRIu64" MHz", samplerate / 1000000);
- else if (samplerate >= KHZ(1))
- snprintf(sbuf, 10, "%"PRIu64" KHz", samplerate / 1000);
- else
- snprintf(sbuf, 10, "%"PRIu64" Hz", samplerate);
+ if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL)
+ return -1; /* FIXME */
/* Wires / channels */
wbuf[0] = '\0';
for (i = 0; i < ctx->num_enabled_probes; i++) {
c = (char *)&wbuf + strlen((char *)&wbuf);
sprintf(c, "$var wire 1 %c channel%s $end\n",
- (char)('!' + i), ctx->probelist[i]);
+ (char)('!' + i), ctx->probelist[i]);
}
- /* TODO: date: File or signals? Make y/n configurable. */
+ /* TODO: Date: File or signals? Make y/n configurable. */
b = snprintf(ctx->header, MAX_HEADER_LEN, vcd_header, "TODO: Date",
PACKAGE_STRING, ctx->num_enabled_probes, num_probes,
- (char *)&sbuf, 1, "ns", PACKAGE, (char *)&wbuf);
+ samplerate_s, 1, "ns", PACKAGE, (char *)&wbuf);
/* TODO: Handle snprintf errors. */
+ free(samplerate_s);
+
ctx->prevbits = calloc(sizeof(int), num_probes);
if (ctx->prevbits == NULL)
return SIGROK_ERR_MALLOC;
int outlen;
ctx = o->internal;
- switch(event_type) {
+ switch (event_type) {
case DF_TRIGGER:
break;
case DF_END:
char **data_out, uint64_t *length_out)
{
struct context *ctx;
- int offset, outsize, p, curbit, prevbit;
+ unsigned int offset, outsize;
+ int p, curbit, prevbit;
uint64_t sample, prevsample;
char *outbuf, *c;
ctx = o->internal;
outsize = strlen(ctx->header);
- outbuf = calloc(1, outsize + 1 + 10000); // FIXME: Use realloc().
+ outbuf = calloc(1, outsize + 1 + 10000); /* FIXME: Use realloc(). */
if (outbuf == NULL)
return SIGROK_ERR_MALLOC;
if (ctx->header) {
/* TODO: Are disabled probes handled correctly? */
for (offset = 0; offset <= length_in - ctx->unitsize;
- offset += ctx->unitsize) {
+ offset += ctx->unitsize) {
memcpy(&sample, data_in + offset, ctx->unitsize);
for (p = 0; p < ctx->num_enabled_probes; p++) {
curbit = (sample & ((uint64_t) (1 << p))) != 0;
if (offset == 0) {
prevbit = ~curbit;
} else {
- memcpy(&prevsample, data_in + offset - 1, ctx->unitsize);
- prevbit = (prevsample & ((uint64_t) (1 << p))) != 0;
+ memcpy(&prevsample, data_in + offset - 1,
+ ctx->unitsize);
+ prevbit =
+ (prevsample & ((uint64_t) (1 << p))) != 0;
}
if (prevbit != curbit) {
sprintf(c, "#%i\n", offset * 1 /* TODO */);
c = outbuf + strlen(outbuf);
- sprintf(c, "%i%c\n", curbit, (char)('!' + p /* FIXME? */));
+ sprintf(c, "%i%c\n", curbit,
+ (char)('!' + p /* FIXME? */));
}
}
- /* TODO: Do a realloc() here if strlen(outbuf) is almost "full"... */
+ /* TODO: Use realloc() if strlen(outbuf) is almost "full"... */
}
*data_out = outbuf;