From: Aurelien Jacobs Date: Sun, 22 Feb 2015 23:32:01 +0000 (+0100) Subject: rigol-ds: add PROBE_FACTOR support. X-Git-Tag: libsigrok-0.5.0~301 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=934cf6cf5078f01517da303f21ed2ffee9b878f3;p=libsigrok.git rigol-ds: add PROBE_FACTOR support. --- diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 4d105381..d21cff7d 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -53,6 +53,7 @@ static const uint32_t analog_devopts[] = { SR_CONF_NUM_VDIV | SR_CONF_GET, SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; static const uint64_t timebases[][2] = { @@ -160,6 +161,19 @@ static const char *coupling[] = { "GND", }; +static const uint64_t probe_factor[] = { + 1, + 2, + 5, + 10, + 20, + 50, + 100, + 200, + 500, + 1000, +}; + /* Do not change the order of entries */ static const char *data_sources[] = { "Live", @@ -616,6 +630,13 @@ 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; + case SR_CONF_PROBE_FACTOR: + if (analog_channel < 0) { + sr_dbg("Negative analog channel: %d.", analog_channel); + return SR_ERR_NA; + } + *data = g_variant_new_uint64(devc->attenuation[analog_channel]); + break; default: return SR_ERR_NA; } @@ -764,6 +785,30 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd } sr_dbg("Didn't set coupling, unknown channel(group)."); return SR_ERR_NA; + case SR_CONF_PROBE_FACTOR: + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; + } + p = g_variant_get_uint64(data); + for (i = 0; i < devc->model->analog_channels; i++) { + if (cg == devc->analog_groups[i]) { + for (j = 0; j < ARRAY_SIZE(probe_factor); j++) { + if (p == probe_factor[j]) { + devc->attenuation[i] = p; + ret = rigol_ds_config_set(sdi, ":CHAN%d:PROB %"PRIu64, + i + 1, p); + if (ret == SR_OK) + rigol_ds_get_dev_cfg_vertical(sdi); + return ret; + } + } + sr_err("Invalid probe factor: %"PRIu64".", p); + return SR_ERR_ARG; + } + } + sr_dbg("Didn't set probe factor, unknown channel(group)."); + return SR_ERR_NA; case SR_CONF_DATA_SOURCE: tmp_str = g_variant_get_string(data, NULL); if (!strcmp(tmp_str, "Live")) @@ -843,6 +888,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling)); break; + case SR_CONF_PROBE_FACTOR: + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; + } + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, + probe_factor, ARRAY_SIZE(probe_factor), sizeof(uint64_t)); + break; case SR_CONF_VDIV: if (!devc) /* Can't know this until we have the exact model. */ diff --git a/src/hardware/rigol-ds/protocol.c b/src/hardware/rigol-ds/protocol.c index 140963a8..0a60957c 100644 --- a/src/hardware/rigol-ds/protocol.c +++ b/src/hardware/rigol-ds/protocol.c @@ -813,6 +813,18 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) return SR_ERR; sr_dbg("Current timebase %g", devc->timebase); + /* Probe attenuation. */ + for (i = 0; i < devc->model->analog_channels; i++) { + cmd = g_strdup_printf(":CHAN%d:PROB?", i + 1); + res = sr_scpi_get_float(sdi->conn, cmd, &devc->attenuation[i]); + g_free(cmd); + if (res != SR_OK) + return SR_ERR; + } + sr_dbg("Current probe attenuation:"); + for (i = 0; i < devc->model->analog_channels; i++) + sr_dbg("CH%d %g", i + 1, devc->attenuation[i]); + /* Vertical gain and offset. */ if (rigol_ds_get_dev_cfg_vertical(sdi) != SR_OK) return SR_ERR; diff --git a/src/hardware/rigol-ds/protocol.h b/src/hardware/rigol-ds/protocol.h index 787adffb..cdf43f8b 100644 --- a/src/hardware/rigol-ds/protocol.h +++ b/src/hardware/rigol-ds/protocol.h @@ -117,6 +117,7 @@ struct dev_context { gboolean digital_channels[MAX_DIGITAL_CHANNELS]; gboolean la_enabled; float timebase; + float attenuation[MAX_ANALOG_CHANNELS]; float vdiv[MAX_ANALOG_CHANNELS]; int vert_reference[MAX_ANALOG_CHANNELS]; float vert_offset[MAX_ANALOG_CHANNELS];