@@ -92,6 +92,11 @@ public abstract class PartialFlashingBaseService extends IntentService {
92
92
// Regions
93
93
String [] regions = {"SoftDevice" , "DAL" , "MakeCode" };
94
94
95
+ // Partial Flashing Return Vals
96
+ private static final int PF_SUCCESS = 0x0 ;
97
+ private static final int PF_ATTEMPT_DFU = 0x1 ;
98
+ private static final int PF_FAILED = 0x2 ;
99
+
95
100
public final static String ACTION_GATT_CONNECTED =
96
101
"com.example.bluetooth.le.ACTION_GATT_CONNECTED" ;
97
102
public final static String ACTION_GATT_DISCONNECTED =
@@ -289,8 +294,7 @@ public Boolean writePartialFlash(byte data[]){
289
294
290
295
}
291
296
292
-
293
- public Boolean attemptPartialFlash (String filePath ) {
297
+ public int attemptPartialFlash (String filePath ) {
294
298
Log .v (TAG , "Flashing: " + filePath );
295
299
long startTime = SystemClock .elapsedRealtime ();
296
300
@@ -312,7 +316,7 @@ public Boolean attemptPartialFlash(String filePath) {
312
316
String hashes = hex .getDataFromIndex (magicIndex + 1 );
313
317
if (!hashes .substring (0 , 16 ).equals (dalHash )) {
314
318
Log .v (TAG , hashes .substring (0 , 16 ) + " " + (dalHash ));
315
- return false ;
319
+ return PF_ATTEMPT_DFU ;
316
320
}
317
321
318
322
numOfLines = hex .numOfLines () - magicIndex ;
@@ -326,7 +330,7 @@ public Boolean attemptPartialFlash(String filePath) {
326
330
int lineCount = 0 ;
327
331
while (true ){
328
332
// Timeout if total is > 60 seconds
329
- if (SystemClock .elapsedRealtime () - startTime > 60000 ) return false ;
333
+ if (SystemClock .elapsedRealtime () - startTime > 60000 ) return PF_FAILED ;
330
334
331
335
// Get next data to write
332
336
hexData = hex .getDataFromIndex (magicIndex + lineCount );
@@ -371,7 +375,7 @@ public Boolean attemptPartialFlash(String filePath) {
371
375
}
372
376
373
377
// Timeout if longer than 5 seconds
374
- if ((SystemClock .elapsedRealtime () - timeout ) > 5000 ) return false ;
378
+ if ((SystemClock .elapsedRealtime () - timeout ) > 5000 ) return PF_FAILED ;
375
379
}
376
380
377
381
packetState = PACKET_STATE_WAITING ;
@@ -421,7 +425,7 @@ public Boolean attemptPartialFlash(String filePath) {
421
425
}
422
426
423
427
424
- return true ;
428
+ return PF_SUCCESS ;
425
429
}
426
430
427
431
/*
@@ -535,7 +539,8 @@ protected void onHandleIntent(@Nullable Intent intent) {
535
539
Log .v (TAG , "/Initialise" );
536
540
readMemoryMap ();
537
541
// If fails attempt full flash
538
- if (!attemptPartialFlash (filePath ) || Service == null )
542
+ int pf_result = attemptPartialFlash (filePath );
543
+ if ((pf_result == PF_ATTEMPT_DFU ) || Service == null )
539
544
{
540
545
Log .v (TAG , "Partial Flashing not possible" );
541
546
@@ -567,7 +572,12 @@ protected void onHandleIntent(@Nullable Intent intent) {
567
572
final Intent broadcast = new Intent (BROADCAST_PF_FAILED );
568
573
569
574
LocalBroadcastManager .getInstance (this ).sendBroadcast (broadcast );
575
+ } else if (pf_result == PF_FAILED ) {
576
+ // Partial flashing started but failed. Need to PF or USB flash to fix
577
+ final Intent broadcast = new Intent (BROADCAST_PF_FAILED );
578
+ startActivity (broadcast );
570
579
}
580
+
571
581
Log .v (TAG , "onHandleIntent End" );
572
582
}
573
583
0 commit comments