From: Alexandru Gagniuc Date: Thu, 22 Nov 2012 01:18:21 +0000 (-0600) Subject: serial.c: Sanitize serial_stream_detect X-Git-Tag: dsupstream~532 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=551c3d8ce36bebe02765c76ee4d04f4e700d61b2;p=libsigrok.git serial.c: Sanitize serial_stream_detect Print the timeout in miliseconds, not microseconds. Only calculate elapsed time once oer loop. Signed-off-by: Alexandru Gagniuc --- diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 76464970..bdf02163 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -660,8 +660,6 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial, return SR_ERR; } - timeout_ms *= 1000; - /* Assume 8n1 transmission. That is 10 bits for every byte. */ byte_delay_us = 10 * (1000000 / baudrate); start = g_get_monotonic_time(); @@ -676,11 +674,13 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial, } else { /* Error reading byte, but continuing anyway. */ } + + time = g_get_monotonic_time() - start; + time /= 1000; + if ((ibuf - i) >= packet_size) { /* We have at least a packet's worth of data. */ if (is_valid(&buf[i])) { - time = g_get_monotonic_time() - start; - time /= 1000; sr_spew("Found valid %d-byte packet after " "%" PRIu64 "ms.", (ibuf - i), time); *buflen = ibuf; @@ -692,9 +692,9 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial, /* Not a valid packet. Continue searching. */ i++; } - if (g_get_monotonic_time() - start > timeout_ms) { + if (time >= timeout_ms) { /* Timeout */ - sr_dbg("Detection timed out after %dms.", timeout_ms); + sr_dbg("Detection timed out after %dms.", time); break; } g_usleep(byte_delay_us);