Skip to content

Commit

Permalink
Initial delay in Secure DFU: eliminate bytes lost error
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Nov 13, 2019
1 parent 7f085dc commit 9c6885b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ private void sendFirmware(final BluetoothGatt gatt) throws RemoteDfuException,
mProgressInfo.setBytesSent(0);
}

final long startTime = SystemClock.elapsedRealtime();
final long initialDelay = 300; // ms
final long startTime = SystemClock.elapsedRealtime() - initialDelay;

if (info.offset < mImageSizeInBytes) {
int attempt = 1;
Expand All @@ -592,6 +593,10 @@ private void sendFirmware(final BluetoothGatt gatt) throws RemoteDfuException,
writeCreateRequest(OBJECT_DATA, availableObjectSizeInBytes);
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION,
"Data object (" + (currentChunk + 1) + "/" + chunkCount + ") created");
if (currentChunk == 0) {
// Waiting until the device is ready to receive first data object.
mService.waitFor(initialDelay);
}
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION,
"Uploading firmware...");
} else {
Expand Down Expand Up @@ -633,11 +638,15 @@ private void sendFirmware(final BluetoothGatt gatt) throws RemoteDfuException,
mService.terminateConnection(gatt, DfuBaseService.ERROR_FILE_IO_EXCEPTION);
return;
}
// To decrease the chance of loosing data next time let's set PRN to 1. This will make the update very long, but perhaps it will succeed.
numberOfPacketsBeforeNotification = mPacketsBeforeNotification = 1;
setPacketReceiptNotifications(numberOfPacketsBeforeNotification);
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION,
"Packet Receipt Notif Req (Op Code = 2) sent (Value = " + numberOfPacketsBeforeNotification + ")");
// To decrease the chance of loosing data next time let's set PRN to 1.
// This will make the update very long, but perhaps it will succeed.
final int newPrn = 1;
if (mPacketsBeforeNotification == 0 || mPacketsBeforeNotification > newPrn) {
numberOfPacketsBeforeNotification = mPacketsBeforeNotification = newPrn;
setPacketReceiptNotifications(numberOfPacketsBeforeNotification);
mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION,
"Packet Receipt Notif Req (Op Code = 2) sent (Value = " + newPrn + ")");
}
}

// Calculate the CRC32
Expand Down

0 comments on commit 9c6885b

Please sign in to comment.