]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds/protocol.c
rigol-ds: Send FRAME_BEGIN and FRAME_END per frame, not per channel.
[libsigrok.git] / hardware / rigol-ds / protocol.c
index 4a3f80eb6b2d1adc594c72287f4e8d034af1a7ca..4f4ff412b015d7240b37c08ccb5fb30ffe346b02 100644 (file)
@@ -351,7 +351,7 @@ SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi)
                        rigol_ds_set_wait_event(devc, WAIT_NONE);
        }
 
-       devc->num_frame_samples = 0;
+       devc->num_channel_bytes = 0;
        devc->num_block_bytes = 0;
 
        return SR_OK;
@@ -448,7 +448,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_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) {
                                if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
@@ -494,12 +494,6 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
 
                devc->num_block_read += len;
 
-               if (devc->num_frame_samples == 0) {
-                       /* Start of a new frame. */
-                       packet.type = SR_DF_FRAME_BEGIN;
-                       sr_session_send(sdi, &packet);
-               }
-
                if (probe->type == SR_PROBE_ANALOG) {
                        vref = devc->vert_reference[probe->index];
                        vdiv = devc->vdiv[probe->index] / 25.6;
@@ -551,16 +545,13 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                        sr_dbg("%d of %d block bytes read", devc->num_block_read, devc->num_block_bytes);
                }
 
-               devc->num_frame_samples += len;
+               devc->num_channel_bytes += len;
 
-               if (devc->num_frame_samples < expected_data_bytes)
-                       /* Don't have the whole frame yet. */
+               if (devc->num_channel_bytes < expected_data_bytes)
+                       /* Don't have the full data for this channel yet, re-run. */
                        return TRUE;
 
-               /* End of the frame. */
-               sr_dbg("Frame completed, %d samples", devc->num_frame_samples);
-               packet.type = SR_DF_FRAME_END;
-               sr_session_send(sdi, &packet);
+               /* End of data for this channel. */
                if (devc->model->series >= RIGOL_DS1000Z) {
                        /* Signal end of data download to scope */
                        if (devc->data_source != DATA_SOURCE_LIVE)
@@ -585,19 +576,30 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                                /* Now we need to get the digital data. */
                                devc->channel_entry = devc->enabled_digital_probes;
                                rigol_ds_channel_start(sdi);
-                       } else if (++devc->num_frames == devc->limit_frames) {
-                               sdi->driver->dev_acquisition_stop(sdi, cb_data);
                        } else {
-                               /* Get the next frame, starting with the first analog channel. */
-                               if (devc->enabled_analog_probes)
-                                       devc->channel_entry = devc->enabled_analog_probes;
-                               else
-                                       devc->channel_entry = devc->enabled_digital_probes;
-
-                               if (devc->model->series < RIGOL_DS1000Z)
-                                       rigol_ds_channel_start(sdi);
-                               else
-                                       rigol_ds_capture_start(sdi);
+                               /* Done with this frame. */
+                               packet.type = SR_DF_FRAME_END;
+                               sr_session_send(cb_data, &packet);
+
+                               if (++devc->num_frames == devc->limit_frames) {
+                                       /* Last frame, stop capture. */
+                                       sdi->driver->dev_acquisition_stop(sdi, cb_data);
+                               } else {
+                                       /* Get the next frame, starting with the first analog channel. */
+                                       if (devc->enabled_analog_probes)
+                                               devc->channel_entry = devc->enabled_analog_probes;
+                                       else
+                                               devc->channel_entry = devc->enabled_digital_probes;
+
+                                       if (devc->model->series < RIGOL_DS1000Z)
+                                               rigol_ds_channel_start(sdi);
+                                       else
+                                               rigol_ds_capture_start(sdi);
+
+                                       /* Start of next frame. */
+                                       packet.type = SR_DF_FRAME_BEGIN;
+                                       sr_session_send(cb_data, &packet);
+                               }
                        }
                }
        }