mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-13 17:33:00 +00:00
make all SerialPort classes public
and test FtdiSerialPort methods
This commit is contained in:
+3
-3
@@ -79,7 +79,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
||||
return mPorts;
|
||||
}
|
||||
|
||||
class CdcAcmSerialPort extends CommonUsbSerialPort {
|
||||
public class CdcAcmSerialPort extends CommonUsbSerialPort {
|
||||
|
||||
private UsbInterface mControlInterface;
|
||||
private UsbInterface mDataInterface;
|
||||
@@ -109,7 +109,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
protected void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
if (mPortNumber == -1) {
|
||||
Log.d(TAG,"device might be castrated ACM device, trying single interface logic");
|
||||
openSingleInterface();
|
||||
@@ -210,7 +210,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInt() {
|
||||
protected void closeInt() {
|
||||
try {
|
||||
mConnection.releaseInterface(mControlInterface);
|
||||
mConnection.releaseInterface(mDataInterface);
|
||||
|
||||
+2
-2
@@ -90,7 +90,7 @@ public class Ch34xSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
protected void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
|
||||
UsbInterface usbIface = mDevice.getInterface(i);
|
||||
if (!mConnection.claimInterface(usbIface, true)) {
|
||||
@@ -115,7 +115,7 @@ public class Ch34xSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInt() {
|
||||
protected void closeInt() {
|
||||
try {
|
||||
for (int i = 0; i < mDevice.getInterfaceCount(); i++)
|
||||
mConnection.releaseInterface(mDevice.getInterface(i));
|
||||
|
||||
+2
-6
@@ -68,12 +68,8 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
|
||||
mDevice.getDeviceId(), mPortNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently-bound USB device.
|
||||
*
|
||||
* @return the device
|
||||
*/
|
||||
public final UsbDevice getDevice() {
|
||||
@Override
|
||||
public UsbDevice getDevice() {
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -137,7 +137,7 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
protected void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
mIsRestrictedPort = mDevice.getInterfaceCount() == 2 && mPortNumber == 1;
|
||||
if(mPortNumber >= mDevice.getInterfaceCount()) {
|
||||
throw new IOException("Unknown port number");
|
||||
@@ -164,7 +164,7 @@ public class Cp21xxSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInt() {
|
||||
protected void closeInt() {
|
||||
try {
|
||||
setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_DISABLE);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
+23
-23
@@ -117,23 +117,23 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
return mPorts;
|
||||
}
|
||||
|
||||
private class FtdiSerialPort extends CommonUsbSerialPort {
|
||||
public class FtdiSerialPort extends CommonUsbSerialPort {
|
||||
|
||||
public static final int USB_TYPE_STANDARD = 0x00 << 5;
|
||||
public static final int USB_TYPE_CLASS = 0x00 << 5;
|
||||
public static final int USB_TYPE_VENDOR = 0x00 << 5;
|
||||
public static final int USB_TYPE_RESERVED = 0x00 << 5;
|
||||
private static final int USB_TYPE_STANDARD = 0x00 << 5;
|
||||
private static final int USB_TYPE_CLASS = 0x00 << 5;
|
||||
private static final int USB_TYPE_VENDOR = 0x00 << 5;
|
||||
private static final int USB_TYPE_RESERVED = 0x00 << 5;
|
||||
|
||||
public static final int USB_RECIP_DEVICE = 0x00;
|
||||
public static final int USB_RECIP_INTERFACE = 0x01;
|
||||
public static final int USB_RECIP_ENDPOINT = 0x02;
|
||||
public static final int USB_RECIP_OTHER = 0x03;
|
||||
private static final int USB_RECIP_DEVICE = 0x00;
|
||||
private static final int USB_RECIP_INTERFACE = 0x01;
|
||||
private static final int USB_RECIP_ENDPOINT = 0x02;
|
||||
private static final int USB_RECIP_OTHER = 0x03;
|
||||
|
||||
public static final int USB_ENDPOINT_IN = 0x80;
|
||||
public static final int USB_ENDPOINT_OUT = 0x00;
|
||||
private static final int USB_ENDPOINT_IN = 0x80;
|
||||
private static final int USB_ENDPOINT_OUT = 0x00;
|
||||
|
||||
public static final int USB_WRITE_TIMEOUT_MILLIS = 5000;
|
||||
public static final int USB_READ_TIMEOUT_MILLIS = 5000;
|
||||
private static final int USB_WRITE_TIMEOUT_MILLIS = 5000;
|
||||
private static final int USB_READ_TIMEOUT_MILLIS = 5000;
|
||||
|
||||
// From ftdi.h
|
||||
/**
|
||||
@@ -175,10 +175,10 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
*/
|
||||
private static final int SIO_GET_MODEM_STATUS_REQUEST = 5;
|
||||
|
||||
public static final int SIO_MODEM_STATUS_CTS = 0x10;
|
||||
public static final int SIO_MODEM_STATUS_DSR = 0x20;
|
||||
public static final int SIO_MODEM_STATUS_RI = 0x40;
|
||||
public static final int SIO_MODEM_STATUS_RLSD = 0x80;
|
||||
private static final int SIO_MODEM_STATUS_CTS = 0x10;
|
||||
private static final int SIO_MODEM_STATUS_DSR = 0x20;
|
||||
private static final int SIO_MODEM_STATUS_RI = 0x40;
|
||||
private static final int SIO_MODEM_STATUS_RLSD = 0x80;
|
||||
|
||||
/**
|
||||
* Set the latency timer.
|
||||
@@ -190,10 +190,10 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
*/
|
||||
private static final int SIO_GET_LATENCY_TIMER_REQUEST = 10;
|
||||
|
||||
public static final int FTDI_DEVICE_OUT_REQTYPE =
|
||||
private static final int FTDI_DEVICE_OUT_REQTYPE =
|
||||
UsbConstants.USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT;
|
||||
|
||||
public static final int FTDI_DEVICE_IN_REQTYPE =
|
||||
private static final int FTDI_DEVICE_IN_REQTYPE =
|
||||
UsbConstants.USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN;
|
||||
|
||||
/**
|
||||
@@ -246,7 +246,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
return totalBytesRead - (packetsCount * 2);
|
||||
}
|
||||
|
||||
void reset() throws IOException {
|
||||
private void reset() throws IOException {
|
||||
// TODO(mikey): autodetect.
|
||||
mType = DeviceType.TYPE_R;
|
||||
if(mDevice.getInterfaceCount() > 1) {
|
||||
@@ -284,7 +284,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
return data[0];
|
||||
}
|
||||
|
||||
public int getModemStatus() throws IOException {
|
||||
private int getModemStatus() throws IOException {
|
||||
byte[] data = new byte[2];
|
||||
int result = mConnection.controlTransfer(FTDI_DEVICE_IN_REQTYPE, SIO_GET_MODEM_STATUS_REQUEST,
|
||||
0, mIndex, data, data.length, USB_WRITE_TIMEOUT_MILLIS);
|
||||
@@ -295,7 +295,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
protected void openInt(UsbDeviceConnection connection) throws IOException {
|
||||
if (connection.claimInterface(mDevice.getInterface(mPortNumber), true)) {
|
||||
Log.d(TAG, "claimInterface " + mPortNumber + " SUCCESS");
|
||||
} else {
|
||||
@@ -311,7 +311,7 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInt() {
|
||||
protected void closeInt() {
|
||||
try {
|
||||
mConnection.releaseInterface(mDevice.getInterface(mPortNumber));
|
||||
} catch(Exception ignored) {}
|
||||
|
||||
+7
-1
@@ -21,6 +21,7 @@
|
||||
|
||||
package com.hoho.android.usbserial.driver;
|
||||
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbManager;
|
||||
|
||||
@@ -86,7 +87,12 @@ public interface UsbSerialPort extends Closeable {
|
||||
public static final int STOPBITS_2 = 2;
|
||||
|
||||
public UsbSerialDriver getDriver();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the currently-bound USB device.
|
||||
*/
|
||||
public UsbDevice getDevice();
|
||||
|
||||
/**
|
||||
* Port number within driver.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user