mic-985xx: Use sr_dev_inst to store connection handle.
This commit is contained in:
parent
31e5377250
commit
886bd5e056
|
@ -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;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
|
||||
devc = sdi->priv;
|
||||
|
||||
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;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
|
||||
devc = sdi->priv;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -265,6 +266,7 @@ 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;
|
||||
|
||||
|
@ -277,7 +279,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 +289,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 */
|
||||
|
|
|
@ -146,13 +146,15 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
|
|||
static void handle_new_data(struct sr_dev_inst *sdi, int idx)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
int len, i, offset = 0;
|
||||
|
||||
devc = sdi->priv;
|
||||
serial = sdi->conn;
|
||||
|
||||
/* Try to get as much data as the buffer can hold. */
|
||||
len = SERIAL_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;
|
||||
|
@ -182,6 +184,7 @@ static int receive_data(int fd, int revents, int idx, void *cb_data)
|
|||
struct dev_context *devc;
|
||||
int64_t t;
|
||||
static gboolean first_time = TRUE;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
|
||||
(void)fd;
|
||||
|
||||
|
@ -191,13 +194,15 @@ static int receive_data(int fd, int revents, int idx, void *cb_data)
|
|||
if (!(devc = sdi->priv))
|
||||
return TRUE;
|
||||
|
||||
serial = sdi->conn;
|
||||
|
||||
if (revents == G_IO_IN) {
|
||||
/* New data arrived. */
|
||||
handle_new_data(sdi, idx);
|
||||
} else {
|
||||
/* Timeout. */
|
||||
if (first_time) {
|
||||
mic_cmd_set_realtime_mode(devc->serial);
|
||||
mic_cmd_set_realtime_mode(serial);
|
||||
first_time = FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,8 +78,6 @@ struct dev_context {
|
|||
|
||||
int64_t starttime;
|
||||
|
||||
struct sr_serial_dev_inst *serial;
|
||||
|
||||
uint8_t buf[SERIAL_BUFSIZE];
|
||||
int bufoffset;
|
||||
int buflen;
|
||||
|
|
Loading…
Reference in New Issue