fix bug in save code

This commit is contained in:
Thomas Kunze 2020-02-11 22:16:59 +01:00
parent 4dda99b341
commit 445bf05f93
4 changed files with 45 additions and 6 deletions

View File

@ -11,8 +11,8 @@
#endif
#define USE_RF
#define USE_TP
//#define USE_RF
//#define USE_TP
#define USE_IP
//#define USE_USB
//#define USE_CEMI_SERVER

View File

@ -214,7 +214,7 @@ void DeviceObject::hardwareType(const uint8_t* value)
uint16_t DeviceObject::version()
{
Property* prop = property(PID_HARDWARE_TYPE);
Property* prop = property(PID_VERSION);
uint16_t value;
prop->read(value);
return value;
@ -222,7 +222,7 @@ uint16_t DeviceObject::version()
void DeviceObject::version(uint16_t value)
{
Property* prop = property(PID_HARDWARE_TYPE);
Property* prop = property(PID_VERSION);
prop->write(value);
}

View File

@ -9,12 +9,15 @@ Memory::Memory(Platform& platform, DeviceObject& deviceObject)
void Memory::readMemory()
{
println("readMemory");
if (_data != nullptr)
return;
uint16_t flashSize = 512;
_data = _platform.getEepromBuffer(flashSize);
printHex("RESTORED ", _data, _metadataSize);
uint16_t metadataBlockSize = alignToPageSize(_metadataSize);
_freeList = new MemoryBlock(_data + metadataBlockSize, flashSize - metadataBlockSize);
@ -28,21 +31,44 @@ void Memory::readMemory()
uint16_t version = 0;
buffer = popWord(version, buffer);
if (_deviceObject.manufacturerId() != manufacturerId
|| _deviceObject.version() != version
|| memcmp(_deviceObject.hardwareType(), hardwareType, LEN_HARDWARE_TYPE) != 0)
{
println("saved memory doesn't match manufacturerId, version or hardwaretype");
print("manufacturerId: ");
print(manufacturerId, HEX);
print(" ");
println(_deviceObject.manufacturerId(), HEX);
print("version: ");
print(version, HEX);
print(" ");
println(_deviceObject.version(), HEX);
print("hardwareType: ");
printHex("", hardwareType, LEN_HARDWARE_TYPE);
print(" ");
printHex("", _deviceObject.hardwareType(), LEN_HARDWARE_TYPE);
return;
}
println("manufacturerId, version and hardwareType matches");
print("saverestores ");
println(_saveCount);
for (int i = 0; i < _saveCount; i++)
{
println(_data - buffer);
println(".");
buffer = _saveRestores[i]->restore(buffer);
}
println("restored saveRestores");
print("tableObjs ");
println(_tableObjCount);
for (int i = 0; i < _tableObjCount; i++)
{
println(_data - buffer);
println(".");
buffer = _tableObjects[i]->restore(buffer);
uint16_t memorySize = 0;
buffer = popWord(memorySize, buffer);
@ -53,6 +79,7 @@ void Memory::readMemory()
// this works because TableObject saves a relative addr and restores it itself
addNewUsedBlock(_tableObjects[i]->_data, memorySize);
}
println("restored Tableobjects");
}
void Memory::writeMemory()
@ -62,13 +89,23 @@ void Memory::writeMemory()
buffer = pushByteArray(_deviceObject.hardwareType(), LEN_HARDWARE_TYPE, buffer);
buffer = pushWord(_deviceObject.version(), buffer);
print("save saveRestores ");
println(_saveCount);
for (int i = 0; i < _saveCount; i++)
{
println(_data - buffer);
println(".");
println((int)_saveRestores[i], HEX);
buffer = _saveRestores[i]->save(buffer);
}
print("save tableobjs ");
println(_tableObjCount);
for (int i = 0; i < _tableObjCount; i++)
{
println(_data - buffer);
println(".");
println((int)_tableObjects[i], HEX);
buffer = _tableObjects[i]->save(buffer);
//save to size of the memoryblock for tableobject too, so that we can rebuild the usedList and freeList
@ -84,10 +121,11 @@ void Memory::writeMemory()
buffer = pushWord(block->size, buffer);
}
else
pushWord(0, buffer);
buffer = pushWord(0, buffer);
}
_platform.commitToEeprom();
printHex("SAVED ", _data, _metadataSize);
}
void Memory::addSaveRestore(SaveRestore* obj)

View File

@ -224,6 +224,7 @@
</DebugSettingsOverride>
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.arduino.extension">
<BoardID>esp8266:esp8266:nodemcuv2</BoardID>
<COMPort>COM5</COMPort>
<Properties>
<Entries>
<KeyValue>