---
 hardware/rigol-ds/api.c      |   12 ++++++++++--
 hardware/rigol-ds/protocol.c |   16 +++++++---------
 hardware/rigol-ds/protocol.h |    5 +++++
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c
index 757a1d2..37dc9d0 100644
--- a/hardware/rigol-ds/api.c
+++ b/hardware/rigol-ds/api.c
@@ -139,6 +139,7 @@ static const char *coupling[] = {
        "GND",
 };
 
+/* Do not change the order of entries */
 static const char *data_sources[] = {
        "Live",
        "Memory",
@@ -170,6 +171,8 @@ static void clear_helper(void *priv)
 
        devc = priv;
 
+       g_free(devc->data);
+       g_free(devc->buffer);
        g_free(devc->coupling[0]);
        g_free(devc->coupling[1]);
        g_free(devc->trigger_source);
@@ -262,7 +265,7 @@ static int probe_port(const char *port, GSList **devices)
        }
 
        if (!model || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
-               manufacturer, model_name, version))) {
+                                             manufacturer, model_name, 
version))) {
                g_strfreev(tokens);
                return SR_ERR_NA;
        }
@@ -281,7 +284,7 @@ static int probe_port(const char *port, GSList **devices)
 
        for (i = 0; i < 2; i++) {
                if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
-                               i == 0 ? "CH1" : "CH2")))
+                                          i == 0 ? "CH1" : "CH2")))
                        return SR_ERR_MALLOC;
                sdi->probes = g_slist_append(sdi->probes, probe);
        }
@@ -312,6 +315,11 @@ static int probe_port(const char *port, GSList **devices)
                }
        }
 
+       if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
+               return SR_ERR_MALLOC;
+       if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float))))
+               return SR_ERR_MALLOC;
+
        devc->data_source = DATA_SOURCE_LIVE;
 
        sdi->priv = devc;
diff --git a/hardware/rigol-ds/protocol.c b/hardware/rigol-ds/protocol.c
index c9f3b3c..912c2e9 100644
--- a/hardware/rigol-ds/protocol.c
+++ b/hardware/rigol-ds/protocol.c
@@ -262,9 +262,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog analog;
        struct sr_datafeed_logic logic;
-       unsigned char buf[DS2000_ANALOG_WAVEFORM_SIZE];
        double vdiv, offset;
-       float data[DS2000_ANALOG_WAVEFORM_SIZE];
        int len, i, waveform_size, vref;
        struct sr_probe *probe;
 
@@ -299,7 +297,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                         */
                        if (len < DS2000_ANALOG_WAVEFORM_SIZE) {
                                sr_dbg("Discarding short data block");
-                               serial_read(serial, buf, len + 1);
+                               serial_read(serial, devc->buffer, len + 1);
                                return TRUE;
                        }
                        devc->num_block_bytes = len;
@@ -309,12 +307,12 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                probe = devc->channel_frame;
                if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                        len = devc->num_block_bytes - devc->num_block_read;
-                       len = serial_read(serial, buf,
+                       len = serial_read(serial, devc->buffer,
                                        len < DS2000_ANALOG_WAVEFORM_SIZE ? len 
: DS2000_ANALOG_WAVEFORM_SIZE);
                } else {
                        waveform_size = probe->type == SR_PROBE_ANALOG ?
                                        DS1000_ANALOG_WAVEFORM_SIZE : 
DIGITAL_WAVEFORM_SIZE;
-                       len = serial_read(serial, buf, waveform_size - 
devc->num_frame_bytes);
+                       len = serial_read(serial, devc->buffer, waveform_size - 
devc->num_frame_bytes);
                }
                sr_dbg("Received %d bytes.", len);
                if (len == -1)
@@ -334,13 +332,13 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                        offset = devc->vert_offset[probe->index];
                        if (devc->model->protocol == PROTOCOL_IEEE488_2)
                                for (i = 0; i < len; i++)
-                                       data[i] = ((int)buf[i] - vref) * vdiv - 
offset;
+                                       devc->data[i] = ((int)devc->buffer[i] - 
vref) * vdiv - offset;
                        else
                                for (i = 0; i < len; i++)
-                                       data[i] = (128 - buf[i]) * vdiv - 
offset;
+                                       devc->data[i] = (128 - devc->buffer[i]) 
* vdiv - offset;
                        analog.probes = g_slist_append(NULL, probe);
                        analog.num_samples = len;
-                       analog.data = data;
+                       analog.data = devc->data;
                        analog.mq = SR_MQ_VOLTAGE;
                        analog.unit = SR_UNIT_VOLT;
                        analog.mqflags = 0;
@@ -365,7 +363,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                } else {
                        logic.length = len - 10;
                        logic.unitsize = 2;
-                       logic.data = buf + 10;
+                       logic.data = devc->buffer + 10;
                        packet.type = SR_DF_LOGIC;
                        packet.payload = &logic;
                        sr_session_send(cb_data, &packet);
diff --git a/hardware/rigol-ds/protocol.h b/hardware/rigol-ds/protocol.h
index d63d756..09e29ad 100644
--- a/hardware/rigol-ds/protocol.h
+++ b/hardware/rigol-ds/protocol.h
@@ -38,6 +38,8 @@
 #define DS1000_ANALOG_WAVEFORM_SIZE 600
 #define DS2000_ANALOG_WAVEFORM_SIZE 1400
 #define DIGITAL_WAVEFORM_SIZE 1210
+/* Size of acquisition buffers */
+#define ACQ_BUFFER_SIZE 32768
 
 enum rigol_ds_series {
        RIGOL_DS1000,
@@ -112,6 +114,9 @@ struct dev_context {
        uint64_t num_block_read;
        /* Trigger waiting status, 0 - don't wait */
        int trigger_wait_status;
+       /* Acq buffers used for reading from the scope and sending data to app 
*/
+       unsigned char *buffer;
+       float *data;
 };
 
 SR_PRIV int rigol_ds_acquisition_start(const struct sr_dev_inst *sdi, gboolean 
wait_for_trigger);
-- 
1.7.10.4


------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to