RTFM LOL :(

This commit is contained in:
rusefi 2020-07-05 18:52:40 -04:00
parent fd279e266c
commit 74a938fd8f
7 changed files with 17 additions and 10 deletions

View File

@ -6,9 +6,12 @@ public class DfuConnectionUtil {
public static void waitStatus(DfuLogic.Logger logger, DfuConnection device) {
DfuCommandGetStatus.DeviceStatus state = DfuCommandGetStatus.read(logger, device);
logger.info("First state " + state);
long enter = System.currentTimeMillis();
while (state.getState() == DfuCommandGetStatus.State.DFU_DOWNLOAD_BUSY || state.getState() == DfuCommandGetStatus.State.DFU_ERROR) {
state = DfuCommandGetStatus.read(logger, device);
logger.info("Loop state " + state);
if (System.currentTimeMillis() - enter > 10 * DfuConnection.SECOND)
throw new IllegalStateException("State does not look good");
}
}

View File

@ -33,7 +33,7 @@ public class DfuLogic {
DfuSeCommandSetAddress.execute(logger, device, device.getFlashRange().getBaseAddress() + offset);
DfuConnectionUtil.waitStatus(logger, device);
ByteBuffer buffer = ByteBuffer.allocateDirect(device.getTransferSize());
ByteBuffer buffer = ByteBuffer.allocate(device.getTransferSize());
// last transfer would usually be smaller than transfer size
int size = Math.min(device.getTransferSize(), image.getImage().length - offset);
buffer.put(image.getImage(), offset, size);
@ -45,7 +45,7 @@ public class DfuLogic {
}
public static void leaveDFU(Logger logger, DfuConnection device) {
device.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_DNLOAD, ByteBuffer.allocateDirect(0));
device.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_DNLOAD, ByteBuffer.allocate(0));
// The DFU Leave operation is effectively executed only when a DFU_GETSTATUS request is
// issued by the host.
DfuConnectionUtil.waitStatus(logger, device);

View File

@ -12,13 +12,17 @@ import static android.hardware.usb.UsbConstants.USB_DIR_OUT;
public class AndroidDfuConnection implements DfuConnection {
private final UsbDeviceConnection usbDeviceConnection;
private final byte interfaceNumber;
private final int transferSize;
private final FlashRange flashRange;
private static final byte REQUEST_TYPE_CLASS = 32;
private static final byte RECIPIENT_INTERFACE = 0x01;
public AndroidDfuConnection(UsbDeviceConnection usbDeviceConnection, FlashRange flashRange) {
public AndroidDfuConnection(UsbDeviceConnection usbDeviceConnection, byte interfaceNumber, int transferSize, FlashRange flashRange) {
this.usbDeviceConnection = usbDeviceConnection;
this.interfaceNumber = interfaceNumber;
this.transferSize = transferSize;
this.flashRange = flashRange;
}
@ -29,7 +33,7 @@ public class AndroidDfuConnection implements DfuConnection {
@Override
public int getTransferSize() {
return 0;
return transferSize;
}
@Override
@ -42,8 +46,8 @@ public class AndroidDfuConnection implements DfuConnection {
return transfer(usbDeviceConnection, USB_DIR_OUT, command.getValue(), wValue, data);
}
private static int transfer(UsbDeviceConnection connection, int direction, int request, short wValue, ByteBuffer byteBuffer) {
private int transfer(UsbDeviceConnection connection, int direction, int request, short wValue, ByteBuffer byteBuffer) {
return connection.controlTransfer(REQUEST_TYPE_CLASS | RECIPIENT_INTERFACE | direction, request,
wValue, 0, byteBuffer.array(), byteBuffer.limit(), 500);
wValue, interfaceNumber, byteBuffer.array(), byteBuffer.limit(), DFU_TIMEOUT);
}
}

View File

@ -7,7 +7,7 @@ import java.nio.ByteBuffer;
public class DfuCommandAbort {
public static void execute(DfuConnection session) {
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
ByteBuffer buffer = ByteBuffer.allocate(0);
session.sendData(DfuCommmand.ABORT, (short) 0, buffer);
}
}

View File

@ -7,7 +7,7 @@ import java.nio.ByteBuffer;
public class DfuCommandClearStatus {
public static void execute(DfuConnection session) {
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
ByteBuffer buffer = ByteBuffer.allocate(0);
session.sendData(DfuCommmand.CLRSTATUS, (short) 0, buffer);
}
}

View File

@ -14,7 +14,7 @@ public class DfuCommandGetStatus {
private final static AtomicInteger STATUS_COUNTER = new AtomicInteger();
public static DeviceStatus read(DfuLogic.Logger logger, DfuConnection session) {
ByteBuffer buffer = ByteBuffer.allocateDirect(PACKET_SIZE);
ByteBuffer buffer = ByteBuffer.allocate(PACKET_SIZE);
int count = session.receiveData(DfuCommmand.GETSTATUS, (short) 0, buffer);
if (count != PACKET_SIZE)
return new DeviceStatus(null, State.DFU_ERROR);

View File

@ -26,6 +26,6 @@ public class DfuSeCommandSetAddress {
}
protected static ByteBuffer createBuffer(int capacity) {
return ByteBuffer.allocateDirect(capacity).order(ByteOrder.LITTLE_ENDIAN);
return ByteBuffer.allocate(capacity).order(ByteOrder.LITTLE_ENDIAN);
}
}