]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds/api.c
rigol-ds: prevent config_list() to return empty g_variant
[libsigrok.git] / hardware / rigol-ds / api.c
index 6eafe49434d6cf38df7b9433c47548e53ef1787f..d4e12daf8b6b447e9d55ec4aeeaadf5152544d65 100644 (file)
@@ -170,6 +170,11 @@ static const struct rigol_ds_model supported_models[] = {
        {RIGOL, "DS2072", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, 2, false, 14},
        {RIGOL, "DS2102", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, 2, false, 14},
        {RIGOL, "DS2202", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {500, 1}, {500, 1000000}, 2, false, 14},
+       {RIGOL, "DS2302", RIGOL_DS2000, PROTOCOL_IEEE488_2, {1, 1000000000}, {1000, 1}, {500, 1000000}, 2, false, 14},
+       {RIGOL, "DS2072A", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {1000, 1}, {500, 1000000}, 2, false, 14},
+       {RIGOL, "DS2102A", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {1000, 1}, {500, 1000000}, 2, false, 14},
+       {RIGOL, "DS2202A", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {1000, 1}, {500, 1000000}, 2, false, 14},
+       {RIGOL, "DS2302A", RIGOL_DS2000, PROTOCOL_IEEE488_2, {1, 1000000000}, {1000, 1}, {500, 1000000}, 2, false, 14},
        {RIGOL, "VS5022", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
        {RIGOL, "VS5022D", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
        {RIGOL, "VS5042", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
@@ -180,7 +185,12 @@ static const struct rigol_ds_model supported_models[] = {
        {RIGOL, "VS5102D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
        {RIGOL, "VS5202", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
        {RIGOL, "VS5202D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
+       {AGILENT, "DSO1002A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {5, 1000000000}, {50, 1}, {2, 1000}, 2, false, 12},
+       {AGILENT, "DSO1004A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {5, 1000000000}, {50, 1}, {2, 1000}, 4, false, 12},
+       {AGILENT, "DSO1012A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 12},
        {AGILENT, "DSO1014A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {2, 1000000000}, {50, 1}, {2, 1000}, 4, false, 12},
+       {AGILENT, "DSO1022A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 12},
+       {AGILENT, "DSO1024A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {2, 1000000000}, {50, 1}, {2, 1000}, 4, false, 12},
 };
 
 SR_PRIV struct sr_dev_driver rigol_ds_driver_info;
@@ -236,9 +246,6 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev
 {
        struct dev_context *devc;
        struct sr_dev_inst *sdi;
-       const char *usbtmc_prefix = "/dev/usbtmc";
-       const char *tcp_prefix = "tcp/";
-       gchar **tokens, *address, *port;
        struct sr_scpi_dev_inst *scpi;
        struct sr_scpi_hw_info *hw_info;
        struct sr_probe *probe;
@@ -248,29 +255,8 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev
 
        *devices = NULL;
 
-       if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
-               sr_dbg("Opening USBTMC device %s.", resource);
-               if (!(scpi = scpi_usbtmc_dev_inst_new(resource)))
-                       return SR_ERR_MALLOC;
-       } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
-               sr_dbg("Opening TCP connection %s.", resource);
-               tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
-               address = tokens[0];
-               port = tokens[1];
-               if (!address || !port || tokens[2]) {
-                       sr_err("Invalid parameters.");
-                       g_strfreev(tokens);
-                       return SR_ERR_ARG;
-               }
-               scpi = scpi_tcp_dev_inst_new(address, port);
-               g_strfreev(tokens);
-               if (!scpi)
-                       return SR_ERR_MALLOC;
-       } else {
-               sr_dbg("Opening serial device %s.", resource);
-               if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm)))
-                       return SR_ERR_MALLOC;
-       }
+       if (!(scpi = scpi_dev_inst_new(resource, serialcomm)))
+               return SR_ERR;
 
        if (sr_scpi_open(scpi) != SR_OK) {
                sr_info("Couldn't open SCPI device.");
@@ -351,12 +337,9 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev
                        devc->num_timebases = &timebases[i] - devc->timebases + 1;
        }
 
-       for (i = 0; i < NUM_VDIV; i++) {
-               if (!memcmp(&devc->model->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) {
+       for (i = 0; i < NUM_VDIV; i++)
+               if (!memcmp(&devc->model->min_vdiv, &vdivs[i], sizeof(uint64_t[2])))
                        devc->vdivs = &vdivs[i];
-                       devc->num_vdivs = NUM_VDIV - (&vdivs[i] - &vdivs[0]);
-               }
-       }
 
        if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
                return SR_ERR_MALLOC;
@@ -476,7 +459,6 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_probe_group *probe_group)
 {
        struct dev_context *devc;
-       unsigned int i;
 
        if (!sdi || !(devc = sdi->priv))
                return SR_ERR_ARG;
@@ -492,20 +474,10 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
 
        switch (id) {
        case SR_CONF_NUM_TIMEBASE:
-               *data = g_variant_new_int32(devc->num_timebases);
+               *data = g_variant_new_int32(devc->model->num_horizontal_divs);
                break;
        case SR_CONF_NUM_VDIV:
-               if (!probe_group) {
-                       sr_err("No probe group specified.");
-                       return SR_ERR_PROBE_GROUP;
-               }
-               for (i = 0; i < 2; i++) {
-                       if (probe_group == &devc->analog_groups[i]) {
-                               *data = g_variant_new_int32(devc->num_vdivs);
-                               return SR_OK;
-                       }
-               }
-               return SR_ERR_NA;
+               *data = g_variant_new_int32(8);
        case SR_CONF_DATA_SOURCE:
                if (devc->data_source == DATA_SOURCE_LIVE)
                        *data = g_variant_new_string("Live");
@@ -737,7 +709,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                        return SR_ERR_PROBE_GROUP;
                }
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-               for (i = 0; i < devc->num_vdivs; i++) {
+               for (i = 0; i < NUM_VDIV; i++) {
                        rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
                        rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
                        tuple = g_variant_new_tuple(rational, 2);
@@ -749,6 +721,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                if (!devc)
                        /* Can't know this until we have the exact model. */
                        return SR_ERR_ARG;
+               if (devc->num_timebases <= 0)
+                       return SR_ERR_NA;
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                for (i = 0; i < devc->num_timebases; i++) {
                        rational[0] = g_variant_new_uint64(devc->timebases[i][0]);