diff --git a/src/knx/memory.cpp b/src/knx/memory.cpp index be96714..17ebc70 100644 --- a/src/knx/memory.cpp +++ b/src/knx/memory.cpp @@ -15,6 +15,8 @@ bool Memory::isMemoryModified() return _modified; } +// TODO implement flash layout: manufacturerID, HarwareType, Version, addr[0], size[0], addr[1], size[1], ... +// reconstruct free flash list and used list on read void Memory::readMemory() { _data = _platform.getEepromBuffer(512); @@ -41,7 +43,9 @@ void Memory::writeMemory() int size = _saveCount; for (int i = 0; i < size; i++) { - buffer = _saveRestores[i]->save(buffer); + SaveRestore* saveRestore = dynamic_cast(_saveRestores[i]); + if(saveRestore) + buffer = saveRestore->save(buffer); } _platform.commitToEeprom(); _modified = false; diff --git a/src/knx/memory.h b/src/knx/memory.h index c299d22..505048a 100644 --- a/src/knx/memory.h +++ b/src/knx/memory.h @@ -25,7 +25,7 @@ public: private: Platform& _platform; bool _modified = false; - SaveRestore* _saveRestores[MAXSAVE] = {0}; + Restore* _saveRestores[MAXSAVE] = {0}; int _saveCount = 0; uint8_t* _data = 0; }; diff --git a/src/knx/restore.h b/src/knx/restore.h new file mode 100644 index 0000000..fe8ca41 --- /dev/null +++ b/src/knx/restore.h @@ -0,0 +1,21 @@ +#pragma once + +#pragma once +#include + +/** + * Interface for classes that can restore data from a buffer. + */ +class Restore +{ + public: + /** + * This method is called when the object should restore its state from the buffer. + * + * @param buffer The buffer the object should restore its state from. + * + * @return The buffer plus the size of the object state. The next object will use this value as + * the start of its buffer. + */ + virtual uint8_t* restore(uint8_t* buffer) = 0; +}; \ No newline at end of file diff --git a/src/knx/save_restore.h b/src/knx/save_restore.h index f87091d..d36d563 100644 --- a/src/knx/save_restore.h +++ b/src/knx/save_restore.h @@ -1,10 +1,11 @@ #pragma once #include +#include "restore.h" /** * Interface for classes that can save and restore data from a buffer. */ -class SaveRestore +class SaveRestore : public Restore { public: /** @@ -16,13 +17,4 @@ class SaveRestore * the start of its buffer. */ virtual uint8_t* save(uint8_t* buffer) = 0; - /** - * This method is called when the object should restore its state from the buffer. - * - * @param buffer The buffer the object should restore its state from. - * - * @return The buffer plus the size of the object state. The next object will use this value as - * the start of its buffer. - */ - virtual uint8_t* restore(uint8_t* buffer) = 0; }; \ No newline at end of file