colead-slm: use new serial API
This commit is contained in:
parent
109a3ba413
commit
f306ca61f6
|
@ -27,6 +27,9 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* The Colead SL-5868P uses this. */
|
||||||
|
#define SERIALCOMM "2400/8n1"
|
||||||
|
|
||||||
static const int hwopts[] = {
|
static const int hwopts[] = {
|
||||||
SR_HWOPT_CONN,
|
SR_HWOPT_CONN,
|
||||||
SR_HWOPT_SERIALCOMM,
|
SR_HWOPT_SERIALCOMM,
|
||||||
|
@ -116,6 +119,8 @@ static GSList *hw_scan(GSList *options)
|
||||||
}
|
}
|
||||||
if (!conn)
|
if (!conn)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (!serialcomm)
|
||||||
|
serialcomm = SERIALCOMM;
|
||||||
|
|
||||||
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Colead",
|
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Colead",
|
||||||
"SL-5868P", NULL)))
|
"SL-5868P", NULL)))
|
||||||
|
@ -126,12 +131,9 @@ static GSList *hw_scan(GSList *options)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!serialcomm)
|
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm)))
|
||||||
/* The Colead SL-5868P uses this. */
|
return NULL;
|
||||||
serialcomm = "2400/8n1";
|
|
||||||
|
|
||||||
devc->serial = sr_serial_dev_inst_new(conn, -1);
|
|
||||||
devc->serialcomm = g_strdup(serialcomm);
|
|
||||||
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")))
|
||||||
|
@ -161,17 +163,9 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
sr_dbg("opening %s with %s", devc->serial->port, devc->serialcomm);
|
if (serial_open(devc->serial, O_RDWR) != SR_OK)
|
||||||
devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK);
|
|
||||||
if (devc->serial->fd == -1) {
|
|
||||||
sr_err("Couldn't open serial port '%s'.",
|
|
||||||
devc->serial->port);
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
|
||||||
if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) {
|
|
||||||
sr_err("Unable to set serial parameters.");
|
|
||||||
return SR_ERR;
|
|
||||||
}
|
|
||||||
sdi->status = SR_ST_ACTIVE;
|
sdi->status = SR_ST_ACTIVE;
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -187,8 +181,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->serial && devc->serial->fd != -1) {
|
if (devc->serial && devc->serial->fd != -1) {
|
||||||
serial_close(devc->serial->fd);
|
serial_close(devc->serial);
|
||||||
devc->serial->fd = -1;
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,8 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
|
||||||
int len;
|
int len;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
|
(void)fd;
|
||||||
|
|
||||||
if (!(sdi = cb_data))
|
if (!(sdi = cb_data))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -194,20 +196,21 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (devc->state == IDLE) {
|
if (devc->state == IDLE) {
|
||||||
if (serial_read(fd, buf, 128) != 1 || buf[0] != 0x10)
|
if (serial_read(devc->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(fd, "\x20", 1) == -1)
|
if (serial_write(devc->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(fd, devc->buf + devc->buflen, 10 - devc->buflen);
|
len = serial_read(devc->serial, devc->buf + devc->buflen,
|
||||||
|
10 - devc->buflen);
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
devc->buflen += len;
|
devc->buflen += len;
|
||||||
|
|
|
@ -52,7 +52,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;
|
struct sr_serial_dev_inst *serial;
|
||||||
char *serialcomm;
|
|
||||||
int state;
|
int state;
|
||||||
char buf[10];
|
char buf[10];
|
||||||
int buflen;
|
int buflen;
|
||||||
|
|
Loading…
Reference in New Issue