From: Bert Vermeulen Date: Wed, 7 Nov 2012 00:25:10 +0000 (+0100) Subject: agilent-dmm: use standard serial_readline() X-Git-Tag: dsupstream~577 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=63f7cb9791d2b5fbd32a897e94790c9a6def8462;p=libsigrok.git agilent-dmm: use standard serial_readline() --- diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index ddc22ee9..0e2bc7d8 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -108,48 +108,6 @@ static int hw_init(void) return SR_OK; } -/* TODO: Merge into serial_readline() from serial.c. */ -static int serial_readline2(int fd, char **buf, int *buflen, uint64_t timeout_ms) -{ - uint64_t start; - int maxlen, len; - - timeout_ms *= 1000; - start = g_get_monotonic_time(); - - maxlen = *buflen; - *buflen = len = 0; - while(1) { - len = maxlen - *buflen - 1; - if (len < 1) - break; - len = serial_read(fd, *buf + *buflen, len); - if (len > 0) { - *buflen += len; - *(*buf + *buflen) = '\0'; - if (*buflen > 0 && *(*buf + *buflen - 1) == '\n') - /* End of line */ - break; - } - if (g_get_monotonic_time() - start > timeout_ms) - /* Timeout */ - break; - g_usleep(2000); - } - - /* Strip CRLF */ - while (*buflen) { - if (*(*buf + *buflen - 1) == '\r' || *(*buf + *buflen - 1) == '\n') - *(*buf + --*buflen) = '\0'; - else - break; - } - if (*buflen) - sr_dbg("Received '%s'.", *buf); - - return SR_OK; -} - static GSList *hw_scan(GSList *options) { struct sr_dev_inst *sdi; @@ -206,7 +164,7 @@ static GSList *hw_scan(GSList *options) sr_err("Serial buffer malloc failed."); return NULL; } - serial_readline2(fd, &buf, &len, 150); + serial_readline(fd, &buf, &len, 150); if (!len) return NULL;