fluke-dmm: Use sr_dev_inst to store connection handle
This commit is contained in:
parent
aa7066353c
commit
919681f0e8
|
@ -65,6 +65,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))
|
||||||
|
@ -76,7 +77,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);
|
||||||
|
@ -157,7 +159,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
devc->profile = &supported_flukedmm[i];
|
devc->profile = &supported_flukedmm[i];
|
||||||
devc->serial = serial;
|
sdi->conn = 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")))
|
||||||
|
@ -225,14 +227,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 | 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;
|
||||||
|
@ -242,12 +240,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,6 +319,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.");
|
||||||
|
@ -334,9 +332,10 @@ 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 100ms, or whenever some data comes in. */
|
/* Poll every 100ms, or whenever some data comes in. */
|
||||||
sr_source_add(devc->serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
|
serial = sdi->conn;
|
||||||
|
sr_source_add(serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
|
||||||
|
|
||||||
if (serial_write(devc->serial, "QM\r", 3) == -1) {
|
if (serial_write(serial, "QM\r", 3) == -1) {
|
||||||
sr_err("Unable to send QM: %s.", strerror(errno));
|
sr_err("Unable to send QM: %s.", strerror(errno));
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
@ -349,7 +348,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 flukedmm_driver_info = {
|
SR_PRIV struct sr_dev_driver flukedmm_driver_info = {
|
||||||
|
|
|
@ -54,7 +54,6 @@ struct dev_context {
|
||||||
const struct flukedmm_profile *profile;
|
const struct flukedmm_profile *profile;
|
||||||
uint64_t limit_samples;
|
uint64_t limit_samples;
|
||||||
uint64_t limit_msec;
|
uint64_t limit_msec;
|
||||||
struct sr_serial_dev_inst *serial;
|
|
||||||
|
|
||||||
/* Opaque pointer passed in by the frontend. */
|
/* Opaque pointer passed in by the frontend. */
|
||||||
void *cb_data;
|
void *cb_data;
|
||||||
|
|
|
@ -414,12 +414,14 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
|
||||||
static void handle_line(const struct sr_dev_inst *sdi)
|
static void handle_line(const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_analog *analog;
|
struct sr_datafeed_analog *analog;
|
||||||
int num_tokens, n, i;
|
int num_tokens, n, i;
|
||||||
char cmd[16], **tokens;
|
char cmd[16], **tokens;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
serial = sdi->conn;
|
||||||
sr_spew("Received line '%s' (%d).", devc->buf, devc->buflen);
|
sr_spew("Received line '%s' (%d).", devc->buf, devc->buflen);
|
||||||
|
|
||||||
if (devc->buflen == 1) {
|
if (devc->buflen == 1) {
|
||||||
|
@ -456,7 +458,7 @@ static void handle_line(const struct sr_dev_inst *sdi)
|
||||||
/* Slip the request in now, before the main
|
/* Slip the request in now, before the main
|
||||||
* timer loop asks for metadata again. */
|
* timer loop asks for metadata again. */
|
||||||
n = sprintf(cmd, "QM %d\r", devc->meas_type);
|
n = sprintf(cmd, "QM %d\r", devc->meas_type);
|
||||||
if (serial_write(devc->serial, cmd, n) == -1)
|
if (serial_write(serial, cmd, n) == -1)
|
||||||
sr_err("Unable to send QM (measurement): %s.",
|
sr_err("Unable to send QM (measurement): %s.",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
@ -485,6 +487,7 @@ SR_PRIV int fluke_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;
|
||||||
int len;
|
int len;
|
||||||
int64_t now, elapsed;
|
int64_t now, elapsed;
|
||||||
|
|
||||||
|
@ -496,10 +499,11 @@ SR_PRIV int fluke_receive_data(int fd, int revents, 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. */
|
||||||
while(FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) {
|
while(FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) {
|
||||||
len = serial_read(devc->serial, devc->buf + devc->buflen, 1);
|
len = serial_read(serial, devc->buf + devc->buflen, 1);
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
break;
|
break;
|
||||||
devc->buflen++;
|
devc->buflen++;
|
||||||
|
@ -524,7 +528,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
|
||||||
* out-of-sync or temporary disconnect issues. */
|
* out-of-sync or temporary disconnect issues. */
|
||||||
if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period)
|
if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period)
|
||||||
|| elapsed > devc->profile->timeout) {
|
|| elapsed > devc->profile->timeout) {
|
||||||
if (serial_write(devc->serial, "QM\r", 3) == -1)
|
if (serial_write(serial, "QM\r", 3) == -1)
|
||||||
sr_err("Unable to send QM: %s.", strerror(errno));
|
sr_err("Unable to send QM: %s.", strerror(errno));
|
||||||
devc->cmd_sent_at = now;
|
devc->cmd_sent_at = now;
|
||||||
devc->expect_response = TRUE;
|
devc->expect_response = TRUE;
|
||||||
|
|
Loading…
Reference in New Issue