@@ -228,6 +228,8 @@ public PartialFlashingBaseService() {
228
228
}
229
229
230
230
public static final String BROADCAST_PROGRESS = "org.microbit.android.partialflashing.broadcast.BROADCAST_PROGRESS" ;
231
+ public static final String BROADCAST_START = "org.microbit.android.partialflashing.broadcast.BROADCAST_START" ;
232
+ public static final String BROADCAST_COMPLETE = "org.microbit.android.partialflashing.broadcast.BROADCAST_COMPLETE" ;
231
233
public static final String EXTRA_PROGRESS = "org.microbit.android.partialflashing.extra.EXTRA_PROGRESS" ;
232
234
233
235
private void sendProgressBroadcast (final int progress ) {
@@ -239,6 +241,24 @@ private void sendProgressBroadcast(final int progress) {
239
241
240
242
LocalBroadcastManager .getInstance (this ).sendBroadcast (broadcast );
241
243
}
244
+
245
+ private void sendProgressBroadcastStart () {
246
+
247
+ Log .v (TAG , "Sending progress broadcast start" );
248
+
249
+ final Intent broadcast = new Intent (BROADCAST_START );
250
+
251
+ LocalBroadcastManager .getInstance (this ).sendBroadcast (broadcast );
252
+ }
253
+
254
+ private void sendProgressBroadcastComplete () {
255
+
256
+ Log .v (TAG , "Sending progress broadcast complete" );
257
+
258
+ final Intent broadcast = new Intent (BROADCAST_COMPLETE );
259
+
260
+ LocalBroadcastManager .getInstance (this ).sendBroadcast (broadcast );
261
+ }
242
262
243
263
// Write to BLE Flash Characteristic
244
264
public Boolean writePartialFlash (byte data []){
@@ -267,6 +287,12 @@ public Boolean attemptPartialFlash(String filePath) {
267
287
if (magicIndex > -1 ) {
268
288
269
289
Log .v (TAG , "Found PXT_MAGIC" );
290
+
291
+ // Find DAL hash
292
+ String hashes = hex .getDataFromIndex (magicIndex + 1 );
293
+ if !(hashes .substring (0 , 8 ).equals (dalHash )) {
294
+ return false ;
295
+ }
270
296
271
297
numOfLines = hex .numOfLines () - magicIndex ;
272
298
Log .v (TAG , "Total lines: " + numOfLines );
@@ -446,6 +472,8 @@ private boolean initialize(String deviceId) {
446
472
447
473
return true ;
448
474
}
475
+
476
+ public static final String BROADCAST_PF_FAILED = "org.microbit.android.partialflashing.broadcast.BROADCAST_PF_FAILED" ;
449
477
450
478
@ Override
451
479
protected void onHandleIntent (@ Nullable Intent intent ) {
@@ -462,9 +490,11 @@ protected void onHandleIntent(@Nullable Intent intent) {
462
490
if (!attemptPartialFlash (filePath ))
463
491
{
464
492
Log .v (TAG , "Partial Flashing not possible" );
465
- }
466
493
494
+ final Intent broadcast = new Intent (BROADCAST_PF_FAILED );
467
495
496
+ LocalBroadcastManager .getInstance (this ).sendBroadcast (broadcast );
497
+ }
468
498
}
469
499
470
500
/*
0 commit comments