Skip to content

Commit

Permalink
back to previous ftdi syncRead method
Browse files Browse the repository at this point in the history
  • Loading branch information
felHR85 committed Jul 3, 2019
1 parent 3465c50 commit 9f32a3b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions usbserial/src/main/java/com/felhr/usbserial/FTDISerialDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,30 @@ private static void copyData(byte[] src, byte[] dst)

public class FTDIUtilities
{
// Special treatment needed to FTDI devices
public 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);
}
}

public void checkModemStatus(byte[] data)
{
if(data.length == 0) // Safeguard for zero length arrays
Expand Down Expand Up @@ -624,10 +648,6 @@ public int syncRead(byte[] buffer, int timeout)
return 0;
}

if (mr1Version) {
return readSyncJelly(buffer, timeout, stopTime);
}

int n = buffer.length / 62;
if(buffer.length % 62 != 0)
{
Expand All @@ -654,7 +674,7 @@ public int syncRead(byte[] buffer, int timeout)

if(numberBytes > 2) // Data received
{
byte[] newBuffer = adaptArray(tempBuffer);
byte[] newBuffer = this.ftdiUtilities.adaptArray(tempBuffer);
System.arraycopy(newBuffer, 0, buffer, 0, buffer.length);

int p = numberBytes / 64;
Expand Down

0 comments on commit 9f32a3b

Please sign in to comment.