Skip to content

Commit

Permalink
Further changes to verification ref #53 and #49
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bjorfoss committed Nov 6, 2014
1 parent 5a9a103 commit 3dae37d
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/no/group09/stk500_v1/STK500v1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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 " +
Expand Down Expand Up @@ -1550,6 +1555,7 @@ else if (timeoutOccurred) {
hexPosition + " / " + hexParser.getDataSize(), "d");
}
else {
logger.logcat("uploadFile: Failed writing data.", "d");
success = false;
}
}
Expand All @@ -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();
Expand All @@ -1571,17 +1585,22 @@ 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;
}
}

//Programming was unsuccessful. Try again without incrementing
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;
Expand Down

0 comments on commit 3dae37d

Please sign in to comment.