Skip to content

Commit bb77b46

Browse files
committed
Builds
1 parent 3e8c7c0 commit bb77b46

File tree

5 files changed

+74
-33
lines changed

5 files changed

+74
-33
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ android {
1919

2020
dependencies {
2121
compile fileTree(dir: 'libs', include: ['*.jar'])
22+
compile 'com.android.support:support-annotations:+'
23+
compile 'com.android.support:support-v4:19.0.+'
2224
}
2325

2426

local.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## This file is automatically generated by Android Studio.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must *NOT* be checked into Version Control Systems,
5+
# as it contains information specific to your local configuration.
6+
#
7+
# Location of the SDK. This is only used by Gradle.
8+
# For customization when using a Version Control System, please read the
9+
# header note.
10+
#Mon Apr 08 16:37:30 BST 2019
11+
sdk.dir=/Users/admin/Library/Android/sdk

pfLibrary.iml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
12+
</configuration>
13+
</facet>
14+
</component>
15+
<component name="NewModuleRootManager" inherit-compiler-output="true">
16+
<exclude-output />
17+
<content url="file://$MODULE_DIR$" />
18+
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
19+
<orderEntry type="sourceFolder" forTests="false" />
20+
</component>
21+
</module>

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.microbit.android.hexutils
1+
package org.microbit.android.partialflashing;
22

33
import android.util.Log;
44

@@ -10,6 +10,12 @@
1010
import java.io.InputStreamReader;
1111
import java.io.InterruptedIOException;
1212

13+
import java.util.*;
14+
import java.util.List;
15+
import java.util.ArrayList;
16+
import java.util.Iterator;
17+
18+
1319
/**
1420
* Created by Sam Kent on 01/11/2017.
1521
*
@@ -50,8 +56,12 @@ public class HexUtils {
5056
public void HexUtils(String filePath){
5157
// Hex Utils initialization
5258
// Open File
53-
if(!openHexFile(filePath)){
54-
status = INVALID_FILE;
59+
try {
60+
if(!openHexFile(filePath)){
61+
status = INVALID_FILE;
62+
}
63+
} catch(Exception e) {
64+
Log.e(TAG, "Error opening file: " + e);
5565
}
5666
}
5767

@@ -72,8 +82,8 @@ public Boolean openHexFile(String filePath) throws IOException {
7282

7383
// Create reader for hex file
7484
reader = new BufferedReader(new InputStreamReader(fis));
75-
76-
while((String line = reader.readLine()) != null) {
85+
String line;
86+
while((line = reader.readLine()) != null) {
7787
hexLines.add(line);
7888
}
7989
reader.close();
@@ -82,13 +92,13 @@ public Boolean openHexFile(String filePath) throws IOException {
8292

8393
public int searchForData(String search) throws IOException {
8494
// Iterate through
85-
Iterator i = hexLines.iterator();
95+
ListIterator i = hexLines.listIterator();
8696
while (i.hasNext()) {
8797
// Have to call nextIndex() before next()
8898
int index = i.nextIndex();
8999

90100
// Return index if successful
91-
if(i.next().contains(search)){ return index; }
101+
if(i.next().toString().contains(search)){ return index; }
92102
}
93103

94104
// Return -1 if no match
@@ -100,11 +110,11 @@ public String getDataFromIndex(int index) throws IOException {
100110
}
101111

102112
public int getRecordTypeFromIndex(int index) throws IOException {
103-
return getRecordType(hexLines.get(index);
113+
return getRecordType(hexLines.get(index));
104114
}
105115

106116
public int getRecordAddressFromIndex(int index) throws IOException {
107-
return getRecordOffset(hexLines.get(index));
117+
return getRecordAddress(hexLines.get(index));
108118
}
109119

110120
public int getSegmentAddress(int index) throws IOException {
@@ -251,7 +261,7 @@ public String getProgramHash(){
251261
Find HEX Meta Data
252262
*/
253263
public Boolean findHexMetaData(String filePath) throws IOException {
254-
264+
return false;
255265
}
256266

257267
/*
@@ -267,10 +277,6 @@ public Integer getSectionAddress(){
267277
public int getRecordOffset(){
268278
return currentRecordOffset;
269279
}
270-
271-
public int getRecordOffset(){
272-
return currentRecordOffset;
273-
}
274280

275281
/*
276282
Set mark to beginning of page

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.micrbit.android.partialflashing;
1+
package org.microbit.android.partialflashing;
22

33
import android.app.Activity;
44
import android.app.IntentService;
@@ -23,8 +23,7 @@
2323
import android.util.Log;
2424
import android.util.TimingLogger;
2525

26-
import com.microbitreactnative.MainApplication;
27-
import com.microbitreactnative.pf.HexUtils;
26+
import org.microbit.android.partialflashing.HexUtils;
2827

2928
import java.io.IOException;
3029
import java.util.Arrays;
@@ -42,7 +41,7 @@ public abstract class PartialFlashingBaseService extends IntentService {
4241
public static final UUID PARTIAL_FLASH_CHARACTERISTIC = UUID.fromString("e97d3b10-251d-470a-a062-fa1922dfa9a8");
4342
public static final UUID PARTIAL_FLASHING_SERVICE = UUID.fromString("e97dd91d-251d-470a-a062-fa1922dfa9a8");
4443

45-
private final static String TAG = PartialFlashService.class.getSimpleName();
44+
private final static String TAG = PartialFlashingBaseService.class.getSimpleName();
4645

4746
private BluetoothManager mBluetoothManager;
4847
private BluetoothAdapter mBluetoothAdapter;
@@ -59,9 +58,9 @@ public abstract class PartialFlashingBaseService extends IntentService {
5958
private static final byte PACKET_STATE_RETRANSMIT = (byte)0xAA;
6059
private byte packetState = PACKET_STATE_WAITING;
6160

62-
private static final byte BLE_WAITING = 0;
63-
private static final byte BLE_READY = 0;
64-
private Boolean bluetoothStatus = BLE_WAITING;
61+
private static final boolean BLE_WAITING = false;
62+
private static final boolean BLE_READY = true;
63+
private boolean bluetoothStatus = BLE_WAITING;
6564

6665
private static final int STATE_DISCONNECTED = 0;
6766
private static final int STATE_CONNECTING = 1;
@@ -131,7 +130,7 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
131130
if (Service == null) {
132131
Log.e(TAG, "service not found!");
133132
}
134-
bleStatus = BLE_READY;
133+
bluetoothStatus = BLE_READY;
135134

136135
}
137136

@@ -141,7 +140,7 @@ public void onCharacteristicRead(BluetoothGatt gatt,
141140
BluetoothGattCharacteristic characteristic,
142141
int status) {
143142
if (status == BluetoothGatt.GATT_SUCCESS) {
144-
bleStatus = BLE_READY;
143+
bluetoothStatus = BLE_READY;
145144
}
146145

147146
}
@@ -153,7 +152,7 @@ public void onCharacteristicWrite(BluetoothGatt gatt,
153152
if(status == BluetoothGatt.GATT_SUCCESS) {
154153
// Success
155154
Log.v(TAG, "GATT status: Success");
156-
bleStatus = BLE_READY;
155+
bluetoothStatus = BLE_READY;
157156
} else {
158157
// TODO Attempt to resend?
159158
Log.v(TAG, "GATT status:" + Integer.toString(status));
@@ -200,15 +199,15 @@ public void onDescriptorWrite (BluetoothGatt gatt,
200199
int status){
201200
if(status == BluetoothGatt.GATT_SUCCESS) {
202201
Log.v(TAG, "Descriptor success");
203-
bleStatus = BLE_READY;
202+
bluetoothStatus = BLE_READY;
204203
}
205204
Log.v(TAG, "GATT: " + gatt.toString() + ", Desc: " + descriptor.toString() + ", Status: " + status);
206205
}
207206

208207
};
209208

210-
public void PartialFlashingBaseService() {
211-
super(TAG);
209+
public PartialFlashingBaseService() {
210+
super(TAG);
212211
}
213212

214213
// Write to BLE Flash Characteristic
@@ -401,7 +400,7 @@ private boolean initialize(String deviceId) {
401400
return false;
402401
}
403402

404-
while(!bleStatus);
403+
while(!bluetoothStatus);
405404
// Get Characteristic
406405
partialFlashCharacteristic = Service.getCharacteristic(PARTIAL_FLASH_CHARACTERISTIC);
407406

@@ -416,11 +415,11 @@ private boolean initialize(String deviceId) {
416415
BluetoothGattDescriptor descriptor = partialFlashCharacteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
417416
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
418417

419-
if(bleStatus) {
420-
bleStatus = BLE_WAITING;
418+
if(bluetoothStatus) {
419+
bluetoothStatus = BLE_WAITING;
421420
mBluetoothGatt.writeDescriptor(descriptor);
422421
}
423-
while(!bleStatus);
422+
while(!bluetoothStatus);
424423

425424
return true;
426425
}
@@ -456,11 +455,11 @@ private Boolean readMemoryMap() {
456455
// Request Region
457456
byte[] payload = {REGION_INFO_COMMAND, (byte)i};
458457
partialFlashCharacteristic.setValue(payload);
459-
bleStatus = BLE_WAITING;
458+
bluetoothStatus = BLE_WAITING;
460459
notificationReceived = false;
461460
status = mBluetoothGatt.writeCharacteristic(partialFlashCharacteristic);
462461
Log.v(TAG, "Request Region " + i);
463-
while(!bleStatus);
462+
while(!bluetoothStatus);
464463
}
465464

466465

@@ -491,5 +490,7 @@ public void onReceive(Context context, final Intent intent) {
491490
Log.v(TAG, "Received Broadcast: " + intent.toString());
492491
}
493492
};
493+
494+
protected abstract Class<? extends Activity> getNotificationTarget();
494495
}
495496

0 commit comments

Comments
 (0)