X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fscpi-pps%2Fapi.c;h=a29744edefa0b79e6744906b414121511de0a37d;hb=3a322bbc3b0f4d79a79cffac00aeb05ff69ce535;hp=b62574e2abbb02492e8305f8aaad18139c97efac;hpb=0af636bed97c174bea46e61e961eaa1b0b162e0f;p=libsigrok.git
diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c
index b62574e2..a29744ed 100644
--- a/src/hardware/scpi-pps/api.c
+++ b/src/hardware/scpi-pps/api.c
@@ -17,31 +17,31 @@
* along with this program. If not, see .
*/
+#include
#include
+#include
+#include "scpi.h"
#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 const uint32_t devopts_driver[] = {
+static const uint32_t drvopts[] = {
SR_CONF_POWER_SUPPLY,
- SR_CONF_CONTINUOUS,
};
-static struct pps_channel_instance pci[] = {
+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);
}
@@ -74,8 +74,8 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
device = NULL;
for (i = 0; i < num_pps_profiles; i++) {
- vendor = get_vendor(hw_info->manufacturer);
- if (strcasecmp(vendor, pps_profiles[i].vendor))
+ vendor = sr_vendor_alias(hw_info->manufacturer);
+ if (g_ascii_strcasecmp(vendor, pps_profiles[i].vendor))
continue;
model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL);
if (g_regex_match(model_re, hw_info->model, 0, &model_mi))
@@ -90,13 +90,12 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
return NULL;
}
- sdi = sr_dev_inst_new();
- sdi->status = SR_ST_ACTIVE;
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
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);
@@ -106,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. */
@@ -130,17 +129,17 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
for (ch_num = 0; ch_num < num_channels; ch_num++) {
/* Create one channel per measurable output unit. */
for (i = 0; i < ARRAY_SIZE(pci); i++) {
- if (!scpi_cmd_get(sdi, pci[i].command))
+ if (!scpi_cmd_get(devc->device->commands, pci[i].command))
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);
}
}
@@ -167,23 +166,22 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
sr_scpi_hw_info_free(hw_info);
hw_info = NULL;
- scpi_cmd(sdi, SCPI_CMD_LOCAL);
- sr_scpi_close(scpi);
+ scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL);
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);
+ return sr_scpi_scan(di->context, 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;
+ return ((struct drv_context *)(di->context))->instances;
}
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear(di, NULL);
}
@@ -194,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;
@@ -203,13 +201,15 @@ static int dev_open(struct sr_dev_inst *sdi)
sdi->status = SR_ST_ACTIVE;
- scpi_cmd(sdi, SCPI_CMD_REMOTE);
+ devc = sdi->priv;
+ scpi_cmd(sdi, devc->device->commands, SCPI_CMD_REMOTE);
devc = sdi->priv;
devc->beeper_was_set = FALSE;
- if (scpi_cmd_resp(sdi, &beeper, G_VARIANT_TYPE_BOOLEAN, SCPI_CMD_BEEPER) == SR_OK) {
+ if (scpi_cmd_resp(sdi, devc->device->commands, &beeper,
+ G_VARIANT_TYPE_BOOLEAN, SCPI_CMD_BEEPER) == SR_OK) {
if (g_variant_get_boolean(beeper)) {
devc->beeper_was_set = TRUE;
- scpi_cmd(sdi, SCPI_CMD_BEEPER_DISABLE);
+ scpi_cmd(sdi, devc->device->commands, SCPI_CMD_BEEPER_DISABLE);
}
g_variant_unref(beeper);
}
@@ -229,8 +229,8 @@ static int dev_close(struct sr_dev_inst *sdi)
scpi = sdi->conn;
if (scpi) {
if (devc->beeper_was_set)
- scpi_cmd(sdi, SCPI_CMD_BEEPER_ENABLE);
- scpi_cmd(sdi, SCPI_CMD_LOCAL);
+ scpi_cmd(sdi, devc->device->commands, SCPI_CMD_BEEPER_ENABLE);
+ scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL);
sr_scpi_close(scpi);
sdi->status = SR_ST_INACTIVE;
}
@@ -248,7 +248,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);
}
@@ -260,6 +260,7 @@ 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;
@@ -289,23 +290,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;
@@ -337,16 +346,38 @@ 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;
}
- if (gvtype) {
- if (cg)
- select_channel(sdi, cg->channels->data);
- ret = scpi_cmd_resp(sdi, data, gvtype, cmd);
- } else
- ret = SR_ERR_NA;
+ if (!gvtype)
+ return SR_ERR_NA;
+
+ if (cg)
+ select_channel(sdi, cg->channels->data);
+ ret = scpi_cmd_resp(sdi, devc->device->commands, data, gvtype, cmd);
+
+ if (cmd == SCPI_CMD_GET_OUTPUT_REGULATION) {
+ /*
+ * The Rigol DP800 series return CV/CC/UR, Philips PM2800
+ * return VOLT/CURR. We always return a GVariant string in
+ * the Rigol notation.
+ */
+ s = g_variant_get_string(*data, NULL);
+ if (!strcmp(s, "VOLT")) {
+ g_variant_unref(*data);
+ *data = g_variant_new_string("CV");
+ } else if (!strcmp(s, "CURR")) {
+ g_variant_unref(*data);
+ *data = g_variant_new_string("CC");
+ }
+
+ s = g_variant_get_string(*data, NULL);
+ if (strcmp(s, "CV") && strcmp(s, "CC") && strcmp(s, "UR")) {
+ sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s);
+ ret = SR_ERR_DATA;
+ }
+ }
return ret;
}
@@ -354,6 +385,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
+ struct dev_context *devc;
double d;
int ret;
@@ -367,47 +399,65 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
/* Channel group specified. */
select_channel(sdi, cg->channels->data);
- ret = SR_OK;
+ devc = sdi->priv;
+
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);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OUTPUT_ENABLE);
else
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_DISABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OUTPUT_DISABLE);
+ break;
+ case SR_CONF_VOLTAGE_TARGET:
+ d = g_variant_get_double(data);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_VOLTAGE_TARGET, d);
break;
- case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+ case SR_CONF_OUTPUT_FREQUENCY_TARGET:
d = g_variant_get_double(data);
- ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_TARGET, d);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_FREQUENCY_TARGET, d);
break;
- case SR_CONF_OUTPUT_CURRENT_LIMIT:
+ case SR_CONF_CURRENT_LIMIT:
d = g_variant_get_double(data);
- ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_LIMIT, d);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_CURRENT_LIMIT, d);
break;
case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
if (g_variant_get_boolean(data))
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE);
else
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE);
break;
case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
d = g_variant_get_double(data);
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, d);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, d);
break;
case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
if (g_variant_get_boolean(data))
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE);
else
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE);
break;
case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
d = g_variant_get_double(data);
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, d);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, d);
break;
case SR_CONF_OVER_TEMPERATURE_PROTECTION:
if (g_variant_get_boolean(data))
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE);
else
- ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE);
+ ret = scpi_cmd(sdi, devc->device->commands,
+ SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE);
break;
default:
ret = SR_ERR_NA;
@@ -421,7 +471,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;
@@ -434,7 +484,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
return SR_OK;
} else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts_driver, ARRAY_SIZE(devopts_driver), sizeof(uint32_t));
+ drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
@@ -451,7 +501,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)
@@ -488,7 +538,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. */
@@ -498,7 +548,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++) {
@@ -516,8 +576,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
return ret;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi,
- void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
struct dev_context *devc;
struct sr_scpi_dev_inst *scpi;
@@ -538,19 +597,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
std_session_send_df_header(sdi, LOG_PREFIX);
/* Prime the pipe with the first channel's fetch. */
- ch = next_enabled_channel(sdi, NULL);
+ ch = sr_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)
cmd = SCPI_CMD_GET_MEAS_POWER;
else
return SR_ERR;
- scpi_cmd(sdi, cmd, pch->hwname);
+ scpi_cmd(sdi, devc->device->commands, cmd, pch->hwname);
return SR_OK;
}
@@ -598,5 +659,5 @@ SR_PRIV struct sr_dev_driver scpi_pps_driver_info = {
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};