Split Restore from SaveRestore.

This commit is contained in:
Thomas Kunze 2019-10-29 22:39:44 +01:00
parent 94b91278bd
commit 2770f5eaa9
4 changed files with 29 additions and 12 deletions

View File

@ -15,6 +15,8 @@ bool Memory::isMemoryModified()
return _modified; 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() void Memory::readMemory()
{ {
_data = _platform.getEepromBuffer(512); _data = _platform.getEepromBuffer(512);
@ -41,7 +43,9 @@ void Memory::writeMemory()
int size = _saveCount; int size = _saveCount;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
buffer = _saveRestores[i]->save(buffer); SaveRestore* saveRestore = dynamic_cast<SaveRestore*>(_saveRestores[i]);
if(saveRestore)
buffer = saveRestore->save(buffer);
} }
_platform.commitToEeprom(); _platform.commitToEeprom();
_modified = false; _modified = false;

View File

@ -25,7 +25,7 @@ public:
private: private:
Platform& _platform; Platform& _platform;
bool _modified = false; bool _modified = false;
SaveRestore* _saveRestores[MAXSAVE] = {0}; Restore* _saveRestores[MAXSAVE] = {0};
int _saveCount = 0; int _saveCount = 0;
uint8_t* _data = 0; uint8_t* _data = 0;
}; };

21
src/knx/restore.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#pragma once
#include <stdint.h>
/**
* 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;
};

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "restore.h"
/** /**
* Interface for classes that can save and restore data from a buffer. * Interface for classes that can save and restore data from a buffer.
*/ */
class SaveRestore class SaveRestore : public Restore
{ {
public: public:
/** /**
@ -16,13 +17,4 @@ class SaveRestore
* the start of its buffer. * the start of its buffer.
*/ */
virtual uint8_t* save(uint8_t* buffer) = 0; 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;
}; };