drivers: Factor out std_cg_idx().

This commit is contained in:
Uwe Hermann 2017-08-03 23:18:01 +02:00
parent d1ac53ccd5
commit fcd6a8bdf1
6 changed files with 138 additions and 197 deletions

View File

@ -130,7 +130,6 @@ static int dev_close(struct sr_dev_inst *sdi)
static int check_channel_group(struct dev_context *devc, static int check_channel_group(struct dev_context *devc,
const struct sr_channel_group *cg) const struct sr_channel_group *cg)
{ {
unsigned int i;
const struct scope_config *model; const struct scope_config *model;
model = devc->model_config; model = devc->model_config;
@ -138,12 +137,10 @@ static int check_channel_group(struct dev_context *devc,
if (!cg) if (!cg)
return CG_NONE; return CG_NONE;
for (i = 0; i < model->analog_channels; i++) if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) >= 0)
if (cg == devc->analog_groups[i])
return CG_ANALOG; return CG_ANALOG;
for (i = 0; i < model->digital_pods; i++) if (std_cg_idx(cg, devc->digital_groups, model->digital_pods) >= 0)
if (cg == devc->digital_groups[i])
return CG_DIGITAL; return CG_DIGITAL;
sr_err("Invalid channel group specified."); sr_err("Invalid channel group specified.");
@ -154,8 +151,7 @@ static int check_channel_group(struct dev_context *devc,
static int config_get(uint32_t key, GVariant **data, static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int cg_type; int cg_type, idx;
unsigned int i;
struct dev_context *devc; struct dev_context *devc;
const struct scope_config *model; const struct scope_config *model;
struct scope_state *state; struct scope_state *state;
@ -183,12 +179,9 @@ static int config_get(uint32_t key, GVariant **data,
if (cg_type == CG_NONE) { if (cg_type == CG_NONE) {
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type == CG_ANALOG) { } else if (cg_type == CG_ANALOG) {
for (i = 0; i < model->analog_channels; i++) { if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue;
*data = g_variant_new_int32(model->num_ydivs); *data = g_variant_new_int32(model->num_ydivs);
break;
}
} else { } else {
return SR_ERR_NA; return SR_ERR_NA;
} }
@ -197,14 +190,11 @@ static int config_get(uint32_t key, GVariant **data,
if (cg_type == CG_NONE) { if (cg_type == CG_NONE) {
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type == CG_ANALOG) { } else if (cg_type == CG_ANALOG) {
for (i = 0; i < model->analog_channels; i++) { if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
(*model->vdivs)[state->analog_channels[i].vdiv][0], (*model->vdivs)[state->analog_channels[idx].vdiv][0],
(*model->vdivs)[state->analog_channels[i].vdiv][1]); (*model->vdivs)[state->analog_channels[idx].vdiv][1]);
break;
}
} else { } else {
return SR_ERR_NA; return SR_ERR_NA;
} }
@ -222,12 +212,9 @@ static int config_get(uint32_t key, GVariant **data,
if (cg_type == CG_NONE) { if (cg_type == CG_NONE) {
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type == CG_ANALOG) { } else if (cg_type == CG_ANALOG) {
for (i = 0; i < model->analog_channels; i++) { if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue; *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
*data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]);
break;
}
} else { } else {
return SR_ERR_NA; return SR_ERR_NA;
} }
@ -245,8 +232,7 @@ static int config_get(uint32_t key, GVariant **data,
static int config_set(uint32_t key, GVariant *data, static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int ret, cg_type, idx; int ret, cg_type, idx, j;
unsigned int j;
char command[MAX_COMMAND_SIZE], float_str[30]; char command[MAX_COMMAND_SIZE], float_str[30];
struct dev_context *devc; struct dev_context *devc;
const struct scope_config *model; const struct scope_config *model;
@ -287,9 +273,8 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 0; j < model->analog_channels; j++) { if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[j]) return SR_ERR_ARG;
continue;
state->analog_channels[j].vdiv = idx; state->analog_channels[j].vdiv = idx;
g_ascii_formatd(float_str, sizeof(float_str), "%E", g_ascii_formatd(float_str, sizeof(float_str), "%E",
(float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
@ -299,8 +284,6 @@ static int config_set(uint32_t key, GVariant *data,
if (sr_scpi_send(sdi->conn, command) != SR_OK || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break;
}
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
@ -344,9 +327,8 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 0; j <= model->analog_channels; j++) { if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[j]) return SR_ERR_ARG;
continue;
state->analog_channels[j].coupling = idx; state->analog_channels[j].coupling = idx;
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_COUPLING], (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
@ -354,8 +336,6 @@ static int config_set(uint32_t key, GVariant *data,
if (sr_scpi_send(sdi->conn, command) != SR_OK || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break;
}
ret = SR_OK; ret = SR_OK;
break; break;
default: default:

View File

@ -134,7 +134,7 @@ static int dev_close(struct sr_dev_inst *sdi)
static int config_get(uint32_t key, GVariant **data, static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
unsigned int i; int idx;
struct dev_context *devc; struct dev_context *devc;
const struct scope_config *model; const struct scope_config *model;
struct scope_state *state; struct scope_state *state;
@ -158,20 +158,16 @@ static int config_get(uint32_t key, GVariant **data,
(*model->timebases)[state->timebase][1]); (*model->timebases)[state->timebase][1]);
break; break;
case SR_CONF_NUM_VDIV: case SR_CONF_NUM_VDIV:
for (i = 0; i < model->analog_channels; i++) { if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue;
*data = g_variant_new_int32(model->num_ydivs); *data = g_variant_new_int32(model->num_ydivs);
}
break; break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
for (i = 0; i < model->analog_channels; i++) { if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
(*model->vdivs)[state->analog_channels[i].vdiv][0], (*model->vdivs)[state->analog_channels[idx].vdiv][0],
(*model->vdivs)[state->analog_channels[i].vdiv][1]); (*model->vdivs)[state->analog_channels[idx].vdiv][1]);
}
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
*data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
@ -183,11 +179,9 @@ static int config_get(uint32_t key, GVariant **data,
*data = g_variant_new_double(state->horiz_triggerpos); *data = g_variant_new_double(state->horiz_triggerpos);
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
for (i = 0; i < model->analog_channels; i++) { if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue; *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
*data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]);
}
break; break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(state->sample_rate); *data = g_variant_new_uint64(state->sample_rate);
@ -205,8 +199,7 @@ static int config_get(uint32_t key, GVariant **data,
static int config_set(uint32_t key, GVariant *data, static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int ret, idx; int ret, idx, j;
unsigned int j;
char command[MAX_COMMAND_SIZE]; char command[MAX_COMMAND_SIZE];
struct dev_context *devc; struct dev_context *devc;
const struct scope_config *model; const struct scope_config *model;
@ -241,17 +234,14 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_VDIV: case SR_CONF_VDIV:
if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 0; j < model->analog_channels; j++) { if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[j]) return SR_ERR_ARG;
continue;
state->analog_channels[j].vdiv = idx; state->analog_channels[j].vdiv = idx;
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
"C%d:VDIV %E", j + 1, (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); "C%d:VDIV %E", j + 1, (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
if (sr_scpi_send(sdi->conn, command) != SR_OK || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break;
}
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
@ -290,17 +280,14 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 0; j < model->analog_channels; j++) { if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[j]) return SR_ERR_ARG;
continue;
state->analog_channels[j].coupling = idx; state->analog_channels[j].coupling = idx;
g_snprintf(command, sizeof(command), "C%d:COUPLING %s", g_snprintf(command, sizeof(command), "C%d:COUPLING %s",
j + 1, (*model->coupling_options)[idx]); j + 1, (*model->coupling_options)[idx]);
if (sr_scpi_send(sdi->conn, command) != SR_OK || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break;
}
ret = SR_OK; ret = SR_OK;
break; break;
default: default:

View File

@ -619,8 +619,7 @@ static int config_set(uint32_t key, GVariant *data,
struct dev_context *devc; struct dev_context *devc;
uint64_t p; uint64_t p;
double t_dbl; double t_dbl;
unsigned int i; int ret, idx, i;
int ret, idx;
const char *tmp_str; const char *tmp_str;
char buffer[16]; char buffer[16];
@ -689,52 +688,36 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_VDIV: case SR_CONF_VDIV:
if (!cg) if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
for (i = 0; i < devc->model->analog_channels; i++) { if ((i = std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels)) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue;
if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0) if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
devc->vdiv[i] = (float)vdivs[idx][0] / vdivs[idx][1]; devc->vdiv[i] = (float)vdivs[idx][0] / vdivs[idx][1];
g_ascii_formatd(buffer, sizeof(buffer), "%.3f", g_ascii_formatd(buffer, sizeof(buffer), "%.3f", devc->vdiv[i]);
devc->vdiv[i]); return rigol_ds_config_set(sdi, ":CHAN%d:SCAL %s", i + 1, buffer);
return rigol_ds_config_set(sdi, ":CHAN%d:SCAL %s", i + 1,
buffer);
}
sr_dbg("Didn't set vdiv, unknown channel(group).");
return SR_ERR_NA;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (!cg) if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
for (i = 0; i < devc->model->analog_channels; i++) { if ((i = std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels)) < 0)
if (cg != devc->analog_groups[i]) return SR_ERR_ARG;
continue;
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0) if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
g_free(devc->coupling[i]); g_free(devc->coupling[i]);
devc->coupling[i] = g_strdup(coupling[idx]); devc->coupling[i] = g_strdup(coupling[idx]);
return rigol_ds_config_set(sdi, ":CHAN%d:COUP %s", i + 1, return rigol_ds_config_set(sdi, ":CHAN%d:COUP %s", i + 1, devc->coupling[i]);
devc->coupling[i]);
}
sr_dbg("Didn't set coupling, unknown channel(group).");
return SR_ERR_NA;
case SR_CONF_PROBE_FACTOR: case SR_CONF_PROBE_FACTOR:
if (!cg) if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
p = g_variant_get_uint64(data); if ((i = std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels)) < 0)
for (i = 0; i < devc->model->analog_channels; i++) { return SR_ERR_ARG;
if (cg != devc->analog_groups[i])
continue;
if ((idx = std_u64_idx(data, ARRAY_AND_SIZE(probe_factor))) < 0) if ((idx = std_u64_idx(data, ARRAY_AND_SIZE(probe_factor))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
p = g_variant_get_uint64(data);
devc->attenuation[i] = probe_factor[idx]; devc->attenuation[i] = probe_factor[idx];
ret = rigol_ds_config_set(sdi, ":CHAN%d:PROB %"PRIu64, ret = rigol_ds_config_set(sdi, ":CHAN%d:PROB %"PRIu64, i + 1, p);
i + 1, p);
if (ret == SR_OK) if (ret == SR_OK)
rigol_ds_get_dev_cfg_vertical(sdi); rigol_ds_get_dev_cfg_vertical(sdi);
return ret; return ret;
}
sr_dbg("Didn't set probe factor, unknown channel(group).");
return SR_ERR_NA;
case SR_CONF_DATA_SOURCE: case SR_CONF_DATA_SOURCE:
tmp_str = g_variant_get_string(data, NULL); tmp_str = g_variant_get_string(data, NULL);
if (!strcmp(tmp_str, "Live")) if (!strcmp(tmp_str, "Live"))
@ -760,7 +743,6 @@ static int config_set(uint32_t key, GVariant *data,
static int config_list(uint32_t key, GVariant **data, static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
unsigned int i;
struct dev_context *devc; struct dev_context *devc;
devc = (sdi) ? sdi->priv : NULL; devc = (sdi) ? sdi->priv : NULL;
@ -774,14 +756,11 @@ static int config_list(uint32_t key, GVariant **data,
*data = std_gvar_array_u32(NULL, 0); *data = std_gvar_array_u32(NULL, 0);
return SR_OK; return SR_OK;
} else { } else {
for (i = 0; i < devc->model->analog_channels; i++) { if (std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels) < 0)
if (cg == devc->analog_groups[i]) { return SR_ERR_ARG;
*data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog)); *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog));
return SR_OK; return SR_OK;
} }
}
return SR_ERR_NA;
}
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (!cg) if (!cg)

View File

@ -162,7 +162,6 @@ static int dev_close(struct sr_dev_inst *sdi)
static int check_channel_group(struct dev_context *devc, static int check_channel_group(struct dev_context *devc,
const struct sr_channel_group *cg) const struct sr_channel_group *cg)
{ {
unsigned int i;
const struct scope_config *model; const struct scope_config *model;
model = devc->model_config; model = devc->model_config;
@ -170,23 +169,21 @@ static int check_channel_group(struct dev_context *devc,
if (!cg) if (!cg)
return CG_NONE; return CG_NONE;
for (i = 0; i < model->analog_channels; i++) if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) >= 0)
if (cg == devc->analog_groups[i])
return CG_ANALOG; return CG_ANALOG;
for (i = 0; i < model->pods; i++) if (std_cg_idx(cg, devc->digital_groups, model->pods) >= 0)
if (cg == devc->digital_groups[i])
return CG_DIGITAL; return CG_DIGITAL;
sr_err("Invalid channel group specified."); sr_err("Invalid channel group specified.");
return CG_INVALID; return CG_INVALID;
} }
static int config_get(uint32_t key, GVariant **data, static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int ret, cg_type; int ret, cg_type, idx;
unsigned int i;
struct dev_context *devc; struct dev_context *devc;
const struct scope_config *model; const struct scope_config *model;
struct scope_state *state; struct scope_state *state;
@ -230,17 +227,13 @@ static int config_get(uint32_t key, GVariant **data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type != CG_ANALOG) } else if (cg_type != CG_ANALOG)
break; break;
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
for (i = 0; i < model->analog_channels; i++) { return SR_ERR_ARG;
if (cg != devc->analog_groups[i])
continue;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
dlm_vdivs[state->analog_states[i].vdiv][0], dlm_vdivs[state->analog_states[idx].vdiv][0],
dlm_vdivs[state->analog_states[i].vdiv][1]); dlm_vdivs[state->analog_states[idx].vdiv][1]);
ret = SR_OK; ret = SR_OK;
break; break;
}
break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
*data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
ret = SR_OK; ret = SR_OK;
@ -259,15 +252,11 @@ static int config_get(uint32_t key, GVariant **data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type != CG_ANALOG) } else if (cg_type != CG_ANALOG)
break; break;
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
for (i = 0; i < model->analog_channels; i++) { return SR_ERR_ARG;
if (cg != devc->analog_groups[i]) *data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]);
continue;
*data = g_variant_new_string((*model->coupling_options)[state->analog_states[i].coupling]);
ret = SR_OK; ret = SR_OK;
break; break;
}
break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(state->sample_rate); *data = g_variant_new_uint64(state->sample_rate);
ret = SR_OK; ret = SR_OK;
@ -282,8 +271,7 @@ static int config_get(uint32_t key, GVariant **data,
static int config_set(uint32_t key, GVariant *data, static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int ret, cg_type, idx; int ret, cg_type, idx, j;
unsigned int j;
char float_str[30]; char float_str[30];
struct dev_context *devc; struct dev_context *devc;
const struct scope_config *model; const struct scope_config *model;
@ -320,17 +308,14 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_vdivs))) < 0) if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_vdivs))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 0; j < model->analog_channels; j++) { if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[j]) return SR_ERR_ARG;
continue;
state->analog_states[j].vdiv = idx; state->analog_states[j].vdiv = idx;
g_ascii_formatd(float_str, sizeof(float_str), g_ascii_formatd(float_str, sizeof(float_str),
"%E", (float) dlm_vdivs[idx][0] / dlm_vdivs[idx][1]); "%E", (float) dlm_vdivs[idx][0] / dlm_vdivs[idx][1]);
if (dlm_analog_chan_vdiv_set(sdi->conn, j + 1, float_str) != SR_OK || if (dlm_analog_chan_vdiv_set(sdi->conn, j + 1, float_str) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break;
}
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
@ -370,15 +355,12 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 0; j <= model->analog_channels; j++) { if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
if (cg != devc->analog_groups[j]) return SR_ERR_ARG;
continue;
state->analog_states[j].coupling = idx; state->analog_states[j].coupling = idx;
if (dlm_analog_chan_coupl_set(sdi->conn, j + 1, (*model->coupling_options)[idx]) != SR_OK || if (dlm_analog_chan_coupl_set(sdi->conn, j + 1, (*model->coupling_options)[idx]) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break;
}
ret = SR_OK; ret = SR_OK;
break; break;
default: default:

View File

@ -984,6 +984,8 @@ SR_PRIV int std_u64_tuple_idx(GVariant *data, const uint64_t a[][2], unsigned in
SR_PRIV int std_double_tuple_idx(GVariant *data, const double a[][2], unsigned int n); SR_PRIV int std_double_tuple_idx(GVariant *data, const double a[][2], unsigned int n);
SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigned int n); SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigned int n);
SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_group *a[], unsigned int n);
/*--- resource.c ------------------------------------------------------------*/ /*--- resource.c ------------------------------------------------------------*/
SR_PRIV int64_t sr_file_get_size(FILE *file); SR_PRIV int64_t sr_file_get_size(FILE *file);

View File

@ -828,3 +828,14 @@ SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigne
return -1; return -1;
} }
SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_group *a[], unsigned int n)
{
unsigned int i;
for (i = 0; i < n; i++)
if (cg == a[i])
return i;
return -1;
}