mirror of https://github.com/rusefi/dfu_java.git
DFU file read fix
This commit is contained in:
parent
d09aecef78
commit
d665e158b8
|
@ -1,9 +1,18 @@
|
|||
package com.rusefi.dfu;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface BinaryImage {
|
||||
byte[] getImage();
|
||||
|
||||
default int getImageSize() {
|
||||
return getImage().length;
|
||||
}
|
||||
|
||||
default void saveToFile(String fileName) throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(fileName);
|
||||
fos.write(getImage(), 0, getImageSize());
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi.dfu;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Inspired by https://github.com/UmbrelaSmart/android-stm32-dfu-programmer
|
||||
|
@ -13,6 +14,7 @@ public class DfuImage implements BinaryImage {
|
|||
private final static int TARGET_NAME_MAX_END = 276;
|
||||
private final static int TARGET_SIZE = 277;
|
||||
private final static int TARGET_NUM_ELEMENTS = 281;
|
||||
private final static int ELEMENT1_OFFSET = 293; // constant offset in file array where image data starts
|
||||
|
||||
private byte[] content;
|
||||
private int PID;
|
||||
|
@ -42,7 +44,7 @@ public class DfuImage implements BinaryImage {
|
|||
|
||||
@Override
|
||||
public byte[] getImage() {
|
||||
return content;
|
||||
return Arrays.copyOfRange(content, ELEMENT1_OFFSET, ELEMENT1_OFFSET + elementLength);
|
||||
}
|
||||
|
||||
private static int calculateCRC(byte[] FileData) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.rusefi.dfu.usb4java.USBDfuConnection;
|
|||
import cz.jaybee.intelhex.IntelHexException;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Sandbox {
|
||||
|
@ -21,9 +20,9 @@ public class Sandbox {
|
|||
return;
|
||||
}
|
||||
|
||||
HexImage image = HexImage.loadHexToBuffer(new FileInputStream("rusefi.hex"), device.getFlashRange());
|
||||
//BinaryImage image = HexImage.loadHexToBuffer(new FileInputStream("rusefi.hex"), device.getFlashRange());
|
||||
|
||||
//DfuImage image = new DfuImage().read("rusefi_disco.dfu");
|
||||
BinaryImage image = new DfuImage().read("rusefi.dfu");
|
||||
DfuLogic.uploadImage(logger, device, image, device.getFlashRange());
|
||||
|
||||
log.info("STM32 DFU " + device);
|
||||
|
|
Loading…
Reference in New Issue