1
0
mirror of https://github.com/mik3y/usb-serial-for-android.git synced 2026-08-17 11:23:00 +00:00

SerialInputOutputManager: use optimal read buffer size to reduce latency for FTDI and CH34x

This commit is contained in:
kai-morich
2021-04-04 20:48:46 +02:00
parent c917ac5c83
commit 848d4e7713
5 changed files with 27 additions and 15 deletions
@@ -66,16 +66,10 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
return mPortNumber;
}
/**
* Returns the write endpoint.
* @return write endpoint
*/
@Override
public UsbEndpoint getWriteEndpoint() { return mWriteEndpoint; }
/**
* Returns the read endpoint.
* @return read endpoint
*/
@Override
public UsbEndpoint getReadEndpoint() { return mReadEndpoint; }
/**
@@ -8,6 +8,7 @@ package com.hoho.android.usbserial.driver;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbManager;
import androidx.annotation.IntDef;
@@ -74,6 +75,18 @@ public interface UsbSerialPort extends Closeable {
*/
int getPortNumber();
/**
* Returns the write endpoint.
* @return write endpoint
*/
UsbEndpoint getWriteEndpoint();
/**
* Returns the read endpoint.
* @return read endpoint
*/
UsbEndpoint getReadEndpoint();
/**
* The serial number of the underlying UsbDeviceConnection, or {@code null}.
*
@@ -34,7 +34,7 @@ public class SerialInputOutputManager implements Runnable {
private final Object mReadBufferLock = new Object();
private final Object mWriteBufferLock = new Object();
private ByteBuffer mReadBuffer = ByteBuffer.allocate(BUFSIZ);
private ByteBuffer mReadBuffer; // default size = getReadEndpoint().getMaxPacketSize()
private ByteBuffer mWriteBuffer = ByteBuffer.allocate(BUFSIZ);
public enum State {
@@ -62,11 +62,13 @@ public class SerialInputOutputManager implements Runnable {
public SerialInputOutputManager(UsbSerialPort serialPort) {
mSerialPort = serialPort;
mReadBuffer = ByteBuffer.allocate(serialPort.getReadEndpoint().getMaxPacketSize());
}
public SerialInputOutputManager(UsbSerialPort serialPort, Listener listener) {
mSerialPort = serialPort;
mListener = listener;
mReadBuffer = ByteBuffer.allocate(serialPort.getReadEndpoint().getMaxPacketSize());
}
public synchronized void setListener(Listener listener) {