From: Bert Vermeulen Date: Sun, 7 Apr 2013 22:38:58 +0000 (+0200) Subject: rigol-ds1xx2: properly send frame begin/end packets X-Git-Tag: dsupstream~174 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=75d8a4e5766cccdcd7f017093fa822e7218749b8;p=libsigrok.git rigol-ds1xx2: properly send frame begin/end packets --- diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index a357d63b..0bc2a23c 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -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); diff --git a/hardware/rigol-ds1xx2/protocol.c b/hardware/rigol-ds1xx2/protocol.c index 6879a04c..161e73bb 100644 --- a/hardware/rigol-ds1xx2/protocol.c +++ b/hardware/rigol-ds1xx2/protocol.c @@ -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; diff --git a/hardware/rigol-ds1xx2/protocol.h b/hardware/rigol-ds1xx2/protocol.h index fa056030..62970e72 100644 --- a/hardware/rigol-ds1xx2/protocol.h +++ b/hardware/rigol-ds1xx2/protocol.h @@ -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;