]> sigrok.org Git - libsigrok.git/commitdiff
agilent-dmm: make parser deal with input better
authorBert Vermeulen <redacted>
Sun, 9 Sep 2012 20:48:22 +0000 (22:48 +0200)
committerBert Vermeulen <redacted>
Sun, 9 Sep 2012 20:48:22 +0000 (22:48 +0200)
hardware/agilent-dmm/sched.c

index 82fd2cc093d46dd54edd12f0b21710531461ffd3..68880660c02c2ed41df7126c9b7e8231a1c3741d 100644 (file)
@@ -83,7 +83,8 @@ static void receive_line(const struct sr_dev_inst *sdi)
                recv->recv(sdi, match);
                g_match_info_unref(match);
                g_regex_unref(reg);
-       }
+       } else
+               sr_dbg("agilent-dmm: unknown line '%s'", devc->buf);
 
        /* Done with this. */
        devc->buflen = 0;
@@ -104,15 +105,16 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
 
        if (revents == G_IO_IN) {
                /* Serial data arrived. */
-               len = AGDMM_BUFSIZE - devc->buflen - 1;
-               if (len > 0) {
-                       len = serial_read(fd, devc->buf + devc->buflen, len);
-                       if (len > 0) {
-                               devc->buflen += len;
-                               *(devc->buf + devc->buflen) = '\0';
-                               if (devc->buflen > 0 && *(devc->buf + devc->buflen - 1) == '\n')
-                                       /* End of line */
-                                       receive_line(sdi);
+               while(AGDMM_BUFSIZE - devc->buflen - 1 > 0) {
+                       len = serial_read(fd, devc->buf + devc->buflen, 1);
+                       if (len < 1)
+                               break;
+                       devc->buflen += len;
+                       *(devc->buf + devc->buflen) = '\0';
+                       if (*(devc->buf + devc->buflen - 1) == '\n') {
+                               /* End of line */
+                               receive_line(sdi);
+                               break;
                        }
                }
        }