output: if device has no plugin, don't report samplerate

This commit is contained in:
Bert Vermeulen 2010-05-05 19:56:48 -07:00
parent db91a1c3c1
commit 7aae74622e
3 changed files with 55 additions and 34 deletions

View File

@ -34,11 +34,14 @@ struct context {
const char *gnuplot_header = "\ const char *gnuplot_header = "\
# Sample data in space-separated columns format usable by gnuplot\n\ # Sample data in space-separated columns format usable by gnuplot\n\
#\n\ #\n\
# Generated by: %s on %s\n\ # Generated by: %s on %s\n%s\
# Comment: Acquisition with %d/%d probes at %s\n\
# Timescale: %d %s\n\ # Timescale: %d %s\n\
# Column assignment:\n%s\n"; # Column assignment:\n%s\n";
const char *gnuplot_header_comment = "\
# Comment: Acquisition with %d/%d probes at %s\n";
static int init(struct output *o) static int init(struct output *o)
{ {
/* Maximum header length */ /* Maximum header length */
@ -51,7 +54,7 @@ static int init(struct output *o)
unsigned int i; unsigned int i;
int b, num_probes; int b, num_probes;
char *c, *samplerate_s; char *c, *samplerate_s;
char wbuf[1000]; char wbuf[1000], comment[128];
ctx = malloc(sizeof(struct context)); ctx = malloc(sizeof(struct context));
if (ctx == NULL) if (ctx == NULL)
@ -74,11 +77,17 @@ static int init(struct output *o)
return SIGROK_ERR_MALLOC; return SIGROK_ERR_MALLOC;
num_probes = g_slist_length(o->device->probes); num_probes = g_slist_length(o->device->probes);
/* TODO: Handle num_probes == 0, too many probes, etc. */ /* TODO: Handle num_probes == 0, too many probes, etc. */
if (o->device->plugin) {
samplerate = *((uint64_t *) o->device->plugin->get_device_info( samplerate = *((uint64_t *) o->device->plugin->get_device_info(
o->device->plugin_index, DI_CUR_SAMPLERATE)); o->device->plugin_index, DI_CUR_SAMPLERATE));
if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL) if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL)
return -1; /* FIXME */ return SIGROK_ERR;
snprintf(comment, 127, gnuplot_header_comment, ctx->num_enabled_probes,
num_probes, samplerate_s);
free(samplerate_s);
}
else
comment[0] = '\0';
/* Columns / channels */ /* Columns / channels */
wbuf[0] = '\0'; wbuf[0] = '\0';
@ -90,10 +99,7 @@ static int init(struct output *o)
/* TODO: date: File or signals? Make y/n configurable. */ /* TODO: date: File or signals? Make y/n configurable. */
/* TODO: Timescale */ /* TODO: Timescale */
b = snprintf(ctx->header, MAX_HEADER_LEN, gnuplot_header, b = snprintf(ctx->header, MAX_HEADER_LEN, gnuplot_header,
PACKAGE_STRING, "TODO", ctx->num_enabled_probes, PACKAGE_STRING, "TODO", comment, 1, "ns", (char *)&wbuf);
num_probes, samplerate_s, 1, "ns", (char *)&wbuf);
free(samplerate_s);
/* TODO: Handle snprintf errors. */ /* TODO: Handle snprintf errors. */

View File

@ -100,6 +100,7 @@ static int init(struct output *o, int default_spl)
else else
ctx->samples_per_line = default_spl; ctx->samples_per_line = default_spl;
if (o->device->plugin) {
ctx->header = malloc(512); ctx->header = malloc(512);
num_probes = g_slist_length(o->device->probes); num_probes = g_slist_length(o->device->probes);
samplerate = *((uint64_t *) o->device->plugin->get_device_info( samplerate = *((uint64_t *) o->device->plugin->get_device_info(
@ -111,6 +112,13 @@ static int init(struct output *o, int default_spl)
return -1; /* FIXME */ return -1; /* FIXME */
snprintf(ctx->header + strlen(ctx->header), 512, "%s\n", samplerate_s); snprintf(ctx->header + strlen(ctx->header), 512, "%s\n", samplerate_s);
free(samplerate_s); free(samplerate_s);
} else {
/*
* device has no plugin: this is just a dummy device, the data
* comes from a file.
*/
ctx->header = NULL;
}
ctx->linebuf_len = ctx->samples_per_line * 2; ctx->linebuf_len = ctx->samples_per_line * 2;
ctx->linebuf = calloc(1, num_probes * ctx->linebuf_len); ctx->linebuf = calloc(1, num_probes * ctx->linebuf_len);

View File

@ -34,8 +34,7 @@ struct context {
const char *vcd_header = "\ const char *vcd_header = "\
$date\n %s\n$end\n\ $date\n %s\n$end\n\
$version\n %s\n$end\n\ $version\n %s\n$end\n%s\
$comment\n Acquisition with %d/%d probes at %s\n$end\n\
$timescale\n %i %s\n$end\n\ $timescale\n %i %s\n$end\n\
$scope module %s $end\n\ $scope module %s $end\n\
%s\ %s\
@ -43,6 +42,10 @@ $upscope $end\n\
$enddefinitions $end\n\ $enddefinitions $end\n\
$dumpvars\n"; $dumpvars\n";
const char *vcd_header_comment = "\
$comment\n Acquisition with %d/%d probes at %s\n$end\n";
static int init(struct output *o) static int init(struct output *o)
{ {
/* Maximum header length */ /* Maximum header length */
@ -54,7 +57,7 @@ static int init(struct output *o)
uint64_t samplerate; uint64_t samplerate;
int i, b, num_probes; int i, b, num_probes;
char *c, *samplerate_s; char *c, *samplerate_s;
char wbuf[1000]; char wbuf[1000], comment[128];
ctx = malloc(sizeof(struct context)); ctx = malloc(sizeof(struct context));
if (ctx == NULL) if (ctx == NULL)
@ -76,12 +79,19 @@ static int init(struct output *o)
if (ctx->header == NULL) if (ctx->header == NULL)
return SIGROK_ERR_MALLOC; return SIGROK_ERR_MALLOC;
num_probes = g_slist_length(o->device->probes); num_probes = g_slist_length(o->device->probes);
if (o->device->plugin) {
/* TODO: Handle num_probes == 0, too many probes, etc. */ /* TODO: Handle num_probes == 0, too many probes, etc. */
samplerate = *((uint64_t *) o->device->plugin->get_device_info( samplerate = *((uint64_t *) o->device->plugin->get_device_info(
o->device->plugin_index, DI_CUR_SAMPLERATE)); o->device->plugin_index, DI_CUR_SAMPLERATE));
if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL) if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL)
return -1; /* FIXME */ return SIGROK_ERR;
snprintf(comment, 127, vcd_header_comment, ctx->num_enabled_probes,
num_probes, samplerate_s);
free(samplerate_s);
}
else
comment[0] = '\0';
/* Wires / channels */ /* Wires / channels */
wbuf[0] = '\0'; wbuf[0] = '\0';
@ -93,12 +103,9 @@ static int init(struct output *o)
/* 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", b = snprintf(ctx->header, MAX_HEADER_LEN, vcd_header, "TODO: Date",
PACKAGE_STRING, ctx->num_enabled_probes, num_probes, PACKAGE_STRING, comment, 1, "ns", PACKAGE, (char *)&wbuf);
samplerate_s, 1, "ns", PACKAGE, (char *)&wbuf);
/* TODO: Handle snprintf errors. */ /* TODO: Handle snprintf errors. */
free(samplerate_s);
ctx->prevbits = calloc(sizeof(int), num_probes); ctx->prevbits = calloc(sizeof(int), num_probes);
if (ctx->prevbits == NULL) if (ctx->prevbits == NULL)
return SIGROK_ERR_MALLOC; return SIGROK_ERR_MALLOC;