From 18bdda9a377cae97648558254efd11d03447be3d Mon Sep 17 00:00:00 2001 From: Dan Walkes Date: Thu, 2 Feb 2017 22:34:00 -0700 Subject: [PATCH] Mark position after execute for CRC retry I've noticed when using in a noisy environment if I ever see a CRC error all of the subsequent retries fail and the download fails. I noticed if I print the CRC values expected they change on each retry attempt. This seems wrong, since I believe the intent is just to re-send the last chunk. I suspect there's a mark() call missing in the success transfer case, and the position of the last successful create->execute transfer should be saved. The next retry transfer should only reset to this mark position and not the beginning of the file. If I add a call to mFirwmareStream.mark in the CRC success case after writeExecute() completes I am able to successfully recover from CRC errors. --- .../main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java b/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java index 43f49e6..cf27c69 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java @@ -514,13 +514,16 @@ import no.nordicsemi.android.error.SecureDfuError; // Increment iterator currentChunk++; attempt = 1; + mFirmwareStream.mark(0); } else { if (attempt < MAX_ATTEMPTS) { attempt++; - logi("CRC does not match! Retrying...(" + attempt + "/" + MAX_ATTEMPTS + ")"); + logi(String.format(Locale.US,"CRC does not match! Expected %08X Retrying...(%d/%d)",crc,attempt,MAX_ATTEMPTS)); mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_WARNING, "CRC does not match! Retrying...(" + attempt + "/" + MAX_ATTEMPTS + ")"); try { mFirmwareStream.reset(); + final int crcAfterReset = (int) (((ArchiveInputStream) mFirmwareStream).getCrc32() & 0xFFFFFFFFL); + logi(String.format(Locale.US,"CRC after reset is %08X",crcAfterReset)); mProgressInfo.setBytesSent(checksum.offset - info.maxSize); } catch (final IOException e) { loge("Error while resetting the firmware stream", e); @@ -528,7 +531,7 @@ import no.nordicsemi.android.error.SecureDfuError; return; } } else { - loge("CRC does not match!"); + loge(String.format("CRC does not match! Expected %08X",crc)); mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_ERROR, "CRC does not match!"); mService.terminateConnection(gatt, DfuBaseService.ERROR_CRC_ERROR); return;