colead-slm: Use sr_dev_inst to store connection handle

This commit is contained in:
Bert Vermeulen 2013-04-22 00:27:11 +02:00
parent fb3a150599
commit aa7066353c
3 changed files with 21 additions and 20 deletions

View File

@ -51,6 +51,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))
@ -61,7 +62,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);
} }
g_slist_free(drvc->instances); g_slist_free(drvc->instances);
@ -116,9 +118,10 @@ static GSList *hw_scan(GSList *options)
return NULL; return NULL;
} }
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) if (!(sdi->conn = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL; return NULL;
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc; sdi->priv = devc;
sdi->driver = di; sdi->driver = di;
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
@ -137,14 +140,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;
if (!(devc = sdi->priv)) { serial = sdi->conn;
sr_err("sdi->priv was NULL."); if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return SR_ERR_BUG;
}
if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK)
return SR_ERR; return SR_ERR;
sdi->status = SR_ST_ACTIVE; sdi->status = SR_ST_ACTIVE;
@ -154,12 +153,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;
} }
@ -233,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 (!(devc = sdi->priv)) { if (!(devc = sdi->priv)) {
sr_err("sdi->priv was NULL."); sr_err("sdi->priv was NULL.");
@ -245,7 +244,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 150ms, or whenever some data comes in. */ /* Poll every 150ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 150, colead_slm_receive_data, serial = sdi->conn;
sr_source_add(serial->fd, G_IO_IN, 150, colead_slm_receive_data,
(void *)sdi); (void *)sdi);
return SR_OK; return SR_OK;
@ -254,7 +254,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 colead_slm_driver_info = { SR_PRIV struct sr_dev_driver colead_slm_driver_info = {

View File

@ -181,6 +181,7 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
{ {
const struct sr_dev_inst *sdi; const struct sr_dev_inst *sdi;
struct dev_context *devc; struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int len; int len;
char buf[128]; char buf[128];
@ -196,21 +197,22 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
/* Timeout event. */ /* Timeout event. */
return TRUE; return TRUE;
serial = sdi->conn;
if (devc->state == IDLE) { if (devc->state == IDLE) {
if (serial_read(devc->serial, buf, 128) != 1 || buf[0] != 0x10) if (serial_read(serial, buf, 128) != 1 || buf[0] != 0x10)
/* Nothing there, or caught the tail end of a previous packet, /* Nothing there, or caught the tail end of a previous packet,
* or some garbage. Unless it's a single "data ready" byte, * or some garbage. Unless it's a single "data ready" byte,
* we don't want it. */ * we don't want it. */
return TRUE; return TRUE;
/* Got 0x10, "measurement ready". */ /* Got 0x10, "measurement ready". */
if (serial_write(devc->serial, "\x20", 1) == -1) if (serial_write(serial, "\x20", 1) == -1)
sr_err("unable to send command: %s", strerror(errno)); sr_err("unable to send command: %s", strerror(errno));
else { else {
devc->state = COMMAND_SENT; devc->state = COMMAND_SENT;
devc->buflen = 0; devc->buflen = 0;
} }
} else { } else {
len = serial_read(devc->serial, devc->buf + devc->buflen, len = serial_read(serial, devc->buf + devc->buflen,
10 - devc->buflen); 10 - devc->buflen);
if (len < 1) if (len < 1)
return TRUE; return TRUE;

View File

@ -51,7 +51,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;
char buf[10]; char buf[10];
int buflen; int buflen;