static const int32_t analog_hwcaps[] = {
SR_CONF_NUM_VDIV,
SR_CONF_VDIV,
- SR_CONF_COUPLING
+ SR_CONF_COUPLING,
};
static const uint64_t timebases[][2] = {
{
struct dev_context *devc;
- for (l = drvc->instances; l; l = l->next) {
- if (!(sdi = l->data))
- continue;
-
- if (sdi->conn)
- sr_serial_dev_inst_free(sdi->conn);
-
- g_slist_free(sdi->probe_groups);
-
- if (!(devc = sdi->priv))
- continue;
-
- g_free(devc->coupling[0]);
- g_free(devc->coupling[1]);
- g_free(devc->trigger_source);
- g_free(devc->trigger_slope);
- g_slist_free(devc->analog_groups[0].probes);
- g_slist_free(devc->analog_groups[1].probes);
- g_slist_free(devc->digital_group.probes);
-
- sr_dev_inst_free(sdi);
- }
-
+ devc = priv;
g_free(devc->coupling[0]);
g_free(devc->coupling[1]);
g_free(devc->trigger_source);
g_free(devc->trigger_slope);
+ g_slist_free(devc->analog_groups[0].probes);
+ g_slist_free(devc->analog_groups[1].probes);
+ g_slist_free(devc->digital_group.probes);
}
static int dev_clear(void)
if (!sdi || !(devc = sdi->priv))
return SR_ERR_ARG;
+ /* If a probe group is specified, it must be a valid one. */
+ if (probe_group) {
+ if (probe_group != &devc->analog_groups[0]
+ && probe_group != &devc->analog_groups[1]) {
+ sr_err("Invalid probe group specified.");
+ return SR_ERR;
+ }
+ }
+
switch (id) {
case SR_CONF_NUM_TIMEBASE:
*data = g_variant_new_int32(NUM_TIMEBASE);
break;
case SR_CONF_NUM_VDIV:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
for (i = 0; i < 2; i++) {
if (probe_group == &devc->analog_groups[i]) {
*data = g_variant_new_int32(NUM_VDIV);
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
+ /* If a probe group is specified, it must be a valid one. */
+ if (probe_group) {
+ if (probe_group != &devc->analog_groups[0]
+ && probe_group != &devc->analog_groups[1]) {
+ sr_err("Invalid probe group specified.");
+ return SR_ERR;
+ }
+ }
+
ret = SR_OK;
switch (id) {
case SR_CONF_LIMIT_FRAMES:
ret = SR_ERR_ARG;
break;
case SR_CONF_VDIV:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < 2; i++) {
- if (probe_group == &devc->analog_groups[i])
- {
- for (j = 0; j < ARRAY_SIZE(vdivs); j++)
- {
+ if (probe_group == &devc->analog_groups[i]) {
+ for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
if (vdivs[j][0] != p || vdivs[j][1] != q)
continue;
devc->vdiv[i] = (float)p / q;
}
return SR_ERR_NA;
case SR_CONF_COUPLING:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
tmp_str = g_variant_get_string(data, NULL);
for (i = 0; i < 2; i++) {
- if (probe_group == &devc->analog_groups[i])
- {
- for (j = 0; j < ARRAY_SIZE(coupling); j++)
- {
- if (!strcmp(tmp_str, coupling[j]))
- {
+ if (probe_group == &devc->analog_groups[i]) {
+ for (j = 0; j < ARRAY_SIZE(coupling); j++) {
+ if (!strcmp(tmp_str, coupling[j])) {
g_free(devc->coupling[i]);
devc->coupling[i] = g_strdup(coupling[j]);
return set_cfg(sdi, ":CHAN%d:COUP %s", i + 1,
if (!sdi || !(devc = sdi->priv))
return SR_ERR_ARG;
+ /* If a probe group is specified, it must be a valid one. */
+ if (probe_group) {
+ if (probe_group != &devc->analog_groups[0]
+ && probe_group != &devc->analog_groups[1]) {
+ sr_err("Invalid probe group specified.");
+ return SR_ERR;
+ }
+ }
+
switch (key) {
break;
case SR_CONF_DEVICE_OPTIONS:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
if (probe_group == &devc->digital_group) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
NULL, 0, sizeof(int32_t));
}
return SR_ERR_NA;
}
+ break;
case SR_CONF_COUPLING:
- for (i = 0; i < 2; i++) {
- if (probe_group == &devc->analog_groups[i]) {
- *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
- return SR_OK;
- }
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
}
- return SR_ERR_NA;
+ *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
+ break;
case SR_CONF_VDIV:
- for (i = 0; i < 2; i++) {
- if (probe_group == &devc->analog_groups[i]) {
- rational[0] = g_variant_new_uint64(vdivs[i][0]);
- rational[1] = g_variant_new_uint64(vdivs[i][1]);
- *data = g_variant_new_tuple(rational, 2);
- return SR_OK;
- }
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
}
- return SR_ERR_NA;
+ g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+ for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
+ rational[0] = g_variant_new_uint64(vdivs[i][0]);
+ rational[1] = g_variant_new_uint64(vdivs[i][1]);
+ tuple = g_variant_new_tuple(rational, 2);
+ g_variant_builder_add_value(&gvb, tuple);
+ }
+ *data = g_variant_builder_end(&gvb);
+ break;
case SR_CONF_TIMEBASE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(timebases); i++) {