Skip to content

Commit

Permalink
Some fixes for verification
Browse files Browse the repository at this point in the history
Make basic fixes to verification. These will not be enough to
react properly to errors. See issues #53 and #49

* Fix failed verification being ignored
* Fix memory type accessed when verifying data
* Fix progress calculation when verification is enabled
* Change logged message for EOF reached when uploading and
  verification is enabled
  • Loading branch information
bjorfoss committed Nov 5, 2014
1 parent bdc4680 commit 5a9a103
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/no/group09/stk500_v1/STK500v1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1457,8 +1457,10 @@ private boolean writeAndReadFile(boolean checkWrittenData, int bytesToLoad) {
boolean success = uploadFile(bytesToLoad, true);

if(success && checkWrittenData) {
if(uploadFile(bytesToLoad, false)) {
success = true;
success = uploadFile(bytesToLoad, false);
if (!success) {
logger.logcat("writeAndReadFile: Upload verification"+
"failed.", "d");
}
}

Expand All @@ -1485,6 +1487,8 @@ private boolean uploadFile(int bytesToLoad, boolean write) {

logger.logcat("uploadFile: Data bytes to write: " +
bytesToLoad, "d");
//make sure of the memory type to manipulate:
boolean useFlash = true;

// Counter used to keep the position in the hex-file
int hexPosition = 0;
Expand Down Expand Up @@ -1515,6 +1519,8 @@ private boolean uploadFile(int bytesToLoad, boolean write) {
if(hardwareReset()) continue;

if (timeoutOccurred && !recoverySuccessful){
logger.logcat("uploadFile: Unable to load address " +
hexPosition, "d");
return false;
}
else if (timeoutOccurred) {
Expand All @@ -1531,7 +1537,7 @@ else if (timeoutOccurred) {

// Check if programming of page was successful.
// Increment counter and program next page
if (programPage(true, tempArray)) {
if (programPage(useFlash, tempArray)) {
hexPosition+=tempArray.length;

// Calculate progress
Expand All @@ -1552,13 +1558,15 @@ else if (timeoutOccurred) {

// Check if reading of written data was successful.
// Increment counter and read next page
if(readPage(bytesToLoad, false) == tempArray) {

if(readPage(bytesToLoad, useFlash) == tempArray) {
hexPosition+=tempArray.length;

// Calculate progress
logger.logcat("hexPosition: " + hexPosition +
", hexParser.getDataSize(): " + hexParser.getDataSize(), "d");
setProgress((double)hexPosition / (double)hexParser.getDataSize() + 50);
// Calculate progress
double tempProgress = (double)hexPosition / (double)hexParser.getDataSize();
setProgress((tempProgress * 50) + 50);

logger.logcat("progress: " + getProgress() + " % ", "d");
}
Expand Down Expand Up @@ -1612,9 +1620,15 @@ else if (timeoutOccurred) {
// }
}
}
logger.logcat("uploadFile: End of file. "+
"Upload finished with success.", "d");

if (write) {
if (readWrittenPage) {
logger.logcat("uploadFile: End of file. "+
"All data uploaded, verification to follow", "d");
} else {
logger.logcat("uploadFile: End of file. "+
"Upload finished with success.", "d");
}
}
return true;
}

Expand Down

0 comments on commit 5a9a103

Please sign in to comment.