]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds/protocol.c
Rename 'struct sr_probe' to 'struct sr_channel' everywhere.
[libsigrok.git] / hardware / rigol-ds / protocol.c
index de91e0709a877db19e230e54c8239216f5f19f25..d609b06079dd14bc9a29c0a7535e4467fc4eb471 100644 (file)
@@ -207,7 +207,7 @@ static int rigol_ds_stop_wait(const struct sr_dev_inst *sdi)
 static int rigol_ds_check_stop(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
-       struct sr_probe *probe;
+       struct sr_channel *probe;
        int tmp;
 
        if (!(devc = sdi->priv))
@@ -261,29 +261,32 @@ static int rigol_ds_block_wait(const struct sr_dev_inst *sdi)
        if (!(devc = sdi->priv))
                return SR_ERR;
 
-       start = time(NULL);
+       if (devc->model->series->protocol >= PROTOCOL_V3) {
 
-       do {
-               if (time(NULL) - start >= 3) {
-                       sr_dbg("Timeout waiting for data block");
-                       return SR_ERR_TIMEOUT;
-               }
+               start = time(NULL);
 
-               /*
-                * The scope copies data really slowly from sample
-                * memory to its output buffer, so try not to bother
-                * it too much with SCPI requests but don't wait too
-                * long for short sample frame sizes.
-                */
-               g_usleep(devc->analog_frame_size < 15000 ? 100000 : 1000000);
+               do {
+                       if (time(NULL) - start >= 3) {
+                               sr_dbg("Timeout waiting for data block");
+                               return SR_ERR_TIMEOUT;
+                       }
 
-               /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */
-               if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK)
-                       return SR_ERR;
+                       /*
+                        * The scope copies data really slowly from sample
+                        * memory to its output buffer, so try not to bother
+                        * it too much with SCPI requests but don't wait too
+                        * long for short sample frame sizes.
+                        */
+                       g_usleep(devc->analog_frame_size < 15000 ? 100000 : 1000000);
 
-               if (parse_int(buf + 5, &len) != SR_OK)
-                       return SR_ERR;
-       } while (buf[0] == 'R' && len < 1000000);
+                       /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */
+                       if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK)
+                               return SR_ERR;
+
+                       if (parse_int(buf + 5, &len) != SR_OK)
+                               return SR_ERR;
+               } while (buf[0] == 'R' && len < 1000000);
+       }
 
        rigol_ds_set_wait_event(devc, WAIT_NONE);
 
@@ -373,7 +376,7 @@ SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
 SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
-       struct sr_probe *probe;
+       struct sr_channel *probe;
 
        if (!(devc = sdi->priv))
                return SR_ERR;
@@ -419,18 +422,18 @@ static int rigol_ds_read_header(struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi = sdi->conn;
        struct dev_context *devc = sdi->priv;
        char *buf = (char *) devc->buffer;
-       int len;
-       int tmp;
+       size_t header_length;
+       int ret;
 
        /* Try to read the hashsign and length digit. */
        if (devc->num_header_bytes < 2) {
-               tmp = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
+               ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
                                2 - devc->num_header_bytes);
-               if (tmp < 0) {
+               if (ret < 0) {
                        sr_err("Read error while reading data header.");
                        return SR_ERR;
                }
-               devc->num_header_bytes += tmp;
+               devc->num_header_bytes += ret;
        }
 
        if (devc->num_header_bytes < 2)
@@ -441,33 +444,33 @@ static int rigol_ds_read_header(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       len = buf[1] - '0';
+       header_length = 2 + buf[1] - '0';
 
        /* Try to read the length. */
-       if (devc->num_header_bytes < 2 + len) {
-               tmp = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
-                               2 + len - devc->num_header_bytes);
-               if (tmp < 0) {
+       if (devc->num_header_bytes < header_length) {
+               ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
+                               header_length - devc->num_header_bytes);
+               if (ret < 0) {
                        sr_err("Read error while reading data header.");
                        return SR_ERR;
                }
-               devc->num_header_bytes += tmp;
+               devc->num_header_bytes += ret;
        }
 
-       if (devc->num_header_bytes < 2 + len)
+       if (devc->num_header_bytes < header_length)
                return 0;
 
        /* Read the data length. */
-       buf[2 + len] = '\0';
+       buf[header_length] = '\0';
 
-       if (parse_int(buf + 2, &len) != SR_OK) {
+       if (parse_int(buf + 2, &ret) != SR_OK) {
                sr_err("Received invalid data block length '%s'.", buf + 2);
                return -1;
        }
 
-       sr_dbg("Received data block header: '%s' -> block length %d", buf, len);
+       sr_dbg("Received data block header: '%s' -> block length %d", buf, ret);
 
-       return len;
+       return ret;
 }
 
 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
@@ -480,7 +483,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
        struct sr_datafeed_logic logic;
        double vdiv, offset;
        int len, i, vref;
-       struct sr_probe *probe;
+       struct sr_channel *probe;
        gsize expected_data_bytes;
 
        (void)fd;
@@ -502,7 +505,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                                return TRUE;
                        if (rigol_ds_channel_start(sdi) != SR_OK)
                                return TRUE;
-                       break;
+                       return TRUE;
                case WAIT_BLOCK:
                        if (rigol_ds_block_wait(sdi) != SR_OK)
                                return TRUE;