X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fscpi-pps%2Fapi.c;h=c728f2b0fde2b494f855f2d6c516f5a0d9fb5ce0;hb=da005885c8ebbf98772f75126764f758b2640d11;hp=fc06e906370372729d44f79fe46a661af8b445ff;hpb=4a471029c230a7e2e0b15528d22bf30fb7cf2472;p=libsigrok.git diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index fc06e906..c728f2b0 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -18,25 +18,28 @@ */ #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[]; static const uint32_t scanopts[] = { SR_CONF_CONN, 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" }, + { SR_MQ_FREQUENCY, SCPI_CMD_GET_MEAS_FREQUENCY, "F" }, }; -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 +88,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 +104,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 +132,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 +171,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 +192,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 +246,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); } @@ -252,7 +258,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; @@ -282,23 +287,31 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s gvtype = NULL; cmd = -1; switch (key) { - case SR_CONF_OUTPUT_ENABLED: + case SR_CONF_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OUTPUT_ENABLED; break; - case SR_CONF_OUTPUT_VOLTAGE: + case SR_CONF_VOLTAGE: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_VOLTAGE; break; - case SR_CONF_OUTPUT_VOLTAGE_TARGET: + case SR_CONF_VOLTAGE_TARGET: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_VOLTAGE_TARGET; break; - case SR_CONF_OUTPUT_CURRENT: + case SR_CONF_OUTPUT_FREQUENCY: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_MEAS_FREQUENCY; + break; + case SR_CONF_OUTPUT_FREQUENCY_TARGET: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_FREQUENCY_TARGET; + break; + case SR_CONF_CURRENT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_CURRENT; break; - case SR_CONF_OUTPUT_CURRENT_LIMIT: + case SR_CONF_CURRENT_LIMIT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_CURRENT_LIMIT; break; @@ -330,7 +343,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION; break; - case SR_CONF_OUTPUT_REGULATION: + case SR_CONF_REGULATION: gvtype = G_VARIANT_TYPE_STRING; cmd = SCPI_CMD_GET_OUTPUT_REGULATION; } @@ -338,25 +351,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; @@ -381,17 +375,21 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd ret = SR_OK; switch (key) { - case SR_CONF_OUTPUT_ENABLED: + case SR_CONF_ENABLED: if (g_variant_get_boolean(data)) ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_ENABLE); else ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_DISABLE); break; - case SR_CONF_OUTPUT_VOLTAGE_TARGET: + case SR_CONF_VOLTAGE_TARGET: d = g_variant_get_double(data); ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_TARGET, d); break; - case SR_CONF_OUTPUT_CURRENT_LIMIT: + case SR_CONF_OUTPUT_FREQUENCY_TARGET: + d = g_variant_get_double(data); + ret = scpi_cmd(sdi, SCPI_CMD_SET_FREQUENCY_TARGET, d); + break; + case SR_CONF_CURRENT_LIMIT: d = g_variant_get_double(data); ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_LIMIT, d); break; @@ -433,7 +431,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; @@ -444,6 +442,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) @@ -459,7 +461,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * devc->device->devopts, devc->device->num_devopts, sizeof(uint32_t)); break; - case SR_CONF_OUTPUT_CHANNEL_CONFIG: + case SR_CONF_CHANNEL_CONFIG: /* Not used. */ i = 0; if (devc->device->features & PPS_INDEPENDENT) @@ -496,7 +498,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * devc->device->devopts_cg, devc->device->num_devopts_cg, sizeof(uint32_t)); break; - case SR_CONF_OUTPUT_VOLTAGE_TARGET: + case SR_CONF_VOLTAGE_TARGET: ch_spec = &(devc->device->channels[ch->index]); g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, write resolution. */ @@ -506,7 +508,17 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } *data = g_variant_builder_end(&gvb); break; - case SR_CONF_OUTPUT_CURRENT_LIMIT: + case SR_CONF_OUTPUT_FREQUENCY_TARGET: + ch_spec = &(devc->device->channels[ch->index]); + g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); + /* Min, max, write resolution. */ + for (i = 0; i < 3; i++) { + gvar = g_variant_new_double(ch_spec->frequency[i]); + g_variant_builder_add_value(&gvb, gvar); + } + *data = g_variant_builder_end(&gvb); + break; + case SR_CONF_CURRENT_LIMIT: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, step. */ for (i = 0; i < 3; i++) { @@ -548,10 +560,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, /* Prime the pipe with the first channel's fetch. */ ch = next_enabled_channel(sdi, NULL); pch = ch->priv; - if ((ret = select_channel(sdi, ch)) != SR_OK) + if ((ret = select_channel(sdi, ch)) < 0) return ret; if (pch->mq == SR_MQ_VOLTAGE) cmd = SCPI_CMD_GET_MEAS_VOLTAGE; + else if (pch->mq == SR_MQ_FREQUENCY) + cmd = SCPI_CMD_GET_MEAS_FREQUENCY; else if (pch->mq == SR_MQ_CURRENT) cmd = SCPI_CMD_GET_MEAS_CURRENT; else if (pch->mq == SR_MQ_POWER)