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;
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);
}
goto scan_cleanup;
}
- devc->serial = serial;
+ sdi->inst_type = SR_INST_SERIAL;
+ sdi->conn = serial;
sdi->priv = devc;
sdi->driver = mic_devs[idx].di;
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;
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;
}
void *cb_data, int idx)
{
struct dev_context *devc;
+ struct sr_serial_dev_inst *serial;
devc = sdi->priv;
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;
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 */
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;
struct dev_context *devc;
int64_t t;
static gboolean first_time = TRUE;
+ struct sr_serial_dev_inst *serial;
(void)fd;
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;
}
}