gwinstek-gpd: Add support to old (hardware) revision units.

Manufacturer revised hardware design without changing model numbers at some point.
Old units have firmware that behaves differently. Responses are terminated with \r
instead of \n. And STATUS? command response format is different.
This commit is contained in:
Timo Kokkonen 2020-07-13 21:32:17 -07:00 committed by Gerhard Sittig
parent 3b316fdca0
commit 13726d30b2
2 changed files with 13 additions and 5 deletions

View File

@ -82,7 +82,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
GSList *l; GSList *l;
struct sr_serial_dev_inst *serial; struct sr_serial_dev_inst *serial;
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
char reply[50]; char reply[100];
unsigned int i; unsigned int i;
struct dev_context *devc; struct dev_context *devc;
char channel[10]; char channel[10];
@ -179,8 +179,16 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
if (sscanf(reply, "%1u%1u%1u%1u%1u%1u%1u%1u", &cc_cv_ch1, if (sscanf(reply, "%1u%1u%1u%1u%1u%1u%1u%1u", &cc_cv_ch1,
&cc_cv_ch2, &track1, &track2, &beep, &cc_cv_ch2, &track1, &track2, &beep,
&devc->output_enabled, &baud1, &baud2) != 8) { &devc->output_enabled, &baud1, &baud2) != 8) {
sr_err("Invalid reply to STATUS: '%s'.", reply); /* old firmware (< 2.00?) responds with different format */
goto error; if (sscanf(reply, "%1u %1u %1u %1u %1u X %1u X", &cc_cv_ch1,
&cc_cv_ch2, &track1, &track2, &beep,
&devc->output_enabled) != 6) {
sr_err("Invalid reply to STATUS: '%s'.", reply);
goto error;
}
/* ignore remaining two lines of status message */
gpd_receive_reply(serial, reply, sizeof(reply));
gpd_receive_reply(serial, reply, sizeof(reply));
} }
for (i = 0; i < model->num_channels; ++i) { for (i = 0; i < model->num_channels; ++i) {

View File

@ -51,7 +51,7 @@ SR_PRIV int gpd_receive_reply(struct sr_serial_dev_inst *serial, char *buf,
{ {
int l_recv = 0, bufpos = 0, retc, l_startpos = 0, lines = 1; int l_recv = 0, bufpos = 0, retc, l_startpos = 0, lines = 1;
gint64 start, remaining; gint64 start, remaining;
const int timeout_ms = 100; const int timeout_ms = 250;
if (!serial || !buf || (buflen <= 0)) if (!serial || !buf || (buflen <= 0))
return SR_ERR_ARG; return SR_ERR_ARG;
@ -69,7 +69,7 @@ SR_PRIV int gpd_receive_reply(struct sr_serial_dev_inst *serial, char *buf,
if (bufpos == 0 && buf[bufpos] == '\n') if (bufpos == 0 && buf[bufpos] == '\n')
continue; continue;
if (buf[bufpos] == '\n') { if (buf[bufpos] == '\n' || buf[bufpos] == '\r') {
buf[bufpos] = '\0'; buf[bufpos] = '\0';
sr_dbg("Received line '%s'.", &buf[l_startpos]); sr_dbg("Received line '%s'.", &buf[l_startpos]);
buf[bufpos] = '\n'; buf[bufpos] = '\n';