1
- package org .micrbit .android .partialflashing ;
1
+ package org .microbit .android .partialflashing ;
2
2
3
3
import android .app .Activity ;
4
4
import android .app .IntentService ;
23
23
import android .util .Log ;
24
24
import android .util .TimingLogger ;
25
25
26
- import com .microbitreactnative .MainApplication ;
27
- import com .microbitreactnative .pf .HexUtils ;
26
+ import org .microbit .android .partialflashing .HexUtils ;
28
27
29
28
import java .io .IOException ;
30
29
import java .util .Arrays ;
@@ -42,7 +41,7 @@ public abstract class PartialFlashingBaseService extends IntentService {
42
41
public static final UUID PARTIAL_FLASH_CHARACTERISTIC = UUID .fromString ("e97d3b10-251d-470a-a062-fa1922dfa9a8" );
43
42
public static final UUID PARTIAL_FLASHING_SERVICE = UUID .fromString ("e97dd91d-251d-470a-a062-fa1922dfa9a8" );
44
43
45
- private final static String TAG = PartialFlashService .class .getSimpleName ();
44
+ private final static String TAG = PartialFlashingBaseService .class .getSimpleName ();
46
45
47
46
private BluetoothManager mBluetoothManager ;
48
47
private BluetoothAdapter mBluetoothAdapter ;
@@ -59,9 +58,9 @@ public abstract class PartialFlashingBaseService extends IntentService {
59
58
private static final byte PACKET_STATE_RETRANSMIT = (byte )0xAA ;
60
59
private byte packetState = PACKET_STATE_WAITING ;
61
60
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 ;
65
64
66
65
private static final int STATE_DISCONNECTED = 0 ;
67
66
private static final int STATE_CONNECTING = 1 ;
@@ -131,7 +130,7 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
131
130
if (Service == null ) {
132
131
Log .e (TAG , "service not found!" );
133
132
}
134
- bleStatus = BLE_READY ;
133
+ bluetoothStatus = BLE_READY ;
135
134
136
135
}
137
136
@@ -141,7 +140,7 @@ public void onCharacteristicRead(BluetoothGatt gatt,
141
140
BluetoothGattCharacteristic characteristic ,
142
141
int status ) {
143
142
if (status == BluetoothGatt .GATT_SUCCESS ) {
144
- bleStatus = BLE_READY ;
143
+ bluetoothStatus = BLE_READY ;
145
144
}
146
145
147
146
}
@@ -153,7 +152,7 @@ public void onCharacteristicWrite(BluetoothGatt gatt,
153
152
if (status == BluetoothGatt .GATT_SUCCESS ) {
154
153
// Success
155
154
Log .v (TAG , "GATT status: Success" );
156
- bleStatus = BLE_READY ;
155
+ bluetoothStatus = BLE_READY ;
157
156
} else {
158
157
// TODO Attempt to resend?
159
158
Log .v (TAG , "GATT status:" + Integer .toString (status ));
@@ -200,15 +199,15 @@ public void onDescriptorWrite (BluetoothGatt gatt,
200
199
int status ){
201
200
if (status == BluetoothGatt .GATT_SUCCESS ) {
202
201
Log .v (TAG , "Descriptor success" );
203
- bleStatus = BLE_READY ;
202
+ bluetoothStatus = BLE_READY ;
204
203
}
205
204
Log .v (TAG , "GATT: " + gatt .toString () + ", Desc: " + descriptor .toString () + ", Status: " + status );
206
205
}
207
206
208
207
};
209
208
210
- public void PartialFlashingBaseService () {
211
- super (TAG );
209
+ public PartialFlashingBaseService () {
210
+ super (TAG );
212
211
}
213
212
214
213
// Write to BLE Flash Characteristic
@@ -401,7 +400,7 @@ private boolean initialize(String deviceId) {
401
400
return false ;
402
401
}
403
402
404
- while (!bleStatus );
403
+ while (!bluetoothStatus );
405
404
// Get Characteristic
406
405
partialFlashCharacteristic = Service .getCharacteristic (PARTIAL_FLASH_CHARACTERISTIC );
407
406
@@ -416,11 +415,11 @@ private boolean initialize(String deviceId) {
416
415
BluetoothGattDescriptor descriptor = partialFlashCharacteristic .getDescriptor (CLIENT_CHARACTERISTIC_CONFIG );
417
416
descriptor .setValue (BluetoothGattDescriptor .ENABLE_NOTIFICATION_VALUE );
418
417
419
- if (bleStatus ) {
420
- bleStatus = BLE_WAITING ;
418
+ if (bluetoothStatus ) {
419
+ bluetoothStatus = BLE_WAITING ;
421
420
mBluetoothGatt .writeDescriptor (descriptor );
422
421
}
423
- while (!bleStatus );
422
+ while (!bluetoothStatus );
424
423
425
424
return true ;
426
425
}
@@ -456,11 +455,11 @@ private Boolean readMemoryMap() {
456
455
// Request Region
457
456
byte [] payload = {REGION_INFO_COMMAND , (byte )i };
458
457
partialFlashCharacteristic .setValue (payload );
459
- bleStatus = BLE_WAITING ;
458
+ bluetoothStatus = BLE_WAITING ;
460
459
notificationReceived = false ;
461
460
status = mBluetoothGatt .writeCharacteristic (partialFlashCharacteristic );
462
461
Log .v (TAG , "Request Region " + i );
463
- while (!bleStatus );
462
+ while (!bluetoothStatus );
464
463
}
465
464
466
465
@@ -491,5 +490,7 @@ public void onReceive(Context context, final Intent intent) {
491
490
Log .v (TAG , "Received Broadcast: " + intent .toString ());
492
491
}
493
492
};
493
+
494
+ protected abstract Class <? extends Activity > getNotificationTarget ();
494
495
}
495
496
0 commit comments