sr: change input/output modules to use struct sr_dev_inst *
This commit is contained in:
parent
6f4b1868e8
commit
5c3c1241d2
|
@ -44,6 +44,7 @@ static int format_match(const char *filename)
|
||||||
|
|
||||||
static int init(struct sr_input *in)
|
static int init(struct sr_input *in)
|
||||||
{
|
{
|
||||||
|
struct sr_probe *probe;
|
||||||
int num_probes, i;
|
int num_probes, i;
|
||||||
char name[SR_MAX_PROBENAME_LEN + 1];
|
char name[SR_MAX_PROBENAME_LEN + 1];
|
||||||
char *param;
|
char *param;
|
||||||
|
@ -73,13 +74,15 @@ static int init(struct sr_input *in)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a virtual device. */
|
/* Create a virtual device. */
|
||||||
in->vdev = sr_dev_new(NULL, 0);
|
in->sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, NULL, NULL, NULL);
|
||||||
in->internal = ctx;
|
in->internal = ctx;
|
||||||
|
|
||||||
for (i = 0; i < num_probes; i++) {
|
for (i = 0; i < num_probes; i++) {
|
||||||
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
|
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
|
||||||
/* TODO: Check return value. */
|
/* TODO: Check return value. */
|
||||||
sr_dev_probe_add(in->vdev, name);
|
if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, name)))
|
||||||
|
return SR_ERR;
|
||||||
|
in->sdi->probes = g_slist_append(in->sdi->probes, probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -100,21 +103,21 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||||
if ((fd = open(filename, O_RDONLY)) == -1)
|
if ((fd = open(filename, O_RDONLY)) == -1)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
num_probes = g_slist_length(in->vdev->probes);
|
num_probes = g_slist_length(in->sdi->probes);
|
||||||
|
|
||||||
/* send header */
|
/* send header */
|
||||||
header.feed_version = 1;
|
header.feed_version = 1;
|
||||||
gettimeofday(&header.starttime, NULL);
|
gettimeofday(&header.starttime, NULL);
|
||||||
packet.type = SR_DF_HEADER;
|
packet.type = SR_DF_HEADER;
|
||||||
packet.payload = &header;
|
packet.payload = &header;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
|
|
||||||
/* Send metadata about the SR_DF_LOGIC packets to come. */
|
/* Send metadata about the SR_DF_LOGIC packets to come. */
|
||||||
packet.type = SR_DF_META_LOGIC;
|
packet.type = SR_DF_META_LOGIC;
|
||||||
packet.payload = &meta;
|
packet.payload = &meta;
|
||||||
meta.samplerate = ctx->samplerate;
|
meta.samplerate = ctx->samplerate;
|
||||||
meta.num_probes = num_probes;
|
meta.num_probes = num_probes;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
|
|
||||||
/* chop up the input file into chunks and feed it into the session bus */
|
/* chop up the input file into chunks and feed it into the session bus */
|
||||||
packet.type = SR_DF_LOGIC;
|
packet.type = SR_DF_LOGIC;
|
||||||
|
@ -123,13 +126,13 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||||
logic.data = buffer;
|
logic.data = buffer;
|
||||||
while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
|
while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
|
||||||
logic.length = size;
|
logic.length = size;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
/* end of stream */
|
/* end of stream */
|
||||||
packet.type = SR_DF_END;
|
packet.type = SR_DF_END;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
|
|
||||||
g_free(ctx);
|
g_free(ctx);
|
||||||
in->internal = NULL;
|
in->internal = NULL;
|
||||||
|
|
|
@ -94,6 +94,7 @@ static int format_match(const char *filename)
|
||||||
|
|
||||||
static int init(struct sr_input *in)
|
static int init(struct sr_input *in)
|
||||||
{
|
{
|
||||||
|
struct sr_probe *probe;
|
||||||
int num_probes, i;
|
int num_probes, i;
|
||||||
char name[SR_MAX_PROBENAME_LEN + 1];
|
char name[SR_MAX_PROBENAME_LEN + 1];
|
||||||
char *param;
|
char *param;
|
||||||
|
@ -112,12 +113,14 @@ static int init(struct sr_input *in)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a virtual device. */
|
/* Create a virtual device. */
|
||||||
in->vdev = sr_dev_new(NULL, 0);
|
in->sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, NULL, NULL, NULL);
|
||||||
|
|
||||||
for (i = 0; i < num_probes; i++) {
|
for (i = 0; i < num_probes; i++) {
|
||||||
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
|
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
|
||||||
/* TODO: Check return value. */
|
/* TODO: Check return value. */
|
||||||
sr_dev_probe_add(in->vdev, name);
|
if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, name)))
|
||||||
|
return SR_ERR;
|
||||||
|
in->sdi->probes = g_slist_append(in->sdi->probes, probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -139,7 +142,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
num_probes = g_slist_length(in->vdev->probes);
|
num_probes = g_slist_length(in->sdi->probes);
|
||||||
|
|
||||||
/* Seek to the end of the file, and read the divcount byte. */
|
/* Seek to the end of the file, and read the divcount byte. */
|
||||||
divcount = 0x00; /* TODO: Don't hardcode! */
|
divcount = 0x00; /* TODO: Don't hardcode! */
|
||||||
|
@ -158,14 +161,14 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||||
packet.payload = &header;
|
packet.payload = &header;
|
||||||
header.feed_version = 1;
|
header.feed_version = 1;
|
||||||
gettimeofday(&header.starttime, NULL);
|
gettimeofday(&header.starttime, NULL);
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
|
|
||||||
/* Send metadata about the SR_DF_LOGIC packets to come. */
|
/* Send metadata about the SR_DF_LOGIC packets to come. */
|
||||||
packet.type = SR_DF_META_LOGIC;
|
packet.type = SR_DF_META_LOGIC;
|
||||||
packet.payload = &meta;
|
packet.payload = &meta;
|
||||||
meta.samplerate = samplerate;
|
meta.samplerate = samplerate;
|
||||||
meta.num_probes = num_probes;
|
meta.num_probes = num_probes;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
|
|
||||||
/* TODO: Handle trigger point. */
|
/* TODO: Handle trigger point. */
|
||||||
|
|
||||||
|
@ -181,7 +184,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||||
/* TODO: Handle errors, handle incomplete reads. */
|
/* TODO: Handle errors, handle incomplete reads. */
|
||||||
size = read(fd, buf, PACKET_SIZE);
|
size = read(fd, buf, PACKET_SIZE);
|
||||||
logic.length = size;
|
logic.length = size;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
}
|
}
|
||||||
close(fd); /* FIXME */
|
close(fd); /* FIXME */
|
||||||
|
|
||||||
|
@ -189,7 +192,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||||
sr_dbg("la8 in: %s: sending SR_DF_END", __func__);
|
sr_dbg("la8 in: %s: sending SR_DF_END", __func__);
|
||||||
packet.type = SR_DF_END;
|
packet.type = SR_DF_END;
|
||||||
packet.payload = NULL;
|
packet.payload = NULL;
|
||||||
sr_session_send(in->vdev, &packet);
|
sr_session_send(in->sdi, &packet);
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ struct sr_datafeed_analog {
|
||||||
struct sr_input {
|
struct sr_input {
|
||||||
struct sr_input_format *format;
|
struct sr_input_format *format;
|
||||||
GHashTable *param;
|
GHashTable *param;
|
||||||
struct sr_dev *vdev;
|
struct sr_dev_inst *sdi;
|
||||||
void *internal;
|
void *internal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ struct sr_input_format {
|
||||||
|
|
||||||
struct sr_output {
|
struct sr_output {
|
||||||
struct sr_output_format *format;
|
struct sr_output_format *format;
|
||||||
struct sr_dev *dev;
|
struct sr_dev_inst *sdi;
|
||||||
char *param;
|
char *param;
|
||||||
void *internal;
|
void *internal;
|
||||||
};
|
};
|
||||||
|
|
|
@ -86,20 +86,20 @@ static int init(struct sr_output *o)
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
uint64_t samplerate;
|
uint64_t *samplerate;
|
||||||
|
|
||||||
if (!o) {
|
if (!o) {
|
||||||
sr_warn("la8 out: %s: o was NULL", __func__);
|
sr_warn("la8 out: %s: o was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!o->dev) {
|
if (!o->sdi) {
|
||||||
sr_warn("la8 out: %s: o->dev was NULL", __func__);
|
sr_warn("la8 out: %s: o->sdi was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!o->dev->driver) {
|
if (!o->sdi->driver) {
|
||||||
sr_warn("la8 out: %s: o->dev->driver was NULL", __func__);
|
sr_warn("la8 out: %s: o->sdi->driver was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +111,7 @@ static int init(struct sr_output *o)
|
||||||
o->internal = ctx;
|
o->internal = ctx;
|
||||||
|
|
||||||
/* Get the probe names and the unitsize. */
|
/* Get the probe names and the unitsize. */
|
||||||
/* TODO: Error handling. */
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
|
||||||
probe = l->data;
|
probe = l->data;
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
@ -121,16 +120,14 @@ static int init(struct sr_output *o)
|
||||||
ctx->probelist[ctx->num_enabled_probes] = 0;
|
ctx->probelist[ctx->num_enabled_probes] = 0;
|
||||||
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
||||||
|
|
||||||
if (sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
|
if (sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
|
||||||
samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
|
o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
|
||||||
o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
|
(const void **)&samplerate, o->sdi);
|
||||||
/* TODO: Error checks. */
|
ctx->samplerate = *samplerate;
|
||||||
} else {
|
} else
|
||||||
samplerate = 0; /* TODO: Error or set some value? */
|
ctx->samplerate = 0;
|
||||||
}
|
|
||||||
ctx->samplerate = samplerate;
|
|
||||||
|
|
||||||
return 0; /* TODO: SR_OK? */
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
static int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
||||||
|
|
32
output/csv.c
32
output/csv.c
|
@ -52,7 +52,7 @@ static int init(struct sr_output *o)
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
int num_probes;
|
int num_probes;
|
||||||
uint64_t samplerate;
|
uint64_t *samplerate;
|
||||||
time_t t;
|
time_t t;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ static int init(struct sr_output *o)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!o->dev) {
|
if (!o->sdi) {
|
||||||
sr_err("csv out: %s: o->dev was NULL", __func__);
|
sr_err("csv out: %s: o->sdi was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!o->dev->driver) {
|
if (!o->sdi->driver) {
|
||||||
sr_err("csv out: %s: o->dev->driver was NULL", __func__);
|
sr_err("csv out: %s: o->sdi->driver was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,8 +79,7 @@ static int init(struct sr_output *o)
|
||||||
o->internal = ctx;
|
o->internal = ctx;
|
||||||
|
|
||||||
/* Get the number of probes, their names, and the unitsize. */
|
/* Get the number of probes, their names, and the unitsize. */
|
||||||
/* TODO: Error handling. */
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
|
||||||
probe = l->data;
|
probe = l->data;
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
@ -89,19 +88,16 @@ static int init(struct sr_output *o)
|
||||||
ctx->probelist[ctx->num_enabled_probes] = 0;
|
ctx->probelist[ctx->num_enabled_probes] = 0;
|
||||||
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
||||||
|
|
||||||
num_probes = g_slist_length(o->dev->probes);
|
num_probes = g_slist_length(o->sdi->probes);
|
||||||
|
|
||||||
if (sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
|
if (sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
|
||||||
samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
|
o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
|
||||||
o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
|
(const void **)&samplerate, o->sdi);
|
||||||
/* TODO: Error checks. */
|
ctx->samplerate = *samplerate;
|
||||||
} else {
|
} else
|
||||||
samplerate = 0; /* TODO: Error or set some value? */
|
ctx->samplerate = 0;
|
||||||
}
|
|
||||||
ctx->samplerate = samplerate;
|
|
||||||
|
|
||||||
ctx->separator = ',';
|
ctx->separator = ',';
|
||||||
|
|
||||||
ctx->header = g_string_sized_new(512);
|
ctx->header = g_string_sized_new(512);
|
||||||
|
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
|
@ -119,7 +115,7 @@ static int init(struct sr_output *o)
|
||||||
g_string_append_printf(ctx->header, "%s, ", ctx->probelist[i]);
|
g_string_append_printf(ctx->header, "%s, ", ctx->probelist[i]);
|
||||||
g_string_append_printf(ctx->header, "\n");
|
g_string_append_printf(ctx->header, "\n");
|
||||||
|
|
||||||
return 0; /* TODO: SR_OK? */
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
static int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
||||||
|
|
|
@ -38,10 +38,10 @@ static int init(struct sr_output *o)
|
||||||
if (!o)
|
if (!o)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
|
||||||
if (!o->dev)
|
if (!o->sdi)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
|
||||||
if (!o->dev->driver)
|
if (!o->sdi->driver)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
|
||||||
if (!(ctx = g_try_malloc0(sizeof(struct context))))
|
if (!(ctx = g_try_malloc0(sizeof(struct context))))
|
||||||
|
@ -51,7 +51,7 @@ static int init(struct sr_output *o)
|
||||||
|
|
||||||
/* Get the number of probes and their names. */
|
/* Get the number of probes and their names. */
|
||||||
ctx->probelist = g_ptr_array_new();
|
ctx->probelist = g_ptr_array_new();
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
probe = l->data;
|
probe = l->data;
|
||||||
if (!probe || !probe->enabled)
|
if (!probe || !probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -54,7 +54,7 @@ static int init(struct sr_output *o)
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
uint64_t samplerate;
|
uint64_t *samplerate;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int b, num_probes;
|
int b, num_probes;
|
||||||
char *c, *frequency_s;
|
char *c, *frequency_s;
|
||||||
|
@ -66,13 +66,13 @@ static int init(struct sr_output *o)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!o->dev) {
|
if (!o->sdi) {
|
||||||
sr_err("gnuplot out: %s: o->dev was NULL", __func__);
|
sr_err("gnuplot out: %s: o->sdi was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!o->dev->driver) {
|
if (!o->sdi->driver) {
|
||||||
sr_err("gnuplot out: %s: o->dev->driver was NULL", __func__);
|
sr_err("gnuplot out: %s: o->sdi->driver was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ static int init(struct sr_output *o)
|
||||||
|
|
||||||
o->internal = ctx;
|
o->internal = ctx;
|
||||||
ctx->num_enabled_probes = 0;
|
ctx->num_enabled_probes = 0;
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
probe = l->data; /* TODO: Error checks. */
|
probe = l->data; /* TODO: Error checks. */
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
@ -98,12 +98,12 @@ static int init(struct sr_output *o)
|
||||||
ctx->probelist[ctx->num_enabled_probes] = 0;
|
ctx->probelist[ctx->num_enabled_probes] = 0;
|
||||||
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
||||||
|
|
||||||
num_probes = g_slist_length(o->dev->probes);
|
num_probes = g_slist_length(o->sdi->probes);
|
||||||
comment[0] = '\0';
|
comment[0] = '\0';
|
||||||
if (sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
|
if (sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
|
||||||
samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
|
o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
|
||||||
o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
|
(const void **)&samplerate, o->sdi);
|
||||||
if (!(frequency_s = sr_samplerate_string(samplerate))) {
|
if (!(frequency_s = sr_samplerate_string(*samplerate))) {
|
||||||
sr_err("gnuplot out: %s: sr_samplerate_string failed",
|
sr_err("gnuplot out: %s: sr_samplerate_string failed",
|
||||||
__func__);
|
__func__);
|
||||||
g_free(ctx->header);
|
g_free(ctx->header);
|
||||||
|
@ -122,7 +122,7 @@ static int init(struct sr_output *o)
|
||||||
sprintf(c, "# %d\t\t%s\n", i + 1, ctx->probelist[i]);
|
sprintf(c, "# %d\t\t%s\n", i + 1, ctx->probelist[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(frequency_s = sr_period_string(samplerate))) {
|
if (!(frequency_s = sr_period_string(*samplerate))) {
|
||||||
sr_err("gnuplot out: %s: sr_period_string failed", __func__);
|
sr_err("gnuplot out: %s: sr_period_string failed", __func__);
|
||||||
g_free(ctx->header);
|
g_free(ctx->header);
|
||||||
g_free(ctx);
|
g_free(ctx);
|
||||||
|
|
18
output/ols.c
18
output/ols.c
|
@ -42,7 +42,7 @@ static int init(struct sr_output *o)
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
uint64_t samplerate;
|
uint64_t *samplerate, tmp;
|
||||||
int num_enabled_probes;
|
int num_enabled_probes;
|
||||||
|
|
||||||
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
||||||
|
@ -53,21 +53,23 @@ static int init(struct sr_output *o)
|
||||||
|
|
||||||
ctx->num_samples = 0;
|
ctx->num_samples = 0;
|
||||||
num_enabled_probes = 0;
|
num_enabled_probes = 0;
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
probe = l->data;
|
probe = l->data;
|
||||||
if (probe->enabled)
|
if (probe->enabled)
|
||||||
num_enabled_probes++;
|
num_enabled_probes++;
|
||||||
}
|
}
|
||||||
ctx->unitsize = (num_enabled_probes + 7) / 8;
|
ctx->unitsize = (num_enabled_probes + 7) / 8;
|
||||||
|
|
||||||
if (o->dev->driver && sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE))
|
if (o->sdi->driver && sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE))
|
||||||
samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
|
o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
|
||||||
o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
|
(const void **)&samplerate, o->sdi);
|
||||||
else
|
else {
|
||||||
samplerate = 0;
|
tmp = 0;
|
||||||
|
samplerate = &tmp;
|
||||||
|
}
|
||||||
|
|
||||||
ctx->header = g_string_sized_new(512);
|
ctx->header = g_string_sized_new(512);
|
||||||
g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", samplerate);
|
g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", *samplerate);
|
||||||
g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes);
|
g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes);
|
||||||
g_string_append_printf(ctx->header, ";EnabledChannels: -1\n");
|
g_string_append_printf(ctx->header, ";EnabledChannels: -1\n");
|
||||||
g_string_append_printf(ctx->header, ";Compressed: true\n");
|
g_string_append_printf(ctx->header, ";Compressed: true\n");
|
||||||
|
|
|
@ -70,8 +70,8 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
uint64_t samplerate;
|
uint64_t *samplerate;
|
||||||
int num_probes;
|
int num_probes, ret;
|
||||||
char *samplerate_s;
|
char *samplerate_s;
|
||||||
|
|
||||||
if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
|
if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
|
||||||
|
@ -82,7 +82,7 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
|
||||||
o->internal = ctx;
|
o->internal = ctx;
|
||||||
ctx->num_enabled_probes = 0;
|
ctx->num_enabled_probes = 0;
|
||||||
|
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
probe = l->data;
|
probe = l->data;
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
@ -98,26 +98,29 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
|
||||||
|
|
||||||
if (o->param && o->param[0]) {
|
if (o->param && o->param[0]) {
|
||||||
ctx->samples_per_line = strtoul(o->param, NULL, 10);
|
ctx->samples_per_line = strtoul(o->param, NULL, 10);
|
||||||
if (ctx->samples_per_line < 1)
|
if (ctx->samples_per_line < 1) {
|
||||||
return SR_ERR;
|
ret = SR_ERR;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
ctx->samples_per_line = default_spl;
|
ctx->samples_per_line = default_spl;
|
||||||
|
|
||||||
if (!(ctx->header = g_try_malloc0(512))) {
|
if (!(ctx->header = g_try_malloc0(512))) {
|
||||||
g_free(ctx);
|
|
||||||
sr_err("text out: %s: ctx->header malloc failed", __func__);
|
sr_err("text out: %s: ctx->header malloc failed", __func__);
|
||||||
return SR_ERR_MALLOC;
|
ret = SR_ERR_MALLOC;
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING);
|
snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING);
|
||||||
num_probes = g_slist_length(o->dev->probes);
|
num_probes = g_slist_length(o->sdi->probes);
|
||||||
if (o->dev->driver || sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
|
if (o->sdi->driver || sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
|
||||||
samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
|
ret = o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
|
||||||
o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
|
(const void **)&samplerate, o->sdi);
|
||||||
if (!(samplerate_s = sr_samplerate_string(samplerate))) {
|
if (ret != SR_OK)
|
||||||
g_free(ctx->header);
|
goto err;
|
||||||
g_free(ctx);
|
if (!(samplerate_s = sr_samplerate_string(*samplerate))) {
|
||||||
return SR_ERR;
|
ret = SR_ERR;
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
snprintf(ctx->header + strlen(ctx->header),
|
snprintf(ctx->header + strlen(ctx->header),
|
||||||
511 - strlen(ctx->header),
|
511 - strlen(ctx->header),
|
||||||
|
@ -128,19 +131,23 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
|
||||||
|
|
||||||
ctx->linebuf_len = ctx->samples_per_line * 2 + 4;
|
ctx->linebuf_len = ctx->samples_per_line * 2 + 4;
|
||||||
if (!(ctx->linebuf = g_try_malloc0(num_probes * ctx->linebuf_len))) {
|
if (!(ctx->linebuf = g_try_malloc0(num_probes * ctx->linebuf_len))) {
|
||||||
g_free(ctx->header);
|
|
||||||
g_free(ctx);
|
|
||||||
sr_err("text out: %s: ctx->linebuf malloc failed", __func__);
|
sr_err("text out: %s: ctx->linebuf malloc failed", __func__);
|
||||||
return SR_ERR_MALLOC;
|
ret = SR_ERR_MALLOC;
|
||||||
}
|
goto err;
|
||||||
if (!(ctx->linevalues = g_try_malloc0(num_probes))) {
|
|
||||||
g_free(ctx->header);
|
|
||||||
g_free(ctx);
|
|
||||||
sr_err("text out: %s: ctx->linevalues malloc failed", __func__);
|
|
||||||
return SR_ERR_MALLOC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SR_OK;
|
if (!(ctx->linevalues = g_try_malloc0(num_probes))) {
|
||||||
|
sr_err("text out: %s: ctx->linevalues malloc failed", __func__);
|
||||||
|
ret = SR_ERR_MALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
err:
|
||||||
|
if (ret != SR_OK) {
|
||||||
|
g_free(ctx->header);
|
||||||
|
g_free(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
||||||
|
|
12
output/vcd.c
12
output/vcd.c
|
@ -45,6 +45,7 @@ static int init(struct sr_output *o)
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
uint64_t *samplerate;
|
||||||
int num_probes, i;
|
int num_probes, i;
|
||||||
char *samplerate_s, *frequency_s, *timestamp;
|
char *samplerate_s, *frequency_s, *timestamp;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
@ -57,7 +58,7 @@ static int init(struct sr_output *o)
|
||||||
o->internal = ctx;
|
o->internal = ctx;
|
||||||
ctx->num_enabled_probes = 0;
|
ctx->num_enabled_probes = 0;
|
||||||
|
|
||||||
for (l = o->dev->probes; l; l = l->next) {
|
for (l = o->sdi->probes; l; l = l->next) {
|
||||||
probe = l->data;
|
probe = l->data;
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
@ -71,7 +72,7 @@ static int init(struct sr_output *o)
|
||||||
ctx->probelist[ctx->num_enabled_probes] = 0;
|
ctx->probelist[ctx->num_enabled_probes] = 0;
|
||||||
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
||||||
ctx->header = g_string_sized_new(512);
|
ctx->header = g_string_sized_new(512);
|
||||||
num_probes = g_slist_length(o->dev->probes);
|
num_probes = g_slist_length(o->sdi->probes);
|
||||||
|
|
||||||
/* timestamp */
|
/* timestamp */
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
|
@ -84,9 +85,10 @@ static int init(struct sr_output *o)
|
||||||
g_string_append_printf(ctx->header, "$version %s %s $end\n",
|
g_string_append_printf(ctx->header, "$version %s %s $end\n",
|
||||||
PACKAGE, PACKAGE_VERSION);
|
PACKAGE, PACKAGE_VERSION);
|
||||||
|
|
||||||
if (o->dev->driver && sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
|
if (o->sdi->driver && sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
|
||||||
ctx->samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
|
o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
|
||||||
o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
|
(const void **)&samplerate, o->sdi);
|
||||||
|
ctx->samplerate = *samplerate;
|
||||||
if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) {
|
if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) {
|
||||||
g_string_free(ctx->header, TRUE);
|
g_string_free(ctx->header, TRUE);
|
||||||
g_free(ctx);
|
g_free(ctx);
|
||||||
|
|
Loading…
Reference in New Issue