Skip to content

Commit

Permalink
Still not tested but moved
Browse files Browse the repository at this point in the history
  • Loading branch information
felHR85 committed May 27, 2014
1 parent 51f647e commit a53e715
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 51 deletions.
Binary file not shown.
Binary file modified bin/classes/com/felhr/usbserial/FTDISerialDevice.class
Binary file not shown.
Binary file modified bin/classes/com/felhr/usbserial/UsbSerialDevice$WorkerThread.class
Binary file not shown.
Binary file not shown.
Binary file modified bin/classes/com/felhr/usbserial/UsbSerialDevice.class
Binary file not shown.
Binary file modified bin/usbserial.jar
Binary file not shown.
54 changes: 54 additions & 0 deletions src/com/felhr/usbserial/FTDISerialDevice.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.felhr.usbserial;

import java.util.Arrays;

import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
Expand Down Expand Up @@ -277,5 +279,57 @@ private int setControlCommand(int request, int value, int index, byte[] data)
Log.i(CLASS_ID,"Control Transfer Response: " + String.valueOf(response));
return response;
}

public static class FTDIUtilities
{
// Special treatment needed to FTDI devices
public static byte[] adaptArray(byte[] ftdiData)
{
int length = ftdiData.length;
if(length > 64)
{
int n = 1;
int p = 64;
// Precalculate length without FTDI headers
while(p < length)
{
n++;
p = n*64;
}
int realLength = length - n*2;
byte[] data = new byte[realLength];
copyData(ftdiData, data);
return data;
}else
{
return Arrays.copyOfRange(ftdiData, 2, length);
}
}

// Copy data without FTDI headers
private static void copyData(byte[] src, byte[] dst)
{
int i = 0; // src index
int j = 0; // dst index
while(i <= src.length-1)
{
if(i != 0 || i != 1)
{
if(i % 64 == 0 && i >= 64)
{
i += 2;
}else
{
dst[j] = src[i];
i++;
j++;
}
}else
{
i++;
}
}
}
}

}
52 changes: 1 addition & 51 deletions src/com/felhr/usbserial/UsbSerialDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void run()
if(isFTDIDevice())
{
Log.i(CLASS_ID, String.valueOf(data.length));
byte[] data2 = adaptArray(data);
byte[] data2 = FTDISerialDevice.FTDIUtilities.adaptArray(data);
// Clear buffer and execute the callback
serialBuffer.clearReadBuffer();
onReceivedData(data2);
Expand Down Expand Up @@ -143,56 +143,6 @@ public void stopWorkingThread()
{
working.set(false);
}

// Special treatment needed to FTDI devices
private byte[] adaptArray(byte[] ftdiData)
{
int length = ftdiData.length;
if(length > 64)
{
int n = 1;
int p = 64;
// Precalculate length without FTDI headers
while(p < length)
{
n++;
p = n*64;
}
int realLength = length - n*2;
byte[] data = new byte[realLength];
copyData(ftdiData, data);
return data;
}else
{
return Arrays.copyOfRange(ftdiData, 2, length);
}
}

// Copy data without FTDI headers
private void copyData(byte[] src, byte[] dst)
{
int i = 0; // src index
int j = 0; // dst index
while(i <= src.length-1)
{
if(i != 0 || i != 1)
{
if(i % 64 == 0 && i >= 64)
{
i += 2;
}else
{
dst[j] = src[i];
i++;
j++;
}
}else
{
i++;
}
}
}

}

protected class WriteThread extends Thread
Expand Down

0 comments on commit a53e715

Please sign in to comment.