mirror of https://github.com/rusefi/dfu_java.git
refactoring
This commit is contained in:
parent
86c5b76487
commit
d5af537144
|
@ -3,5 +3,7 @@ package com.rusefi.dfu;
|
|||
public interface BinaryImage {
|
||||
byte[] getImage();
|
||||
|
||||
int getImageSize();
|
||||
default int getImageSize() {
|
||||
return getImage().length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,11 +45,6 @@ public class DfuImage implements BinaryImage {
|
|||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageSize() {
|
||||
return content.length;
|
||||
}
|
||||
|
||||
private static int calculateCRC(byte[] FileData) {
|
||||
int crc = -1;
|
||||
for (int i = 0; i < FileData.length - 4; i++) {
|
||||
|
|
|
@ -6,18 +6,15 @@ import cz.jaybee.intelhex.Parser;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class HexImage implements BinaryImage {
|
||||
private final byte[] image;
|
||||
private final int totalBytes;
|
||||
private final int maxOffset;
|
||||
|
||||
public HexImage(byte[] image, int totalBytes, int maxOffset) {
|
||||
public HexImage(byte[] image) {
|
||||
this.image = image;
|
||||
this.totalBytes = totalBytes;
|
||||
this.maxOffset = maxOffset;
|
||||
}
|
||||
|
||||
static HexImage loadHexToBuffer(InputStream is, FlashRange flashRange) throws IntelHexException, IOException {
|
||||
|
@ -54,7 +51,8 @@ public class HexImage implements BinaryImage {
|
|||
});
|
||||
ihp.parse();
|
||||
|
||||
return new HexImage(image, totalBytesReceived.get(), maxOffset.get());
|
||||
int imageSize = maxOffset.get() - flashRange.getBaseAddress();
|
||||
return new HexImage(Arrays.copyOfRange(image, 0, imageSize));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,17 +60,10 @@ public class HexImage implements BinaryImage {
|
|||
return image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageSize() {
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HexImage{" +
|
||||
"image=" + image.length +
|
||||
", totalBytes=" + totalBytes +
|
||||
", maxOffset=" + maxOffset +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,17 +38,7 @@ public class DfuLogicTest {
|
|||
}
|
||||
};
|
||||
|
||||
BinaryImage image = new BinaryImage() {
|
||||
@Override
|
||||
public byte[] getImage() {
|
||||
return new byte[150];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageSize() {
|
||||
return getImage().length;
|
||||
}
|
||||
};
|
||||
BinaryImage image = () -> new byte[150];
|
||||
|
||||
DfuLogic.actuallyUploadImage(DfuLogic.Logger.VOID, device, image, range);
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ public class Sandbox {
|
|||
return;
|
||||
}
|
||||
|
||||
//HexImage image = HexImage.loadHexToBuffer(new FileInputStream("rusefi.hex"), device.getFlashRange());
|
||||
HexImage image = HexImage.loadHexToBuffer(new FileInputStream("rusefi.hex"), device.getFlashRange());
|
||||
|
||||
DfuImage image = new DfuImage().read("rusefi_disco.dfu");
|
||||
//DfuImage image = new DfuImage().read("rusefi_disco.dfu");
|
||||
DfuLogic.uploadImage(logger, device, image, device.getFlashRange());
|
||||
|
||||
log.info("STM32 DFU " + device);
|
||||
|
|
Loading…
Reference in New Issue