]> sigrok.org Git - libsigrok.git/commitdiff
siglent-sds: Various cosmetics and coding-style fixes.
authorUwe Hermann <redacted>
Fri, 16 Feb 2018 19:33:44 +0000 (20:33 +0100)
committerUwe Hermann <redacted>
Fri, 16 Feb 2018 23:51:53 +0000 (00:51 +0100)
Also, drop some unneeded comments and log messages.

src/hardware/siglent-sds/api.c
src/hardware/siglent-sds/protocol.c
src/hardware/siglent-sds/protocol.h

index 01430234face1501f86b8edfc099afaf9492748a..84ba520b8d73fa8140ad4dc79e0fab9c406e87c0 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include <config.h>
-
 #include <fcntl.h>
 #include <glib.h>
 #include <math.h>
@@ -26,7 +25,6 @@
 #include <string.h>
 #include <strings.h>
 #include <unistd.h>
-
 #include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
 #include "protocol.h"
@@ -34,7 +32,7 @@
 
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
-       SR_CONF_SERIALCOMM
+       SR_CONF_SERIALCOMM,
 };
 
 static const uint32_t devopts[] = {
@@ -129,32 +127,13 @@ static const uint64_t vdivs[][2] = {
 #define NUM_VDIV       ARRAY_SIZE(vdivs)
 
 static const char *trigger_sources[] = {
-       "CH1",
-       "CH2",
-       "Ext",
-       "Ext /5",
-       "AC Line",
-       "D0",
-       "D1",
-       "D2",
-       "D3",
-       "D4",
-       "D5",
-       "D6",
-       "D7",
-       "D8",
-       "D9",
-       "D10",
-       "D11",
-       "D12",
-       "D13",
-       "D14",
-       "D15",
+       "CH1", "CH2", "Ext", "Ext /5", "AC Line",
+       "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
+       "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
 };
 
 static const char *trigger_slopes[] = {
-       "Rising",
-       "Falling",
+       "Rising", "Falling",
 };
 
 static const char *coupling[] = {
@@ -166,22 +145,10 @@ static const char *coupling[] = {
 };
 
 static const uint64_t probe_factor[] = {
-       1,
-       2,
-       5,
-       10,
-       20,
-       50,
-       100,
-       200,
-       500,
-       1000,
-       2000,
-       5000,
-       10000,
+       1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000,
 };
 
-/* Do not change the order of entries */
+/* Do not change the order of entries. */
 static const char *data_sources[] = {
        "Display",
        "History",
@@ -201,7 +168,7 @@ enum series {
        SDS2000X,
 };
 
-/* short name, full name, USB Name */
+/* short name, full name, USB name */
 static const struct siglent_sds_vendor supported_vendors[] = {
        [SIGLENT] = {
                "Siglent", "Siglent Technologies", "Siglent Technologies Co,. Ltd.",
@@ -212,96 +179,50 @@ static const struct siglent_sds_vendor supported_vendors[] = {
 /* vendor, series, protocol, max timebase, min vdiv, number of horizontal divs,
  * number of vertical divs, live waveform samples, memory buffer samples */
 static const struct siglent_sds_series supported_series[] = {
-       [SDS1000CML] = {
-               VENDOR(SIGLENT), "SDS1000CML", NON_SPO_MODEL,
-               { 50, 1 },
-               { 2, 1000 }, 18, 8, 1400363,
-       },
-       [SDS1000CNL] = {
-               VENDOR(SIGLENT), "SDS1000CNL", NON_SPO_MODEL,
-               { 50, 1 },
-               { 2, 1000 }, 18, 8, 1400363,
-       },
-       [SDS1000DL] = {
-               VENDOR(SIGLENT), "SDS1000DL", NON_SPO_MODEL,
-               { 50, 1 },
-               { 2, 1000 }, 18, 8, 1400363,
-       },
-       [SDS1000X] = {
-               VENDOR(SIGLENT), "SDS1000X", SPO_MODEL,
-               { 50, 1 },
-               { 500, 100000 }, 14, 8, 14000363,
-       },
-       [SDS1000XP] = {
-               VENDOR(SIGLENT), "SDS1000X+", SPO_MODEL,
-               { 50, 1 },
-               { 500, 100000 }, 14, 8, 14000363,
-       },
-       [SDS1000XE] = {
-               VENDOR(SIGLENT), "SDS1000XE", SPO_MODEL,
-               { 50, 1 },
-               { 500, 100000 }, 14, 8, 14000363,
-       },
-       [SDS2000X] = {
-               VENDOR(SIGLENT), "SDS2000X", SPO_MODEL,
-               { 50, 1 },
-               { 500, 100000 }, 14, 8, 14000363,
-       },
+       [SDS1000CML] = {VENDOR(SIGLENT), "SDS1000CML", NON_SPO_MODEL,
+               { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
+       [SDS1000CNL] = {VENDOR(SIGLENT), "SDS1000CNL", NON_SPO_MODEL,
+               { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
+       [SDS1000DL] = {VENDOR(SIGLENT), "SDS1000DL", NON_SPO_MODEL,
+               { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
+       [SDS1000X] = {VENDOR(SIGLENT), "SDS1000X", SPO_MODEL,
+               { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
+       [SDS1000XP] = {VENDOR(SIGLENT), "SDS1000X+", SPO_MODEL,
+               { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
+       [SDS1000XE] = {VENDOR(SIGLENT), "SDS1000XE", SPO_MODEL,
+               { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
+       [SDS2000X] = {VENDOR(SIGLENT), "SDS2000X", SPO_MODEL,
+               { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
 };
 
 #define SERIES(x) &supported_series[x]
 /* series, model, min timebase, analog channels, digital */
 static const struct siglent_sds_model supported_models[] = {
-       { SERIES(SDS1000CML), "SDS1152CML",
-               { 20, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000CML), "SDS1102CML",
-               { 10, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000CML), "SDS1072CML",
-               { 5, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000CNL), "SDS1202CNL",
-               { 20, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000CNL), "SDS1102CNL",
-               { 10, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000CNL), "SDS1072CNL",
-               { 5, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000DL), "SDS1202DL",
-               { 20, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000DL), "SDS1102DL",
-               { 10, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000DL), "SDS1022DL",
-               { 5, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000DL), "SDS1052DL",
-               { 5, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000X), "SDS1102X",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000XP), "SDS1102X+",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000X), "SDS1202X",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000XP), "SDS1202X+",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000XE), "SDS1202X-E",
-               { 1, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS1000XE), "SDS1104X-E",
-               { 1, 1000000000 }, 4, true, 16 },
-       { SERIES(SDS1000XE), "SDS1204X-E",
-               { 1, 1000000000 }, 4, true, 16 },
-       { SERIES(SDS2000X), "SDS2072X",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS2000X), "SDS2074X",
-               { 2, 1000000000 }, 4, false, 0 },
-       { SERIES(SDS2000X), "SDS2102X",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS2000X), "SDS2104X",
-               { 2, 1000000000 }, 4, false, 0 },
-       { SERIES(SDS2000X), "SDS2202X",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS2000X), "SDS2204X",
-               { 2, 1000000000 }, 4, false, 0 },
-       { SERIES(SDS2000X), "SDS2302X",
-               { 2, 1000000000 }, 2, false, 0 },
-       { SERIES(SDS2000X), "SDS2304X",
-               { 2, 1000000000 }, 4, false, 0 },
+       { SERIES(SDS1000CML), "SDS1152CML", { 20, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000CML), "SDS1102CML", { 10, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000CML), "SDS1072CML", { 5, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000CNL), "SDS1202CNL", { 20, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000CNL), "SDS1102CNL", { 10, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000CNL), "SDS1072CNL", { 5, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000DL), "SDS1202DL", { 20, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000DL), "SDS1102DL", { 10, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000DL), "SDS1022DL", { 5, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000DL), "SDS1052DL", { 5, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000X), "SDS1102X", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000XP), "SDS1102X+", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000X), "SDS1202X", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000XP), "SDS1202X+", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000XE), "SDS1202X-E", { 1, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS1000XE), "SDS1104X-E", { 1, 1000000000 }, 4, true, 16 },
+       { SERIES(SDS1000XE), "SDS1204X-E", { 1, 1000000000 }, 4, true, 16 },
+       { SERIES(SDS2000X), "SDS2072X", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS2000X), "SDS2074X", { 2, 1000000000 }, 4, false, 0 },
+       { SERIES(SDS2000X), "SDS2102X", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS2000X), "SDS2104X", { 2, 1000000000 }, 4, false, 0 },
+       { SERIES(SDS2000X), "SDS2202X", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS2000X), "SDS2204X", { 2, 1000000000 }, 4, false, 0 },
+       { SERIES(SDS2000X), "SDS2302X", { 2, 1000000000 }, 2, false, 0 },
+       { SERIES(SDS2000X), "SDS2304X", { 2, 1000000000 }, 4, false, 0 },
 };
 
 SR_PRIV struct sr_dev_driver siglent_sds_driver_info;
@@ -319,7 +240,6 @@ static void clear_helper(void *priv)
 
 static int dev_clear(const struct sr_dev_driver *di)
 {
-
        return std_dev_clear_with_callback(di, clear_helper);
 }
 
@@ -333,10 +253,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        const struct siglent_sds_model *model;
        gchar *channel_name;
 
-       sr_info("Device probing decode...");
-
-       /* Setting communication Header Format to OFF*/
-       sr_dbg("Setting Communication Headers to off");
+       sr_dbg("Setting Communication Headers to off.");
        if (sr_scpi_send(scpi, "CHDR OFF") != SR_OK)
                return NULL;
 
@@ -358,30 +275,22 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                }
        }
 
-       sr_info("Decoded Manufacturer: %s", hw_info->manufacturer);
-       sr_info("Decoded Model: %s", hw_info->model);
-
        if (!model) {
                sr_scpi_hw_info_free(hw_info);
                return NULL;
        }
 
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
-       sr_dbg("Setting Device Instance Vendor: %s", model->series->vendor->name);
        sdi->vendor = g_strdup(model->series->vendor->name);
-       sr_dbg("Setting Device Instance model: %s", model->name);
        sdi->model = g_strdup(model->name);
-       sr_dbg("Setting Device Instance version: %s", hw_info->firmware_version);
        sdi->version = g_strdup(hw_info->firmware_version);
        sdi->conn = scpi;
        sdi->driver = &siglent_sds_driver_info;
-       sr_dbg("Setting Device Instance inst_type: SCPI");
        sdi->inst_type = SR_INST_SCPI;
        sdi->serial_num = g_strdup(hw_info->serial_number);
        devc = g_malloc0(sizeof(struct dev_context));
        devc->limit_frames = 1;
        devc->model = model;
-       sr_dbg("Setting device Context model: %s", devc->model->name);
 
        sr_scpi_hw_info_free(hw_info);
 
@@ -434,7 +343,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        }
 
        devc->buffer = g_malloc(devc->model->series->buffer_samples);
-       sr_dbg("Setting device Context buffer Size: %i", devc->model->series->buffer_samples);
+       sr_dbg("Setting device context buffer size: %i.", devc->model->series->buffer_samples);
        devc->data = g_malloc(devc->model->series->buffer_samples * sizeof(float));
 
        devc->data_source = DATA_SOURCE_SCREEN;
@@ -446,8 +355,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
 
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
-
-       // TODO implement RPC call for LXI device discovery.
+       /* TODO: Implement RPC call for LXI device discovery. */
        return sr_scpi_scan(di->context, options, probe_device);
 }
 
@@ -473,11 +381,9 @@ static int dev_open(struct sr_dev_inst *sdi)
 
 static int dev_close(struct sr_dev_inst *sdi)
 {
-
        return sr_scpi_close(sdi->conn);
 }
 
-
 static int config_get(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
@@ -530,7 +436,6 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_SAMPLERATE:
                siglent_sds_get_dev_cfg_horizontal(sdi);
                *data = g_variant_new_uint64(devc->sampleRate);
-               sr_dbg("Sample rate set to %f", devc->sampleRate);
                break;
        case SR_CONF_TRIGGER_SOURCE:
                if (!strcmp(devc->trigger_source, "ACL"))
@@ -650,7 +555,8 @@ static int config_set(uint32_t key, GVariant *data,
        case SR_CONF_TRIGGER_SLOPE:
                tmp_str = g_variant_get_string(data, NULL);
                g_free(devc->trigger_slope);
-               ret = siglent_sds_config_set(sdi, "%s:TRSL %s", devc->trigger_source, devc->trigger_slope);
+               ret = siglent_sds_config_set(sdi, "%s:TRSL %s",
+                       devc->trigger_source, devc->trigger_slope);
                break;
        case SR_CONF_HORIZ_TRIGGERPOS:
                t_dbl = g_variant_get_double(data);
@@ -694,7 +600,7 @@ static int config_set(uint32_t key, GVariant *data,
                                        cmd = g_strdup_printf("%luNS", p);
                                        break;
                                }
-                               sr_dbg("Setting device Timebase: TDIV %s", cmd);
+                               sr_dbg("Setting device timebase: TDIV %s.", cmd);
                                ret = siglent_sds_config_set(sdi, "TDIV %s", cmd);
                                break;
                        }
@@ -736,10 +642,8 @@ static int config_set(uint32_t key, GVariant *data,
                }
                break;
        case SR_CONF_VDIV:
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                g_variant_get(data, "(tt)", &p, &q);
                for (i = 0; i < devc->model->analog_channels; i++) {
                        char *cmd;
@@ -759,8 +663,7 @@ static int config_set(uint32_t key, GVariant *data,
                                                cmd = g_strdup_printf("%luUV", p);
                                                break;
                                        }
-                                       return siglent_sds_config_set(sdi, "C%d:VDIV %s", i + 1,
-                                               cmd);
+                                       return siglent_sds_config_set(sdi, "C%d:VDIV %s", i + 1, cmd);
                                }
                                sr_err("Invalid vdiv index: %d.", j);
                                return SR_ERR_ARG;
@@ -769,10 +672,8 @@ static int config_set(uint32_t key, GVariant *data,
                sr_dbg("Didn't set vdiv, unknown channel(group).");
                return SR_ERR_NA;
        case SR_CONF_COUPLING:
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                tmp_str = g_variant_get_string(data, NULL);
                for (i = 0; i < devc->model->analog_channels; i++) {
                        char cmd[4];
@@ -783,8 +684,7 @@ static int config_set(uint32_t key, GVariant *data,
                                                devc->coupling[i] = g_strdup(coupling[j]);
                                                strncpy(cmd, devc->coupling[i], 3);
                                                cmd[3] = 0;
-                                               return siglent_sds_config_set(sdi, "C%d:CPL %s", i + 1,
-                                                       cmd);
+                                               return siglent_sds_config_set(sdi, "C%d:CPL %s", i + 1, cmd);
                                        }
                                }
                                sr_err("Invalid coupling index: %d.", j);
@@ -794,18 +694,15 @@ static int config_set(uint32_t key, GVariant *data,
                sr_dbg("Didn't set coupling, unknown channel(group).");
                return SR_ERR_NA;
        case SR_CONF_PROBE_FACTOR:
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                p = g_variant_get_uint64(data);
                for (i = 0; i < devc->model->analog_channels; i++) {
                        if (cg == devc->analog_groups[i]) {
                                for (j = 0; j < ARRAY_SIZE(probe_factor); j++) {
                                        if (p == probe_factor[j]) {
                                                devc->attenuation[i] = p;
-                                               ret = siglent_sds_config_set(sdi, "C%d:ATTN %"PRIu64,
-                                                       i + 1, p);
+                                               ret = siglent_sds_config_set(sdi, "C%d:ATTN %" PRIu64, i + 1, p);
                                                if (ret == SR_OK)
                                                        siglent_sds_get_dev_cfg_vertical(sdi);
                                                return ret;
@@ -871,10 +768,8 @@ static int config_list(uint32_t key, GVariant **data,
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                if (cg == devc->digital_group) {
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                NULL, 0, sizeof(uint32_t));
@@ -891,17 +786,13 @@ static int config_list(uint32_t key, GVariant **data,
                }
                break;
        case SR_CONF_COUPLING:
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
                break;
        case SR_CONF_PROBE_FACTOR:
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
                        probe_factor, ARRAY_SIZE(probe_factor), sizeof(uint64_t));
                break;
@@ -909,10 +800,8 @@ static int config_list(uint32_t key, GVariant **data,
                if (!devc)
                        /* Can't know this until we have the exact model. */
                        return SR_ERR_ARG;
-               if (!cg) {
-                       sr_err("No channel group specified.");
+               if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
-               }
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                for (i = 0; i < devc->num_vdivs; i++) {
                        rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
@@ -952,7 +841,7 @@ static int config_list(uint32_t key, GVariant **data,
                        /* Can't know this until we have the exact model. */
                        return SR_ERR_ARG;
                switch (devc->model->series->protocol) {
-               // TODO check what must be done here for the data source buffer sizes
+               /* TODO: Check what must be done here for the data source buffer sizes. */
                case NON_SPO_MODEL:
                        *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
                        break;
@@ -965,7 +854,7 @@ static int config_list(uint32_t key, GVariant **data,
                *data = g_variant_new_int32(devc->model->series->num_horizontal_divs);
                break;
        case SR_CONF_AVERAGING:
-               //TODO implement averaging.
+               /* TODO: Implement averaging. */
                break;
        default:
                return SR_ERR_NA;
@@ -993,18 +882,20 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        devc->num_frames = 0;
        some_digital = FALSE;
 
-       /* Check if there are any logic channels enabled, if so then enable de MSO, otherwise skip the digital channel setup */
-       /* enable and disable channels on the device is very slow and it is faster when checked in a small loop without the actual actions */
+       /*
+        * Check if there are any logic channels enabled, if so then enable
+        * the MSO, otherwise skip the digital channel setup. Enable and
+        * disable channels on the device is very slow and it is faster when
+        * checked in a small loop without the actual actions.
+        */
        for (d = sdi->channels; d; d = d->next) {
                ch = d->data;
-               if (ch->type == SR_CHANNEL_LOGIC && ch->enabled) {
+               if (ch->type == SR_CHANNEL_LOGIC && ch->enabled)
                        some_digital = TRUE;
-               }
        }
 
        for (l = sdi->channels; l; l = l->next) {
                ch = l->data;
-               sr_dbg("handling channel %s", ch->name);
                if (ch->type == SR_CHANNEL_ANALOG) {
                        if (ch->enabled)
                                devc->enabled_channels = g_slist_append(
@@ -1032,7 +923,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        if (siglent_sds_config_set(sdi, "D%d:DGCH %s", ch->index,
                                ch->enabled ? "ON" : "OFF") != SR_OK)
                                return SR_ERR;
-                       /* Slowing the command sequence down to let the device handle it */
+                       /* Slowing the command sequence down to let the device handle it. */
                        g_usleep(630000);
                        devc->digital_channels[ch->index] = ch->enabled;
                }
@@ -1058,7 +949,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        return SR_ERR;
                break;
        case NON_SPO_MODEL:
-               //TODO implement CML/CNL/DL models
+               /* TODO: Implement CML/CNL/DL models. */
                if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK)
                        return SR_ERR;
                if (siglent_sds_config_set(sdi, "ACQW SAMPLING") != SR_OK)
@@ -1109,7 +1000,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 
 SR_PRIV struct sr_dev_driver siglent_sds_driver_info = {
        .name = "siglent-sds",
-       .longname = "Siglent SDS1000/SDS2000 Series",
+       .longname = "Siglent SDS1000/SDS2000",
        .api_version = 1,
        .init = std_init,
        .cleanup = std_cleanup,
index 23951c710f92ff57b9a9305df37bb23d6a14f1f8..af20fde00c952894c157a17a0c2a062c665829f3 100644 (file)
@@ -1,10 +1,7 @@
 /*
  * This file is part of the libsigrok project.
  *
- * Siglent implementation:
  * Copyright (C) 2016 mhooijboer <marchelh@gmail.com>
- *
- * The Siglent implementation is based on Rigol driver sources, which are:
  * Copyright (C) 2012 Martin Ling <martin-git@earth.li>
  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
  * Copyright (C) 2013 Mathias Grimmberger <mgri@zaphod.sax.de>
@@ -26,7 +23,6 @@
 #define _GNU_SOURCE
 
 #include <config.h>
-
 #include <errno.h>
 #include <glib.h>
 #include <glib-2.0/glib/gmacros.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-
 #include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
 #include "scpi.h"
 #include "protocol.h"
 
-/* Set the next event to wait for in siglent_sds_receive */
+/* Set the next event to wait for in siglent_sds_receive(). */
 static void siglent_sds_set_wait_event(struct dev_context *devc, enum wait_events event)
 {
-
        if (event == WAIT_STOP) {
                devc->wait_status = 2;
        } else {
@@ -72,11 +66,11 @@ static int siglent_sds_event_wait(const struct sr_dev_inst *sdi)
 
        start = time(NULL);
 
-       s = 10000; /* Sleep time for status refresh */
+       s = 10000; /* Sleep time for status refresh. */
        if (devc->wait_status == 1) {
                do {
                        if (time(NULL) - start >= 3) {
-                               sr_dbg("Timeout waiting for trigger");
+                               sr_dbg("Timeout waiting for trigger.");
                                return SR_ERR_TIMEOUT;
                        }
 
@@ -85,24 +79,24 @@ static int siglent_sds_event_wait(const struct sr_dev_inst *sdi)
                        sr_atoi(buf, &out);
                        g_usleep(s);
                } while (out == 0);
-               sr_dbg("Device triggerd");
-               if (devc->timebase < 0.51) {
-                       if (devc->timebase > 0.99e-6) {
-                               /*
-                                * Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
-                                * -> 85 percent of sweep time
-                                */
-                               s = (devc->timebase * devc->model->series->num_horizontal_divs * 1000);
-                               sr_spew("Sleeping for %ld usecs after trigger, to let the acq buffer in the device fill", s);
-                               g_usleep(s);
-                       }
 
+               sr_dbg("Device triggered.");
+
+               if ((devc->timebase < 0.51) && (devc->timebase > 0.99e-6)) {
+                       /*
+                        * Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
+                        * -> 85 percent of sweep time
+                        */
+                       s = (devc->timebase * devc->model->series->num_horizontal_divs * 1000);
+                       sr_spew("Sleeping for %ld usecs after trigger, "
+                               "to let the acq buffer in the device fill", s);
+                       g_usleep(s);
                }
        }
        if (devc->wait_status == 2) {
                do {
                        if (time(NULL) - start >= 3) {
-                               sr_dbg("Timeout waiting for trigger");
+                               sr_dbg("Timeout waiting for trigger.");
                                return SR_ERR_TIMEOUT;
                        }
                        if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
@@ -118,7 +112,7 @@ static int siglent_sds_event_wait(const struct sr_dev_inst *sdi)
                 * to get encoded? This needs review, and adjustment.
                 */
                } while ((out | DEVICE_STATE_TRIG_RDY && out | DEVICE_STATE_DATA_ACQ) && out | DEVICE_STATE_STOPPED);
-               sr_dbg("Device triggerd 2");
+               sr_dbg("Device triggerd 2.");
                siglent_sds_set_wait_event(devc, WAIT_NONE);
        }
 
@@ -134,10 +128,9 @@ static int siglent_sds_trigger_wait(const struct sr_dev_inst *sdi)
        return siglent_sds_event_wait(sdi);
 }
 
-/* Wait for scope to got to "Stop" in single shot mode */
+/* Wait for scope to got to "Stop" in single shot mode. */
 static int siglent_sds_stop_wait(const struct sr_dev_inst *sdi)
 {
-
        return siglent_sds_event_wait(sdi);
 }
 
@@ -151,14 +144,10 @@ SR_PRIV int siglent_sds_config_set(const struct sr_dev_inst *sdi, const char *fo
        ret = sr_scpi_send_variadic(sdi->conn, format, args);
        va_end(args);
 
-       if (ret != SR_OK) {
-               return SR_ERR;
-       }
-
-       return SR_OK;
+       return ret;
 }
 
-/* Start capturing a new frameset */
+/* Start capturing a new frameset. */
 SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -182,19 +171,19 @@ SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
                        if (out == DEVICE_STATE_TRIG_RDY) {
                                siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
                        } else if (out == DEVICE_STATE_TRIG_RDY + 1) {
-                               sr_spew("Device Triggerd");
+                               sr_spew("Device triggered.");
                                siglent_sds_set_wait_event(devc, WAIT_BLOCK);
                                return SR_OK;
                        } else {
-                               sr_spew("Device did not enter ARM mode");
+                               sr_spew("Device did not enter ARM mode.");
                                return SR_ERR;
                        }
-               } else { //TODO implement History retrieval
+               } else { /* TODO: Implement history retrieval. */
                        unsigned int framecount;
                        char buf[200];
                        int ret;
 
-                       sr_dbg("Starting data capture for history frameset");
+                       sr_dbg("Starting data capture for history frameset.");
                        if (siglent_sds_config_set(sdi, "FPAR?") != SR_OK)
                                return SR_ERR;
                        ret = sr_scpi_read_data(sdi->conn, buf, 200);
@@ -203,11 +192,10 @@ SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
                                return SR_ERR;
                        }
                        memcpy(&framecount, buf + 40, 4);
-                       if (devc->limit_frames > framecount) {
+                       if (devc->limit_frames > framecount)
                                sr_err("Frame limit higher that frames in buffer of device!");
-                       } else if (devc->limit_frames == 0) {
+                       else if (devc->limit_frames == 0)
                                devc->limit_frames = framecount;
-                       }
                        sr_dbg("Starting data capture for history frameset %" PRIu64 " of %" PRIu64,
                                devc->num_frames + 1, devc->limit_frames);
                        if (siglent_sds_config_set(sdi, "FRAM %i", devc->num_frames + 1) != SR_OK)
@@ -225,7 +213,7 @@ SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-/* Start reading data from the current channel */
+/* Start reading data from the current channel. */
 SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -236,7 +224,7 @@ SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi)
 
        ch = devc->channel_entry->data;
 
-       sr_dbg("Starting reading data from channel %d", ch->index + 1);
+       sr_dbg("Starting reading data from channel %d.", ch->index + 1);
 
        switch (devc->model->series->protocol) {
        case NON_SPO_MODEL:
@@ -263,7 +251,7 @@ SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-/* Read the header of a data block */
+/* Read the header of a data block. */
 static int siglent_sds_read_header(struct sr_dev_inst *sdi, int channelIndex)
 {
        struct sr_scpi_dev_inst *scpi = sdi->conn;
@@ -271,28 +259,31 @@ static int siglent_sds_read_header(struct sr_dev_inst *sdi, int channelIndex)
        char *buf = (char *)devc->buffer;
        int ret;
        int descLength;
-       int blockOffset = 15; // Offset for Descriptor block.
+       int blockOffset = 15; /* Offset for descriptor block. */
        long dataLength = 0;
 
-       /* Read header from device */
-       ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes, devc->model->series->buffer_samples);
+       /* Read header from device. */
+       ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
+               devc->model->series->buffer_samples);
        if (ret < 346) {
                sr_err("Read error while reading data header.");
                return SR_ERR;
        }
-       sr_dbg("Device returned %i bytes", ret);
+       sr_dbg("Device returned %i bytes.", ret);
        devc->num_header_bytes += ret;
-       buf += blockOffset; //Skip to start Descriptor block
+       buf += blockOffset; /* Skip to start descriptor block. */
 
-       // Parse WaveDescriptor Header
-       memcpy(&descLength, buf + 36, 4); // Descriptor block length
-       memcpy(&dataLength, buf + 60, 4); // Data block length
+       /* Parse WaveDescriptor header. */
+       memcpy(&descLength, buf + 36, 4); /* Descriptor block length */
+       memcpy(&dataLength, buf + 60, 4); /* Data block length */
 
        devc->vdiv[channelIndex] = 2;
        devc->vert_offset[channelIndex] = 0;
        devc->blockHeaderSize = descLength + 15;
        ret = dataLength;
+
        sr_dbg("Received data block header: '%s' -> block length %d", buf, ret);
+
        return ret;
 }
 
@@ -343,15 +334,13 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
                        return TRUE;
                break;
        case WAIT_STOP:
-               if (siglent_sds_stop_wait(sdi) != SR_OK) {
+               if (siglent_sds_stop_wait(sdi) != SR_OK)
                        return TRUE;
-               }
-               if (siglent_sds_channel_start(sdi) != SR_OK) {
+               if (siglent_sds_channel_start(sdi) != SR_OK)
                        return TRUE;
-               }
                return TRUE;
        default:
-               sr_err("BUG: Unknown event target encountered");
+               sr_err("BUG: Unknown event target encountered.");
                break;
        }
 
@@ -359,11 +348,11 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
 
        if (devc->num_block_bytes == 0) {
 
-               if (g_ascii_strcasecmp(memsize, "14M") == 0){
-                       sr_err("Device memory depth is set to 14Mpts, so please be patient");
-                       g_usleep(4900000); // Sleep for large memory set
+               if (g_ascii_strcasecmp(memsize, "14M") == 0) {
+                       sr_err("Device memory depth is set to 14Mpts, so please be patient.");
+                       g_usleep(4900000); /* Sleep for large memory set. */
                }
-               sr_dbg("New block header expected");
+               sr_dbg("New block header expected.");
                len = siglent_sds_read_header(sdi, ch->index);
                expected_data_bytes = len;
                if (len == 0)
@@ -379,7 +368,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
 
                if (devc->data_source == DATA_SOURCE_SCREEN
                        && (unsigned)len < expected_data_bytes) {
-                       sr_dbg("Discarding short data block");
+                       sr_dbg("Discarding short data block.");
                        sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
                        return TRUE;
                }
@@ -391,7 +380,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
        if (len > ACQ_BUFFER_SIZE)
                len = ACQ_BUFFER_SIZE;
 
-       /*Offset the data block buffer past the IEEE header and Description Header*/
+       /* Offset the data block buffer past the IEEE header and description header. */
        devc->buffer += devc->blockHeaderSize;
 
        if (len == -1) {
@@ -447,16 +436,14 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
        }
 
        if (devc->num_block_read == devc->num_block_bytes) {
-               sr_dbg("Block has been completed");
-               /* Prepare for possible next block */
-               sr_dbg("Prepare for possible next block");
+               sr_dbg("Block has been completed.");
+               sr_dbg("Preparing for possible next block.");
                devc->num_header_bytes = 0;
                devc->num_block_bytes = 0;
-               if (devc->data_source != DATA_SOURCE_SCREEN) {
+               if (devc->data_source != DATA_SOURCE_SCREEN)
                        siglent_sds_set_wait_event(devc, WAIT_BLOCK);
-               }
                if (!sr_scpi_read_complete(scpi)) {
-                       sr_err("Read should have been completed");
+                       sr_err("Read should have been completed.");
                        packet.type = SR_DF_FRAME_END;
                        sr_session_send(sdi, &packet);
                        sdi->driver->dev_acquisition_stop(sdi);
@@ -464,7 +451,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
                }
                devc->num_block_read = 0;
        } else {
-               sr_dbg("%" PRIu64 " of %" PRIu64 " block bytes read",
+               sr_dbg("%" PRIu64 " of %" PRIu64 " block bytes read.",
                        devc->num_block_read, devc->num_block_bytes);
        }
        devc->num_channel_bytes += len;
@@ -494,6 +481,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
                        sr_session_send(sdi, &packet);
                }
        }
+
        return TRUE;
 }
 
@@ -528,14 +516,14 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        if (devc->model->has_digital) {
                gboolean status;
 
-               sr_dbg("Check Logic Analyzer channel state");
+               sr_dbg("Check logic analyzer channel state.");
                devc->la_enabled = FALSE;
                cmd = g_strdup_printf("DGST?");
                res = sr_scpi_get_bool(sdi->conn, cmd, &status);
                g_free(cmd);
                if (res != SR_OK)
                        return SR_ERR;
-               sr_dbg("Logic Analyzer status: %s", status ? "On" : "Off");
+               sr_dbg("Logic analyzer status: %s", status ? "On" : "Off");
                if (status) {
                        devc->la_enabled = TRUE;
                        for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
@@ -561,7 +549,7 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        /* Timebase. */
        if (sr_scpi_get_float(sdi->conn, ":TDIV?", &devc->timebase) != SR_OK)
                return SR_ERR;
-       sr_dbg("Current timebase %g", devc->timebase);
+       sr_dbg("Current timebase: %g.", devc->timebase);
 
        /* Probe attenuation. */
        for (i = 0; i < devc->model->analog_channels; i++) {
@@ -607,12 +595,12 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        }
        g_free(response);
        devc->trigger_source = g_strstrip(g_strdup(tokens[2]));
-       sr_dbg("Current trigger source %s", devc->trigger_source);
+       sr_dbg("Current trigger source: %s.", devc->trigger_source);
 
-       /* TODO Horizontal trigger position. */
+       /* TODO: Horizontal trigger position. */
 
        devc->horiz_triggerpos = 0;
-       sr_dbg("Current horizontal trigger position %g", devc->horiz_triggerpos);
+       sr_dbg("Current horizontal trigger position: %g.", devc->horiz_triggerpos);
 
        /* Trigger slope. */
        cmd = g_strdup_printf("%s:TRSL?", devc->trigger_source);
@@ -620,7 +608,7 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        g_free(cmd);
        if (res != SR_OK)
                return SR_ERR;
-       sr_dbg("Current trigger slope %s", devc->trigger_slope);
+       sr_dbg("Current trigger slope: %s.", devc->trigger_slope);
 
        /* Trigger level. */
        cmd = g_strdup_printf("%s:TRLV?", devc->trigger_source);
@@ -628,7 +616,7 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        g_free(cmd);
        if (res != SR_OK)
                return SR_ERR;
-       sr_dbg("Current trigger level %g", devc->trigger_level);
+       sr_dbg("Current trigger level: %g.", devc->trigger_level);
        return SR_OK;
 }
 
@@ -709,10 +697,11 @@ SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi)
                }
                samplerateScope = fvalue * 1000;
        }
-       /* Get the Timebase. */
+       /* Get the timebase. */
        if (sr_scpi_get_float(sdi->conn, ":TDIV?", &devc->timebase) != SR_OK)
                return SR_ERR;
-       sr_dbg("Current timebase %g", devc->timebase);
+       sr_dbg("Current timebase: %g.", devc->timebase);
        devc->sampleRate = samplerateScope / (devc->timebase * devc->model->series->num_horizontal_divs);
+
        return SR_OK;
 }
index 198fa757c510778bb90e92a5e1659bdfb9bddeec..0a7e5f3a0fb869433f91806b0280623428b9e11f 100644 (file)
@@ -47,10 +47,6 @@ enum protocol_version {
        NON_SPO_MODEL,
 };
 
-enum data_format {
-       FORMAT_IEEE488_2,
-};
-
 enum data_source {
        DATA_SOURCE_SCREEN,
        DATA_SOURCE_HISTORY,
@@ -89,7 +85,6 @@ enum wait_events {
        WAIT_STOP,      /* Wait for scope stopping (only single shots) */
 };
 
-/** Private, per-device-instance driver context. */
 struct dev_context {
        /* Device model */
        const struct siglent_sds_model *model;
@@ -137,17 +132,17 @@ struct dev_context {
        GSList *channel_entry;
        /* Number of bytes received for current channel. */
        uint64_t num_channel_bytes;
-       /* Number of bytes of block header read */
+       /* Number of bytes of block header read. */
        uint64_t num_header_bytes;
-       /* Number of bytes in current data block, if 0 block header expected */
+       /* Number of bytes in current data block, if 0 block header expected. */
        uint64_t num_block_bytes;
-       /* Number of data block bytes already read */
+       /* Number of data block bytes already read. */
        uint64_t num_block_read;
-       /* What to wait for in *_receive */
+       /* What to wait for in *_receive. */
        enum wait_events wait_event;
-       /* Trigger/block copying/stop waiting status */
+       /* Trigger/block copying/stop waiting status. */
        int wait_status;
-       /* Acq buffers used for reading from the scope and sending data to app */
+       /* Acq buffers used for reading from the scope and sending data to app. */
        unsigned char *buffer;
        float *data;
 };