Skip to content

From300 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:+'
implementation "com.android.support:appcompat-v7:23.0.0"
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}


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="51"
android:versionName="3.0.1" >
android:versionCode="52"
android:versionName="3.0.2" >

<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
Expand Down
62 changes: 60 additions & 2 deletions src/main/java/org/microbit/android/partialflashing/HexUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,66 @@ public int searchForDataRegEx(String search) throws IOException {
// Return -1 if no match
return -1;
}


/*
* A function to search for an address in a hex file
* @param search the address to search for
* @return the index of the address. -1 if not found.
*/
public int searchForAddress( long address) throws IOException {
long lastBaseAddr = 0;
String data;
// Iterate through
ListIterator i = hexLines.listIterator();
while ( i.hasNext()) {
// Have to call nextIndex() before next()
int index = i.nextIndex();
String line = i.next().toString();

switch (getRecordType(line)) {
case 2: { // Extended Segment Address
data = getRecordData(line);
if ( data.length() != 4) {
return -1;
}
int hi = Integer.parseInt( data.substring(0, 1), 16);
int lo = Integer.parseInt( data.substring(1), 16);
lastBaseAddr = (long) hi * (long) 0x1000 + (long) lo * (long) 0x10;
if ( lastBaseAddr > address) {
return -1;
}
break;
}
case 4: {
data = getRecordData(line);
if ( data.length() != 4) {
return -1;
}
lastBaseAddr = Integer.parseInt( data, 16);
lastBaseAddr *= (long) 0x10000;
if ( lastBaseAddr > address) {
return -1;
}
break;
}
case 0:
case 0x0D: {
if ( address - lastBaseAddr < 0x10000) {
long a = lastBaseAddr + getRecordAddress(line);
int n = getRecordDataLength( line) / 2; // bytes
if ( a <= address && a + n > address) {
return index;
}
}
break;
}
}
}

// Return -1 if no match
return -1;
}

/*
* Returns data from an index
* @param index
Expand Down Expand Up @@ -267,6 +326,5 @@ public static byte[] recordToByteArray(String hexString, int offset, int packetN

return data;
}

}

Loading