]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds/api.c
rigol-ds: Separate function to compute analog frame size.
[libsigrok.git] / hardware / rigol-ds / api.c
index 9007ea18d0b70c51e534f24e1fb354df25269755..ec67d22d9372c1b3f33bb8310d2cd146089eb189 100644 (file)
@@ -40,6 +40,7 @@ static const int32_t hwcaps[] = {
        SR_CONF_TRIGGER_SLOPE,
        SR_CONF_HORIZ_TRIGGERPOS,
        SR_CONF_NUM_TIMEBASE,
+       SR_CONF_LIMIT_FRAMES,
 };
 
 static const int32_t analog_hwcaps[] = {
@@ -246,10 +247,6 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev
 {
        struct dev_context *devc;
        struct sr_dev_inst *sdi;
-       const char *usbtmc_prefix = "/dev/usbtmc";
-       const char *tcp_prefix = "tcp/";
-       const char *vxi_prefix = "vxi/";
-       gchar **tokens, *address, *port, *instrument;
        struct sr_scpi_dev_inst *scpi;
        struct sr_scpi_hw_info *hw_info;
        struct sr_probe *probe;
@@ -259,43 +256,8 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev
 
        *devices = NULL;
 
-       if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
-               sr_dbg("Opening USBTMC device %s.", resource);
-               if (!(scpi = scpi_usbtmc_dev_inst_new(resource)))
-                       return SR_ERR_MALLOC;
-       } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
-               sr_dbg("Opening TCP connection %s.", resource);
-               tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
-               address = tokens[0];
-               port = tokens[1];
-               if (!address || !port || tokens[2]) {
-                       sr_err("Invalid parameters.");
-                       g_strfreev(tokens);
-                       return SR_ERR_ARG;
-               }
-               scpi = scpi_tcp_dev_inst_new(address, port);
-               g_strfreev(tokens);
-               if (!scpi)
-                       return SR_ERR_MALLOC;
-       } else if (HAVE_RPC && !strncmp(resource, vxi_prefix, strlen(vxi_prefix))) {
-               sr_dbg("Opening VXI connection %s.", resource);
-               tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
-               address = tokens[0];
-               instrument = tokens[1];
-               if (!address) {
-                       sr_err("Invalid parameters.");
-                       g_strfreev(tokens);
-                       return SR_ERR_ARG;
-               }
-               scpi = scpi_vxi_dev_inst_new(address, instrument);
-               g_strfreev(tokens);
-               if (!scpi)
-                       return SR_ERR_MALLOC;
-       } else {
-               sr_dbg("Opening serial device %s.", resource);
-               if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm)))
-                       return SR_ERR_MALLOC;
-       }
+       if (!(scpi = scpi_dev_inst_new(resource, serialcomm)))
+               return SR_ERR;
 
        if (sr_scpi_open(scpi) != SR_OK) {
                sr_info("Couldn't open SCPI device.");
@@ -494,6 +456,38 @@ static int cleanup(void)
        return dev_clear();
 }
 
+static int analog_frame_size(const struct sr_dev_inst *sdi)
+{
+       struct dev_context *devc = sdi->priv;
+       struct sr_probe *probe;
+       int analog_probes = 0;
+       GSList *l;
+
+       if (devc->model->protocol == PROTOCOL_LEGACY) {
+               if (devc->model->series == RIGOL_VS5000)
+                       return VS5000_ANALOG_LIVE_WAVEFORM_SIZE;
+               else
+                       return DS1000_ANALOG_LIVE_WAVEFORM_SIZE;
+       } else {
+               for (l = sdi->probes; l; l = l->next) {
+                       probe = l->data;
+                       if (probe->type == SR_PROBE_ANALOG && probe->enabled)
+                               analog_probes++;
+               }
+               if (devc->data_source == DATA_SOURCE_MEMORY) {
+                       if (analog_probes == 1)
+                               return DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C;
+                       else
+                               return DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C;
+               } else {
+                       if (devc->model->series == AGILENT_DSO1000)
+                               return DSO1000_ANALOG_LIVE_WAVEFORM_SIZE;
+                       else
+                               return DS2000_ANALOG_LIVE_WAVEFORM_SIZE;
+               }
+       }
+}
+
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_probe_group *probe_group)
 {
@@ -503,12 +497,10 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
                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;
-               }
+       if (probe_group && !g_slist_find(sdi->probe_groups, probe_group))
+       {
+               sr_err("Invalid probe group specified.");
+               return SR_ERR;
        }
 
        switch (id) {
@@ -549,12 +541,10 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                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;
-               }
+       if (probe_group && !g_slist_find(sdi->probe_groups, probe_group))
+       {
+               sr_err("Invalid probe group specified.");
+               return SR_ERR;
        }
 
        ret = SR_OK;
@@ -711,7 +701,6 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        }
 
        switch (key) {
-               break;
        case SR_CONF_DEVICE_OPTIONS:
                if (!probe_group) {
                        sr_err("No probe group specified.");
@@ -760,6 +749,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                if (!devc)
                        /* Can't know this until we have the exact model. */
                        return SR_ERR_ARG;
+               if (devc->num_timebases <= 0)
+                       return SR_ERR_NA;
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                for (i = 0; i < devc->num_timebases; i++) {
                        rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
@@ -858,10 +849,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        else
                devc->channel_entry = devc->enabled_digital_probes;
 
+       devc->analog_frame_size = analog_frame_size(sdi);
+
        if (devc->model->protocol == PROTOCOL_LEGACY) {
-               devc->analog_frame_size = (devc->model->series == RIGOL_VS5000 ?
-                               VS5000_ANALOG_LIVE_WAVEFORM_SIZE :
-                               DS1000_ANALOG_LIVE_WAVEFORM_SIZE);
                /* Fetch the first frame. */
                if (rigol_ds_channel_start(sdi) != SR_OK)
                        return SR_ERR;
@@ -869,10 +859,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                if (devc->enabled_analog_probes) {
                        if (devc->data_source == DATA_SOURCE_MEMORY)
                        {
-                               if (g_slist_length(devc->enabled_analog_probes) == 1)
-                                       devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C;
-                               else
-                                       devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C;
                                /* Apparently for the DS2000 the memory
                                 * depth can only be set in Running state -
                                 * this matches the behaviour of the UI. */
@@ -882,11 +868,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                                        return SR_ERR;
                                if (set_cfg(sdi, ":STOP") != SR_OK)
                                        return SR_ERR;
-                       } else {
-                               if (devc->model->series == AGILENT_DSO1000)
-                                       devc->analog_frame_size = DSO1000_ANALOG_LIVE_WAVEFORM_SIZE;
-                               else
-                                       devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE;
                        }
                        if (rigol_ds_capture_start(sdi) != SR_OK)
                                return SR_ERR;