steps towards Android implementation

This commit is contained in:
rusefi 2020-06-28 14:39:37 -04:00
parent e7a9ef5653
commit c01cc60ab0
13 changed files with 122 additions and 16 deletions

6
.idea/compiler.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>

View File

@ -11,5 +11,10 @@
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

View File

@ -2,12 +2,18 @@ apply plugin: 'java'
repositories {
mavenCentral()
google()
}
dependencies {
implementation group: 'org.usb4java', name: 'usb4java', version: '1.3.0'
implementation group: 'commons-logging', name: 'commons-logging', version: '1.2'
implementation files('lib/IntelHexParser.jar')
// 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'
testImplementation group: 'junit', name: 'junit', version: '4.13'
}

View File

@ -7,6 +7,12 @@ import com.rusefi.dfu.usb4java.USBDfuConnection;
import java.nio.ByteBuffer;
public class DfuLogic {
public static final short ST_VENDOR = 0x0483;
public static final short ST_DFU_PRODUCT = (short) 0xdf11;
public static final byte USB_CLASS_APP_SPECIFIC = (byte) 0xfe;
public static final byte DFU_SUBCLASS = 0x01;
public static final byte USB_DT_DFU = 0x21;
static void uploadImage(USBDfuConnection device, HexImage image) {
// todo: smarter erase handling!
DfuSeCommandErasePage.execute(device, 0x08000000);

View File

@ -1,4 +1,4 @@
package com.rusefi.dfu.usb4java;
package com.rusefi.dfu;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@ -0,0 +1,39 @@
package com.rusefi.dfu.android;
import android.hardware.usb.UsbDeviceConnection;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.DfuConnection;
import com.rusefi.dfu.FlashRange;
import java.nio.ByteBuffer;
public class AndroidDfuConnection implements DfuConnection {
private final UsbDeviceConnection usbDeviceConnection;
private final FlashRange flashRange;
public AndroidDfuConnection(UsbDeviceConnection usbDeviceConnection, FlashRange flashRange) {
this.usbDeviceConnection = usbDeviceConnection;
this.flashRange = flashRange;
}
@Override
public FlashRange getFlashRange() {
return flashRange;
}
@Override
public int getTransferSize() {
return 0;
}
@Override
public int receiveData(DfuCommmand command, short wValue, ByteBuffer data) {
//return usbDeviceConnection.controlTransfer();
return 0;
}
@Override
public int sendData(DfuCommmand command, short wValue, ByteBuffer data) {
return 0;
}
}

View File

@ -0,0 +1,48 @@
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;
public class DfuDeviceLocator {
private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
private 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;
}
}
return null;
}
public short xxx(UsbManager usbManager) {
UsbDevice dfuDevice = findDevice(usbManager);
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));
UsbDeviceConnection connection = usbManager.openDevice(dfuDevice);
}
}
return 0;
}
}

View File

@ -3,7 +3,7 @@ package com.rusefi.dfu.commands;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.DfuConnection;
import com.rusefi.dfu.DfuSeCommand;
import com.rusefi.dfu.usb4java.LogUtil;
import com.rusefi.dfu.LogUtil;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import org.apache.commons.logging.Log;

View File

@ -2,7 +2,7 @@ package com.rusefi.dfu.commands;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.DfuSeCommand;
import com.rusefi.dfu.usb4java.LogUtil;
import com.rusefi.dfu.LogUtil;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import org.apache.commons.logging.Log;

View File

@ -1,7 +1,9 @@
package com.rusefi.dfu.usb4java;
import com.rusefi.dfu.DfuLogic;
import com.rusefi.dfu.DfuSeFlashDescriptor;
import com.rusefi.dfu.FlashRange;
import com.rusefi.dfu.LogUtil;
import com.rusefi.dfu.commands.DfuCommandAbort;
import com.rusefi.dfu.commands.DfuCommandClearStatus;
import com.rusefi.dfu.commands.DfuCommandGetStatus;
@ -11,12 +13,6 @@ import org.usb4java.*;
import java.nio.ByteBuffer;
public class DfuDeviceLocator {
private static final short ST_VENDOR = 0x0483;
private static final short ST_DFU_PRODUCT = (short) 0xdf11;
private static final byte USB_CLASS_APP_SPECIFIC = (byte) 0xfe;
private static final byte DFU_SUBCLASS = 0x01;
private static final byte USB_DT_DFU = 0x21;
private static final Log log = LogUtil.getLog(DfuDeviceLocator.class);
@ -30,7 +26,7 @@ public class DfuDeviceLocator {
}
public static USBDfuConnection findDevice() {
return findDevice(openContext(), ST_VENDOR, ST_DFU_PRODUCT);
return findDevice(openContext(), DfuLogic.ST_VENDOR, DfuLogic.ST_DFU_PRODUCT);
}
private static USBDfuConnection findDevice(Context context, short vendorId, short productId) {
@ -99,7 +95,7 @@ public class DfuDeviceLocator {
if (extra.limit() > 2) {
int len = extra.get();
byte type = extra.get();
if (type == USB_DT_DFU) {
if (type == DfuLogic.USB_DT_DFU) {
System.out.println(len + " " + type);
extra.get(); // bmAttributes
extra.get(); // wDetachTimeOut
@ -126,8 +122,8 @@ public class DfuDeviceLocator {
setting.bInterfaceProtocol()
));
if (setting.bInterfaceClass() == USB_CLASS_APP_SPECIFIC &&
setting.bInterfaceSubClass() == DFU_SUBCLASS) {
if (setting.bInterfaceClass() == DfuLogic.USB_CLASS_APP_SPECIFIC &&
setting.bInterfaceSubClass() == DfuLogic.DFU_SUBCLASS) {
log.debug(String.format("Found DFU interface: %d", interfaceNumber));
String stringDescriptor = LibUsb.getStringDescriptor(deviceHandle, setting.iInterface());

View File

@ -1,7 +1,6 @@
package com.rusefi.dfu;
import com.rusefi.dfu.usb4java.DfuDeviceLocator;
import com.rusefi.dfu.usb4java.LogUtil;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import cz.jaybee.intelhex.IntelHexException;
import org.apache.commons.logging.Log;