return SR_OK;
}
-static int serial_readline(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, 1);
- if (len > 0) {
- *buflen += len;
- *(*buf + *buflen) = '\0';
- if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') {
- /* Strip LF and terminate. */
- *(*buf + --*buflen) = '\0';
- break;
- }
- }
- if (g_get_monotonic_time() - start > timeout_ms)
- /* Timeout */
- break;
- g_usleep(2000);
- }
-
- return SR_OK;
-}
-
static GSList *lcd14_scan(const char *conn, const char *serialcomm)
{
struct sr_dev_inst *sdi;
struct drv_context *drvc;
struct dev_context *devc;
struct sr_probe *probe;
- struct lcd14_packet *packet;
GSList *devices;
int i, len, fd, retry, good_packets = 0, dropped, ret;
- char buf[128], *b;
+ uint8_t buf[128], *b;
if ((fd = serial_open(conn, O_RDONLY | O_NONBLOCK)) == -1) {
sr_err("Unable to open %s: %s.", conn, strerror(errno));
/* Let's get a bit of data and see if we can find a packet. */
len = sizeof(buf);
- serial_readline(fd, &b, &len, 500);
- if ((len == 0) || (len < LCD14_PACKET_SIZE)) {
+ serial_readline(fd, (char **)&b, &len, 500);
+ if ((len == 0) || (len < FS9721_PACKET_SIZE)) {
/* Not enough data received, is the DMM connected? */
continue;
}
/* Let's treat our buffer like a stream, and find any
* valid packets */
- for (i = 0; i < len - LCD14_PACKET_SIZE + 1;) {
- packet = (void *)(&buf[i]);
- if (!lcd14_is_packet_valid(packet, NULL)) {
+ for (i = 0; i < len - FS9721_PACKET_SIZE + 1;) {
+ if (!sr_fs9721_packet_valid(&buf[i])) {
i++;
continue;
}
good_packets++;
- i += LCD14_PACKET_SIZE;
+ i += FS9721_PACKET_SIZE;
}
/*
* If we dropped more than two packets worth of data,
* something is wrong.
*/
- dropped = len - (good_packets * LCD14_PACKET_SIZE);
- if (dropped > 2 * LCD14_PACKET_SIZE)
+ dropped = len - (good_packets * FS9721_PACKET_SIZE);
+ if (dropped > 2 * FS9721_PACKET_SIZE)
continue;
/* Let's see if we have anything good. */