serial-dmm: Use sr_dev_inst to store connection handle.
This commit is contained in:
parent
625cc7834a
commit
1e1bfcd0fe
|
@ -173,6 +173,7 @@ static int clear_instances(int dmm)
|
||||||
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;
|
||||||
struct sr_dev_driver *di;
|
struct sr_dev_driver *di;
|
||||||
|
|
||||||
|
@ -187,7 +188,8 @@ static int clear_instances(int dmm)
|
||||||
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);
|
||||||
|
@ -271,7 +273,8 @@ static GSList *scan(const char *conn, const char *serialcomm, int dmm)
|
||||||
goto scan_cleanup;
|
goto scan_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
devc->serial = serial;
|
sdi->inst_type = SR_INST_SERIAL;
|
||||||
|
sdi->conn = serial;
|
||||||
|
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
sdi->driver = dmms[dmm].di;
|
sdi->driver = dmms[dmm].di;
|
||||||
|
@ -326,14 +329,10 @@ static GSList *hw_dev_list(int dmm)
|
||||||
|
|
||||||
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 | SERIAL_NONBLOCK) != SR_OK)
|
||||||
return SR_ERR_BUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -343,12 +342,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +415,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
void *cb_data, int dmm)
|
void *cb_data, int dmm)
|
||||||
{
|
{
|
||||||
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.");
|
||||||
|
@ -437,7 +436,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 50ms, or whenever some data comes in. */
|
/* Poll every 50ms, or whenever some data comes in. */
|
||||||
sr_source_add(devc->serial->fd, G_IO_IN, 50,
|
serial = sdi->conn;
|
||||||
|
sr_source_add(serial->fd, G_IO_IN, 50,
|
||||||
dmms[dmm].receive_data, (void *)sdi);
|
dmms[dmm].receive_data, (void *)sdi);
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -446,7 +446,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Driver-specific API function wrappers */
|
/* Driver-specific API function wrappers */
|
||||||
|
|
|
@ -122,12 +122,14 @@ static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
int len, i, offset = 0;
|
int len, i, offset = 0;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
serial = sdi->conn;
|
||||||
|
|
||||||
/* Try to get as much data as the buffer can hold. */
|
/* Try to get as much data as the buffer can hold. */
|
||||||
len = DMM_BUFSIZE - devc->buflen;
|
len = DMM_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) {
|
if (len < 1) {
|
||||||
sr_err("Serial port read error: %d.", len);
|
sr_err("Serial port read error: %d.", len);
|
||||||
return;
|
return;
|
||||||
|
@ -154,6 +156,7 @@ static int receive_data(int fd, int revents, int dmm, void *info, 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;
|
||||||
int64_t time;
|
int64_t time;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -165,13 +168,15 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
|
||||||
if (!(devc = sdi->priv))
|
if (!(devc = sdi->priv))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
serial = sdi->conn;
|
||||||
|
|
||||||
if (revents == G_IO_IN) {
|
if (revents == G_IO_IN) {
|
||||||
/* Serial data arrived. */
|
/* Serial data arrived. */
|
||||||
handle_new_data(sdi, dmm, info);
|
handle_new_data(sdi, dmm, info);
|
||||||
} else {
|
} else {
|
||||||
/* Timeout, send another packet request (if DMM needs it). */
|
/* Timeout, send another packet request (if DMM needs it). */
|
||||||
if (dmms[dmm].packet_request) {
|
if (dmms[dmm].packet_request) {
|
||||||
ret = dmms[dmm].packet_request(devc->serial);
|
ret = dmms[dmm].packet_request(serial);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
sr_err("Failed to request packet: %d.", ret);
|
sr_err("Failed to request packet: %d.", ret);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -85,8 +85,6 @@ struct dev_context {
|
||||||
|
|
||||||
int64_t starttime;
|
int64_t starttime;
|
||||||
|
|
||||||
struct sr_serial_dev_inst *serial;
|
|
||||||
|
|
||||||
uint8_t buf[DMM_BUFSIZE];
|
uint8_t buf[DMM_BUFSIZE];
|
||||||
int bufoffset;
|
int bufoffset;
|
||||||
int buflen;
|
int buflen;
|
||||||
|
|
Loading…
Reference in New Issue