arachnid-labs-re-load-pro: Change serial read in acquisition mode.
Use serial_readline in acquisition mode, otherwise data from the Re:load Pro could get lost. Use reloadpro_receive_data() for all commands when in acquisition mode. When not using a single point of receiving data, data could get lost.
This commit is contained in:
parent
4389a54204
commit
a217289951
|
@ -289,6 +289,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
devc->acquisition_running = TRUE;
|
||||||
|
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
|
|
||||||
/* Send the 'monitor <ms>' command (doesn't have a reply). */
|
/* Send the 'monitor <ms>' command (doesn't have a reply). */
|
||||||
|
@ -311,6 +313,16 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi)
|
||||||
|
{
|
||||||
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
devc->acquisition_running = FALSE;
|
||||||
|
|
||||||
|
return std_serial_dev_acquisition_stop(sdi);
|
||||||
|
}
|
||||||
|
|
||||||
static struct sr_dev_driver arachnid_labs_re_load_pro_driver_info = {
|
static struct sr_dev_driver arachnid_labs_re_load_pro_driver_info = {
|
||||||
.name = "arachnid-labs-re-load-pro",
|
.name = "arachnid-labs-re-load-pro",
|
||||||
.longname = "Arachnid Labs Re:load Pro",
|
.longname = "Arachnid Labs Re:load Pro",
|
||||||
|
@ -326,7 +338,7 @@ static struct sr_dev_driver arachnid_labs_re_load_pro_driver_info = {
|
||||||
.dev_open = std_serial_dev_open,
|
.dev_open = std_serial_dev_open,
|
||||||
.dev_close = dev_close,
|
.dev_close = dev_close,
|
||||||
.dev_acquisition_start = dev_acquisition_start,
|
.dev_acquisition_start = dev_acquisition_start,
|
||||||
.dev_acquisition_stop = std_serial_dev_acquisition_stop,
|
.dev_acquisition_stop = dev_acquisition_stop,
|
||||||
.context = NULL,
|
.context = NULL,
|
||||||
};
|
};
|
||||||
SR_REGISTER_DEV_DRIVER(arachnid_labs_re_load_pro_driver_info);
|
SR_REGISTER_DEV_DRIVER(arachnid_labs_re_load_pro_driver_info);
|
||||||
|
|
|
@ -28,8 +28,10 @@ static int send_cmd(const struct sr_dev_inst *sdi, const char *cmd,
|
||||||
{
|
{
|
||||||
char *bufptr;
|
char *bufptr;
|
||||||
int len, ret;
|
int len, ret;
|
||||||
|
struct dev_context *devc;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
|
|
||||||
/* Send the command (blocking, with timeout). */
|
/* Send the command (blocking, with timeout). */
|
||||||
|
@ -40,21 +42,23 @@ static int send_cmd(const struct sr_dev_inst *sdi, const char *cmd,
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the reply (blocking, with timeout). */
|
if (!devc->acquisition_running) {
|
||||||
memset(replybuf, 0, replybufsize);
|
/* Read the reply (blocking, with timeout). */
|
||||||
bufptr = replybuf;
|
memset(replybuf, 0, replybufsize);
|
||||||
len = replybufsize;
|
bufptr = replybuf;
|
||||||
ret = serial_readline(serial, &bufptr, &len, READ_TIMEOUT_MS);
|
|
||||||
|
|
||||||
/* If we got 0 characters (possibly one \r or \n), retry once. */
|
|
||||||
if (len == 0) {
|
|
||||||
len = replybufsize;
|
len = replybufsize;
|
||||||
ret = serial_readline(serial, &bufptr, &len, READ_TIMEOUT_MS);
|
ret = serial_readline(serial, &bufptr, &len, READ_TIMEOUT_MS);
|
||||||
}
|
|
||||||
|
|
||||||
if (g_str_has_prefix((const char *)&bufptr, "err ")) {
|
/* If we got 0 characters (possibly one \r or \n), retry once. */
|
||||||
sr_err("Device replied with an error: '%s'.", bufptr);
|
if (len == 0) {
|
||||||
return SR_ERR;
|
len = replybufsize;
|
||||||
|
ret = serial_readline(serial, &bufptr, &len, READ_TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_str_has_prefix((const char *)&bufptr, "err ")) {
|
||||||
|
sr_err("Device replied with an error: '%s'.", bufptr);
|
||||||
|
return SR_ERR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -108,14 +112,19 @@ SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
if ((ret = send_cmd(sdi, "set\n", (char *)&buf, sizeof(buf))) < 0) {
|
if ((ret = send_cmd(sdi, "set\n", (char *)&buf, sizeof(buf))) < 0) {
|
||||||
sr_err("Error sending current limit query: %d.", ret);
|
sr_err("Error sending current limit query: %d.", ret);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hardware sends current in mA, integer (0..6000). */
|
if (!devc->acquisition_running) {
|
||||||
*current = g_ascii_strtod(buf + 4, NULL) / 1000;
|
/* Hardware sends current in mA, integer (0..6000). */
|
||||||
|
*current = g_ascii_strtod(buf + 4, NULL) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -126,19 +135,24 @@ SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi,
|
||||||
int ret;
|
int ret;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
char **tokens;
|
char **tokens;
|
||||||
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
if ((ret = send_cmd(sdi, "read\n", (char *)&buf, sizeof(buf))) < 0) {
|
if ((ret = send_cmd(sdi, "read\n", (char *)&buf, sizeof(buf))) < 0) {
|
||||||
sr_err("Error sending voltage/current query: %d.", ret);
|
sr_err("Error sending voltage/current query: %d.", ret);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reply: "read <current> <voltage>". */
|
if (!devc->acquisition_running) {
|
||||||
tokens = g_strsplit((const char *)&buf, " ", 3);
|
/* Reply: "read <current> <voltage>". */
|
||||||
if (voltage)
|
tokens = g_strsplit((const char *)&buf, " ", 3);
|
||||||
*voltage = g_ascii_strtod(tokens[2], NULL) / 1000;
|
if (voltage)
|
||||||
if (current)
|
*voltage = g_ascii_strtod(tokens[2], NULL) / 1000;
|
||||||
*current = g_ascii_strtod(tokens[1], NULL) / 1000;
|
if (current)
|
||||||
g_strfreev(tokens);
|
*current = g_ascii_strtod(tokens[1], NULL) / 1000;
|
||||||
|
g_strfreev(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -268,13 +282,18 @@ static void handle_new_data(const struct sr_dev_inst *sdi)
|
||||||
int len;
|
int len;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
|
|
||||||
/* Try to get as much data as the buffer can hold. */
|
|
||||||
len = RELOADPRO_BUFSIZE - devc->buflen;
|
len = RELOADPRO_BUFSIZE - devc->buflen;
|
||||||
len = serial_read_nonblocking(serial, devc->buf + devc->buflen, len);
|
buf = devc->buf;
|
||||||
|
if (serial_readline(serial, &buf, &len, 250) != SR_OK) {
|
||||||
|
sr_err("Err: ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return; /* No new bytes, nothing to do. */
|
return; /* No new bytes, nothing to do. */
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
|
@ -283,11 +302,9 @@ static void handle_new_data(const struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
devc->buflen += len;
|
devc->buflen += len;
|
||||||
|
|
||||||
if (g_str_has_suffix((const char *)devc->buf, "\n")) {
|
handle_packet(sdi);
|
||||||
handle_packet(sdi);
|
memset(devc->buf, 0, RELOADPRO_BUFSIZE);
|
||||||
memset(devc->buf, 0, RELOADPRO_BUFSIZE);
|
devc->buflen = 0;
|
||||||
devc->buflen = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data)
|
SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data)
|
||||||
|
|
|
@ -30,8 +30,9 @@
|
||||||
#define RELOADPRO_BUFSIZE 100
|
#define RELOADPRO_BUFSIZE 100
|
||||||
|
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
|
gboolean acquisition_running;
|
||||||
struct sr_sw_limits limits;
|
struct sr_sw_limits limits;
|
||||||
uint8_t buf[RELOADPRO_BUFSIZE];
|
char buf[RELOADPRO_BUFSIZE];
|
||||||
int buflen;
|
int buflen;
|
||||||
gboolean otp_active;
|
gboolean otp_active;
|
||||||
gboolean uvc_active;
|
gboolean uvc_active;
|
||||||
|
|
Loading…
Reference in New Issue