FTDI: properly remove out-of-band info from data.

FTDI chips send packets of at most 62 bytes of data, with a 2 byte
header. The code assumed that the chip would return at most 64 bytes,
but with new (USB2) chips this is not the case anymore. As a result,
it was skipping only the first header in a packet and leaving the other
ones in the data stream.
This commit is contained in:
Adrien Destugues 2017-10-28 19:54:57 +02:00
parent e1ca67697e
commit 309c068978

View File

@ -249,11 +249,31 @@ FTDIDevice::SetHardwareFlowControl(bool enable)
void
FTDIDevice::OnRead(char **buffer, size_t *numBytes)
{
fStatusMSR = FTDI_GET_MSR(*buffer);
fStatusLSR = FTDI_GET_LSR(*buffer);
TRACE("FTDIDevice::OnRead(): MSR: 0x%02x LSR: 0x%02x\n", fStatusMSR, fStatusLSR);
*buffer += 2;
*numBytes -= 2;
/* The input consists of 64-byte packets, in which the first two bytes
* give the status (16C550 like) of the UART. A single buffer may have
* several of these packets in it.
*/
size_t i = 0;
size_t j = 0;
while (i < *numBytes) {
if ((i % 64) == 0) {
fStatusMSR = FTDI_GET_MSR(*buffer + i);
fStatusLSR = FTDI_GET_LSR(*buffer + i);
TRACE("FTDIDevice::OnRead(): MSR: 0x%02x LSR: 0x%02x\n",
fStatusMSR, fStatusLSR);
// Skip over the buffer header
i += 2;
} else {
// Group normal bytes towards the start of the buffer
(*buffer)[j++] = (*buffer)[i++];
}
}
// Tell the caller about the number of "real" bytes remaining in the buffer
*numBytes = j;
}