mirror of https://github.com/rusefi/dfu_java.git
Android progress
This commit is contained in:
parent
49600d0303
commit
bee24af97d
|
@ -1,14 +1,16 @@
|
|||
package com.rusefi.dfu.android;
|
||||
|
||||
import android.hardware.usb.*;
|
||||
|
||||
import com.rusefi.dfu.DfuLogic;
|
||||
import com.rusefi.dfu.LogUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
//import com.rusefi.dfu.LogUtil;
|
||||
//import org.apache.commons.logging.Log;
|
||||
|
||||
public class DfuDeviceLocator {
|
||||
private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
|
||||
// private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
|
||||
|
||||
private static UsbDevice findDevice(UsbManager usbManager) {
|
||||
|
||||
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) {
|
||||
return usbDevice;
|
||||
|
@ -18,24 +20,34 @@ public class DfuDeviceLocator {
|
|||
}
|
||||
|
||||
|
||||
public short xxx(UsbManager usbManager) {
|
||||
UsbDevice dfuDevice = findDevice(usbManager);
|
||||
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++) {
|
||||
UsbInterface usbInterface = dfuDevice.getInterface(interfaceIndex);
|
||||
if (usbInterface.getInterfaceClass() == DfuLogic.USB_CLASS_APP_SPECIFIC &&
|
||||
usbInterface.getInterfaceSubclass() == DfuLogic.DFU_SUBCLASS) {
|
||||
log.debug(String.format("Found DFU interface: " + usbInterface));
|
||||
// log.debug(String.format("Found DFU interface: " + usbInterface));
|
||||
|
||||
|
||||
UsbDeviceConnection connection = usbManager.openDevice(dfuDevice);
|
||||
|
||||
UsbInterface intf = dfuDevice.getInterface(0);
|
||||
connection.claimInterface(intf, true);
|
||||
|
||||
byte[] rawDescs = connection.getRawDescriptors();
|
||||
// todo: need proper handling of this rawDesc area since I have no clue what's the format
|
||||
if (rawDescs.length != 72)
|
||||
throw new IllegalStateException("Unexpected RawDescriptors length");
|
||||
if (rawDescs[64] != DfuLogic.USB_DT_DFU)
|
||||
throw new IllegalStateException("Unexpected USB_DT_DFU");
|
||||
int transferSize = rawDescs[69] * 256 + rawDescs[68];
|
||||
|
||||
System.out.println(rawDescs + " " + transferSize);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue