]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/siglent-sds/api.c
siglent-sds: Drop obsolete SR_ST_ACTIVE checks.
[libsigrok.git] / src / hardware / siglent-sds / api.c
index 84ba520b8d73fa8140ad4dc79e0fab9c406e87c0..a1b1ed71d4c490aed37dfa145275d92f59830b22 100644 (file)
@@ -98,6 +98,7 @@ static const uint64_t timebases[][2] = {
        { 10, 1 },
        { 20, 1 },
        { 50, 1 },
+       { 100, 1 },
 };
 
 static const uint64_t vdivs[][2] = {
@@ -123,9 +124,6 @@ static const uint64_t vdivs[][2] = {
        { 100, 1 },
 };
 
-#define NUM_TIMEBASE   ARRAY_SIZE(timebases)
-#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",
@@ -133,7 +131,7 @@ static const char *trigger_sources[] = {
 };
 
 static const char *trigger_slopes[] = {
-       "Rising", "Falling",
+       "r", "f",
 };
 
 static const char *coupling[] = {
@@ -168,11 +166,9 @@ enum series {
        SDS2000X,
 };
 
-/* short name, full name, USB name */
+/* short name, full name */
 static const struct siglent_sds_vendor supported_vendors[] = {
-       [SIGLENT] = {
-               "Siglent", "Siglent Technologies", "Siglent Technologies Co,. Ltd.",
-       },
+       [SIGLENT] = {"Siglent", "Siglent Technologies"},
 };
 
 #define VENDOR(x) &supported_vendors[x]
@@ -208,6 +204,7 @@ static const struct siglent_sds_model supported_models[] = {
        { 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(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 },
@@ -324,7 +321,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                        devc->digital_group);
        }
 
-       for (i = 0; i < NUM_TIMEBASE; i++) {
+       for (i = 0; i < ARRAY_SIZE(timebases); i++) {
                if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
                        devc->timebases = &timebases[i];
 
@@ -332,12 +329,12 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                        devc->num_timebases = &timebases[i] - devc->timebases + 1;
        }
 
-       for (i = 0; i < NUM_VDIV; i++) {
+       for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
                devc->vdivs = &vdivs[i];
                if (!memcmp(&devc->model->series->min_vdiv,
                        &vdivs[i], sizeof(uint64_t[2]))) {
                        devc->vdivs = &vdivs[i];
-                       devc->num_vdivs = NUM_VDIV - i;
+                       devc->num_vdivs = ARRAY_SIZE(vdivs) - i;
                        break;
                }
        }
@@ -374,8 +371,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       sdi->status = SR_ST_ACTIVE;
-
        return SR_OK;
 }
 
@@ -435,7 +430,7 @@ static int config_get(uint32_t key, GVariant **data,
                break;
        case SR_CONF_SAMPLERATE:
                siglent_sds_get_dev_cfg_horizontal(sdi);
-               *data = g_variant_new_uint64(devc->sampleRate);
+               *data = g_variant_new_uint64(devc->samplerate);
                break;
        case SR_CONF_TRIGGER_SOURCE:
                if (!strcmp(devc->trigger_source, "ACL"))
@@ -532,15 +527,12 @@ static int config_set(uint32_t key, GVariant *data,
        uint64_t p, q;
        double t_dbl;
        unsigned int i, j;
-       int ret;
+       int ret, idx;
        const char *tmp_str;
        char buffer[16];
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        /* If a channel group is specified, it must be a valid one. */
        if (cg && !g_slist_find(sdi->channel_groups, cg)) {
                sr_err("Invalid channel group specified.");
@@ -553,8 +545,10 @@ static int config_set(uint32_t key, GVariant *data,
                devc->limit_frames = g_variant_get_uint64(data);
                break;
        case SR_CONF_TRIGGER_SLOPE:
-               tmp_str = g_variant_get_string(data, NULL);
+               if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_slopes))) < 0)
+                       return SR_ERR_ARG;
                g_free(devc->trigger_slope);
+               devc->trigger_slope = g_strdup((trigger_slopes[idx][0] == 'r') ? "POS" : "NEG");
                ret = siglent_sds_config_set(sdi, "%s:TRSL %s",
                        devc->trigger_source, devc->trigger_slope);
                break;
@@ -579,7 +573,6 @@ static int config_set(uint32_t key, GVariant *data,
                        devc->trigger_level = t_dbl;
                break;
        case SR_CONF_TIMEBASE:
-               sr_dbg("Setting device Timebase");
                g_variant_get(data, "(tt)", &p, &q);
                for (i = 0; i < devc->num_timebases; i++) {
                        char *cmd;
@@ -588,16 +581,16 @@ static int config_set(uint32_t key, GVariant *data,
                                devc->timebase = (float) p / q;
                                switch (q) {
                                case 1:
-                                       cmd = g_strdup_printf("%luS", p);
+                                       cmd = g_strdup_printf("%" PRIu64 "S", p);
                                        break;
                                case 1000:
-                                       cmd = g_strdup_printf("%luMS", p);
+                                       cmd = g_strdup_printf("%" PRIu64 "MS", p);
                                        break;
                                case 1000000:
-                                       cmd = g_strdup_printf("%luUS", p);
+                                       cmd = g_strdup_printf("%" PRIu64 "US", p);
                                        break;
                                case 100000000:
-                                       cmd = g_strdup_printf("%luNS", p);
+                                       cmd = g_strdup_printf("%" PRIu64 "NS", p);
                                        break;
                                }
                                sr_dbg("Setting device timebase: TDIV %s.", cmd);
@@ -654,13 +647,13 @@ static int config_set(uint32_t key, GVariant *data,
                                        cmd = "";
                                        switch (q) {
                                        case 1:
-                                               cmd = g_strdup_printf("%luV", p);
+                                               cmd = g_strdup_printf("%" PRIu64 "V", p);
                                                break;
                                        case 1000:
-                                               cmd = g_strdup_printf("%luMV", p);
+                                               cmd = g_strdup_printf("%" PRIu64 "MV", p);
                                                break;
                                        case 100000:
-                                               cmd = g_strdup_printf("%luUV", p);
+                                               cmd = g_strdup_printf("%" PRIu64 "UV", p);
                                                break;
                                        }
                                        return siglent_sds_config_set(sdi, "C%d:VDIV %s", i + 1, cmd);
@@ -708,7 +701,7 @@ static int config_set(uint32_t key, GVariant *data,
                                                return ret;
                                        }
                                }
-                               sr_err("Invalid probe factor: %"PRIu64".", p);
+                               sr_err("Invalid probe factor: %" PRIu64 ".", p);
                                return SR_ERR_ARG;
                        }
                }
@@ -728,7 +721,7 @@ static int config_set(uint32_t key, GVariant *data,
                break;
        case SR_CONF_SAMPLERATE:
                siglent_sds_get_dev_cfg_horizontal(sdi);
-               data = g_variant_new_uint64(devc->sampleRate);
+               data = g_variant_new_uint64(devc->samplerate);
                break;
        default:
                return SR_ERR_NA;
@@ -870,11 +863,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct sr_channel *ch;
        struct sr_datafeed_packet packet;
        gboolean some_digital;
-       GSList *l;
-       GSList *d;
-
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
+       GSList *l, *d;
 
        scpi = sdi->conn;
        devc = sdi->priv;
@@ -983,11 +972,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't stop acquisition.");
-               return SR_ERR;
-       }
-
        std_session_send_df_end(sdi);
 
        g_slist_free(devc->enabled_channels);