]> sigrok.org Git - libsigrok.git/commitdiff
brymen-dmm: Use sr_dev_inst to store connection handle.
authorUwe Hermann <redacted>
Sun, 28 Apr 2013 06:01:51 +0000 (08:01 +0200)
committerUwe Hermann <redacted>
Tue, 30 Apr 2013 18:22:17 +0000 (20:22 +0200)
hardware/brymen-dmm/api.c
hardware/brymen-dmm/protocol.c
hardware/brymen-dmm/protocol.h

index 678f67b8a92cce2f8814cdc0e6cc7b1277b49372..4952217eef1a6046ffe624dfd1bb698bc7171618 100644 (file)
@@ -42,13 +42,13 @@ static int hw_init(struct sr_context *sr_ctx)
 static void free_instance(void *inst)
 {
        struct sr_dev_inst *sdi;
-       struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
 
        if (!(sdi = inst))
                return;
-       if (!(devc = sdi->priv))
-               return;
-       sr_serial_dev_inst_free(devc->serial);
+
+       serial = sdi->conn;
+       sr_serial_dev_inst_free(serial);
        sr_dev_inst_free(sdi);
 }
 
@@ -110,7 +110,8 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm)
                goto scan_cleanup;
        }
 
-       devc->serial = serial;
+       sdi->inst_type = SR_INST_SERIAL;
+       sdi->conn = serial;
        drvc = di->priv;
        sdi->priv = devc;
        sdi->driver = di;
@@ -135,8 +136,6 @@ static GSList *hw_scan(GSList *options)
        GSList *devices, *l;
        const char *conn, *serialcomm;
 
-       (void)options;
-
        devices = NULL;
        drvc = di->priv;
        drvc->instances = NULL;
@@ -153,9 +152,8 @@ static GSList *hw_scan(GSList *options)
                        break;
                }
        }
-       if (!conn) {
+       if (!conn)
                return NULL;
-       }
 
        if (serialcomm) {
                /* Use the provided comm specs. */
@@ -175,14 +173,10 @@ static GSList *hw_dev_list(void)
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
-       struct dev_context *devc;
-
-       if (!(devc = sdi->priv)) {
-               sr_err("sdi->priv was NULL.");
-               return SR_ERR_BUG;
-       }
+       struct sr_serial_dev_inst *serial;
 
-       if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
+       serial = sdi->conn;
+       if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
                return SR_ERR;
 
        sdi->status = SR_ST_ACTIVE;
@@ -192,12 +186,11 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 
 static int hw_dev_close(struct sr_dev_inst *sdi)
 {
-       struct dev_context *devc;
-
-       devc = sdi->priv;
+       struct sr_serial_dev_inst *serial;
 
-       if (devc->serial && devc->serial->fd != -1) {
-               serial_close(devc->serial);
+       serial = sdi->conn;
+       if (serial && serial->fd != -1) {
+               serial_close(serial);
                sdi->status = SR_ST_INACTIVE;
        }
 
@@ -263,6 +256,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                                    void *cb_data)
 {
        struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -286,7 +280,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
 
        /* Poll every 50ms, or whenever some data comes in. */
-       sr_source_add(devc->serial->fd, G_IO_IN, 50,
+       serial = sdi->conn;
+       sr_source_add(serial->fd, G_IO_IN, 50,
                      brymen_dmm_receive_data, (void *)sdi);
 
        return SR_OK;
@@ -295,7 +290,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
-              ((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
+                                                 sdi->conn, DRIVER_LOG_DOMAIN);
 }
 
 SR_PRIV struct sr_dev_driver brymen_bm857_driver_info = {
index 425697ee7bea3a8728aa07384a90512e822c2f38..4456568a110df68184eac7c37030c242c56d44ca 100644 (file)
@@ -53,12 +53,14 @@ static void handle_new_data(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        int len, status, offset = 0;
+       struct sr_serial_dev_inst *serial;
 
        devc = sdi->priv;
+       serial = sdi->conn;
 
        /* Try to get as much data as the buffer can hold. */
        len = DMM_BUFSIZE - devc->buflen;
-       len = serial_read(devc->serial, devc->buf + devc->buflen, len);
+       len = serial_read(serial, devc->buf + devc->buflen, len);
        if (len < 1) {
                sr_err("Serial port read error: %d.", len);
                return;
@@ -112,6 +114,7 @@ SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
        int ret;
        int64_t time;
 
@@ -123,12 +126,14 @@ SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data)
        if (!(devc = sdi->priv))
                return TRUE;
 
+       serial = sdi->conn;
+
        if (revents == G_IO_IN) {
                /* Serial data arrived. */
                handle_new_data(sdi);
        } else {
                /* Timeout, send another packet request. */
-               if ((ret = brymen_packet_request(devc->serial)) < 0) {
+               if ((ret = brymen_packet_request(serial)) < 0) {
                        sr_err("Failed to request packet: %d.", ret);
                        return FALSE;
                }
index 278d7d6890b39fbd72ba583ce7a4889af6ec4f1f..623e969d07e0c3a2d37ea3b6e68655d433d5fc69 100644 (file)
@@ -62,8 +62,6 @@ struct dev_context {
        /** Start time of acquisition session */
        int64_t starttime;
 
-       struct sr_serial_dev_inst *serial;
-
        uint8_t buf[DMM_BUFSIZE];
        int bufoffset;
        int buflen;