From 695dc75037fca7f49a9d0aad1ffbc46e43c1e3c5 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 15 Feb 2011 18:06:24 +0000 Subject: [PATCH] uart: fix remaining bytes computation --- libnfc/buses/uart_posix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 88c90a5..07b8de9 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -216,6 +216,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx) fd_set rfds; int iExpectedByteCount = (int)*pszRx; + DBG ("iExpectedByteCount == %d", iExpectedByteCount); struct timeval tvTimeout = { .tv_sec = 0, .tv_usec = uiTimeoutStatic + (uiTimeoutPerByte * iExpectedByteCount), @@ -253,7 +254,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx) } // There is something available, read the data res = read (((serial_port_unix *) sp)->fd, pbtRx + (*pszRx), MIN(byteCount, iExpectedByteCount)); - iExpectedByteCount -= byteCount; + iExpectedByteCount -= MIN (byteCount, iExpectedByteCount); // Stop if the OS has some troubles reading the data if (res <= 0) { @@ -265,7 +266,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx) tv.tv_usec = uiTimeoutPerByte * MIN( iExpectedByteCount, 16 ); // DBG("Timeout reloaded at: %d µs", tv.tv_usec); } while (byteCount && (iExpectedByteCount > 0)); - + DBG ("byteCount == %d, iExpectedByteCount == %d", byteCount, iExpectedByteCount); return 0; }