]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-pps/api.c
Simplify channel creation.
[libsigrok.git] / src / hardware / scpi-pps / api.c
index fc06e906370372729d44f79fe46a661af8b445ff..4647031c289df9d7a30926e49c91ed9fdbb42915 100644 (file)
@@ -30,6 +30,10 @@ static const uint32_t scanopts[] = {
        SR_CONF_SERIALCOMM,
 };
 
+static const uint32_t drvopts[] = {
+       SR_CONF_POWER_SUPPLY,
+};
+
 static struct pps_channel_instance pci[] = {
        { SR_MQ_VOLTAGE, SCPI_CMD_GET_MEAS_VOLTAGE, "V" },
        { SR_MQ_CURRENT, SCPI_CMD_GET_MEAS_CURRENT, "I" },
@@ -85,8 +89,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                return NULL;
        }
 
-       sdi = sr_dev_inst_new(SR_ST_ACTIVE, vendor, hw_info->model,
-                       hw_info->firmware_version);
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi->status = SR_ST_ACTIVE;
+       sdi->vendor = g_strdup(vendor);
+       sdi->model = g_strdup(hw_info->model);
+       sdi->version = g_strdup(hw_info->firmware_version);
        sdi->conn = scpi;
        sdi->driver = di;
        sdi->inst_type = SR_INST_SCPI;
@@ -126,13 +133,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                                continue;
                        g_snprintf(ch_name, 16, "%s%s", pci[i].prefix,
                                        channels[ch_num].name);
-                       ch = sr_channel_new(ch_idx++, SR_CHANNEL_ANALOG, TRUE, ch_name);
+                       ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_ANALOG, TRUE,
+                                       ch_name);
                        pch = g_malloc0(sizeof(struct pps_channel));
                        pch->hw_output_idx = ch_num;
                        pch->hwname = channels[ch_num].name;
                        pch->mq = pci[i].mq;
                        ch->priv = pch;
-                       sdi->channels = g_slist_append(sdi->channels, ch);
                }
        }
 
@@ -252,7 +259,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        const GVariantType *gvtype;
        unsigned int i;
        int cmd, ret;
-       const char *s;
 
        if (!sdi)
                return SR_ERR_ARG;
@@ -338,25 +344,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                if (cg)
                        select_channel(sdi, cg->channels->data);
                ret = scpi_cmd_resp(sdi, data, gvtype, cmd);
-
-               if (gvtype == G_VARIANT_TYPE_STRING && ret == SR_OK) {
-                       /* Non-standard data type responses. */
-                       switch (key) {
-                       case SCPI_CMD_GET_OUTPUT_REGULATION:
-                               /*
-                                * This is specific to the Rigol DP800 series.
-                                * We return the same string for now until more
-                                * models with this key are supported. Do a check
-                                * just for the hell of it.
-                                */
-                               s = g_variant_get_string(*data, NULL);
-                               if (strcmp(s, "CC") && strcmp(s, "CV") && strcmp(s, "UR")) {
-                                       sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s);
-                                       ret = SR_ERR_DATA;
-                               }
-                               break;
-                       }
-               }
        } else
                ret = SR_ERR_NA;
 
@@ -444,6 +431,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
                return SR_OK;
+       } else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
+               return SR_OK;
        }
 
        if (!sdi)