From: Martin Ling Date: Sun, 14 Apr 2013 00:58:35 +0000 (+0100) Subject: rigol-ds1xx2: fix handling of partial frames. X-Git-Tag: dsupstream~162 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ee7e9bee5d943261d866f92cb8b81584e290df01;p=libsigrok.git rigol-ds1xx2: fix handling of partial frames. --- diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index e38105b6..d3fe909a 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -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; } diff --git a/hardware/rigol-ds1xx2/protocol.c b/hardware/rigol-ds1xx2/protocol.c index d95716d7..95ff3263 100644 --- a/hardware/rigol-ds1xx2/protocol.c +++ b/hardware/rigol-ds1xx2/protocol.c @@ -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) { diff --git a/hardware/rigol-ds1xx2/protocol.h b/hardware/rigol-ds1xx2/protocol.h index 4026fc16..644a771b 100644 --- a/hardware/rigol-ds1xx2/protocol.h +++ b/hardware/rigol-ds1xx2/protocol.h @@ -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; };