Skip to content

Commit 3f15257

Browse files
committed
bail to Nordic DFU
1 parent 4a9d74d commit 3f15257

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public abstract class PartialFlashingBaseService extends IntentService {
9292
// Regions
9393
String[] regions = {"SoftDevice", "DAL", "MakeCode"};
9494

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+
95100
public final static String ACTION_GATT_CONNECTED =
96101
"com.example.bluetooth.le.ACTION_GATT_CONNECTED";
97102
public final static String ACTION_GATT_DISCONNECTED =
@@ -289,8 +294,7 @@ public Boolean writePartialFlash(byte data[]){
289294

290295
}
291296

292-
293-
public Boolean attemptPartialFlash(String filePath) {
297+
public int attemptPartialFlash(String filePath) {
294298
Log.v(TAG, "Flashing: " + filePath);
295299
long startTime = SystemClock.elapsedRealtime();
296300

@@ -312,7 +316,7 @@ public Boolean attemptPartialFlash(String filePath) {
312316
String hashes = hex.getDataFromIndex(magicIndex + 1);
313317
if(!hashes.substring(0, 16).equals(dalHash)) {
314318
Log.v(TAG, hashes.substring(0, 16) + " " + (dalHash));
315-
return false;
319+
return PF_ATTEMPT_DFU;
316320
}
317321

318322
numOfLines = hex.numOfLines() - magicIndex;
@@ -326,7 +330,7 @@ public Boolean attemptPartialFlash(String filePath) {
326330
int lineCount = 0;
327331
while(true){
328332
// Timeout if total is > 60 seconds
329-
if(SystemClock.elapsedRealtime() - startTime > 60000) return false;
333+
if(SystemClock.elapsedRealtime() - startTime > 60000) return PF_FAILED;
330334

331335
// Get next data to write
332336
hexData = hex.getDataFromIndex(magicIndex + lineCount);
@@ -371,7 +375,7 @@ public Boolean attemptPartialFlash(String filePath) {
371375
}
372376

373377
// Timeout if longer than 5 seconds
374-
if((SystemClock.elapsedRealtime() - timeout) > 5000) return false;
378+
if((SystemClock.elapsedRealtime() - timeout) > 5000) return PF_FAILED;
375379
}
376380

377381
packetState = PACKET_STATE_WAITING;
@@ -421,7 +425,7 @@ public Boolean attemptPartialFlash(String filePath) {
421425
}
422426

423427

424-
return true;
428+
return PF_SUCCESS;
425429
}
426430

427431
/*
@@ -535,7 +539,8 @@ protected void onHandleIntent(@Nullable Intent intent) {
535539
Log.v(TAG, "/Initialise");
536540
readMemoryMap();
537541
// 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)
539544
{
540545
Log.v(TAG, "Partial Flashing not possible");
541546

@@ -567,7 +572,12 @@ protected void onHandleIntent(@Nullable Intent intent) {
567572
final Intent broadcast = new Intent(BROADCAST_PF_FAILED);
568573

569574
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);
570579
}
580+
571581
Log.v(TAG, "onHandleIntent End");
572582
}
573583

0 commit comments

Comments
 (0)