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:
Frank Stettner 2017-11-11 18:29:19 +01:00 committed by Uwe Hermann
parent 4389a54204
commit a217289951
3 changed files with 60 additions and 30 deletions

View File

@ -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);

View File

@ -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,6 +42,7 @@ static int send_cmd(const struct sr_dev_inst *sdi, const char *cmd,
return SR_ERR; return SR_ERR;
} }
if (!devc->acquisition_running) {
/* Read the reply (blocking, with timeout). */ /* Read the reply (blocking, with timeout). */
memset(replybuf, 0, replybufsize); memset(replybuf, 0, replybufsize);
bufptr = replybuf; bufptr = replybuf;
@ -56,6 +59,7 @@ static int send_cmd(const struct sr_dev_inst *sdi, const char *cmd,
sr_err("Device replied with an error: '%s'.", bufptr); sr_err("Device replied with an error: '%s'.", bufptr);
return SR_ERR; 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;
} }
if (!devc->acquisition_running) {
/* Hardware sends current in mA, integer (0..6000). */ /* Hardware sends current in mA, integer (0..6000). */
*current = g_ascii_strtod(buf + 4, NULL) / 1000; *current = g_ascii_strtod(buf + 4, NULL) / 1000;
}
return SR_OK; return SR_OK;
} }
@ -126,12 +135,16 @@ 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;
} }
if (!devc->acquisition_running) {
/* Reply: "read <current> <voltage>". */ /* Reply: "read <current> <voltage>". */
tokens = g_strsplit((const char *)&buf, " ", 3); tokens = g_strsplit((const char *)&buf, " ", 3);
if (voltage) if (voltage)
@ -139,6 +152,7 @@ SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi,
if (current) if (current)
*current = g_ascii_strtod(tokens[1], NULL) / 1000; *current = g_ascii_strtod(tokens[1], NULL) / 1000;
g_strfreev(tokens); 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)

View File

@ -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;