]> sigrok.org Git - libsigrok.git/commitdiff
rigol-ds1xx2: fix handling of partial frames.
authorMartin Ling <redacted>
Sun, 14 Apr 2013 00:58:35 +0000 (01:58 +0100)
committerBert Vermeulen <redacted>
Sun, 14 Apr 2013 14:57:01 +0000 (16:57 +0200)
hardware/rigol-ds1xx2/api.c
hardware/rigol-ds1xx2/protocol.c
hardware/rigol-ds1xx2/protocol.h

index e38105b65c972ed4edd5a61d46ee22265d22317f..d3fe909a1f595b45bfcdbfbd32bd3d52b26abefc 100644 (file)
@@ -552,6 +552,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                        devc->channel_frame->name[2]) != SR_OK)
                return SR_ERR;
 
+       devc->num_frame_bytes = 0;
+
        return SR_OK;
 }
 
index d95716d7a59e3abef63dc487e7f40501adeac3b9..95ff3263dedde5ba48e96c04469f0ce41f66136e 100644 (file)
@@ -47,12 +47,12 @@ SR_PRIV int rigol_ds1xx2_receive(int fd, int revents, void *cb_data)
                return TRUE;
 
        if (revents == G_IO_IN) {
-               len = read(fd, buf, WAVEFORM_SIZE);
+               len = read(fd, buf, WAVEFORM_SIZE - devc->num_frame_bytes);
                sr_dbg("Received %d bytes.", len);
                if (len == -1)
                        return TRUE;
 
-               if (devc->num_frame_samples == 0) {
+               if (devc->num_frame_bytes == 0) {
                        /* Start of a new frame. */
                        packet.type = SR_DF_FRAME_BEGIN;
                        sr_session_send(sdi, &packet);
@@ -75,13 +75,17 @@ SR_PRIV int rigol_ds1xx2_receive(int fd, int revents, void *cb_data)
                sr_session_send(cb_data, &packet);
                g_slist_free(analog.probes);
 
-               if (len != WAVEFORM_SIZE)
+               devc->num_frame_bytes += len;
+
+               if (devc->num_frame_bytes != WAVEFORM_SIZE) {
                        /* Don't have the whole frame yet. */
                        return TRUE;
+               }
 
                /* End of the frame. */
                packet.type = SR_DF_FRAME_END;
                sr_session_send(sdi, &packet);
+               devc->num_frame_bytes = 0;
 
                if (devc->channel_frame == devc->enabled_probes->data
                                && devc->enabled_probes->next != NULL) {
index 4026fc162ac63788e209002de76ae43c91e6e0f8..644a771b1989c1bc5e495332d559978266acc757 100644 (file)
@@ -57,7 +57,7 @@ struct dev_context {
        char *device;
        int fd;
        uint64_t num_frames;
-       uint64_t num_frame_samples;
+       uint64_t num_frame_bytes;
        struct sr_probe *channel_frame;
 };