static int init(struct sr_input *in)
{
+ struct sr_probe *probe;
int num_probes, i;
char name[SR_MAX_PROBENAME_LEN + 1];
char *param;
}
/* 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;
for (i = 0; i < num_probes; i++) {
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
/* 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;
if ((fd = open(filename, O_RDONLY)) == -1)
return SR_ERR;
- num_probes = g_slist_length(in->vdev->probes);
+ num_probes = g_slist_length(in->sdi->probes);
/* send header */
header.feed_version = 1;
gettimeofday(&header.starttime, NULL);
packet.type = SR_DF_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. */
packet.type = SR_DF_META_LOGIC;
packet.payload = &meta;
meta.samplerate = ctx->samplerate;
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 */
packet.type = SR_DF_LOGIC;
logic.data = buffer;
while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
logic.length = size;
- sr_session_send(in->vdev, &packet);
+ sr_session_send(in->sdi, &packet);
}
close(fd);
/* end of stream */
packet.type = SR_DF_END;
- sr_session_send(in->vdev, &packet);
+ sr_session_send(in->sdi, &packet);
g_free(ctx);
in->internal = NULL;
static int init(struct sr_input *in)
{
+ struct sr_probe *probe;
int num_probes, i;
char name[SR_MAX_PROBENAME_LEN + 1];
char *param;
}
/* 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++) {
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
/* 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_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. */
divcount = 0x00; /* TODO: Don't hardcode! */
packet.payload = &header;
header.feed_version = 1;
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. */
packet.type = SR_DF_META_LOGIC;
packet.payload = &meta;
meta.samplerate = samplerate;
meta.num_probes = num_probes;
- sr_session_send(in->vdev, &packet);
+ sr_session_send(in->sdi, &packet);
/* TODO: Handle trigger point. */
/* TODO: Handle errors, handle incomplete reads. */
size = read(fd, buf, PACKET_SIZE);
logic.length = size;
- sr_session_send(in->vdev, &packet);
+ sr_session_send(in->sdi, &packet);
}
close(fd); /* FIXME */
sr_dbg("la8 in: %s: sending SR_DF_END", __func__);
packet.type = SR_DF_END;
packet.payload = NULL;
- sr_session_send(in->vdev, &packet);
+ sr_session_send(in->sdi, &packet);
return SR_OK;
}
struct sr_input {
struct sr_input_format *format;
GHashTable *param;
- struct sr_dev *vdev;
+ struct sr_dev_inst *sdi;
void *internal;
};
struct sr_output {
struct sr_output_format *format;
- struct sr_dev *dev;
+ struct sr_dev_inst *sdi;
char *param;
void *internal;
};
struct context *ctx;
struct sr_probe *probe;
GSList *l;
- uint64_t samplerate;
+ uint64_t *samplerate;
if (!o) {
sr_warn("la8 out: %s: o was NULL", __func__);
return SR_ERR_ARG;
}
- if (!o->dev) {
- sr_warn("la8 out: %s: o->dev was NULL", __func__);
+ if (!o->sdi) {
+ sr_warn("la8 out: %s: o->sdi was NULL", __func__);
return SR_ERR_ARG;
}
- if (!o->dev->driver) {
- sr_warn("la8 out: %s: o->dev->driver was NULL", __func__);
+ if (!o->sdi->driver) {
+ sr_warn("la8 out: %s: o->sdi->driver was NULL", __func__);
return SR_ERR_ARG;
}
o->internal = ctx;
/* Get the probe names and the unitsize. */
- /* TODO: Error handling. */
- for (l = o->dev->probes; l; l = l->next) {
+ for (l = o->sdi->probes; l; l = l->next) {
probe = l->data;
if (!probe->enabled)
continue;
ctx->probelist[ctx->num_enabled_probes] = 0;
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
- if (sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
- samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
- o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
- /* TODO: Error checks. */
- } else {
- samplerate = 0; /* TODO: Error or set some value? */
- }
- ctx->samplerate = samplerate;
+ if (sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
+ o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
+ (const void **)&samplerate, o->sdi);
+ ctx->samplerate = *samplerate;
+ } else
+ ctx->samplerate = 0;
- return 0; /* TODO: SR_OK? */
+ return SR_OK;
}
static int event(struct sr_output *o, int event_type, uint8_t **data_out,
struct sr_probe *probe;
GSList *l;
int num_probes;
- uint64_t samplerate;
+ uint64_t *samplerate;
time_t t;
unsigned int i;
return SR_ERR_ARG;
}
- if (!o->dev) {
- sr_err("csv out: %s: o->dev was NULL", __func__);
+ if (!o->sdi) {
+ sr_err("csv out: %s: o->sdi was NULL", __func__);
return SR_ERR_ARG;
}
- if (!o->dev->driver) {
- sr_err("csv out: %s: o->dev->driver was NULL", __func__);
+ if (!o->sdi->driver) {
+ sr_err("csv out: %s: o->sdi->driver was NULL", __func__);
return SR_ERR_ARG;
}
o->internal = ctx;
/* Get the number of probes, their names, and the unitsize. */
- /* TODO: Error handling. */
- for (l = o->dev->probes; l; l = l->next) {
+ for (l = o->sdi->probes; l; l = l->next) {
probe = l->data;
if (!probe->enabled)
continue;
ctx->probelist[ctx->num_enabled_probes] = 0;
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)) {
- samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
- o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
- /* TODO: Error checks. */
- } else {
- samplerate = 0; /* TODO: Error or set some value? */
- }
- ctx->samplerate = samplerate;
+ if (sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
+ o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
+ (const void **)&samplerate, o->sdi);
+ ctx->samplerate = *samplerate;
+ } else
+ ctx->samplerate = 0;
ctx->separator = ',';
-
ctx->header = g_string_sized_new(512);
t = time(NULL);
g_string_append_printf(ctx->header, "%s, ", ctx->probelist[i]);
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,
if (!o)
return SR_ERR_ARG;
- if (!o->dev)
+ if (!o->sdi)
return SR_ERR_ARG;
- if (!o->dev->driver)
+ if (!o->sdi->driver)
return SR_ERR_ARG;
if (!(ctx = g_try_malloc0(sizeof(struct context))))
/* Get the number of probes and their names. */
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;
if (!probe || !probe->enabled)
continue;
struct context *ctx;
struct sr_probe *probe;
GSList *l;
- uint64_t samplerate;
+ uint64_t *samplerate;
unsigned int i;
int b, num_probes;
char *c, *frequency_s;
return SR_ERR_ARG;
}
- if (!o->dev) {
- sr_err("gnuplot out: %s: o->dev was NULL", __func__);
+ if (!o->sdi) {
+ sr_err("gnuplot out: %s: o->sdi was NULL", __func__);
return SR_ERR_ARG;
}
- if (!o->dev->driver) {
- sr_err("gnuplot out: %s: o->dev->driver was NULL", __func__);
+ if (!o->sdi->driver) {
+ sr_err("gnuplot out: %s: o->sdi->driver was NULL", __func__);
return SR_ERR_ARG;
}
o->internal = ctx;
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. */
if (!probe->enabled)
continue;
ctx->probelist[ctx->num_enabled_probes] = 0;
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';
- if (sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
- samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
- o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
- if (!(frequency_s = sr_samplerate_string(samplerate))) {
+ if (sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
+ o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
+ (const void **)&samplerate, o->sdi);
+ if (!(frequency_s = sr_samplerate_string(*samplerate))) {
sr_err("gnuplot out: %s: sr_samplerate_string failed",
__func__);
g_free(ctx->header);
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__);
g_free(ctx->header);
g_free(ctx);
struct context *ctx;
struct sr_probe *probe;
GSList *l;
- uint64_t samplerate;
+ uint64_t *samplerate, tmp;
int num_enabled_probes;
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
ctx->num_samples = 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;
if (probe->enabled)
num_enabled_probes++;
}
ctx->unitsize = (num_enabled_probes + 7) / 8;
- if (o->dev->driver && sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE))
- samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
- o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
- else
- samplerate = 0;
+ if (o->sdi->driver && sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE))
+ o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
+ (const void **)&samplerate, o->sdi);
+ else {
+ tmp = 0;
+ samplerate = &tmp;
+ }
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, ";EnabledChannels: -1\n");
g_string_append_printf(ctx->header, ";Compressed: true\n");
struct context *ctx;
struct sr_probe *probe;
GSList *l;
- uint64_t samplerate;
- int num_probes;
+ uint64_t *samplerate;
+ int num_probes, ret;
char *samplerate_s;
if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
o->internal = ctx;
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;
if (!probe->enabled)
continue;
if (o->param && o->param[0]) {
ctx->samples_per_line = strtoul(o->param, NULL, 10);
- if (ctx->samples_per_line < 1)
- return SR_ERR;
+ if (ctx->samples_per_line < 1) {
+ ret = SR_ERR;
+ goto err;
+ }
} else
ctx->samples_per_line = default_spl;
if (!(ctx->header = g_try_malloc0(512))) {
- g_free(ctx);
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);
- num_probes = g_slist_length(o->dev->probes);
- if (o->dev->driver || sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
- samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
- o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
- if (!(samplerate_s = sr_samplerate_string(samplerate))) {
- g_free(ctx->header);
- g_free(ctx);
- return SR_ERR;
+ num_probes = g_slist_length(o->sdi->probes);
+ if (o->sdi->driver || sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
+ ret = o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
+ (const void **)&samplerate, o->sdi);
+ if (ret != SR_OK)
+ goto err;
+ if (!(samplerate_s = sr_samplerate_string(*samplerate))) {
+ ret = SR_ERR;
+ goto err;
}
snprintf(ctx->header + strlen(ctx->header),
511 - strlen(ctx->header),
ctx->linebuf_len = ctx->samples_per_line * 2 + 4;
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__);
- return SR_ERR_MALLOC;
+ ret = SR_ERR_MALLOC;
+ goto err;
}
+
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);
- sr_err("text out: %s: ctx->linevalues malloc failed", __func__);
- return SR_ERR_MALLOC;
}
- return SR_OK;
+ return ret;
}
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
struct context *ctx;
struct sr_probe *probe;
GSList *l;
+ uint64_t *samplerate;
int num_probes, i;
char *samplerate_s, *frequency_s, *timestamp;
time_t t;
o->internal = ctx;
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;
if (!probe->enabled)
continue;
ctx->probelist[ctx->num_enabled_probes] = 0;
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
ctx->header = g_string_sized_new(512);
- num_probes = g_slist_length(o->dev->probes);
+ num_probes = g_slist_length(o->sdi->probes);
/* timestamp */
t = time(NULL);
g_string_append_printf(ctx->header, "$version %s %s $end\n",
PACKAGE, PACKAGE_VERSION);
- if (o->dev->driver && sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) {
- ctx->samplerate = *((uint64_t *) o->dev->driver->dev_info_get(
- o->dev->driver_index, SR_DI_CUR_SAMPLERATE));
+ if (o->sdi->driver && sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) {
+ o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE,
+ (const void **)&samplerate, o->sdi);
+ ctx->samplerate = *samplerate;
if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) {
g_string_free(ctx->header, TRUE);
g_free(ctx);