mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-15 18:33:02 +00:00
FTDI read() now waits until timeout
previously returned after periodic FTDI status response (default 16 msec)
This commit is contained in:
+3
-6
@@ -158,15 +158,12 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
|
||||
}
|
||||
nread = buf.position();
|
||||
}
|
||||
if (nread > 0) {
|
||||
return readFilter(dest, nread);
|
||||
} else {
|
||||
if (nread > 0)
|
||||
return nread;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected int readFilter(final byte[] buffer, int len) throws IOException { return len; }
|
||||
|
||||
@Override
|
||||
public int write(final byte[] src, final int timeout) throws IOException {
|
||||
int offset = 0;
|
||||
|
||||
+17
-1
@@ -136,7 +136,22 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int readFilter(byte[] buffer, int totalBytesRead) throws IOException {
|
||||
public int read(final byte[] dest, final int timeout) throws IOException {
|
||||
int nread;
|
||||
if (timeout != 0) {
|
||||
long endTime = System.currentTimeMillis() + timeout;
|
||||
do {
|
||||
nread = super.read(dest, Math.max(1, (int)(endTime - System.currentTimeMillis())));
|
||||
} while (nread == READ_HEADER_LENGTH && System.currentTimeMillis() < endTime);
|
||||
} else {
|
||||
do {
|
||||
nread = super.read(dest, timeout);
|
||||
} while (nread == READ_HEADER_LENGTH);
|
||||
}
|
||||
return readFilter(dest, nread);
|
||||
}
|
||||
|
||||
private int readFilter(byte[] buffer, int totalBytesRead) throws IOException {
|
||||
final int maxPacketSize = mReadEndpoint.getMaxPacketSize();
|
||||
int destPos = 0;
|
||||
for(int srcPos = 0; srcPos < totalBytesRead; srcPos += maxPacketSize) {
|
||||
@@ -146,6 +161,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
System.arraycopy(buffer, srcPos + READ_HEADER_LENGTH, buffer, destPos, length);
|
||||
destPos += length;
|
||||
}
|
||||
//Log.d(TAG, "read filter " + totalBytesRead + " -> " + destPos);
|
||||
return destPos;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user