]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/gmc-mh-1x-2x/api.c
std_serial_dev_acquisition_stop(): Drop unneeded parameter.
[libsigrok.git] / src / hardware / gmc-mh-1x-2x / api.c
index 13918c6365d6846ddcc4451f7d95c433ad16d08d..15bf7f9f4845021adcea0bb6d4578ff172fb5fe2 100644 (file)
@@ -22,6 +22,7 @@
  *  @internal
  */
 
+#include <config.h>
 #include <string.h>
 #include "protocol.h"
 
@@ -58,7 +59,6 @@ static const uint32_t devopts_bd[] = {
        SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET,
 };
 
-
 /* TODO:
  * - For the 29S SR_CONF_ENERGYMETER, too.
  * - SR_CONF_PATTERN_MODE for some 2x devices
@@ -66,7 +66,6 @@ static const uint32_t devopts_bd[] = {
  * Need to implement device-specific lists.
  */
 
-/** Init driver. */
 static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
 {
        return std_init(sr_ctx, di, LOG_PREFIX);
@@ -110,7 +109,7 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial)
        gint64 timeout_us;
 
        model = METRAHIT_NONE;
-       timeout_us = g_get_monotonic_time() + 1 * 1000 * 1000;
+       timeout_us = g_get_monotonic_time() + (1 * 1000 * 1000);
 
        /*
         * Try to find message consisting of device code and several
@@ -163,10 +162,9 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options)
        gboolean serialcomm_given;
 
        devices = NULL;
-       drvc = di->priv;
+       drvc = di->context;
        drvc->instances = NULL;
        conn = serialcomm = NULL;
-       model = METRAHIT_NONE;
        serialcomm_given = FALSE;
 
        sr_spew("scan_1x_2x_rs232() called!");
@@ -237,8 +235,9 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options)
        return devices;
 }
 
-/** Scan for Metrahit 2x in a bidirectional mode using Gossen Metrawatt 'BD 232' interface.
- *
+/**
+ * Scan for Metrahit 2x in a bidirectional mode using Gossen Metrawatt
+ * 'BD 232' interface.
  */
 static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
 {
@@ -257,7 +256,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
        conn = serialcomm = NULL;
        devices = NULL;
 
-       drvc = di->priv;
+       drvc = di->context;
        drvc->instances = NULL;
 
        sr_spew("scan_2x_bd232() called!");
@@ -297,18 +296,18 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
                goto exit_err;
 
        /* Wait for reply from device(s) for up to 2s. */
-       timeout_us = g_get_monotonic_time() + 2*1000*1000;
+       timeout_us = g_get_monotonic_time() + (2 * 1000 * 1000);
 
        while (timeout_us > g_get_monotonic_time()) {
                /* Receive reply (14 bytes) */
                devc->buflen = 0;
-               for (cnt = 0; cnt < 14; cnt++) {
+               for (cnt = 0; cnt < GMC_REPLY_SIZE; cnt++) {
                        byte = read_byte(serial, timeout_us);
                        if (byte != -1)
                                devc->buf[devc->buflen++] = (byte & MASK_6BITS);
                }
 
-               if (devc->buflen != 14)
+               if (devc->buflen != GMC_REPLY_SIZE)
                        continue;
 
                devc->addr = devc->buf[0];
@@ -346,18 +345,16 @@ exit_err:
 
        if (serial)
                sr_serial_dev_inst_free(serial);
-       if (devc)
-               g_free(devc);
+       g_free(devc);
        if (sdi)
                sr_dev_inst_free(sdi);
 
        return NULL;
 }
 
-/** Driver device list function */
 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_close(struct sr_dev_inst *sdi)
@@ -383,7 +380,6 @@ static int cleanup(const struct sr_dev_driver *di)
        return std_dev_clear(di, NULL);
 }
 
-/** Get value of configuration item */
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
@@ -392,8 +388,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
 
        (void)cg;
 
-       ret = SR_OK;
-
        if (!sdi || !(devc = sdi->priv))
                return SR_ERR_ARG;
 
@@ -415,7 +409,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        return ret;
 }
 
-/** Implementation of config_list, auxiliary function for common parts, */
+/** Implementation of config_list, auxiliary function for common parts. */
 static int config_list_common(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
@@ -466,24 +460,19 @@ static int config_list_bd(uint32_t key, GVariant **data, const struct sr_dev_ins
        return SR_OK;
 }
 
-static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi,
-                                            void *cb_data)
+static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       if (!sdi || !cb_data || !(devc = sdi->priv))
-               return SR_ERR_BUG;
-
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       devc->cb_data = cb_data;
+       devc = sdi->priv;
        devc->settings_ok = FALSE;
        devc->buflen = 0;
 
-       /* Send header packet to the session bus. */
-       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)
@@ -497,24 +486,19 @@ static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi,
-                                         void *cb_data)
+static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       if (!sdi || !cb_data || !(devc = sdi->priv))
-               return SR_ERR_BUG;
-
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       devc->cb_data = cb_data;
+       devc = sdi->priv;
        devc->settings_ok = FALSE;
        devc->buflen = 0;
 
-       /* Send header packet to the session bus. */
-       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)
@@ -529,7 +513,7 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi,
        return req_meas14(sdi);
 }
 
-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;
 
@@ -537,7 +521,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, dev_close,
+       return std_serial_dev_acquisition_stop(sdi, dev_close,
                        sdi->conn, LOG_PREFIX);
 }
 
@@ -557,7 +541,7 @@ SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = {
        .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start_1x_2x_rs232,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };
 
 SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info = {
@@ -576,5 +560,5 @@ SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info = {
        .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start_2x_bd232,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };