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))
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);
}
struct sr_probe *probe;
GSList *devices, *l;
const char *conn, *serialcomm;
+ struct sr_serial_dev_inst *serial;
drvc = di->priv;
drvc->instances = NULL;
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");
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)
{
struct dev_context *devc;
+ struct sr_serial_dev_inst *serial;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
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;
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 = {
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
+ struct sr_serial_dev_inst *serial;
uint8_t buf[3];
int ret;
(void)revents;
sdi = cb_data;
+ serial = sdi->conn;
devc = sdi->priv;
/* TODO: Parts of this code need to be improved later. */
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;
}
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;
}
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);