Also, extended logging and random whitespace fixes.
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;
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);
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) {
GVariant *gvar;
GVariantBuilder gvb;
- (void)sdi;
(void)cg;
switch (key) {
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);
break;
}
devc->samplerate = samplerate;
- sr_dbg("Setting samplerate to %" PRIu64, devc->samplerate);
break;
case SR_CONF_PROBE_FACTOR:
if (!cg)
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;
}
{
struct dev_context *devc = sdi->priv;
uint64_t tmp_u64;
+
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
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;
(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) {
return SR_ERR;
}
return SR_OK;
-
default:
return SR_ERR_NA;
}
GVariantBuilder gvb;
(void)sdi;
- (void)data;
(void)cg;
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_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;
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;
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);
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));
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;
(void)cg;
- ret = SR_OK;
-
if (!sdi || !(devc = sdi->priv))
return SR_ERR_ARG;
}
}
-/** @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)
{
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;
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;
const uint64_t *vdiv;
int ch_idx;
- (void)cg;
-
switch (key) {
case SR_CONF_NUM_HDIV:
*data = g_variant_new_int32(NUM_TIMEBASE);
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;
(void)cg;
ret = SR_OK;
-
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
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;
ret = SR_ERR_ARG;
} else {
devc->limit_samples = num_samples;
- sr_dbg("setting limit_samples to %i\n",
- num_samples);
ret = SR_OK;
}
break;
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;
/* 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)
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;
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. */
*data = g_variant_new_strv(channel_modes, ARRAY_SIZE(channel_modes));
}
return SR_OK;
- break;
default:
return SR_ERR_NA;
}
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;
if (p_ols_open(devc) != SR_OK) {
return SR_ERR;
} else {
- sdi->status = SR_ST_ACTIVE;
+ sdi->status = SR_ST_ACTIVE;
return SR_OK;
}
}
*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;
}
}
break;
default:
- sr_dbg("Tried to set unknown config key: %d.", key);
- ret = SR_ERR_NA;
- break;
+ return SR_ERR_NA;
}
return ret;
}
break;
default:
- sr_dbg("Tried to list unknown config key: %d.", key);
return SR_ERR_NA;
}
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];
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;
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;
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;
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;
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;
{
struct sr_dev_driver *di = sdi->driver;
struct dev_context *devc;
- int ret;
const char *tmp_str;
(void)cg;
}
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);
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;
struct sr_dev_driver *di = sdi->driver;
struct dev_context *devc;
gint64 now;
- int ret;
(void)cg;
}
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,
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;
}
+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;
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. */
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);
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);
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;
}