uart: fix remaining bytes computation
This commit is contained in:
parent
e110a78de7
commit
695dc75037
1 changed files with 3 additions and 2 deletions
|
@ -216,6 +216,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
|
|
||||||
int iExpectedByteCount = (int)*pszRx;
|
int iExpectedByteCount = (int)*pszRx;
|
||||||
|
DBG ("iExpectedByteCount == %d", iExpectedByteCount);
|
||||||
struct timeval tvTimeout = {
|
struct timeval tvTimeout = {
|
||||||
.tv_sec = 0,
|
.tv_sec = 0,
|
||||||
.tv_usec = uiTimeoutStatic + (uiTimeoutPerByte * iExpectedByteCount),
|
.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
|
// There is something available, read the data
|
||||||
res = read (((serial_port_unix *) sp)->fd, pbtRx + (*pszRx), MIN(byteCount, iExpectedByteCount));
|
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
|
// Stop if the OS has some troubles reading the data
|
||||||
if (res <= 0) {
|
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 );
|
tv.tv_usec = uiTimeoutPerByte * MIN( iExpectedByteCount, 16 );
|
||||||
// DBG("Timeout reloaded at: %d µs", tv.tv_usec);
|
// DBG("Timeout reloaded at: %d µs", tv.tv_usec);
|
||||||
} while (byteCount && (iExpectedByteCount > 0));
|
} while (byteCount && (iExpectedByteCount > 0));
|
||||||
|
DBG ("byteCount == %d, iExpectedByteCount == %d", byteCount, iExpectedByteCount);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue