API progress

This commit is contained in:
rusefi 2020-07-05 14:53:22 -04:00
parent f888811a1f
commit f3d134933e
8 changed files with 13 additions and 15 deletions

View File

@ -1,10 +1,9 @@
package com.rusefi.dfu;
import com.rusefi.dfu.commands.DfuCommandGetStatus;
import com.rusefi.dfu.usb4java.USBDfuConnection;
public class DfuConnectionUtil {
public static void waitStatus(USBDfuConnection device) {
public static void waitStatus(DfuConnection device) {
DfuCommandGetStatus.State state = DfuCommandGetStatus.read(device);
System.out.println(" state " + state);
while (state == DfuCommandGetStatus.State.DFU_DOWNLOAD_BUSY || state == DfuCommandGetStatus.State.DFU_ERROR) {

View File

@ -25,7 +25,7 @@ public class DfuImage implements BinaryImage {
private int TargetSize;
private int NumElements;
public void read(String fileName) {
public DfuImage read(String fileName) {
File file = new File(fileName);
this.content = new byte[(int) file.length()];
FileInputStream fileInputStream;
@ -37,6 +37,7 @@ public class DfuImage implements BinaryImage {
throw new IllegalStateException(e);
}
verifyFile();
return this;
}
@Override

View File

@ -2,7 +2,6 @@ package com.rusefi.dfu;
import com.rusefi.dfu.commands.DfuSeCommandErasePage;
import com.rusefi.dfu.commands.DfuSeCommandSetAddress;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import java.nio.ByteBuffer;
import java.util.List;
@ -15,7 +14,7 @@ public class DfuLogic {
public static final byte USB_DT_DFU = 0x21;
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());
// todo: smarted start address logic
int eraseAddress = 0x08000000;

View File

@ -1,12 +1,12 @@
package com.rusefi.dfu.commands;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import com.rusefi.dfu.DfuConnection;
import java.nio.ByteBuffer;
public class DfuCommandAbort {
public static void execute(USBDfuConnection session) {
public static void execute(DfuConnection session) {
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
session.sendData(DfuCommmand.ABORT, (short) 0, buffer);
}

View File

@ -1,12 +1,12 @@
package com.rusefi.dfu.commands;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import com.rusefi.dfu.DfuConnection;
import java.nio.ByteBuffer;
public class DfuCommandClearStatus {
public static void execute(USBDfuConnection session) {
public static void execute(DfuConnection session) {
ByteBuffer buffer = ByteBuffer.allocateDirect(0);
session.sendData(DfuCommmand.CLRSTATUS, (short) 0, buffer);
}

View File

@ -1,14 +1,14 @@
package com.rusefi.dfu.commands;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import com.rusefi.dfu.DfuConnection;
import java.nio.ByteBuffer;
public class DfuCommandGetStatus {
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);
int count = session.receiveData(DfuCommmand.GETSTATUS, (short) 0, buffer);
if (count == 0)

View File

@ -1,7 +1,6 @@
package com.rusefi.dfu.commands;
import com.rusefi.dfu.*;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import org.apache.commons.logging.Log;
import java.nio.ByteBuffer;
@ -9,7 +8,7 @@ import java.nio.ByteBuffer;
public class DfuSeCommandErasePage {
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));
ByteBuffer buffer = DfuSeCommandSetAddress.createSpecialCommandBuffer(DfuSeCommand.SE_ERASE_PAGE, address);
session.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_SPECIAL, buffer);

View File

@ -1,9 +1,9 @@
package com.rusefi.dfu.commands;
import com.rusefi.dfu.DfuCommmand;
import com.rusefi.dfu.DfuConnection;
import com.rusefi.dfu.DfuSeCommand;
import com.rusefi.dfu.LogUtil;
import com.rusefi.dfu.usb4java.USBDfuConnection;
import org.apache.commons.logging.Log;
import java.nio.ByteBuffer;
@ -12,7 +12,7 @@ import java.nio.ByteOrder;
public class DfuSeCommandSetAddress {
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));
ByteBuffer buffer = createSpecialCommandBuffer(DfuSeCommand.SE_SET_ADDRESS, address);
session.sendData(DfuCommmand.DNLOAD, DfuSeCommand.W_SPECIAL, buffer);