mirror of https://github.com/rusefi/dfu_java.git
Android progress
This commit is contained in:
parent
e9d3f2c3f0
commit
ac48084f29
|
@ -12,7 +12,7 @@ dependencies {
|
||||||
// windows/linux/darwin
|
// windows/linux/darwin
|
||||||
compile group: 'org.usb4java', name: 'usb4java', version: '1.3.0'
|
compile group: 'org.usb4java', name: 'usb4java', version: '1.3.0'
|
||||||
// todo: someone one day should move android into sub-project
|
// 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'
|
testImplementation group: 'junit', name: 'junit', version: '4.13'
|
||||||
|
|
Binary file not shown.
|
@ -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.
|
|
@ -3,13 +3,14 @@ package com.rusefi.dfu.android;
|
||||||
import android.hardware.usb.*;
|
import android.hardware.usb.*;
|
||||||
|
|
||||||
import com.rusefi.dfu.DfuLogic;
|
import com.rusefi.dfu.DfuLogic;
|
||||||
|
import com.rusefi.dfu.DfuSeFlashDescriptor;
|
||||||
|
import com.rusefi.dfu.FlashRange;
|
||||||
//import com.rusefi.dfu.LogUtil;
|
//import com.rusefi.dfu.LogUtil;
|
||||||
//import org.apache.commons.logging.Log;
|
//import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
public class DfuDeviceLocator {
|
public class DfuDeviceLocator {
|
||||||
// private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
|
// private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
|
||||||
|
|
||||||
|
|
||||||
public static UsbDevice findDevice(UsbManager usbManager) {
|
public static UsbDevice findDevice(UsbManager usbManager) {
|
||||||
for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) {
|
for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) {
|
||||||
if (usbDevice.getVendorId() == DfuLogic.ST_VENDOR && usbDevice.getProductId() == DfuLogic.ST_DFU_PRODUCT) {
|
if (usbDevice.getVendorId() == DfuLogic.ST_VENDOR && usbDevice.getProductId() == DfuLogic.ST_DFU_PRODUCT) {
|
||||||
|
@ -19,20 +20,16 @@ public class DfuDeviceLocator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result openDfu(UsbManager usbManager, UsbDevice dfuDevice) {
|
||||||
public short openDfu(UsbManager usbManager, UsbDevice dfuDevice) {
|
|
||||||
|
|
||||||
for (int interfaceIndex = 0; interfaceIndex < dfuDevice.getInterfaceCount(); interfaceIndex++) {
|
|
||||||
UsbInterface usbInterface = dfuDevice.getInterface(interfaceIndex);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int interfaceIndex = 0; interfaceIndex < dfuDevice.getInterfaceCount(); interfaceIndex++) {
|
for (int interfaceIndex = 0; interfaceIndex < dfuDevice.getInterfaceCount(); interfaceIndex++) {
|
||||||
UsbInterface usbInterface = dfuDevice.getInterface(interfaceIndex);
|
UsbInterface usbInterface = dfuDevice.getInterface(interfaceIndex);
|
||||||
|
String stringDescriptor = usbInterface.getName();
|
||||||
if (usbInterface.getInterfaceClass() == DfuLogic.USB_CLASS_APP_SPECIFIC &&
|
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));
|
// log.debug(String.format("Found DFU interface: " + usbInterface));
|
||||||
|
|
||||||
|
FlashRange flashRange = DfuSeFlashDescriptor.parse(stringDescriptor);
|
||||||
|
|
||||||
UsbDeviceConnection connection = usbManager.openDevice(dfuDevice);
|
UsbDeviceConnection connection = usbManager.openDevice(dfuDevice);
|
||||||
|
|
||||||
|
@ -47,14 +44,33 @@ public class DfuDeviceLocator {
|
||||||
throw new IllegalStateException("Unexpected USB_DT_DFU");
|
throw new IllegalStateException("Unexpected USB_DT_DFU");
|
||||||
int transferSize = rawDescs[69] * 256 + rawDescs[68];
|
int transferSize = rawDescs[69] * 256 + rawDescs[68];
|
||||||
|
|
||||||
System.out.println(rawDescs + " " + transferSize);
|
return new Result(connection, flashRange, transferSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue