]> sigrok.org Git - libsigrok.git/commitdiff
rigol-ds: Cleanup and fix check for short data blocks.
authorMartin Ling <redacted>
Fri, 17 Jan 2014 14:46:10 +0000 (14:46 +0000)
committerMartin Ling <redacted>
Mon, 20 Jan 2014 00:24:57 +0000 (00:24 +0000)
hardware/rigol-ds/protocol.c

index 4b18530eba2da0949eb06de7591645aea551a67a..4a3f80eb6b2d1adc594c72287f4e8d034af1a7ca 100644 (file)
@@ -404,6 +404,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
        double vdiv, offset;
        int len, i, vref;
        struct sr_probe *probe;
+       gsize expected_data_bytes;
 
        (void)fd;
 
@@ -444,6 +445,9 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                }
 
                probe = devc->channel_entry->data;
+
+               expected_data_bytes = probe->type == SR_PROBE_ANALOG ?
+                               devc->analog_frame_size : devc->digital_frame_size;
                
                if (devc->num_block_bytes == 0 &&
                    devc->model->series >= RIGOL_DS1000Z) {
@@ -452,8 +456,10 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                }
 
                if (devc->num_block_bytes == 0) {
+
                        if (sr_scpi_read_begin(scpi) != SR_OK)
                                return TRUE;
+
                        if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                                sr_dbg("New block header expected");
                                len = rigol_ds_read_header(scpi);
@@ -466,15 +472,14 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                                 * appear eventually.
                                 */
                                if (devc->data_source == DATA_SOURCE_LIVE
-                                               && (unsigned)len < devc->num_frame_samples) {
+                                               && (unsigned)len < expected_data_bytes) {
                                        sr_dbg("Discarding short data block");
                                        sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
                                        return TRUE;
                                }
                                devc->num_block_bytes = len;
                        } else {
-                               devc->num_block_bytes = probe->type == SR_PROBE_ANALOG ?
-                                       devc->analog_frame_size : devc->digital_frame_size;
+                               devc->num_block_bytes = expected_data_bytes;
                        }
                        devc->num_block_read = 0;
                }
@@ -548,8 +553,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
 
                devc->num_frame_samples += len;
 
-               if (devc->num_frame_samples < (probe->type == SR_PROBE_ANALOG ?
-                                       devc->analog_frame_size : devc->digital_frame_size))
+               if (devc->num_frame_samples < expected_data_bytes)
                        /* Don't have the whole frame yet. */
                        return TRUE;