X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fmic-985xx%2Fapi.c;h=4c093148750de14b6598e61466c1de2d21ce33d8;hb=3a277f3b2b01da3d7d1e26ddbb30471db68fc11c;hp=8a18313ffa5aa2ada66a11a6d36837d25423d0f2;hpb=bd6fbf628abef9fab5293e016ad11e1a1ac4a0a9;p=libsigrok.git diff --git a/hardware/mic-985xx/api.c b/hardware/mic-985xx/api.c index 8a18313f..4c093148 100644 --- a/hardware/mic-985xx/api.c +++ b/hardware/mic-985xx/api.c @@ -54,6 +54,7 @@ static int clear_instances(int idx) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; + struct sr_serial_dev_inst *serial; GSList *l; struct sr_dev_driver *di; @@ -67,7 +68,8 @@ static int clear_instances(int idx) 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); } @@ -118,7 +120,8 @@ static GSList *scan(const char *conn, const char *serialcomm, int idx) goto scan_cleanup; } - devc->serial = serial; + sdi->inst_type = SR_INST_SERIAL; + sdi->conn = serial; sdi->priv = devc; sdi->driver = mic_devs[idx].di; @@ -181,11 +184,10 @@ static GSList *hw_dev_list(int idx) 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; @@ -195,12 +197,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; } @@ -219,7 +220,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) struct dev_context *devc; if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + return SR_ERR_DEV_CLOSED; devc = sdi->priv; @@ -265,11 +266,13 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data, int idx) { struct dev_context *devc; + struct sr_serial_dev_inst *serial; - devc = sdi->priv; + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; + devc = sdi->priv; devc->cb_data = cb_data; - devc->num_samples = 0; devc->starttime = g_get_monotonic_time(); @@ -277,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 100ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 100, + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 100, mic_devs[idx].receive_data, (void *)sdi); return SR_OK; @@ -286,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); } /* Driver-specific API function wrappers */