]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/motech-lps-30x/api.c
std_serial_dev_acquisition_stop(): Drop unneeded parameter.
[libsigrok.git] / src / hardware / motech-lps-30x / api.c
index ff4b9e21599d7b78a46ce8ba76212077cd1faed4..cee97b575f909fee37ae44832a5fe9a267a95629 100644 (file)
  *  @internal
  */
 
+#include <config.h>
 #include <ctype.h>
-#include <errno.h>
 #include <math.h>
 #include <string.h>
-
 #include "protocol.h"
 
 /* Forward declarations */
 SR_PRIV struct sr_dev_driver motech_lps_301_driver_info;
 SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen);
-SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const charfmt, va_list args);
-SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const charfmt, ...);
-SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const char* fmt, ...);
-SR_PRIV int lps_query_status(struct sr_dev_instsdi);
+SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args);
+SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...);
+SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...);
+SR_PRIV int lps_query_status(struct sr_dev_inst *sdi);
 
 /* Serial communication parameters */
 #define SERIALCOMM "2400/8n1/dtr=1/rts=1/flow=0"
@@ -64,22 +63,22 @@ static const uint32_t devopts[] = {
        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_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
 /** Hardware capabilities channel 1, 2. */
 static const uint32_t devopts_ch12[] = {
-       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,
 };
 
 /** Hardware capabilities channel 3. (LPS-304/305 only). */
 static const uint32_t devopts_ch3[] = {
-       SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
-       SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_VOLTAGE | SR_CONF_GET,
+       SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
 };
 
 static const char *channel_modes[] = {
@@ -141,7 +140,7 @@ static int init_lps301(struct sr_dev_driver *di, struct sr_context *sr_ctx)
 
 /** Send command to device with va_list.
  */
-SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const charfmt, va_list args)
+SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args)
 {
        int retc;
        char auxfmt[LINELEN_MAX];
@@ -152,7 +151,8 @@ SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_l
 
        sr_spew("lps_send_va: \"%s\"", buf);
 
-       retc = serial_write_blocking(serial, buf, strlen(buf), 0);
+       retc = serial_write_blocking(serial, buf, strlen(buf),
+                       serial_timeout(serial, strlen(buf)));
 
        if (retc < 0)
                return SR_ERR;
@@ -162,7 +162,7 @@ SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_l
 
 /** Send command to device.
  */
-SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const charfmt, ...)
+SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char *fmt, ...)
 {
        int retc;
        va_list args;
@@ -175,12 +175,12 @@ SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char* fmt, ...
 }
 
 /** Send command and consume simple OK reply. */
-SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const charfmt, ...)
+SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...)
 {
        int retc;
        va_list args;
        char buf[LINELEN_MAX];
-       charbufptr;
+       char *bufptr;
        int  buflen;
 
        /* Send command */
@@ -203,14 +203,14 @@ SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char* fmt, ...)
 }
 
 /** Send command and read reply string.
- *  \param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
+ *  @param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
  */
-SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const char* fmt, ...)
+SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...)
 {
        int retc;
        va_list args;
        char buf[LINELEN_MAX];
-       charbufptr;
+       char *bufptr;
        int  buflen;
 
        reply[0] = '\0';
@@ -237,12 +237,12 @@ SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const
 }
 
 /** Process integer value returned by STATUS command. */
-SR_PRIV int lps_process_status(struct sr_dev_instsdi, int stat)
+SR_PRIV int lps_process_status(struct sr_dev_inst *sdi, int stat)
 {
-       struct dev_contextdevc;
+       struct dev_context *devc;
        int tracking_mode;
 
-       devc = (struct dev_context*)sdi->priv;
+       devc = (struct dev_context *)sdi->priv;
 
        sr_spew("Status: %d", stat);
        devc->channel_status[0].cc_mode = (stat & 0x01) != 0;
@@ -283,18 +283,19 @@ SR_PRIV int lps_process_status(struct sr_dev_inst* sdi, int stat)
 }
 
 /** Send STATUS commend and process status string. */
-SR_PRIV int lps_query_status(struct sr_dev_instsdi)
+SR_PRIV int lps_query_status(struct sr_dev_inst *sdi)
 {
        char buf[LINELEN_MAX];
-       int stat;
-       struct dev_contextdevc;
+       int stat, ret;
+       struct dev_context *devc;
 
-       devc = (struct dev_context*)sdi->priv;
+       devc = (struct dev_context *)sdi->priv;
 
        devc->req_sent_at = g_get_real_time();
 
-       if (lps_cmd_reply(buf, sdi->conn, "STATUS") < 0) {
-               sr_err("%s: Failed to read status: %d %s", __func__, errno, strerror(errno));
+       if ((ret = lps_cmd_reply(buf, sdi->conn, "STATUS")) < 0) {
+               sr_err("%s: Failed to read status: %s.", __func__,
+                       sr_strerror(ret));
                return SR_ERR;
        }
 
@@ -315,8 +316,8 @@ static gint64 calc_timeout_ms(gint64 start_us)
 }
 
 /** Read message into buf until "OK" received.
- *  \retval SR_OK Msg received; buf and buflen contain result, if any except OK.
- *  \retval SR_ERR Error, including timeout.
+ *  @retval SR_OK Msg received; buf and buflen contain result, if any except OK.
+ *  @retval SR_ERR Error, including timeout.
 */
 SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen)
 {
@@ -380,7 +381,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        struct sr_channel_group *cg;
        GSList *devices;
        const char *conn, *serialcomm;
-       int cnt;
+       int cnt, ret;
        gchar buf[LINELEN_MAX];
        gchar channel[10];
        char *verstr;
@@ -390,7 +391,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        conn = serialcomm = NULL;
        devices = NULL;
 
-       drvc = drv->priv;
+       drvc = drv->context;
        drvc->instances = NULL;
 
        sr_spew("scan() called!");
@@ -435,7 +436,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
 
        /* Query version */
        verstr = NULL;
-       if (lps_cmd_reply(buf, serial, "VERSION") == SR_OK) {
+       if ((ret = lps_cmd_reply(buf, serial, "VERSION")) == SR_OK) {
                if (strncmp(buf, "Ver-", 4)) {
                        sr_spew("Version string %s not recognized.", buf);
                        goto exit_err;
@@ -446,7 +447,8 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        }
        else  /* Bug in device FW 1.17: Querying version string fails while output is active.
                Therefore just print an error message, but do not exit with error. */
-               sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno));
+               sr_err("Failed to query for hardware version: %s.",
+                       sr_strerror(ret));
 
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
        sdi->status = SR_ST_INACTIVE;
@@ -502,8 +504,7 @@ exit_err:
                serial_close(serial);
                sr_serial_dev_inst_free(serial);
        }
-       if (devc)
-               g_free(devc);
+       g_free(devc);
        if (sdi)
                sr_dev_inst_free(sdi);
 
@@ -518,10 +519,10 @@ static GSList *scan_lps301(struct sr_dev_driver *di, GSList *options)
 
 static GSList *dev_list_lps301(const struct sr_dev_driver *di)
 {
-       return ((struct drv_context *)(di->priv))->instances;
+       return ((struct drv_context *)(di->context))->instances;
 }
 
-static void dev_clear_private(struct dev_contextdevc)
+static void dev_clear_private(struct dev_context *devc)
 {
        int ch_idx;
 
@@ -563,7 +564,7 @@ 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_CHANNEL_CONFIG:
+               case SR_CONF_CHANNEL_CONFIG:
                        *data = g_variant_new_string(channel_modes[devc->tracking_mode]);
                        break;
                default:
@@ -574,19 +575,19 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                ch = cg->channels->data;
                ch_idx = ch->index;
                switch (key) {
-               case SR_CONF_OUTPUT_VOLTAGE:
+               case SR_CONF_VOLTAGE:
                        *data = g_variant_new_double(devc->channel_status[ch_idx].output_voltage_last);
                        break;
-               case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+               case SR_CONF_VOLTAGE_TARGET:
                        *data = g_variant_new_double(devc->channel_status[ch_idx].output_voltage_max);
                        break;
-               case SR_CONF_OUTPUT_CURRENT:
+               case SR_CONF_CURRENT:
                        *data = g_variant_new_double(devc->channel_status[ch_idx].output_current_last);
                        break;
-               case SR_CONF_OUTPUT_CURRENT_LIMIT:
+               case SR_CONF_CURRENT_LIMIT:
                        *data = g_variant_new_double(devc->channel_status[ch_idx].output_current_max);
                        break;
-               case SR_CONF_OUTPUT_ENABLED:
+               case SR_CONF_ENABLED:
                        *data = g_variant_new_boolean(devc->channel_status[ch_idx].output_enabled);
                        break;
                default:
@@ -628,7 +629,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                case SR_CONF_LIMIT_SAMPLES:
                        devc->limit_samples = g_variant_get_uint64(data);
                        break;
-               case SR_CONF_OUTPUT_CHANNEL_CONFIG:
+               case SR_CONF_CHANNEL_CONFIG:
                        sval = g_variant_get_string(data, NULL);
                        found = FALSE;
                        for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) {
@@ -656,7 +657,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                ch_idx = ch->index;
 
                switch (key) {
-               case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+               case SR_CONF_VOLTAGE_TARGET:
                        dval = g_variant_get_double(data);
                        if (dval < 0 || dval > devc->model->channels[ch_idx].voltage[1])
                                return SR_ERR_ARG;
@@ -677,7 +678,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        else
                                return lps_cmd_ok(sdi->conn, "VSET%d %05.3f", ch_idx+1, dval);
                        break;
-               case SR_CONF_OUTPUT_CURRENT_LIMIT:
+               case SR_CONF_CURRENT_LIMIT:
                        dval = g_variant_get_double(data);
                        if (dval < 0 || dval > devc->model->channels[ch_idx].current[1])
                                return SR_ERR_ARG;
@@ -686,7 +687,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        devc->channel_status[ch_idx].output_current_max = dval;
                        return lps_cmd_ok(sdi->conn, "ISET%d %05.4f", ch_idx+1, dval);
                        break;
-               case SR_CONF_OUTPUT_ENABLED:
+               case SR_CONF_ENABLED:
                        bval = g_variant_get_boolean(data);
                        if (bval == devc->channel_status[ch_idx].output_enabled) /* Nothing to do. */
                                break;
@@ -744,7 +745,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));
                        return SR_OK;
-               case SR_CONF_OUTPUT_CHANNEL_CONFIG:
+               case SR_CONF_CHANNEL_CONFIG:
                        if (devc->model->modelid <= LPS_303) {
                                /* The 1-channel models. */
                                *data = g_variant_new_strv(channel_modes, 1);
@@ -770,7 +771,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_ch3, ARRAY_SIZE(devopts_ch3), 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 (i = 0; i < 3; i++) {
@@ -779,7 +780,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 (i = 0; i < 3; i++) {
@@ -795,8 +796,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;
@@ -811,7 +811,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        serial = sdi->conn;
        serial_source_add(sdi->session, serial, G_IO_IN, 50,
                        motech_lps_30x_receive_data, (void *)sdi);
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Start timer, if required. */
        if (devc->limit_msec)
@@ -823,7 +823,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        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)
 {
        struct dev_context *devc;
 
@@ -831,7 +831,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        if (sdi && (devc = sdi->priv) && devc->limit_msec)
                g_timer_stop(devc->elapsed_msec);
 
-       return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close,
+       return std_serial_dev_acquisition_stop(sdi, std_serial_dev_close,
                        sdi->conn, LOG_PREFIX);
 }
 
@@ -851,5 +851,5 @@ SR_PRIV struct sr_dev_driver motech_lps_301_driver_info = {
        .dev_close = std_serial_dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };