mirror of https://github.com/rusefi/dfu_java.git
API progress
This commit is contained in:
parent
f888811a1f
commit
f3d134933e
|
@ -1,10 +1,9 @@
|
||||||
package com.rusefi.dfu;
|
package com.rusefi.dfu;
|
||||||
|
|
||||||
import com.rusefi.dfu.commands.DfuCommandGetStatus;
|
import com.rusefi.dfu.commands.DfuCommandGetStatus;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
|
||||||
|
|
||||||
public class DfuConnectionUtil {
|
public class DfuConnectionUtil {
|
||||||
public static void waitStatus(USBDfuConnection device) {
|
public static void waitStatus(DfuConnection device) {
|
||||||
DfuCommandGetStatus.State state = DfuCommandGetStatus.read(device);
|
DfuCommandGetStatus.State state = DfuCommandGetStatus.read(device);
|
||||||
System.out.println(" state " + state);
|
System.out.println(" state " + state);
|
||||||
while (state == DfuCommandGetStatus.State.DFU_DOWNLOAD_BUSY || state == DfuCommandGetStatus.State.DFU_ERROR) {
|
while (state == DfuCommandGetStatus.State.DFU_DOWNLOAD_BUSY || state == DfuCommandGetStatus.State.DFU_ERROR) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class DfuImage implements BinaryImage {
|
||||||
private int TargetSize;
|
private int TargetSize;
|
||||||
private int NumElements;
|
private int NumElements;
|
||||||
|
|
||||||
public void read(String fileName) {
|
public DfuImage read(String fileName) {
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
this.content = new byte[(int) file.length()];
|
this.content = new byte[(int) file.length()];
|
||||||
FileInputStream fileInputStream;
|
FileInputStream fileInputStream;
|
||||||
|
@ -37,6 +37,7 @@ public class DfuImage implements BinaryImage {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
verifyFile();
|
verifyFile();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.rusefi.dfu;
|
||||||
|
|
||||||
import com.rusefi.dfu.commands.DfuSeCommandErasePage;
|
import com.rusefi.dfu.commands.DfuSeCommandErasePage;
|
||||||
import com.rusefi.dfu.commands.DfuSeCommandSetAddress;
|
import com.rusefi.dfu.commands.DfuSeCommandSetAddress;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -15,7 +14,7 @@ public class DfuLogic {
|
||||||
public static final byte USB_DT_DFU = 0x21;
|
public static final byte USB_DT_DFU = 0x21;
|
||||||
public static final String FLASH_TAG = "Flash";
|
public static final String FLASH_TAG = "Flash";
|
||||||
|
|
||||||
static void uploadImage(USBDfuConnection device, HexImage image, FlashRange range) {
|
static void uploadImage(DfuConnection device, HexImage image, FlashRange range) {
|
||||||
List<Integer> erasePages = range.pagesForSize(image.getImageSize());
|
List<Integer> erasePages = range.pagesForSize(image.getImageSize());
|
||||||
// todo: smarted start address logic
|
// todo: smarted start address logic
|
||||||
int eraseAddress = 0x08000000;
|
int eraseAddress = 0x08000000;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.rusefi.dfu.commands;
|
package com.rusefi.dfu.commands;
|
||||||
|
|
||||||
import com.rusefi.dfu.DfuCommmand;
|
import com.rusefi.dfu.DfuCommmand;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
import com.rusefi.dfu.DfuConnection;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class DfuCommandAbort {
|
public class DfuCommandAbort {
|
||||||
public static void execute(USBDfuConnection session) {
|
public static void execute(DfuConnection session) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
|
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
|
||||||
session.sendData(DfuCommmand.ABORT, (short) 0, buffer);
|
session.sendData(DfuCommmand.ABORT, (short) 0, buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.rusefi.dfu.commands;
|
package com.rusefi.dfu.commands;
|
||||||
|
|
||||||
import com.rusefi.dfu.DfuCommmand;
|
import com.rusefi.dfu.DfuCommmand;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
import com.rusefi.dfu.DfuConnection;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class DfuCommandClearStatus {
|
public class DfuCommandClearStatus {
|
||||||
public static void execute(USBDfuConnection session) {
|
public static void execute(DfuConnection session) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
|
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
|
||||||
session.sendData(DfuCommmand.CLRSTATUS, (short) 0, buffer);
|
session.sendData(DfuCommmand.CLRSTATUS, (short) 0, buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package com.rusefi.dfu.commands;
|
package com.rusefi.dfu.commands;
|
||||||
|
|
||||||
import com.rusefi.dfu.DfuCommmand;
|
import com.rusefi.dfu.DfuCommmand;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
import com.rusefi.dfu.DfuConnection;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class DfuCommandGetStatus {
|
public class DfuCommandGetStatus {
|
||||||
private static final int PACKET_SIZE = 6;
|
private static final int PACKET_SIZE = 6;
|
||||||
|
|
||||||
public static State read(USBDfuConnection session) {
|
public static State read(DfuConnection session) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(PACKET_SIZE);
|
ByteBuffer buffer = ByteBuffer.allocateDirect(PACKET_SIZE);
|
||||||
int count = session.receiveData(DfuCommmand.GETSTATUS, (short) 0, buffer);
|
int count = session.receiveData(DfuCommmand.GETSTATUS, (short) 0, buffer);
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.rusefi.dfu.commands;
|
package com.rusefi.dfu.commands;
|
||||||
|
|
||||||
import com.rusefi.dfu.*;
|
import com.rusefi.dfu.*;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -9,7 +8,7 @@ import java.nio.ByteBuffer;
|
||||||
public class DfuSeCommandErasePage {
|
public class DfuSeCommandErasePage {
|
||||||
private static final Log log = LogUtil.getLog(DfuSeCommandErasePage.class);
|
private static final Log log = LogUtil.getLog(DfuSeCommandErasePage.class);
|
||||||
|
|
||||||
public static void execute(USBDfuConnection session, int address) {
|
public static void execute(DfuConnection session, int address) {
|
||||||
log.info(String.format("SetAddress %x", address));
|
log.info(String.format("SetAddress %x", address));
|
||||||
ByteBuffer buffer = DfuSeCommandSetAddress.createSpecialCommandBuffer(DfuSeCommand.SE_ERASE_PAGE, address);
|
ByteBuffer buffer = DfuSeCommandSetAddress.createSpecialCommandBuffer(DfuSeCommand.SE_ERASE_PAGE, address);
|
||||||
session.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_SPECIAL, buffer);
|
session.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_SPECIAL, buffer);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.rusefi.dfu.commands;
|
package com.rusefi.dfu.commands;
|
||||||
|
|
||||||
import com.rusefi.dfu.DfuCommmand;
|
import com.rusefi.dfu.DfuCommmand;
|
||||||
|
import com.rusefi.dfu.DfuConnection;
|
||||||
import com.rusefi.dfu.DfuSeCommand;
|
import com.rusefi.dfu.DfuSeCommand;
|
||||||
import com.rusefi.dfu.LogUtil;
|
import com.rusefi.dfu.LogUtil;
|
||||||
import com.rusefi.dfu.usb4java.USBDfuConnection;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -12,7 +12,7 @@ import java.nio.ByteOrder;
|
||||||
public class DfuSeCommandSetAddress {
|
public class DfuSeCommandSetAddress {
|
||||||
private static final Log log = LogUtil.getLog(DfuSeCommandSetAddress.class);
|
private static final Log log = LogUtil.getLog(DfuSeCommandSetAddress.class);
|
||||||
|
|
||||||
public static void execute(USBDfuConnection session, int address) {
|
public static void execute(DfuConnection session, int address) {
|
||||||
log.info(String.format("SetAddress %x", address));
|
log.info(String.format("SetAddress %x", address));
|
||||||
ByteBuffer buffer = createSpecialCommandBuffer(DfuSeCommand.SE_SET_ADDRESS, address);
|
ByteBuffer buffer = createSpecialCommandBuffer(DfuSeCommand.SE_SET_ADDRESS, address);
|
||||||
session.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_SPECIAL, buffer);
|
session.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_SPECIAL, buffer);
|
||||||
|
|
Loading…
Reference in New Issue