+ state->high_resolution = tmp_bool;
+ ret = SR_OK;
+ break;
+ case SR_CONF_PEAK_DETECTION:
+ tmp_bool = g_variant_get_boolean(data);
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
+ tmp_bool ? "AUTO" : "OFF");
+ if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+ sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;
+ /* Peak Detection automatically switches off High Resolution mode. */
+ if (tmp_bool) {
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
+ "OFF");
+ if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+ sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;
+ state->high_resolution = FALSE;
+ }
+ state->peak_detection = tmp_bool;
+ ret = SR_OK;
+ break;
+ case SR_CONF_COUPLING:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
+ return SR_ERR_ARG;
+ if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
+ return SR_ERR_ARG;
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
+ j + 1, (*model->coupling_options)[idx]);
+ if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+ sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;
+ state->analog_channels[j].coupling = idx;
+ ret = SR_OK;
+ break;
+ case SR_CONF_LOGIC_THRESHOLD:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ if (cg_type != CG_DIGITAL)
+ return SR_ERR_NA;
+ if (!model)
+ return SR_ERR_ARG;
+ if ((idx = std_str_idx(data, *model->logic_threshold, model->num_logic_threshold)) < 0)
+ return SR_ERR_ARG;
+ if ((j = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
+ return SR_ERR_ARG;
+ /* Check if the threshold command is based on the POD or digital channel index. */
+ if (model->logic_threshold_for_pod)
+ i = j + 1;
+ else
+ i = j * DIGITAL_CHANNELS_PER_POD;
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
+ i, (*model->logic_threshold)[idx]);
+ if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+ sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;
+ state->digital_pods[j].threshold = idx;
+ ret = SR_OK;
+ break;
+ case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ if (cg_type != CG_DIGITAL)
+ return SR_ERR_NA;
+ if (!model)
+ return SR_ERR_ARG;
+ if ((j = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
+ return SR_ERR_ARG;
+ tmp_d = g_variant_get_double(data);
+ if (tmp_d < -2.0 || tmp_d > 8.0)
+ return SR_ERR;
+ g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
+ /* Check if the threshold command is based on the POD or digital channel index. */
+ if (model->logic_threshold_for_pod)
+ idx = j + 1;
+ else
+ idx = j * DIGITAL_CHANNELS_PER_POD;
+ /* Try to support different dialects exhaustively. */
+ for (i = 0; i < model->num_logic_threshold; i++) {
+ if (!strcmp("USER2", (*model->logic_threshold)[i])) {
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
+ idx, 2, float_str); /* USER2 */
+ g_snprintf(command2, sizeof(command2),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
+ idx, "USER2");
+ break;
+ }
+ if (!strcmp("USER", (*model->logic_threshold)[i])) {
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
+ idx, float_str);
+ g_snprintf(command2, sizeof(command2),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
+ idx, "USER");
+ break;
+ }
+ if (!strcmp("MAN", (*model->logic_threshold)[i])) {
+ g_snprintf(command, sizeof(command),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
+ idx, float_str);
+ g_snprintf(command2, sizeof(command2),
+ (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
+ idx, "MAN");
+ break;
+ }
+ }
+ if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+ sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;
+ if (sr_scpi_send(sdi->conn, command2) != SR_OK ||
+ sr_scpi_get_opc(sdi->conn) != SR_OK)
+ return SR_ERR;
+ state->digital_pods[j].user_threshold = tmp_d;