X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fscpi-pps%2Fapi.c;h=e68836b7acf34438e1a26e3e8e6a8dcbda3c5a34;hb=ba464a121766fda8f8a1799b1b140b225c9774ee;hp=2ed2c976be7d67169d5fe426871e09e8a4bfb44a;hpb=c1d56d20131a0f34d819721f7fd9c4952482557f;p=libsigrok.git diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 2ed2c976..e68836b7 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -18,10 +18,10 @@ */ #include +#include #include "protocol.h" SR_PRIV struct sr_dev_driver scpi_pps_driver_info; -static struct sr_dev_driver *di = &scpi_pps_driver_info; extern unsigned int num_pps_profiles; extern const struct scpi_pps pps_profiles[]; @@ -30,13 +30,17 @@ static const uint32_t scanopts[] = { SR_CONF_SERIALCOMM, }; -static struct pps_channel_instance pci[] = { +static const uint32_t drvopts[] = { + SR_CONF_POWER_SUPPLY, +}; + +static const struct pps_channel_instance pci[] = { { SR_MQ_VOLTAGE, SCPI_CMD_GET_MEAS_VOLTAGE, "V" }, { SR_MQ_CURRENT, SCPI_CMD_GET_MEAS_CURRENT, "I" }, { SR_MQ_POWER, SCPI_CMD_GET_MEAS_POWER, "P" }, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -85,10 +89,13 @@ 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_INACTIVE; + 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->driver = &scpi_pps_driver_info; sdi->inst_type = SR_INST_SCPI; sdi->serial_num = g_strdup(hw_info->serial_number); @@ -98,9 +105,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) if (device->num_channels) { /* Static channels and groups. */ - channels = device->channels; + channels = (struct channel_spec *)device->channels; num_channels = device->num_channels; - channel_groups = device->channel_groups; + channel_groups = (struct channel_group_spec *)device->channel_groups; num_channel_groups = device->num_channel_groups; } else { /* Channels and groups need to be probed. */ @@ -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); } } @@ -165,17 +172,17 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) return sdi; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { return sr_scpi_scan(di->priv, options, probe_device); } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } @@ -186,7 +193,7 @@ static int dev_open(struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi; GVariant *beeper; - if (sdi->status != SR_ST_ACTIVE) + if (sdi->status != SR_ST_INACTIVE) return SR_ERR; scpi = sdi->conn; @@ -240,7 +247,7 @@ static void clear_helper(void *priv) g_free(devc); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } @@ -413,7 +420,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * { struct dev_context *devc; struct sr_channel *ch; - struct channel_spec *ch_spec; + const struct channel_spec *ch_spec; GVariant *gvar; GVariantBuilder gvb; int ret, i; @@ -424,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)