Simplify a few config_set() callbacks.
Also, extended logging and random whitespace fixes.
This commit is contained in:
parent
329733d92c
commit
dcd438ee35
|
@ -192,18 +192,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
/* TODO: not yet implemented */
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("LIMIT_MSEC can't be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -174,11 +174,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_DATA_SOURCE: {
|
||||
tmp_str = g_variant_get_string(data, NULL);
|
||||
|
@ -201,7 +199,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg)
|
||||
{
|
||||
(void)sdi;
|
||||
(void)cg;
|
||||
|
||||
switch (key) {
|
||||
|
|
|
@ -884,7 +884,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
|
||||
(void)sdi;
|
||||
(void)cg;
|
||||
|
||||
switch (key) {
|
||||
|
|
|
@ -358,7 +358,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,12 +228,10 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
devc->limit_msec = 0;
|
||||
sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data) * 1000;
|
||||
devc->limit_samples = 0;
|
||||
sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_SAMPLERATE:
|
||||
samplerate = g_variant_get_uint64(data);
|
||||
|
@ -243,7 +241,6 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
break;
|
||||
}
|
||||
devc->samplerate = samplerate;
|
||||
sr_dbg("Setting samplerate to %" PRIu64, devc->samplerate);
|
||||
break;
|
||||
case SR_CONF_PROBE_FACTOR:
|
||||
if (!cg)
|
||||
|
|
|
@ -226,25 +226,22 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
const struct sr_channel_group *cg)
|
||||
{
|
||||
struct dev_context *devc = sdi->priv;
|
||||
|
||||
(void)cg;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
*data = g_variant_new_uint64(devc->limit_samples);
|
||||
break;
|
||||
|
||||
case SR_CONF_SAMPLERATE:
|
||||
*data = g_variant_new_uint64(devc->cur_samplerate);
|
||||
break;
|
||||
|
||||
case SR_CONF_CAPTURE_RATIO:
|
||||
*data = g_variant_new_uint64(devc->capture_ratio);
|
||||
break;
|
||||
|
||||
case SR_CONF_NUM_LOGIC_CHANNELS:
|
||||
*data = g_variant_new_uint32(g_slist_length(sdi->channels));
|
||||
break;
|
||||
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
@ -257,6 +254,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
{
|
||||
struct dev_context *devc = sdi->priv;
|
||||
uint64_t tmp_u64;
|
||||
|
||||
(void)cg;
|
||||
|
||||
if (sdi->status != SR_ST_ACTIVE)
|
||||
|
@ -266,7 +264,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
case SR_CONF_SAMPLERATE:
|
||||
devc->cur_samplerate = g_variant_get_uint64(data);
|
||||
return beaglelogic_set_samplerate(devc);
|
||||
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
tmp_u64 = g_variant_get_uint64(data);
|
||||
devc->limit_samples = tmp_u64;
|
||||
|
@ -284,7 +281,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
(SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000));
|
||||
}
|
||||
return beaglelogic_set_triggerflags(devc);
|
||||
|
||||
case SR_CONF_CAPTURE_RATIO:
|
||||
devc->capture_ratio = g_variant_get_uint64(data);
|
||||
if (devc->capture_ratio > 100) {
|
||||
|
@ -292,7 +288,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
return SR_ERR;
|
||||
}
|
||||
return SR_OK;
|
||||
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
@ -308,7 +303,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
GVariantBuilder gvb;
|
||||
|
||||
(void)sdi;
|
||||
(void)data;
|
||||
(void)cg;
|
||||
|
||||
ret = SR_OK;
|
||||
|
|
|
@ -210,11 +210,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -137,18 +137,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
/* TODO: not yet implemented */
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("LIMIT_MSEC can't be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);;
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -487,17 +487,14 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_SAMPLERATE:
|
||||
devc->cur_samplerate = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting samplerate to %" PRIu64, devc->cur_samplerate);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_msec = 0;
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
devc->limit_samples = 0;
|
||||
sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_AVERAGING:
|
||||
devc->avg = g_variant_get_boolean(data);
|
||||
|
@ -575,8 +572,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
|
||||
(void)sdi;
|
||||
|
||||
if (key == SR_CONF_SCAN_OPTIONS) {
|
||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
||||
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
|
||||
|
|
|
@ -216,18 +216,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
/* TODO: not yet implemented */
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("LIMIT_MSEC can't be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -389,8 +389,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
|
||||
(void)cg;
|
||||
|
||||
ret = SR_OK;
|
||||
|
||||
if (!sdi || !(devc = sdi->priv))
|
||||
return SR_ERR_ARG;
|
||||
|
||||
|
|
|
@ -1496,8 +1496,7 @@ SR_PRIV const char *gmc_model_str(enum model mcode)
|
|||
}
|
||||
}
|
||||
|
||||
/** @copydoc sr_dev_driver.config_set
|
||||
*/
|
||||
/** @copydoc sr_dev_driver.config_set */
|
||||
SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg)
|
||||
{
|
||||
|
@ -1533,18 +1532,10 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s
|
|||
g_usleep(2000000); /* Wait to ensure transfer before interface switched off. */
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("LIMIT_MSEC can't be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -169,7 +169,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
|
|||
struct sr_channel_group *cg;
|
||||
struct drv_context *drvc;
|
||||
struct dev_context *devc;
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
||||
sdi->status = SR_ST_INITIALIZING;
|
||||
|
@ -434,8 +434,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
const uint64_t *vdiv;
|
||||
int ch_idx;
|
||||
|
||||
(void)cg;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_NUM_HDIV:
|
||||
*data = g_variant_new_int32(NUM_TIMEBASE);
|
||||
|
|
|
@ -67,7 +67,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct dev_context *devc;
|
||||
struct sr_usb_dev_inst *usb;
|
||||
struct device_info dev_info;
|
||||
int ret, i;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
|
||||
(void)options;
|
||||
|
||||
|
@ -354,7 +355,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
(void)cg;
|
||||
|
||||
ret = SR_OK;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
||||
|
|
|
@ -215,18 +215,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
ret = SR_OK;
|
||||
switch (key) {
|
||||
case SR_CONF_DATALOG:
|
||||
if (g_variant_get_boolean(data)) {
|
||||
/* Start logging. */
|
||||
if (g_variant_get_boolean(data))
|
||||
ret = lascar_start_logging(sdi);
|
||||
} else {
|
||||
/* Stop logging. */
|
||||
else
|
||||
ret = lascar_stop_logging(sdi);
|
||||
}
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
ret = SR_ERR_NA;
|
||||
|
|
|
@ -320,8 +320,6 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
|
|||
ret = SR_ERR_ARG;
|
||||
} else {
|
||||
devc->limit_samples = num_samples;
|
||||
sr_dbg("setting limit_samples to %i\n",
|
||||
num_samples);
|
||||
ret = SR_OK;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -169,13 +169,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -623,24 +623,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
/* No channel group: global options. */
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("LIMIT_MSEC can't be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_OUTPUT_CHANNEL_CONFIG:
|
||||
sval = g_variant_get_string(data, NULL);
|
||||
found = FALSE;
|
||||
for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++)
|
||||
{
|
||||
for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) {
|
||||
if (!strcmp(sval, channel_modes[idx])) {
|
||||
found = TRUE;
|
||||
if (devc->tracking_mode == idx)
|
||||
|
@ -652,9 +643,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
if (devc->model->modelid <= LPS_303) /* Only first setting possible for smaller models. */
|
||||
break;
|
||||
}
|
||||
if (!found) {
|
||||
if (!found)
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
@ -728,25 +718,23 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
|
||||
(void)data;
|
||||
|
||||
/* Driver options, no device instance necessary. */
|
||||
switch (key) {
|
||||
case SR_CONF_SCAN_OPTIONS:
|
||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
||||
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
|
||||
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
|
||||
return SR_OK;
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
if (sdi != NULL)
|
||||
break;
|
||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
||||
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
|
||||
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
|
||||
return SR_OK;
|
||||
default:
|
||||
if (sdi == NULL)
|
||||
if (!sdi)
|
||||
return SR_ERR_ARG;
|
||||
|
||||
devc = sdi->priv;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Device options, independent from channel groups. */
|
||||
|
@ -765,7 +753,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
*data = g_variant_new_strv(channel_modes, ARRAY_SIZE(channel_modes));
|
||||
}
|
||||
return SR_OK;
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
|
|
@ -219,18 +219,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("LIMIT_MSEC can't be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -443,7 +443,7 @@ static int dev_open(struct sr_dev_inst *sdi)
|
|||
if (p_ols_open(devc) != SR_OK) {
|
||||
return SR_ERR;
|
||||
} else {
|
||||
sdi->status = SR_ST_ACTIVE;
|
||||
sdi->status = SR_ST_ACTIVE;
|
||||
return SR_OK;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -630,7 +630,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
*data = g_variant_new_string(devc->coupling[analog_channel]);
|
||||
break;
|
||||
default:
|
||||
sr_dbg("Tried to get unknown config key: %d.", key);
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
|
@ -795,9 +794,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
}
|
||||
break;
|
||||
default:
|
||||
sr_dbg("Tried to set unknown config key: %d.", key);
|
||||
ret = SR_ERR_NA;
|
||||
break;
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -921,7 +918,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
}
|
||||
break;
|
||||
default:
|
||||
sr_dbg("Tried to list unknown config key: %d.", key);
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,7 +148,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
GSList *l, *devices, *conn_devices;
|
||||
struct libusb_device_descriptor des;
|
||||
libusb_device **devlist;
|
||||
int ret, i, j;
|
||||
int ret, j;
|
||||
unsigned int i;
|
||||
const char *conn;
|
||||
char connection_id[64];
|
||||
|
||||
|
|
|
@ -178,13 +178,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -160,11 +160,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -295,13 +295,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
now = g_get_monotonic_time() / 1000;
|
||||
devc->end_time = now + devc->limit_msec;
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
ret = SR_ERR_NA;
|
||||
|
|
|
@ -130,8 +130,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -328,22 +328,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("Time limit cannot be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("Sample limit cannot be 0.");
|
||||
return SR_ERR;
|
||||
}
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -217,7 +217,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
{
|
||||
struct sr_dev_driver *di = sdi->driver;
|
||||
struct dev_context *devc;
|
||||
int ret;
|
||||
const char *tmp_str;
|
||||
|
||||
(void)cg;
|
||||
|
@ -231,12 +230,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
}
|
||||
|
||||
devc = sdi->priv;
|
||||
ret = SR_OK;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
case SR_CONF_DATA_SOURCE:
|
||||
tmp_str = g_variant_get_string(data, NULL);
|
||||
|
@ -248,16 +245,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
return SR_ERR;
|
||||
break;
|
||||
default:
|
||||
ret = SR_ERR_NA;
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg)
|
||||
{
|
||||
|
||||
(void)sdi;
|
||||
(void)cg;
|
||||
|
||||
|
|
|
@ -231,7 +231,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
struct sr_dev_driver *di = sdi->driver;
|
||||
struct dev_context *devc;
|
||||
gint64 now;
|
||||
int ret;
|
||||
|
||||
(void)cg;
|
||||
|
||||
|
@ -244,25 +243,21 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
}
|
||||
|
||||
devc = sdi->priv;
|
||||
ret = SR_OK;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
now = g_get_monotonic_time() / 1000;
|
||||
devc->end_time = now + devc->limit_msec;
|
||||
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||
devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||
devc->limit_samples);
|
||||
break;
|
||||
default:
|
||||
ret = SR_ERR_NA;
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||
|
|
|
@ -391,35 +391,26 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
const struct sr_channel_group *cg)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
GVariant *range[2];
|
||||
|
||||
(void)cg;
|
||||
|
||||
if (!sdi)
|
||||
return SR_ERR_ARG;
|
||||
|
||||
devc = sdi->priv;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_SAMPLERATE:
|
||||
if (sdi) {
|
||||
devc = sdi->priv;
|
||||
*data = g_variant_new_uint64(devc->cur_samplerate);
|
||||
sr_spew("Returning samplerate: %" PRIu64 "Hz.",
|
||||
devc->cur_samplerate);
|
||||
} else
|
||||
return SR_ERR_ARG;
|
||||
*data = g_variant_new_uint64(devc->cur_samplerate);
|
||||
break;
|
||||
case SR_CONF_CAPTURE_RATIO:
|
||||
if (sdi) {
|
||||
devc = sdi->priv;
|
||||
*data = g_variant_new_uint64(devc->capture_ratio);
|
||||
} else
|
||||
return SR_ERR_ARG;
|
||||
*data = g_variant_new_uint64(devc->capture_ratio);
|
||||
break;
|
||||
case SR_CONF_VOLTAGE_THRESHOLD:
|
||||
if (sdi) {
|
||||
GVariant *range[2];
|
||||
devc = sdi->priv;
|
||||
range[0] = g_variant_new_double(devc->cur_threshold);
|
||||
range[1] = g_variant_new_double(devc->cur_threshold);
|
||||
*data = g_variant_new_tuple(range, 2);
|
||||
} else
|
||||
return SR_ERR_ARG;
|
||||
range[0] = g_variant_new_double(devc->cur_threshold);
|
||||
range[1] = g_variant_new_double(devc->cur_threshold);
|
||||
*data = g_variant_new_tuple(range, 2);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -464,9 +464,27 @@ SR_PRIV void sr_config_free(struct sr_config *src)
|
|||
|
||||
}
|
||||
|
||||
static void log_key(const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg, uint32_t key, int op, GVariant *data)
|
||||
{
|
||||
const char *opstr;
|
||||
const struct sr_config_info *srci;
|
||||
|
||||
/* Don't log SR_CONF_DEVICE_OPTIONS, it's verbose and not too useful. */
|
||||
if (key == SR_CONF_DEVICE_OPTIONS)
|
||||
return;
|
||||
|
||||
opstr = op == SR_CONF_GET ? "get" : op == SR_CONF_SET ? "set" : "list";
|
||||
srci = sr_config_info_get(key);
|
||||
|
||||
sr_spew("sr_config_%s(): key %d (%s) sdi %p cg %s -> %s", opstr, key,
|
||||
srci ? srci->id : "NULL", sdi, cg ? cg->name : "NULL",
|
||||
data ? g_variant_print(data, TRUE) : "NULL");
|
||||
}
|
||||
|
||||
static int check_key(const struct sr_dev_driver *driver,
|
||||
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
|
||||
uint32_t key, int op)
|
||||
uint32_t key, int op, GVariant *data)
|
||||
{
|
||||
const struct sr_config_info *srci;
|
||||
gsize num_opts, i;
|
||||
|
@ -487,8 +505,20 @@ static int check_key(const struct sr_dev_driver *driver,
|
|||
return SR_ERR_ARG;
|
||||
}
|
||||
opstr = op == SR_CONF_GET ? "get" : op == SR_CONF_SET ? "set" : "list";
|
||||
sr_spew("sr_config_%s(): key %d (%s) sdi %p cg %s", opstr, key,
|
||||
srci->id, sdi, cg ? cg->name : "NULL");
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
case SR_CONF_LIMIT_SAMPLES:
|
||||
case SR_CONF_SAMPLERATE:
|
||||
/* Setting any of these to 0 is not useful. */
|
||||
if (op != SR_CONF_SET || !data)
|
||||
break;
|
||||
if (g_variant_get_uint64(data) == 0) {
|
||||
sr_err("Cannot set '%s' to 0.", srci->id);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS, &gvar_opts) != SR_OK) {
|
||||
/* Driver publishes no options. */
|
||||
|
@ -554,10 +584,11 @@ SR_API int sr_config_get(const struct sr_dev_driver *driver,
|
|||
if (!driver->config_get)
|
||||
return SR_ERR_ARG;
|
||||
|
||||
if (check_key(driver, sdi, cg, key, SR_CONF_GET) != SR_OK)
|
||||
if (check_key(driver, sdi, cg, key, SR_CONF_GET, NULL) != SR_OK)
|
||||
return SR_ERR_ARG;
|
||||
|
||||
if ((ret = driver->config_get(key, data, sdi, cg)) == SR_OK) {
|
||||
log_key(sdi, cg, key, SR_CONF_GET, *data);
|
||||
/* Got a floating reference from the driver. Sink it here,
|
||||
* caller will need to unref when done with it. */
|
||||
g_variant_ref_sink(*data);
|
||||
|
@ -597,10 +628,12 @@ SR_API int sr_config_set(const struct sr_dev_inst *sdi,
|
|||
ret = SR_ERR;
|
||||
else if (!sdi->driver->config_set)
|
||||
ret = SR_ERR_ARG;
|
||||
else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET) != SR_OK)
|
||||
else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET, data) != SR_OK)
|
||||
return SR_ERR_ARG;
|
||||
else if ((ret = sr_variant_type_check(key, data)) == SR_OK)
|
||||
else if ((ret = sr_variant_type_check(key, data)) == SR_OK) {
|
||||
log_key(sdi, cg, key, SR_CONF_SET, data);
|
||||
ret = sdi->driver->config_set(key, data, sdi, cg);
|
||||
}
|
||||
|
||||
g_variant_unref(data);
|
||||
|
||||
|
@ -665,11 +698,13 @@ SR_API int sr_config_list(const struct sr_dev_driver *driver,
|
|||
else if (!driver->config_list)
|
||||
return SR_ERR_ARG;
|
||||
else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
|
||||
if (check_key(driver, sdi, cg, key, SR_CONF_LIST) != SR_OK)
|
||||
if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK)
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK)
|
||||
if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) {
|
||||
log_key(sdi, cg, key, SR_CONF_LIST, *data);
|
||||
g_variant_ref_sink(*data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue