]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-pps/api.c
scpi-pps: Minor cleanups.
[libsigrok.git] / src / hardware / scpi-pps / api.c
index 0539e81aaacfc158d3a9e1cd83f52909349f843f..d4aa4923ff71f06941e049fab2e110d2a98e6313 100644 (file)
  */
 
 #include <string.h>
+#include <strings.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,
@@ -34,13 +32,14 @@ static const uint32_t drvopts[] = {
        SR_CONF_POWER_SUPPLY,
 };
 
-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);
 }
@@ -95,7 +94,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        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);
 
@@ -105,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. */
@@ -172,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);
 }
@@ -247,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);
 }
@@ -300,6 +299,14 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                gvtype = G_VARIANT_TYPE_DOUBLE;
                cmd = SCPI_CMD_GET_VOLTAGE_TARGET;
                break;
+       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_OUTPUT_CURRENT:
                gvtype = G_VARIANT_TYPE_DOUBLE;
                cmd = SCPI_CMD_GET_MEAS_CURRENT;
@@ -378,6 +385,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                d = g_variant_get_double(data);
                ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_TARGET, d);
                break;
+       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_OUTPUT_CURRENT_LIMIT:
                d = g_variant_get_double(data);
                ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_LIMIT, d);
@@ -420,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;
@@ -497,6 +508,16 @@ 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_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_OUTPUT_CURRENT_LIMIT:
                        g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                        /* Min, max, step. */
@@ -543,6 +564,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                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)