output: Use sr_config_get() wrapper

This obviates the need for a valid driver, and thus makes converting
from any (non-sr) input format to any output format possible; the only
thing missing is the samplerate.

Fixes bug 105.
This commit is contained in:
Bert Vermeulen 2013-04-30 16:03:37 +02:00
parent 0a7da5f8c9
commit af51a7718e
5 changed files with 13 additions and 33 deletions

View File

@ -105,11 +105,6 @@ static int init(struct sr_output *o)
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!o->sdi->driver) {
sr_warn("%s: o->sdi->driver was NULL", __func__);
return SR_ERR_ARG;
}
if (!(ctx = g_try_malloc0(sizeof(struct context)))) { if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
sr_warn("%s: ctx malloc failed", __func__); sr_warn("%s: ctx malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
@ -126,8 +121,8 @@ static int init(struct sr_output *o)
} }
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8; ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); o->sdi) == SR_OK) {
ctx->samplerate = g_variant_get_uint64(gvar); ctx->samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar); g_variant_unref(gvar);
} else } else

View File

@ -73,11 +73,6 @@ static int init(struct sr_output *o)
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!o->sdi->driver) {
sr_err("%s: o->sdi->driver was NULL", __func__);
return SR_ERR_ARG;
}
if (!(ctx = g_try_malloc0(sizeof(struct context)))) { if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
sr_err("%s: ctx malloc failed", __func__); sr_err("%s: ctx malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
@ -96,8 +91,8 @@ static int init(struct sr_output *o)
num_probes = g_slist_length(o->sdi->probes); num_probes = g_slist_length(o->sdi->probes);
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); o->sdi) == SR_OK) {
ctx->samplerate = g_variant_get_uint64(gvar); ctx->samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar); g_variant_unref(gvar);
} else } else

View File

@ -78,11 +78,6 @@ static int init(struct sr_output *o)
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!o->sdi->driver) {
sr_err("%s: o->sdi->driver was NULL", __func__);
return SR_ERR_ARG;
}
if (!(ctx = g_try_malloc0(sizeof(struct context)))) { if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
sr_err("%s: ctx malloc failed", __func__); sr_err("%s: ctx malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
@ -100,19 +95,18 @@ static int init(struct sr_output *o)
num_probes = g_slist_length(o->sdi->probes); num_probes = g_slist_length(o->sdi->probes);
comment[0] = '\0'; comment[0] = '\0';
samplerate = 0; samplerate = 0;
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); o->sdi) == SR_OK) {
samplerate = g_variant_get_uint64(gvar); samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
if (!(frequency_s = sr_samplerate_string(samplerate))) { if (!(frequency_s = sr_samplerate_string(samplerate))) {
sr_err("%s: sr_samplerate_string failed", __func__); sr_err("%s: sr_samplerate_string failed", __func__);
g_free(ctx); g_free(ctx);
g_variant_unref(gvar);
return SR_ERR; return SR_ERR;
} }
snprintf(comment, 127, gnuplot_header_comment, snprintf(comment, 127, gnuplot_header_comment,
ctx->num_enabled_probes, num_probes, frequency_s); ctx->num_enabled_probes, num_probes, frequency_s);
g_free(frequency_s); g_free(frequency_s);
g_variant_unref(gvar);
} }
/* Columns / channels */ /* Columns / channels */

View File

@ -129,14 +129,12 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING); snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING);
num_probes = g_slist_length(o->sdi->probes); num_probes = g_slist_length(o->sdi->probes);
if (o->sdi->driver || sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
if ((ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi) == SR_OK) {
o->sdi)) != SR_OK)
goto err;
samplerate = g_variant_get_uint64(gvar); samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
if (!(samplerate_s = sr_samplerate_string(samplerate))) { if (!(samplerate_s = sr_samplerate_string(samplerate))) {
ret = SR_ERR; ret = SR_ERR;
g_variant_unref(gvar);
goto err; goto err;
} }
snprintf(ctx->header + strlen(ctx->header), snprintf(ctx->header + strlen(ctx->header),
@ -144,7 +142,6 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
"Acquisition with %d/%d probes at %s\n", "Acquisition with %d/%d probes at %s\n",
ctx->num_enabled_probes, num_probes, samplerate_s); ctx->num_enabled_probes, num_probes, samplerate_s);
g_free(samplerate_s); g_free(samplerate_s);
g_variant_unref(gvar);
} }
ctx->linebuf_len = ctx->samples_per_line * 2 + 4; ctx->linebuf_len = ctx->samples_per_line * 2 + 4;

View File

@ -95,19 +95,18 @@ 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->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); o->sdi) == SR_OK) {
ctx->samplerate = g_variant_get_uint64(gvar); ctx->samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
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);
g_variant_unref(gvar);
return SR_ERR; return SR_ERR;
} }
g_string_append_printf(ctx->header, vcd_header_comment, g_string_append_printf(ctx->header, vcd_header_comment,
ctx->num_enabled_probes, num_probes, samplerate_s); ctx->num_enabled_probes, num_probes, samplerate_s);
g_free(samplerate_s); g_free(samplerate_s);
g_variant_unref(gvar);
} }
/* timescale */ /* timescale */