]> sigrok.org Git - libsigrok.git/commitdiff
rigol-ds: add PROBE_FACTOR support.
authorAurelien Jacobs <redacted>
Sun, 22 Feb 2015 23:32:01 +0000 (00:32 +0100)
committerAurelien Jacobs <redacted>
Sat, 25 Jun 2016 15:24:45 +0000 (17:24 +0200)
src/hardware/rigol-ds/api.c
src/hardware/rigol-ds/protocol.c
src/hardware/rigol-ds/protocol.h

index 4d105381bc38dba1759cb2ba0f932eeea3865e72..d21cff7d34c511383f69cacd4149434fa94cc13e 100644 (file)
@@ -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. */
index 140963a8a78e421f91cc7fa455c78bb821fd5c2d..0a60957cf1eff338b3deeea18ee35e3ac8885e01 100644 (file)
@@ -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;
index 787adffbbddee1d4a581aa8b6b3a1b50dba460e4..cdf43f8b2a9f883ca6b454ecd69714b3016aff91 100644 (file)
@@ -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];