Skip to content

Commit a26416b

Browse files
authored
Merge pull request #7 from martinwork/from300
From300
2 parents 9f76625 + 84d5370 commit a26416b

File tree

4 files changed

+417
-109
lines changed

4 files changed

+417
-109
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ android {
2222

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

2929

src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:versionCode="51"
3-
android:versionName="3.0.1" >
2+
android:versionCode="52"
3+
android:versionName="3.0.2" >
44

55
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
66
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>

src/main/java/org/microbit/android/partialflashing/HexUtils.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,66 @@ public int searchForDataRegEx(String search) throws IOException {
124124
// Return -1 if no match
125125
return -1;
126126
}
127-
127+
128+
/*
129+
* A function to search for an address in a hex file
130+
* @param search the address to search for
131+
* @return the index of the address. -1 if not found.
132+
*/
133+
public int searchForAddress( long address) throws IOException {
134+
long lastBaseAddr = 0;
135+
String data;
136+
// Iterate through
137+
ListIterator i = hexLines.listIterator();
138+
while ( i.hasNext()) {
139+
// Have to call nextIndex() before next()
140+
int index = i.nextIndex();
141+
String line = i.next().toString();
142+
143+
switch (getRecordType(line)) {
144+
case 2: { // Extended Segment Address
145+
data = getRecordData(line);
146+
if ( data.length() != 4) {
147+
return -1;
148+
}
149+
int hi = Integer.parseInt( data.substring(0, 1), 16);
150+
int lo = Integer.parseInt( data.substring(1), 16);
151+
lastBaseAddr = (long) hi * (long) 0x1000 + (long) lo * (long) 0x10;
152+
if ( lastBaseAddr > address) {
153+
return -1;
154+
}
155+
break;
156+
}
157+
case 4: {
158+
data = getRecordData(line);
159+
if ( data.length() != 4) {
160+
return -1;
161+
}
162+
lastBaseAddr = Integer.parseInt( data, 16);
163+
lastBaseAddr *= (long) 0x10000;
164+
if ( lastBaseAddr > address) {
165+
return -1;
166+
}
167+
break;
168+
}
169+
case 0:
170+
case 0x0D: {
171+
if ( address - lastBaseAddr < 0x10000) {
172+
long a = lastBaseAddr + getRecordAddress(line);
173+
int n = getRecordDataLength( line) / 2; // bytes
174+
if ( a <= address && a + n > address) {
175+
return index;
176+
}
177+
}
178+
break;
179+
}
180+
}
181+
}
182+
183+
// Return -1 if no match
184+
return -1;
185+
}
186+
128187
/*
129188
* Returns data from an index
130189
* @param index
@@ -267,6 +326,5 @@ public static byte[] recordToByteArray(String hexString, int offset, int packetN
267326

268327
return data;
269328
}
270-
271329
}
272330

0 commit comments

Comments
 (0)