]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/manson-hcs-3xxx/api.c
std_serial_dev_acquisition_stop(): Drop unneeded parameter.
[libsigrok.git] / src / hardware / manson-hcs-3xxx / api.c
index d3bd5e1f4a3adf24497425e19985ec279bbaa1e9..cc9ab74a0283d906f0fcb128f057e583b89a3791 100644 (file)
  */
 
 /** @file
-  *  <em>Manson HCS-3xxx Series</em> power supply driver
+  *  <em>Manson HCS-3xxx series</em> power supply driver
   *  @internal
   */
 
+#include <config.h>
 #include "protocol.h"
 
 static const uint32_t drvopts[] = {
@@ -39,20 +40,20 @@ static const uint32_t scanopts[] = {
 static const uint32_t devopts[] = {
        /* Device class */
        SR_CONF_POWER_SUPPLY,
-       /* Aquisition modes. */
+       /* Acquisition modes. */
        SR_CONF_CONTINUOUS,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
        /* Device configuration */
-       SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
-       SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
-       SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
-       SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
-       SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_VOLTAGE | SR_CONF_GET,
+       SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_CURRENT | SR_CONF_GET,
+       SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
 };
 
 /* Note: All models have one power supply output only. */
-static struct hcs_model models[] = {
+static const struct hcs_model models[] = {
        { MANSON_HCS_3100, "HCS-3100",     "3100", { 1, 18, 0.1 }, { 0, 10,   0.10 } },
        { MANSON_HCS_3102, "HCS-3102",     "3102", { 1, 36, 0.1 }, { 0,  5,   0.01 } },
        { MANSON_HCS_3104, "HCS-3104",     "3104", { 1, 60, 0.1 }, { 0,  2.5, 0.01 } },
@@ -69,23 +70,22 @@ static struct hcs_model models[] = {
        { MANSON_HCS_3600, "HCS-3600-USB", "3600", { 1, 16, 0.1 }, { 0, 60,   0.10 } },
        { MANSON_HCS_3602, "HCS-3602-USB", "3602", { 1, 32, 0.1 }, { 0, 30,   0.10 } },
        { MANSON_HCS_3604, "HCS-3604-USB", "3604", { 1, 60, 0.1 }, { 0, 15,   0.10 } },
-       { 0, NULL, NULL, { 0, 0, 0 }, { 0, 0, 0 }, },
+       ALL_ZERO
 };
 
 SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info;
-static struct sr_dev_driver *di = &manson_hcs_3xxx_driver_info;
 
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, NULL);
 }
 
-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);
 }
 
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        int i, model_id;
        struct drv_context *drvc;
@@ -97,7 +97,7 @@ static GSList *scan(GSList *options)
        struct sr_serial_dev_inst *serial;
        char reply[50], **tokens, *dummy;
 
-       drvc = di->priv;
+       drvc = di->context;
        drvc->instances = NULL;
        devices = NULL;
        conn = NULL;
@@ -145,12 +145,12 @@ static GSList *scan(GSList *options)
                if (!strcmp(models[i].id, tokens[0]))
                        model_id = i;
        }
-       g_strfreev(tokens);
-
        if (model_id < 0) {
-               sr_err("Unknown model id '%s' detected, aborting.", tokens[0]);
+               sr_err("Unknown model ID '%s' detected, aborting.", tokens[0]);
+               g_strfreev(tokens);
                return NULL;
        }
+       g_strfreev(tokens);
 
        /* Init device instance, etc. */
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
@@ -173,8 +173,10 @@ static GSList *scan(GSList *options)
            (hcs_read_reply(serial, 2, reply, sizeof(reply)) < 0))
                goto exit_err;
        tokens = g_strsplit((const gchar *)&reply, "\r", 2);
-       if (hcs_parse_volt_curr_mode(sdi, tokens) < 0)
+       if (hcs_parse_volt_curr_mode(sdi, tokens) < 0) {
+               g_strfreev(tokens);
                goto exit_err;
+       }
        g_strfreev(tokens);
 
        /* Get max. voltage and current. */
@@ -198,19 +200,19 @@ static GSList *scan(GSList *options)
 
 exit_err:
        sr_dev_inst_free(sdi);
-       if (devc)
-               g_free(devc);
+       g_free(devc);
+
        return NULL;
 }
 
-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 cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
 {
-       return dev_clear();
+       return dev_clear(di);
 }
 
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -232,19 +234,19 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        case SR_CONF_LIMIT_MSEC:
                *data = g_variant_new_uint64(devc->limit_msec);
                break;
-       case SR_CONF_OUTPUT_VOLTAGE:
+       case SR_CONF_VOLTAGE:
                *data = g_variant_new_double(devc->voltage);
                break;
-       case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+       case SR_CONF_VOLTAGE_TARGET:
                *data = g_variant_new_double(devc->voltage_max);
                break;
-       case SR_CONF_OUTPUT_CURRENT:
+       case SR_CONF_CURRENT:
                *data = g_variant_new_double(devc->current);
                break;
-       case SR_CONF_OUTPUT_CURRENT_LIMIT:
+       case SR_CONF_CURRENT_LIMIT:
                *data = g_variant_new_double(devc->current_max);
                break;
-       case SR_CONF_OUTPUT_ENABLED:
+       case SR_CONF_ENABLED:
                *data = g_variant_new_boolean(devc->output_enabled);
                break;
        default:
@@ -279,7 +281,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        return SR_ERR_ARG;
                devc->limit_samples = g_variant_get_uint64(data);
                break;
-       case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+       case SR_CONF_VOLTAGE_TARGET:
                dval = g_variant_get_double(data);
                if (dval < devc->model->voltage[0] || dval > devc->voltage_max_device)
                        return SR_ERR_ARG;
@@ -290,7 +292,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        return SR_ERR;
                devc->voltage_max = dval;
                break;
-       case SR_CONF_OUTPUT_CURRENT_LIMIT:
+       case SR_CONF_CURRENT_LIMIT:
                dval = g_variant_get_double(data);
                if (dval < devc->model->current[0] || dval > devc->current_max_device)
                        return SR_ERR_ARG;
@@ -301,7 +303,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        return SR_ERR;
                devc->current_max = dval;
                break;
-       case SR_CONF_OUTPUT_ENABLED:
+       case SR_CONF_ENABLED:
                bval = g_variant_get_boolean(data);
                if (bval == devc->output_enabled) /* Nothing to do. */
                        break;
@@ -352,7 +354,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
                break;
-       case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+       case SR_CONF_VOLTAGE_TARGET:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                /* Min, max, step. */
                for (idx = 0; idx < 3; idx++) {
@@ -365,7 +367,7 @@ 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_CURRENT_LIMIT:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                /* Min, max, step. */
                for (idx = 0; idx < 3; idx++) {
@@ -385,7 +387,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        return SR_OK;
 }
 
-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)
 {
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
@@ -394,10 +396,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
-       devc->cb_data = cb_data;
 
-       /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        devc->starttime = g_get_monotonic_time();
        devc->num_samples = 0;
@@ -412,9 +412,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        return SR_OK;
 }
 
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
-       return std_serial_dev_acquisition_stop(sdi, cb_data,
+       return std_serial_dev_acquisition_stop(sdi,
                        std_serial_dev_close, sdi->conn, LOG_PREFIX);
 }
 
@@ -434,5 +434,5 @@ SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info = {
        .dev_close = std_serial_dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };