Android progress

This commit is contained in:
rusefi 2020-06-29 01:36:27 -04:00
parent e9d3f2c3f0
commit ac48084f29
4 changed files with 34 additions and 17 deletions

View File

@ -12,7 +12,7 @@ dependencies {
// windows/linux/darwin
compile group: 'org.usb4java', name: 'usb4java', version: '1.3.0'
// todo: someone one day should move android into sub-project
compile group: 'com.google.android', name: 'android', version: '4.0.1.2'
implementation files('lib/android.jar')
testImplementation group: 'junit', name: 'junit', version: '4.13'

BIN
lib/android.jar Normal file

Binary file not shown.

1
lib/android.md Normal file
View File

@ -0,0 +1 @@
mvn central has android jars up to version 4 (year 2015) I was not able to find a source for newer API jars. We need Android 5 here.

View File

@ -3,13 +3,14 @@ package com.rusefi.dfu.android;
import android.hardware.usb.*;
import com.rusefi.dfu.DfuLogic;
import com.rusefi.dfu.DfuSeFlashDescriptor;
import com.rusefi.dfu.FlashRange;
//import com.rusefi.dfu.LogUtil;
//import org.apache.commons.logging.Log;
public class DfuDeviceLocator {
// private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
public static UsbDevice findDevice(UsbManager usbManager) {
for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) {
if (usbDevice.getVendorId() == DfuLogic.ST_VENDOR && usbDevice.getProductId() == DfuLogic.ST_DFU_PRODUCT) {
@ -19,20 +20,16 @@ public class DfuDeviceLocator {
return null;
}
public short openDfu(UsbManager usbManager, UsbDevice dfuDevice) {
for (int interfaceIndex = 0; interfaceIndex < dfuDevice.getInterfaceCount(); interfaceIndex++) {
UsbInterface usbInterface = dfuDevice.getInterface(interfaceIndex);
}
public Result openDfu(UsbManager usbManager, UsbDevice dfuDevice) {
for (int interfaceIndex = 0; interfaceIndex < dfuDevice.getInterfaceCount(); interfaceIndex++) {
UsbInterface usbInterface = dfuDevice.getInterface(interfaceIndex);
String stringDescriptor = usbInterface.getName();
if (usbInterface.getInterfaceClass() == DfuLogic.USB_CLASS_APP_SPECIFIC &&
usbInterface.getInterfaceSubclass() == DfuLogic.DFU_SUBCLASS) {
usbInterface.getInterfaceSubclass() == DfuLogic.DFU_SUBCLASS &&
stringDescriptor.contains(DfuLogic.FLASH_TAG)) {
// log.debug(String.format("Found DFU interface: " + usbInterface));
FlashRange flashRange = DfuSeFlashDescriptor.parse(stringDescriptor);
UsbDeviceConnection connection = usbManager.openDevice(dfuDevice);
@ -47,14 +44,33 @@ public class DfuDeviceLocator {
throw new IllegalStateException("Unexpected USB_DT_DFU");
int transferSize = rawDescs[69] * 256 + rawDescs[68];
System.out.println(rawDescs + " " + transferSize);
return new Result(connection, flashRange, transferSize);
}
}
return 0;
return null;
}
private class Result {
private final UsbDeviceConnection connection;
private final FlashRange flashRange;
private final int transferSize;
public Result(UsbDeviceConnection connection, FlashRange flashRange, int transferSize) {
this.connection = connection;
this.flashRange = flashRange;
this.transferSize = transferSize;
}
public UsbDeviceConnection getConnection() {
return connection;
}
public FlashRange getFlashRange() {
return flashRange;
}
public int getTransferSize() {
return transferSize;
}
}
}