mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-11 08:22:52 +00:00
Prolific driver with less hardcoded baud rates
Some older devices do not support all values. Use always supported mantissa+exponent based formula instead
This commit is contained in:
Generated
-1
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="NullableNotNullManager">
|
<component name="NullableNotNullManager">
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ android {
|
|||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
testInstrumentationRunnerArguments = [ // Raspi Windows LinuxVM ...
|
testInstrumentationRunnerArguments = [ // Raspi Windows LinuxVM ...
|
||||||
'rfc2217_server_host': '192.168.0.78',
|
'rfc2217_server_host': '192.168.0.124',
|
||||||
'rfc2217_server_nonstandard_baudrates': 'true', // true false false
|
'rfc2217_server_nonstandard_baudrates': 'true', // true false false
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-25
@@ -362,9 +362,9 @@ public class DeviceTest {
|
|||||||
Assume.assumeTrue("only for Prolific", usb.serialDriver instanceof ProlificSerialDriver);
|
Assume.assumeTrue("only for Prolific", usb.serialDriver instanceof ProlificSerialDriver);
|
||||||
|
|
||||||
int[] baudRates = {
|
int[] baudRates = {
|
||||||
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400, 19200,
|
75, 110, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400, 19200,
|
||||||
28800, 38400, 57600, 115200, 128000, 134400, 161280, 201600, 230400, 268800,
|
28800, 38400, 56000, 57600, 115200, 128000, 134400, 161280, 201600, 230400, 256000,
|
||||||
403200, 460800, 614400, 806400, 921600, 1228800, 2457600, 3000000, /*6000000*/
|
268800, 403200, 460800, 614400, 806400, 921600, 1228800, /* 2457600, 3000000, 6000000*/
|
||||||
};
|
};
|
||||||
usb.open();
|
usb.open();
|
||||||
Assume.assumeFalse("only for non PL2303G*", ProlificSerialPortWrapper.isDeviceTypeHxn(usb.serialPort)); // HXN does not use divisor
|
Assume.assumeFalse("only for non PL2303G*", ProlificSerialPortWrapper.isDeviceTypeHxn(usb.serialPort)); // HXN does not use divisor
|
||||||
@@ -396,28 +396,6 @@ public class DeviceTest {
|
|||||||
|
|
||||||
usb.setParameters(baudRate + 1, 8, 1, UsbSerialPort.PARITY_NONE);
|
usb.setParameters(baudRate + 1, 8, 1, UsbSerialPort.PARITY_NONE);
|
||||||
doReadWrite(String.valueOf(baudRate + 1), readWait);
|
doReadWrite(String.valueOf(baudRate + 1), readWait);
|
||||||
|
|
||||||
// silent fallback to 9600 for unsupported baud rates
|
|
||||||
telnet.setParameters(9600, 8, 1, UsbSerialPort.PARITY_NONE);
|
|
||||||
usb.setParameters(baudRate + 1 + (1<<29), 8, 1, UsbSerialPort.PARITY_NONE);
|
|
||||||
doReadWrite(String.valueOf(baudRate + 1) + " + 1<<29", readWait);
|
|
||||||
}
|
|
||||||
|
|
||||||
// some PL2303... data sheets mention additional standard baud rates, others don't
|
|
||||||
// they do not work with my devices and linux driver also excludes them
|
|
||||||
baudRates = new int[]{110, 56000, 256000};
|
|
||||||
for(int baudRate : baudRates) {
|
|
||||||
int readWait = 500;
|
|
||||||
if(baudRate < 300) readWait = 1000;
|
|
||||||
if(baudRate < 150) readWait = 2000;
|
|
||||||
telnet.setParameters(baudRate, 8, 1, UsbSerialPort.PARITY_NONE);
|
|
||||||
usb.setParameters(baudRate, 8, 1, UsbSerialPort.PARITY_NONE);
|
|
||||||
doReadWrite(String.valueOf(baudRate), readWait);
|
|
||||||
|
|
||||||
// silent fallback to 9600 for unsupported baud rates
|
|
||||||
telnet.setParameters(9600, 8, 1, UsbSerialPort.PARITY_NONE);
|
|
||||||
usb.setParameters(baudRate + (1<<29), 8, 1, UsbSerialPort.PARITY_NONE);
|
|
||||||
doReadWrite(String.valueOf(baudRate) + " + 1<<29", readWait);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -30,9 +30,9 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
private final String TAG = ProlificSerialDriver.class.getSimpleName();
|
private final String TAG = ProlificSerialDriver.class.getSimpleName();
|
||||||
|
|
||||||
private final static int[] standardBaudRates = {
|
private final static int[] standardBaudRates = {
|
||||||
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400, 19200,
|
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,
|
||||||
28800, 38400, 57600, 115200, 128000, 134400, 161280, 201600, 230400, 268800,
|
14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,
|
||||||
403200, 460800, 614400, 806400, 921600, 1228800, 2457600, 3000000, 6000000
|
614400, 921600, 1228800, 2457600, 3000000, 6000000
|
||||||
};
|
};
|
||||||
protected enum DeviceType { DEVICE_TYPE_01, DEVICE_TYPE_T, DEVICE_TYPE_HX, DEVICE_TYPE_HXN }
|
protected enum DeviceType { DEVICE_TYPE_01, DEVICE_TYPE_T, DEVICE_TYPE_HX, DEVICE_TYPE_HXN }
|
||||||
|
|
||||||
@@ -342,9 +342,6 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int filterBaudRate(int baudRate) {
|
private int filterBaudRate(int baudRate) {
|
||||||
if(BuildConfig.DEBUG && (baudRate & (3<<29)) == (1<<29)) {
|
|
||||||
return baudRate & ~(1<<29); // for testing purposes accept without further checks
|
|
||||||
}
|
|
||||||
if (baudRate <= 0) {
|
if (baudRate <= 0) {
|
||||||
throw new IllegalArgumentException("Invalid baud rate: " + baudRate);
|
throw new IllegalArgumentException("Invalid baud rate: " + baudRate);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user