tondaj-sl-814: Use sr_dev_inst to store connection handle.
This commit is contained in:
parent
44f91e2950
commit
a5e44c3247
|
@ -46,6 +46,7 @@ static int clear_instances(void)
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct drv_context *drvc;
|
struct drv_context *drvc;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
|
||||||
if (!(drvc = di->priv))
|
if (!(drvc = di->priv))
|
||||||
|
@ -56,7 +57,8 @@ static int clear_instances(void)
|
||||||
continue;
|
continue;
|
||||||
if (!(devc = sdi->priv))
|
if (!(devc = sdi->priv))
|
||||||
continue;
|
continue;
|
||||||
sr_serial_dev_inst_free(devc->serial);
|
serial = sdi->conn;
|
||||||
|
sr_serial_dev_inst_free(serial);
|
||||||
sr_dev_inst_free(sdi);
|
sr_dev_inst_free(sdi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +82,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *devices, *l;
|
GSList *devices, *l;
|
||||||
const char *conn, *serialcomm;
|
const char *conn, *serialcomm;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
drvc = di->priv;
|
drvc = di->priv;
|
||||||
drvc->instances = NULL;
|
drvc->instances = NULL;
|
||||||
|
@ -120,12 +123,15 @@ static GSList *hw_scan(GSList *options)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm)))
|
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
|
||||||
return NULL;
|
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;
|
return NULL;
|
||||||
|
|
||||||
|
sdi->inst_type = SR_INST_SERIAL;
|
||||||
|
sdi->conn = serial;
|
||||||
|
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
sdi->driver = di;
|
sdi->driver = di;
|
||||||
probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1");
|
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)
|
static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
devc = sdi->priv;
|
serial = sdi->conn;
|
||||||
|
if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
|
||||||
if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
sdi->status = SR_ST_ACTIVE;
|
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)
|
static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
devc = sdi->priv;
|
serial = sdi->conn;
|
||||||
|
if (serial && serial->fd != -1) {
|
||||||
if (devc->serial && devc->serial->fd != -1) {
|
serial_close(serial);
|
||||||
serial_close(devc->serial);
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +231,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE)
|
if (sdi->status != SR_ST_ACTIVE)
|
||||||
return SR_ERR_DEV_CLOSED;
|
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);
|
std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
|
||||||
|
|
||||||
/* Poll every 500ms, or whenever some data comes in. */
|
/* 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);
|
tondaj_sl_814_receive_data, (void *)sdi);
|
||||||
|
|
||||||
return SR_OK;
|
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)
|
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,
|
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 = {
|
SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = {
|
||||||
|
|
|
@ -112,6 +112,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
uint8_t buf[3];
|
uint8_t buf[3];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -119,6 +120,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
||||||
(void)revents;
|
(void)revents;
|
||||||
|
|
||||||
sdi = cb_data;
|
sdi = cb_data;
|
||||||
|
serial = sdi->conn;
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
/* TODO: Parts of this code need to be improved later. */
|
/* 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;
|
buf[2] = 0x0d;
|
||||||
sr_spew("Sending init command: %02x %02x %02x.",
|
sr_spew("Sending init command: %02x %02x %02x.",
|
||||||
buf[0], buf[1], buf[2]);
|
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);
|
sr_err("Error sending init command: %d.", ret);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
devc->state = GET_INIT_REPLY;
|
devc->state = GET_INIT_REPLY;
|
||||||
} else if (devc->state == GET_INIT_REPLY) {
|
} else if (devc->state == GET_INIT_REPLY) {
|
||||||
/* If we just sent the "init" command, get its 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);
|
sr_err("Error reading init reply: %d.", ret);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +159,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
||||||
buf[2] = 0x0d;
|
buf[2] = 0x0d;
|
||||||
sr_spew("Sending data request command: %02x %02x %02x.",
|
sr_spew("Sending data request command: %02x %02x %02x.",
|
||||||
buf[0], buf[1], buf[2]);
|
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);
|
sr_err("Error sending request command: %d.", ret);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +167,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
||||||
devc->state = GET_PACKET;
|
devc->state = GET_PACKET;
|
||||||
} else if (devc->state == GET_PACKET) {
|
} else if (devc->state == GET_PACKET) {
|
||||||
/* Read a packet from the device. */
|
/* 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);
|
4 - devc->buflen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
sr_err("Error reading packet: %d.", ret);
|
sr_err("Error reading packet: %d.", ret);
|
||||||
|
|
|
@ -48,8 +48,6 @@ struct dev_context {
|
||||||
/** The current number of already received samples. */
|
/** The current number of already received samples. */
|
||||||
uint64_t num_samples;
|
uint64_t num_samples;
|
||||||
|
|
||||||
struct sr_serial_dev_inst *serial;
|
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
uint8_t buf[4];
|
uint8_t buf[4];
|
||||||
|
|
Loading…
Reference in New Issue