Skip to content

Commit 3b167d4

Browse files
Merge pull request #11 from microbit-foundation/from300
Merge changes through to 3.0.7 to master Recent releases through 3.0.7 have been made from the from300 branch but there's no change on master that's not on this branch so this merges back cleanly. See notes on microbit-foundation/microbit-android#49
2 parents 7baaa07 + e8a21e1 commit 3b167d4

File tree

5 files changed

+1221
-506
lines changed

5 files changed

+1221
-506
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ lint/tmp/
8787
# Android Profiling
8888
*.hprof
8989

90+
# OS-specific files
91+
.DS_Store
92+
.DS_Store?
93+
._*
94+
.Spotlight-V100
95+
.Trashes
96+
ehthumbs.db
97+
Thumbs.db

build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 29
4+
compileSdk 34
55

66
defaultConfig {
77
minSdkVersion 19
8-
targetSdkVersion 29
8+
targetSdk 33
99
}
1010

1111
buildTypes {
@@ -14,12 +14,16 @@ android {
1414
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
1515
}
1616
}
17+
namespace 'org.microbit.partialflashing'
18+
lint {
19+
abortOnError false
20+
}
1721
}
1822

1923
dependencies {
2024
implementation fileTree(dir: 'libs', include: ['*.jar'])
21-
implementation 'com.android.support:support-annotations:+'
22-
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'
2327
}
2428

2529

src/main/AndroidManifest.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="org.microbit.partialflashing"
3-
android:versionCode="1"
4-
android:versionName="1.1" >
2+
android:versionCode="57"
3+
android:versionName="3.0.7" >
54

6-
<uses-permission android:name="android.permission.BLUETOOTH" />
7-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5+
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
6+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
7+
8+
<!-- API 31 Needed only if your app communicates with already-paired Bluetooth devices. -->
9+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
810
</manifest>

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)