]> sigrok.org Git - libsigrok.git/commitdiff
tondaj-sl-814: Use sr_dev_inst to store connection handle.
authorUwe Hermann <redacted>
Wed, 24 Apr 2013 17:14:52 +0000 (19:14 +0200)
committerUwe Hermann <redacted>
Sat, 27 Apr 2013 19:22:15 +0000 (21:22 +0200)
hardware/tondaj-sl-814/api.c
hardware/tondaj-sl-814/protocol.c
hardware/tondaj-sl-814/protocol.h

index bfe4c401ceac42f4fabc0f5679afa2328c39916a..444b372b156c6fe1a60b10c3ac50201dffb14fa3 100644 (file)
@@ -46,6 +46,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))
@@ -56,7 +57,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);
        }
 
@@ -80,6 +82,7 @@ static GSList *hw_scan(GSList *options)
        struct sr_probe *probe;
        GSList *devices, *l;
        const char *conn, *serialcomm;
+       struct sr_serial_dev_inst *serial;
 
        drvc = di->priv;
        drvc->instances = NULL;
@@ -120,12 +123,15 @@ static GSList *hw_scan(GSList *options)
                return NULL;
        }
 
-       if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm)))
+       if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
                return NULL;
 
-       if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
+       if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
                return NULL;
 
+       sdi->inst_type = SR_INST_SERIAL;
+       sdi->conn = serial;
+
        sdi->priv = devc;
        sdi->driver = di;
        probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1");
@@ -147,11 +153,10 @@ static GSList *hw_dev_list(void)
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
-       struct dev_context *devc;
-
-       devc = sdi->priv;
+       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;
@@ -161,12 +166,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;
        }
 
@@ -227,6 +231,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;
@@ -238,7 +243,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 500ms, or whenever some data comes in. */
-       sr_source_add(devc->serial->fd, G_IO_IN, 500,
+       serial = sdi->conn;
+       sr_source_add(serial->fd, G_IO_IN, 500,
                      tondaj_sl_814_receive_data, (void *)sdi);
 
        return SR_OK;
@@ -247,7 +253,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 tondaj_sl_814_driver_info = {
index b97219ac763016880aceab53f04526efb2f42526..b390598f93ebdaddce8c0055994ecb6c97d220fd 100644 (file)
@@ -112,6 +112,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
        uint8_t buf[3];
        int ret;
 
@@ -119,6 +120,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
        (void)revents;
 
        sdi = cb_data;
+       serial = sdi->conn;
        devc = sdi->priv;
 
        /* TODO: Parts of this code need to be improved later. */
@@ -131,14 +133,14 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
                buf[2] = 0x0d;
                sr_spew("Sending init command: %02x %02x %02x.",
                        buf[0], buf[1], buf[2]);
-               if ((ret = serial_write(devc->serial, buf, 3)) < 0) {
+               if ((ret = serial_write(serial, buf, 3)) < 0) {
                        sr_err("Error sending init command: %d.", ret);
                        return FALSE;
                }
                devc->state = GET_INIT_REPLY;
        } else if (devc->state == GET_INIT_REPLY) {
                /* If we just sent the "init" command, get its reply. */
-               if ((ret = serial_read(devc->serial, buf, 2)) < 0) {
+               if ((ret = serial_read(serial, buf, 2)) < 0) {
                        sr_err("Error reading init reply: %d.", ret);
                        return FALSE;
                }
@@ -157,7 +159,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
                buf[2] = 0x0d;
                sr_spew("Sending data request command: %02x %02x %02x.",
                        buf[0], buf[1], buf[2]);
-               if ((ret = serial_write(devc->serial, buf, 3)) < 0) {
+               if ((ret = serial_write(serial, buf, 3)) < 0) {
                        sr_err("Error sending request command: %d.", ret);
                        return FALSE;
                }
@@ -165,7 +167,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
                devc->state = GET_PACKET;
        } else if (devc->state == GET_PACKET) {
                /* Read a packet from the device. */
-               ret = serial_read(devc->serial, devc->buf + devc->buflen,
+               ret = serial_read(serial, devc->buf + devc->buflen,
                                  4 - devc->buflen);
                if (ret < 0) {
                        sr_err("Error reading packet: %d.", ret);
index fad7f501ef3d6a21f88755bba2097575de264da3..ca50b2e89fc341629a7beb7cfa3f82a5525fa9f5 100644 (file)
@@ -48,8 +48,6 @@ struct dev_context {
        /** The current number of already received samples. */
        uint64_t num_samples;
 
-       struct sr_serial_dev_inst *serial;
-
        int state;
 
        uint8_t buf[4];