Differences in protocols are now primarily controlled by the protocol flavor.
There are no more DS2000 specific functions.
---
 hardware/rigol-ds/api.c      |   26 +++++++++++++-------------
 hardware/rigol-ds/protocol.c |   41 +++++++++++++++++++++--------------------
 hardware/rigol-ds/protocol.h |   21 +++++++++++++++++++--
 3 files changed, 53 insertions(+), 35 deletions(-)

diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c
index e706ea9..d1d9e8a 100644
--- a/hardware/rigol-ds/api.c
+++ b/hardware/rigol-ds/api.c
@@ -139,19 +139,19 @@ static const char *coupling[] = {
 };
 
 /* 
- * name, series, min timebase, max timebase, min vdiv, digital channels,
- * number of horizontal divs
+ * name, series, protocol flavor, min timebase, max timebase, min vdiv,
+ * digital channels, number of horizontal divs
  */
 static const struct rigol_ds_model supported_models[] = {
-       {"DS1052E", 1, {5, 1000000000}, {50, 1}, {2, 1000}, false, 12},
-       {"DS1102E", 1, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12},
-       {"DS1152E", 1, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12},
-       {"DS1052D", 1, {5, 1000000000}, {50, 1}, {2, 1000}, true, 12},
-       {"DS1102D", 1, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12},
-       {"DS1152D", 1, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12},
-       {"DS2072", 2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
-       {"DS2102", 2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
-       {"DS2202", 2, {2, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
+       {"DS1052E", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, 
{2, 1000}, false, 12},
+       {"DS1102E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, 
{2, 1000}, false, 12},
+       {"DS1152E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, 
{2, 1000}, false, 12},
+       {"DS1052D", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, 
{2, 1000}, true, 12},
+       {"DS1102D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, 
{2, 1000}, true, 12},
+       {"DS1152D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, 
{2, 1000}, true, 12},
+       {"DS2072", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, 
{500, 1000000}, false, 14},
+       {"DS2102", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, 
{500, 1000000}, false, 14},
+       {"DS2202", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {500, 1}, 
{500, 1000000}, false, 14},
 };
 
 SR_PRIV struct sr_dev_driver rigol_ds_driver_info;
@@ -635,7 +635,7 @@ static int dev_acquisition_start(const struct sr_dev_inst 
*sdi, void *cb_data)
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
-       if (devc->model->series == 1) {
+       if (devc->model->protocol == PROTOCOL_LEGACY) {
                /* Fetch the first frame. */
                if (devc->enabled_analog_probes) {
                        devc->channel_frame = devc->enabled_analog_probes->data;
@@ -653,7 +653,7 @@ static int dev_acquisition_start(const struct sr_dev_inst 
*sdi, void *cb_data)
                if (devc->enabled_analog_probes) {
                        devc->channel_frame = devc->enabled_analog_probes->data;
                        /* Assume there already was a trigger event - don't 
wait */
-                       if (rigol_ds2xx2_acquisition_start(sdi, FALSE) != SR_OK)
+                       if (rigol_ds_acquisition_start(sdi, FALSE) != SR_OK)
                                return SR_ERR;
                }
        }
diff --git a/hardware/rigol-ds/protocol.c b/hardware/rigol-ds/protocol.c
index 164d7c1..24abe65 100644
--- a/hardware/rigol-ds/protocol.c
+++ b/hardware/rigol-ds/protocol.c
@@ -96,7 +96,7 @@ static int parse_int(const char *str, int *ret)
  * order to not block the application.
  */
 
-static int rigol_ds2xx2_trigger_wait(const struct sr_dev_inst *sdi)
+static int rigol_ds_trigger_wait(const struct sr_dev_inst *sdi)
 {
        char buf[20];
        struct dev_context *devc;
@@ -183,8 +183,8 @@ static int rigol_ds2xx2_trigger_wait(const struct 
sr_dev_inst *sdi)
  * for about one sweep time.
  */
 
-SR_PRIV int rigol_ds2xx2_acquisition_start(const struct sr_dev_inst *sdi,
-                                          gboolean wait_for_trigger)
+SR_PRIV int rigol_ds_acquisition_start(const struct sr_dev_inst *sdi,
+                                      gboolean wait_for_trigger)
 {
        struct dev_context *devc;
 
@@ -197,7 +197,7 @@ SR_PRIV int rigol_ds2xx2_acquisition_start(const struct 
sr_dev_inst *sdi,
        if (rigol_ds_send(sdi, ":WAV:FORM BYTE") != SR_OK)
                return SR_ERR;
        if (rigol_ds_send(sdi, ":WAV:SOUR CHAN%d",
-                                 devc->channel_frame->index + 1) != SR_OK)
+                             devc->channel_frame->index + 1) != SR_OK)
                return SR_ERR;
        if (rigol_ds_send(sdi, ":WAV:MODE NORM") != SR_OK)
                return SR_ERR;
@@ -215,7 +215,7 @@ SR_PRIV int rigol_ds2xx2_acquisition_start(const struct 
sr_dev_inst *sdi,
        return SR_OK;
 }
 
-static int rigol_ds2xx2_read_header(struct sr_serial_dev_inst *serial)
+static int rigol_ds_read_header(struct sr_serial_dev_inst *serial)
 {
        char start[3], length[10];
        int len, tmp;
@@ -280,18 +280,19 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
 
        if (revents == G_IO_IN) {
                if (devc->trigger_wait_status > 0) {
-                       if (rigol_ds2xx2_trigger_wait(sdi) != SR_OK)
+                       if (rigol_ds_trigger_wait(sdi) != SR_OK)
                                return TRUE;
                }
 
-               if (devc->model->series == 2 && devc->num_block_bytes == 0) {
+               if (devc->model->protocol == PROTOCOL_IEEE488_2
+                   && devc->num_block_bytes == 0) {
                        sr_dbg("New block header expected");
                        if (rigol_ds_send(sdi, ":WAV:DATA?") != SR_OK)
                                return TRUE;
-                       len = rigol_ds2xx2_read_header(serial);
+                       len = rigol_ds_read_header(serial);
                        if (len == -1)
                                return TRUE;
-                       /* At slow timebases the scope sometimes returns
+                       /* At slow timebases the DS2072 sometimes returns
                         * "short" data blocks, with apparently no way to
                         * get the rest of the data. Discard these, the
                         * complete data block will appear eventually.
@@ -306,7 +307,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                }
 
                probe = devc->channel_frame;
-               if (devc->model->series == 2) {
+               if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                        len = devc->num_block_bytes - devc->num_block_read;
                        len = serial_read(serial, buf,
                                        len < DS2000_ANALOG_WAVEFORM_SIZE ? len 
: DS2000_ANALOG_WAVEFORM_SIZE);
@@ -326,12 +327,12 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                }
 
                if (probe->type == SR_PROBE_ANALOG) {
-                       if (devc->model->series == 2)
+                       if (devc->model->protocol == PROTOCOL_IEEE488_2)
                                devc->num_block_read += len;
                        vref = devc->vert_reference[probe->index];
                        vdiv = devc->vdiv[probe->index] / 25.6;
                        offset = devc->vert_offset[probe->index];
-                       if (devc->model->series == 2)
+                       if (devc->model->protocol == PROTOCOL_IEEE488_2)
                                for (i = 0; i < len; i++)
                                        data[i] = ((int)buf[i] - vref) * vdiv - 
offset;
                        else
@@ -348,7 +349,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                        sr_session_send(cb_data, &packet);
                        g_slist_free(analog.probes);
 
-                       if (devc->model->series == 2) {
+                       if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                                devc->num_frame_bytes += len;
 
                                if (devc->num_frame_bytes < 
DS2000_ANALOG_WAVEFORM_SIZE)
@@ -377,7 +378,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                /* End of the frame. */
                packet.type = SR_DF_FRAME_END;
                sr_session_send(sdi, &packet);
-               if (devc->model->series == 1)
+               if (devc->model->protocol == PROTOCOL_LEGACY)
                        devc->num_frame_bytes = 0;
 
                if (devc->enabled_analog_probes
@@ -386,9 +387,9 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                        /* We got the frame for the first analog channel, but
                         * there's a second analog channel. */
                        devc->channel_frame = 
devc->enabled_analog_probes->next->data;
-                       if (devc->model->series == 2) {
+                       if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                                /* Do not wait for trigger to try and keep 
channel data related. */
-                               rigol_ds2xx2_acquisition_start(sdi, FALSE);
+                               rigol_ds_acquisition_start(sdi, FALSE);
                        } else {
                                rigol_ds_send(sdi, ":WAV:DATA? CHAN%c",
                                                devc->channel_frame->name[2]);
@@ -405,13 +406,13 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void 
*cb_data)
                                sdi->driver->dev_acquisition_stop(sdi, cb_data);
                        } else {
                                /* Get the next frame, starting with the first 
analog channel. */
-                               if (devc->model->series == 2) {
+                               if (devc->model->protocol == 
PROTOCOL_IEEE488_2) {
                                        if (devc->enabled_analog_probes) {
                                                devc->channel_frame = 
devc->enabled_analog_probes->data;
                                                /* Must wait for trigger 
because at
                                                 * slow timebases the scope will
                                                 * return old data otherwise. */
-                                               
rigol_ds2xx2_acquisition_start(sdi, TRUE);
+                                               rigol_ds_acquisition_start(sdi, 
TRUE);
                                        }
                                } else {
                                        if (devc->enabled_analog_probes) {
@@ -466,7 +467,7 @@ static int get_cfg(const struct sr_dev_inst *sdi, char 
*cmd, char *reply, size_t
                return SR_ERR;
        reply[len] = '\0';
 
-       if (devc->model->series == 2) {
+       if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                /* get rid of trailing linefeed */
                if (len >= 1 && reply[len-1] == '\n')
                        reply[len-1] = '\0';
@@ -564,7 +565,7 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst 
*sdi)
                return SR_ERR;
        sr_dbg("Current vertical gain CH1 %g CH2 %g", devc->vdiv[0], 
devc->vdiv[1]);
 
-       if (devc->model->series == 2) {
+       if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                /* Vertical reference - not certain if this is the place to 
read it. */
                if (rigol_ds_send(sdi, ":WAV:SOUR CHAN1") != SR_OK)
                        return SR_ERR;
diff --git a/hardware/rigol-ds/protocol.h b/hardware/rigol-ds/protocol.h
index 52c9d5a..eb8bb4e 100644
--- a/hardware/rigol-ds/protocol.h
+++ b/hardware/rigol-ds/protocol.h
@@ -39,9 +39,26 @@
 #define DS2000_ANALOG_WAVEFORM_SIZE 1400
 #define DIGITAL_WAVEFORM_SIZE 1210
 
+enum rigol_ds_series {
+       RIGOL_DS1000,
+       RIGOL_DS1000Z,
+       RIGOL_DS2000,
+       RIGOL_DS4000,
+       RIGOL_DS6000,
+};
+
+enum rigol_protocol_flavor {
+       /* Used by DS1000 series */
+       PROTOCOL_LEGACY,
+       /* Used by DS2000, DS4000, DS6000, ... series */
+       PROTOCOL_IEEE488_2,
+};
+
+
 struct rigol_ds_model {
        char *name;
-       unsigned int series;
+       enum rigol_ds_series series;
+       enum rigol_protocol_flavor protocol;
        uint64_t min_timebase[2];
        uint64_t max_timebase[2];
        uint64_t min_vdiv[2];
@@ -91,7 +108,7 @@ struct dev_context {
        int trigger_wait_status;
 };
 
-SR_PRIV int rigol_ds2xx2_acquisition_start(const struct sr_dev_inst *sdi, 
gboolean wait_for_trigger);
+SR_PRIV int rigol_ds_acquisition_start(const struct sr_dev_inst *sdi, gboolean 
wait_for_trigger);
 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data);
 SR_PRIV int rigol_ds_send(const struct sr_dev_inst *sdi, const char *format, 
...);
 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
-- 
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