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:
parent
0a7da5f8c9
commit
af51a7718e
|
@ -105,11 +105,6 @@ static int init(struct sr_output *o)
|
|||
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)))) {
|
||||
sr_warn("%s: ctx malloc failed", __func__);
|
||||
return SR_ERR_MALLOC;
|
||||
|
@ -126,8 +121,8 @@ static int init(struct sr_output *o)
|
|||
}
|
||||
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
|
||||
|
||||
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
|
||||
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
|
||||
if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
|
||||
o->sdi) == SR_OK) {
|
||||
ctx->samplerate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
} else
|
||||
|
|
|
@ -73,11 +73,6 @@ static int init(struct sr_output *o)
|
|||
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)))) {
|
||||
sr_err("%s: ctx malloc failed", __func__);
|
||||
return SR_ERR_MALLOC;
|
||||
|
@ -96,8 +91,8 @@ static int init(struct sr_output *o)
|
|||
|
||||
num_probes = g_slist_length(o->sdi->probes);
|
||||
|
||||
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
|
||||
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
|
||||
if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
|
||||
o->sdi) == SR_OK) {
|
||||
ctx->samplerate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
} else
|
||||
|
|
|
@ -78,11 +78,6 @@ static int init(struct sr_output *o)
|
|||
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)))) {
|
||||
sr_err("%s: ctx malloc failed", __func__);
|
||||
return SR_ERR_MALLOC;
|
||||
|
@ -100,19 +95,18 @@ static int init(struct sr_output *o)
|
|||
num_probes = g_slist_length(o->sdi->probes);
|
||||
comment[0] = '\0';
|
||||
samplerate = 0;
|
||||
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
|
||||
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
|
||||
if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
|
||||
o->sdi) == SR_OK) {
|
||||
samplerate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
if (!(frequency_s = sr_samplerate_string(samplerate))) {
|
||||
sr_err("%s: sr_samplerate_string failed", __func__);
|
||||
g_free(ctx);
|
||||
g_variant_unref(gvar);
|
||||
return SR_ERR;
|
||||
}
|
||||
snprintf(comment, 127, gnuplot_header_comment,
|
||||
ctx->num_enabled_probes, num_probes, frequency_s);
|
||||
g_free(frequency_s);
|
||||
g_variant_unref(gvar);
|
||||
}
|
||||
|
||||
/* Columns / channels */
|
||||
|
|
|
@ -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);
|
||||
num_probes = g_slist_length(o->sdi->probes);
|
||||
if (o->sdi->driver || sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
|
||||
if ((ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar,
|
||||
o->sdi)) != SR_OK)
|
||||
goto err;
|
||||
if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
|
||||
o->sdi) == SR_OK) {
|
||||
samplerate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
if (!(samplerate_s = sr_samplerate_string(samplerate))) {
|
||||
ret = SR_ERR;
|
||||
g_variant_unref(gvar);
|
||||
goto err;
|
||||
}
|
||||
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",
|
||||
ctx->num_enabled_probes, num_probes, samplerate_s);
|
||||
g_free(samplerate_s);
|
||||
g_variant_unref(gvar);
|
||||
}
|
||||
|
||||
ctx->linebuf_len = ctx->samples_per_line * 2 + 4;
|
||||
|
|
|
@ -95,19 +95,18 @@ static int init(struct sr_output *o)
|
|||
g_string_append_printf(ctx->header, "$version %s %s $end\n",
|
||||
PACKAGE, PACKAGE_VERSION);
|
||||
|
||||
if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
|
||||
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
|
||||
if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar,
|
||||
o->sdi) == SR_OK) {
|
||||
ctx->samplerate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) {
|
||||
g_string_free(ctx->header, TRUE);
|
||||
g_free(ctx);
|
||||
g_variant_unref(gvar);
|
||||
return SR_ERR;
|
||||
}
|
||||
g_string_append_printf(ctx->header, vcd_header_comment,
|
||||
ctx->num_enabled_probes, num_probes, samplerate_s);
|
||||
g_free(samplerate_s);
|
||||
g_variant_unref(gvar);
|
||||
}
|
||||
|
||||
/* timescale */
|
||||
|
|
Loading…
Reference in New Issue