From 3dae37d83c6f2c944de863b6b624641f4a766c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Arve=20Fossum?= Date: Thu, 6 Nov 2014 16:16:31 +0100 Subject: [PATCH] Further changes to verification ref #53 and #49 * Add protocol version info to log * Alert when uploadFile fails due to too many attempts * Cease to execute the not implemented method hardwareReset() * Fix comparison of written/received data * Log received/expected data when verification fails * Log successful verification of page --- src/no/group09/stk500_v1/STK500v1.java | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/no/group09/stk500_v1/STK500v1.java b/src/no/group09/stk500_v1/STK500v1.java index bf92083..cb69336 100644 --- a/src/no/group09/stk500_v1/STK500v1.java +++ b/src/no/group09/stk500_v1/STK500v1.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.concurrent.TimeoutException; @@ -302,7 +303,7 @@ public boolean programUsingOptiboot(boolean checkWrittenData, int numberOfBytes) long startTime; long endTime; boolean entered; - logger.logcat("programUsingOptiboot: Initializing programmer", "v"); + logger.logcat("programUsingOptiboot: Initializing programmer; fix-verify rev 2", "v"); // Restart the arduino. // This requires the ComputerSerial library on arduino. @@ -1496,7 +1497,10 @@ private boolean uploadFile(int bytesToLoad, boolean write) { //Run through the entire hex file, ignoring the last line while (hexPosition < hexParser.getDataSize()) { // Give up... - if(uploadFileTries>10) return false; + if(uploadFileTries>10) { + logger.logcat("uploadFile: No more attempts left, failed.", "i"); + return false; + } // Get bytes from hex file byte[] tempArray = hexParser.getHexLine(hexPosition, bytesToLoad); @@ -1516,7 +1520,8 @@ private boolean uploadFile(int bytesToLoad, boolean write) { break; } else { // Trying to reset - if(hardwareReset()) continue; + //hw reset not implemented! + //if(hardwareReset()) continue; if (timeoutOccurred && !recoverySuccessful){ logger.logcat("uploadFile: Unable to load address " + @@ -1550,6 +1555,7 @@ else if (timeoutOccurred) { hexPosition + " / " + hexParser.getDataSize(), "d"); } else { + logger.logcat("uploadFile: Failed writing data.", "d"); success = false; } } @@ -1558,11 +1564,19 @@ else if (timeoutOccurred) { // Check if reading of written data was successful. // Increment counter and read next page + byte[] rdata = readPage(bytesToLoad, useFlash); + if (rdata == null) { + logger.logcat("uploadFile: Error reading page. Retrying...", "d"); + uploadFileTries++; + continue; + } - if(readPage(bytesToLoad, useFlash) == tempArray) { + if(Arrays.equals(rdata, tempArray)) { + success = true; hexPosition+=tempArray.length; - logger.logcat("hexPosition: " + hexPosition + + logger.logcat("uploadFile: Verified received bytes.\n" + + "hexPosition: " + hexPosition + ", hexParser.getDataSize(): " + hexParser.getDataSize(), "d"); // Calculate progress double tempProgress = (double)hexPosition / (double)hexParser.getDataSize(); @@ -1571,7 +1585,11 @@ else if (timeoutOccurred) { logger.logcat("progress: " + getProgress() + " % ", "d"); } else { - success = false; + logger.logcat("uploadFile: Received data didn't match the hex file."+ + "\nReceived: " + Arrays.toString(rdata) + + "\nExpected: " + Arrays.toString(tempArray), "d"); + //TODO: Trigger rewrite of line (once sure data is read correctly) + return false; } } @@ -1579,9 +1597,10 @@ else if (timeoutOccurred) { if(!success) { if (timeoutOccurred && !recoverySuccessful) { // Trying to reset - if(hardwareReset()) continue; - - return false; + //hw reset not implemented! TODO: Consider returning false + //if(hardwareReset()) continue; + continue; + //return false; } else if (timeoutOccurred) { timeoutOccurred = false;