]> sigrok.org Git - libsigrok.git/commitdiff
rigol-ds1xx2: properly send frame begin/end packets
authorBert Vermeulen <redacted>
Sun, 7 Apr 2013 22:38:58 +0000 (00:38 +0200)
committerBert Vermeulen <redacted>
Thu, 11 Apr 2013 16:32:08 +0000 (18:32 +0200)
hardware/rigol-ds1xx2/api.c
hardware/rigol-ds1xx2/protocol.c
hardware/rigol-ds1xx2/protocol.h

index a357d63b85a9baa1aa645bbe82bc69704e9e808b..0bc2a23ca670e2bddc2081f8ab9fd6d025df6d80 100644 (file)
@@ -485,7 +485,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        devc = sdi->priv;
 
-       devc->num_frames = 0;
+       devc->num_frames = devc->num_frame_samples = 0;
 
        sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive_data, (void *)sdi);
 
index 6879a04c12a90e8c50bb7f81349baf1237ea1606..161e73bbf0a65d5e26cc5788626bf34804d9c3aa 100644 (file)
@@ -47,6 +47,13 @@ SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data)
                sr_dbg("Received %d bytes.", len);
                if (len == -1)
                        return TRUE;
+
+               if (devc->num_frame_samples == 0) {
+                       /* Start of a new frame. */
+                       packet.type = SR_DF_FRAME_BEGIN;
+                       sr_session_send(sdi, &packet);
+               }
+
                for (i = 0; i < len; i++)
                        data[i] = devc->scale / 25.6 * (128 - buf[i]) - devc->offset;
                analog.probes = devc->enabled_probes;
@@ -59,10 +66,16 @@ SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data)
                packet.payload = &analog;
                sr_session_send(cb_data, &packet);
 
-               if (++devc->num_frames == devc->limit_frames)
-                       sdi->driver->dev_acquisition_stop(sdi, cb_data);
-               else
-                       rigol_ds1xx2_send_data(fd, ":WAV:DATA?\n");
+               if (len == WAVEFORM_SIZE) {
+                       /* End of the frame. */
+                       packet.type = SR_DF_FRAME_END;
+                       sr_session_send(sdi, &packet);
+
+                       if (++devc->num_frames == devc->limit_frames)
+                               sdi->driver->dev_acquisition_stop(sdi, cb_data);
+                       else
+                               rigol_ds1xx2_send_data(fd, ":WAV:DATA?\n");
+               }
        }
 
        return TRUE;
index fa056030f4e49ee10e54338f1221c373281d1607..62970e728787b9af8dc8c5e670b689aea16e350a 100644 (file)
@@ -52,8 +52,8 @@ struct dev_context {
        /** The current number of already received frames. */
        uint64_t num_frames;
 
-       /** The current number of already received samples. */
-       uint64_t num_samples;
+       /** The current number of samples received in this frame. */
+       uint64_t num_frame_samples;
 
        /** Current scale setting. */
        float scale;