The library SpiFlashLogger throws an exception when processing a read, when the oldest log has been intentionally overwritten, due to the log being full.
In _getObject() there is a check that the object marker is as expected. However after the object start code positions have been gathered by _getObjectsStartCodesForSector() and before the object is read by _getObject(), it is possible for the sector to be overwritten, when the buffer if full.
In this case, the object start codes will be out of date and a exception is thrown.
Proposed solution:
In _getObject() replace this:
if (marker != SPIFLASHLOGGER_OBJECT_MARKER) {
throw "Error, marker not found at " + pos;
}
with:
if (marker != SPIFLASHLOGGER_OBJECT_MARKER) {
return null;
}
In function read(), within readObj(), test obj for null and return cont():
if (obj == null) {
return cont();
}
The following code reproduces the problem:
// ------------------------------------------------------------------------
#require “Serializer.class.nut:1.0.0”
#require “SPIFlashLogger.device.lib.nut:2.2.0”
logger <- SPIFlashLogger(0, 4096*4);
function writeFlash() {
logger.write(blob(1000));
imp.wakeup(0.1, writeFlash);
}
function readFlash() {
logger.read(
// For each object in the logs (onData)
function(dataPoint, address, next) {
logger.erase(address);
imp.wakeup(0.5, next);
},
// All finished (onFinish)
function() {
imp.wakeup(0.5, readFlash );
}
);
}
logger.eraseAll(false);
logger.write(blob(4000*4));
writeFlash();
readFlash();
// ------------------------------------------------------------------------
And this results in:
2018-05-11 08:15:36 +01:00|[Status]|Downloading new code; 8.68% program storage used
2018-05-11 08:15:41 +01:00|[Device]|ERROR: Error, marker not found at 3696
2018-05-11 08:15:41 +01:00|[Device]|ERROR: in _getObject …ashlogger.device.lib.nut#2.2.0:510
2018-05-11 08:15:41 +01:00|[Device]|ERROR: from unknown …ashlogger.device.lib.nut#2.2.0:381
I’m running into this issue as well. Is there a fix for this yet? I’m using “SPIFlashLogger.device.lib.nut:2.2.0”.