diff --git a/dfu/dfu.iml b/dfu/dfu.iml index 90a2c9a..66fb322 100644 --- a/dfu/dfu.iml +++ b/dfu/dfu.iml @@ -1,5 +1,5 @@ - + diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java b/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java index 96880cc..6f9bcd4 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java @@ -422,7 +422,7 @@ public abstract class DfuBaseService extends IntentService { */ private int mPacketsBeforeNotification = 10; - private byte[] mBuffer = new byte[MAX_PACKET_SIZE]; + private final byte[] mBuffer = new byte[MAX_PACKET_SIZE]; private InputStream mInputStream; /** * Size of BIN content of all hex files that are going to be transmitted. diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/HexInputStream.java b/dfu/src/main/java/no/nordicsemi/android/dfu/HexInputStream.java index 2233c2f..f3dfe25 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/HexInputStream.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/HexInputStream.java @@ -33,16 +33,15 @@ public class HexInputStream extends FilterInputStream { private int size; private int lastAddress; private int available, bytesRead; - private int MBRsize; + private final int MBRSize; /** * Creates the HEX Input Stream. The constructor calculates the size of the BIN content which is available through {@link #sizeInBytes()}. If HEX file is invalid then the bin size is 0. * * @param in * the input stream to read from - * @param trim - * if true the bin data will be trimmed. All data from addresses < 0x1000 will be skipped. In the Soft Device 7.0.0 it's MBR space and this HEX fragment should not be - * transmitted. However, other DFU implementations (f.e. without Soft Device) may require uploading the whole file. + * @param mbrSize + * The MBR (Master Boot Record) size in bytes. Data with addresses below than number will be trimmed and not transferred to DFU target. * @throws HexFileValidationException * if HEX file is invalid. F.e. there is no semicolon (':') on the beginning of each line. * @throws java.io.IOException @@ -54,7 +53,7 @@ public class HexInputStream extends FilterInputStream { this.localPos = LINE_LENGTH; // we are at the end of the local buffer, new one must be obtained this.size = localBuf.length; this.lastAddress = 0; - this.MBRsize = mbrSize; + this.MBRSize = mbrSize; this.available = calculateBinSize(mbrSize); } @@ -65,7 +64,7 @@ public class HexInputStream extends FilterInputStream { this.localPos = LINE_LENGTH; // we are at the end of the local buffer, new one must be obtained this.size = localBuf.length; this.lastAddress = 0; - this.MBRsize = mbrSize; + this.MBRSize = mbrSize; this.available = calculateBinSize(mbrSize); } @@ -77,7 +76,7 @@ public class HexInputStream extends FilterInputStream { int b, lineSize, offset, type; int lastBaseAddress = 0; // last Base Address, default 0 - int lastAddress = 0; + int lastAddress; try { b = in.read(); while (true) { @@ -214,7 +213,7 @@ public class HexInputStream extends FilterInputStream { final InputStream in = this.in; // temporary value - int b = 0; + int b; int lineSize, type, offset; do { @@ -249,7 +248,7 @@ public class HexInputStream extends FilterInputStream { switch (type) { case 0x00: // data type - if (lastAddress + offset < MBRsize) { // skip MBR + if (lastAddress + offset < MBRSize) { // skip MBR type = -1; // some other than 0 pos += in.skip(lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */); } diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/ZipHexInputStream.java b/dfu/src/main/java/no/nordicsemi/android/dfu/ZipHexInputStream.java index 2a85336..ad2d642 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/ZipHexInputStream.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/ZipHexInputStream.java @@ -43,11 +43,10 @@ public class ZipHexInputStream extends ZipInputStream { * * @param stream * the Zip Input Stream + * @param mbrSize + * The size of the MRB segment (Master Boot Record) on the device. The parser will cut data from addresses below that number from all HEX files. * @param types - * files to read - * @param trim - * if true the bin data will be trimmed. All data from addresses < 0x1000 will be skipped. In the Soft Device 7.0.0 it's MBR space and this HEX fragment should not be - * transmitted. However, other DFU implementations (f.e. without Soft Device) may require uploading the whole file. + * File types that are to be read from the ZIP. Use {@link DfuBaseService#TYPE_APPLICATION} etc. * @throws java.io.IOException */ public ZipHexInputStream(final InputStream stream, final int mbrSize, final int types) throws IOException { @@ -127,7 +126,7 @@ public class ZipHexInputStream extends ZipInputStream { currentSource = source; } else if (systemInit) { systemInitBytes = source; - } else if (applicationInit) { + } else { // if (applicationInit) - always true applicationInitBytes = source; } } @@ -220,7 +219,7 @@ public class ZipHexInputStream extends ZipInputStream { * @return the new source, the same as {@link #currentSource} */ private byte[] startNextFile() { - byte[] ret = null; + byte[] ret; if (currentSource == softDeviceBytes && bootloaderBytes != null) { ret = currentSource = bootloaderBytes; } else if (currentSource != applicationBytes && applicationBytes != null) {