changed sync tests

ftdi_sync_fix
Felipe Herranz 2019-07-05 22:44:45 +02:00
rodzic 10d1088228
commit 2f4a4de99c
3 zmienionych plików z 43 dodań i 22 usunięć

Wyświetl plik

@ -0,0 +1,34 @@
# UsbSerial test: Integration test
# args:
# port (eg /dev/ttyUSB0)
# speed in bauds (eg 115200)
import serial
import sys
import os
class style():
RED = lambda x: '\033[31m' + str(x)
GREEN = lambda x: '\033[32m' + str(x)
BLUE = lambda x: '\033[34m' + str(x)
RESET = lambda x: '\033[0m' + str(x)
port = sys.argv[1]
speed = sys.argv[2]
test_sizes = [1024, 2048, 16384]
for i in range(0,3):
comm = serial.Serial(port, int(speed))
print("Creating " + str(test_sizes[i]) + " bytes buffer")
data_tx = os.urandom(test_sizes[i])
print("Sending buffer of " + str(test_sizes[i]) + " bytes")
comm.write(data_tx)
print("Receiving " + str(test_sizes[i]) + " bytes buffer")
data_rx = comm.read(test_sizes[i])
if data_tx == data_rx:
print(style.GREEN("Success: " + str(test_sizes[i]) + " bytes buffer was transmitted correctly"))
else:
print(style.RED("Error: " + str(test_sizes[i]) + " bytes buffer was not transmitted correctly"))
print(style.RESET(""))

Wyświetl plik

@ -110,6 +110,7 @@ public class MainActivity extends AppCompatActivity {
public void onResume() {
super.onResume();
setFilters(); // Start listening notifications from UsbService
Toast.makeText(this, "Mode: " + String.valueOf(MODE), Toast.LENGTH_LONG).show();
if (MODE == 0) {
startService(UsbService.class, usbConnection, null); // Start UsbService(if it was not started before) and Bind it
}else if (MODE == 1) {
@ -121,7 +122,11 @@ public class MainActivity extends AppCompatActivity {
public void onPause() {
super.onPause();
unregisterReceiver(mUsbReceiver);
unbindService(usbConnection);
if(MODE == 0) {
unbindService(usbConnection);
}else{
unbindService(usbSyncConnection);
}
}
private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {

Wyświetl plik

@ -33,8 +33,6 @@ public class UsbSyncService extends Service {
private static final int SIZE_TEST_1 = 1024;
private static final int SIZE_TEST_2 = 2048;
private static final int SIZE_TEST_3 = 16384;
private static final int SIZE_TEST_4 = 65535;
private static final int SIZE_TEST_5 = 131072;
private static final String TEST_1 = "test1";
private static final String TEST_2 = "test2";
@ -58,10 +56,6 @@ public class UsbSyncService extends Service {
public static final int MESSAGE_TEST_1 = 0;
public static final int MESSAGE_TEST_2 = 1;
public static final int MESSAGE_TEST_3 = 2;
public static final int MESSAGE_TEST_4 = 3;
public static final int MESSAGE_TEST_5 = 4;
public static final int CTS_CHANGE = 1;
public static final int DSR_CHANGE = 2;
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
private static final int BAUD_RATE = 115200; // BaudRate. Change this value if you need
public static boolean SERVICE_CONNECTED = false;
@ -282,11 +276,11 @@ public class UsbSyncService extends Service {
@Override
public void run() {
while(true){
byte[] tmpBuffer = new byte[BUFFER_SYNC];
byte[] tmpBuffer = new byte[16384];
int n = serialPort.syncRead(tmpBuffer, 0);
if(n > 0) {
buffer.write(tmpBuffer);
buffer.write(tmpBuffer, 0, n);
}
if(mode.equals(TEST_1)){
@ -304,21 +298,9 @@ public class UsbSyncService extends Service {
}else if(mode.equals(TEST_3)){
if(buffer.size() == SIZE_TEST_3){
serialPort.syncWrite(buffer.readByteArray(), 0);
mode = TEST_4;
mHandler.obtainMessage(MESSAGE_TEST_3, "Test 16Kb completed correctly").sendToTarget();
}
}else if(mode.equals(TEST_4)){
if(buffer.size() == SIZE_TEST_4){
serialPort.syncWrite(buffer.readByteArray(), 0);
mode = TEST_5;
mHandler.obtainMessage(MESSAGE_TEST_4, "Test 64Kb completed correctly").sendToTarget();
}
}else if(mode.equals(TEST_5)){
if(buffer.size() == SIZE_TEST_5){
serialPort.syncWrite(buffer.readByteArray(), 0);
mode = TEST_1;
mHandler.obtainMessage(MESSAGE_TEST_5, "Test 128Kb completed correctly").sendToTarget();
mHandler.obtainMessage(MESSAGE_TEST_3, "Test 16Kb completed correctly").sendToTarget();
}
}
}