]> sigrok.org Git - libsigrok.git/commitdiff
agilent-dmm: Use sr_dev_inst to store connection handle
authorBert Vermeulen <redacted>
Sun, 21 Apr 2013 19:44:31 +0000 (21:44 +0200)
committerBert Vermeulen <redacted>
Sun, 21 Apr 2013 19:49:15 +0000 (21:49 +0200)
hardware/agilent-dmm/agilent-dmm.h
hardware/agilent-dmm/api.c
hardware/agilent-dmm/sched.c

index d7bdbd31743453e62871beafef63cb6117a2cf04..f3922a1fe9b314be86e46bfbf65cf08468daf2b4 100644 (file)
@@ -55,7 +55,6 @@ struct dev_context {
        const struct agdmm_profile *profile;
        uint64_t limit_samples;
        uint64_t limit_msec;
-       struct sr_serial_dev_inst *serial;
 
        /* Opaque pointer passed in by the frontend. */
        void *cb_data;
index 89e59bbe96d1a9a3bc1bf8a400e00d1d50ee3c1c..3f54481c5e44a58df5f24b4948cb06dbca03eb49 100644 (file)
@@ -67,6 +67,7 @@ static int clear_instances(void)
        struct sr_dev_inst *sdi;
        struct drv_context *drvc;
        struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
        GSList *l;
 
        if (!(drvc = di->priv))
@@ -78,7 +79,8 @@ static int clear_instances(void)
                        continue;
                if (!(devc = sdi->priv))
                        continue;
-               sr_serial_dev_inst_free(devc->serial);
+               serial = sdi->conn;
+               sr_serial_dev_inst_free(serial);
                sr_dev_inst_free(sdi);
        }
        g_slist_free(drvc->instances);
@@ -162,8 +164,9 @@ static GSList *hw_scan(GSList *options)
                                return NULL;
                        }
                        devc->profile = &supported_agdmm[i];
-                       devc->serial = serial;
                        devc->cur_mq = -1;
+                       sdi->inst_type = SR_INST_SERIAL;
+                       sdi->conn = serial;
                        sdi->priv = devc;
                        sdi->driver = di;
                        if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
@@ -191,14 +194,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;
@@ -208,12 +207,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;
        }
 
@@ -284,10 +282,10 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
-               void *cb_data)
+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 (!(devc = sdi->priv)) {
                sr_err("sdi->priv was NULL.");
@@ -300,7 +298,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 100ms, or whenever some data comes in. */
-       sr_source_add(devc->serial->fd, G_IO_IN, 100, agdmm_receive_data, (void *)sdi);
+       serial = sdi->conn;
+       sr_source_add(serial->fd, G_IO_IN, 100, agdmm_receive_data, (void *)sdi);
 
        return SR_OK;
 }
@@ -308,7 +307,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 agdmm_driver_info = {
index d7d720d3227af38c87efc2ffb9eaf46cb4a5350d..0937a2859b4d5557f6f461fd68ef5e730bd9986e 100644 (file)
@@ -91,6 +91,7 @@ SR_PRIV int agdmm_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 len;
 
        (void)fd;
@@ -101,10 +102,11 @@ SR_PRIV int agdmm_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. */
                while(AGDMM_BUFSIZE - devc->buflen - 1 > 0) {
-                       len = serial_read(devc->serial, devc->buf + devc->buflen, 1);
+                       len = serial_read(serial, devc->buf + devc->buflen, 1);
                        if (len < 1)
                                break;
                        devc->buflen += len;
@@ -127,17 +129,18 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
 
 static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd)
 {
-       struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
        char buf[32];
 
-       devc = sdi->priv;
+       serial = sdi->conn;
+
        sr_spew("Sending '%s'.", cmd);
        strncpy(buf, cmd, 28);
        if (!strncmp(buf, "*IDN?", 5))
                strncat(buf, "\r\n", 32);
        else
                strncat(buf, "\n\r\n", 32);
-       if (serial_write(devc->serial, buf, strlen(buf)) == -1) {
+       if (serial_write(serial, buf, strlen(buf)) == -1) {
                sr_err("Failed to send: %s.", strerror(errno));
                return SR_ERR;
        }