Skip to content

Commit

Permalink
Merge pull request #10 from martinwork/from300
Browse files Browse the repository at this point in the history
Fix for files not a multiple of 64 bytes - Version 3.0.7 (57)
  • Loading branch information
martinwork authored Apr 3, 2024
2 parents 384e082 + 6af8f0f commit e8a21e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="54"
android:versionName="3.0.4" >
android:versionCode="57"
android:versionName="3.0.7" >

<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ private int attemptPartialFlash(String filePath) {

// TODO - check size of code in file matches micro:bit

boolean endOfFile = false;
long startTime = SystemClock.elapsedRealtime();
while (true) {
// Timeout if total is > 30 seconds
Expand All @@ -720,19 +721,30 @@ private int attemptPartialFlash(String filePath) {
}

// Check if EOF
if(hex.getRecordTypeFromIndex( dataPos.line + lineCount) != 0) {
break;
if ( endOfFile || hex.getRecordTypeFromIndex( dataPos.line + lineCount) != 0) {
if ( count == 0) {
break;
}
endOfFile = true;
}

addrLo = hex.getRecordAddressFromIndex( dataPos.line + lineCount);
addrHi = hex.getSegmentAddress(dataPos.line + lineCount);
addr = (long) addrLo + (long) addrHi * 256 * 256;

hexData = hex.getDataFromIndex( dataPos.line + lineCount);
if ( part + 32 > hexData.length()) {
partData = hexData.substring( part);
if ( endOfFile) {
// complete the batch of 4 packets with FF
char[] c32 = new char[32];
Arrays.fill( c32, 'F');
hexData = new String( c32);
partData = hexData;
} else {
partData = hexData.substring(part, part + 32);
addrLo = hex.getRecordAddressFromIndex(dataPos.line + lineCount);
addrHi = hex.getSegmentAddress(dataPos.line + lineCount);
addr = (long) addrLo + (long) addrHi * 256 * 256;

hexData = hex.getDataFromIndex(dataPos.line + lineCount);
if (part + 32 > hexData.length()) {
partData = hexData.substring(part);
} else {
partData = hexData.substring(part, part + 32);
}
}

int offsetToSend = 0;
Expand All @@ -748,7 +760,7 @@ private int attemptPartialFlash(String filePath) {
offsetToSend = addr0Hi;
}

logi( packetNum + " " + count + " addr0 " + addr0 + " offsetToSend " + offsetToSend + " line " + lineCount + " addr " + addr + " part " + part + " data " + partData);
logi( packetNum + " " + count + " addr0 " + addr0 + " offsetToSend " + offsetToSend + " line " + lineCount + " addr " + addr + " part " + part + " data " + partData + " endOfFile " + endOfFile);

// recordToByteArray() builds a PF command block with the data
byte[] chunk = HexUtils.recordToByteArray(partData, offsetToSend, packetNum);
Expand Down Expand Up @@ -792,12 +804,15 @@ private int attemptPartialFlash(String filePath) {
if(packetState == PACKET_STATE_RETRANSMIT) {
lineCount = line0;
part = part0;
endOfFile = false;
} else {
// Next part
part = part + partData.length();
if ( part >= hexData.length()) {
part = 0;
lineCount = lineCount + 1;
if ( !endOfFile) {
// Next part
part = part + partData.length();
if (part >= hexData.length()) {
part = 0;
lineCount = lineCount + 1;
}
}
}

Expand Down

0 comments on commit e8a21e1

Please sign in to comment.