diff --git a/examples/knx-demo/.gitignore b/examples/knx-demo/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/examples/knx-demo/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index 36ef4ed..b727148 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -164,9 +164,6 @@ void BauSystemB::memoryRoutingTableWriteIndication(Priority priority, HopCountTy if (_deviceObj.verifyMode()) memoryRoutingTableReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, @@ -176,9 +173,6 @@ void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, if (_deviceObj.verifyMode()) memoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } void BauSystemB::memoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, @@ -199,9 +193,6 @@ void BauSystemB::memoryExtWriteIndication(Priority priority, HopCountType hopTyp _memory.writeMemory(memoryAddress, number, data); applicationLayer().memoryExtWriteResponse(AckRequested, priority, hopType, asap, secCtrl, ReturnCodes::Success, number, memoryAddress, _memory.toAbsolute(memoryAddress)); - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } void BauSystemB::memoryExtReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, uint32_t memoryAddress) @@ -261,9 +252,6 @@ void BauSystemB::userMemoryWriteIndication(Priority priority, HopCountType hopTy if (_deviceObj.verifyMode()) userMemoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress); - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } void BauSystemB::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t objectIndex, @@ -323,9 +311,6 @@ void BauSystemB::propertyValueWriteIndication(Priority priority, HopCountType ho obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); propertyValueReadIndication(priority, hopType, asap, secCtrl, objectIndex, propertyId, numberOfElements, startIndex); - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } void BauSystemB::propertyValueExtWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, ObjectType objectType, uint8_t objectInstance, @@ -344,9 +329,6 @@ void BauSystemB::propertyValueExtWriteIndication(Priority priority, HopCountType { applicationLayer().propertyValueExtWriteConResponse(AckRequested, priority, hopType, asap, secCtrl, objectType, objectInstance, propertyId, numberOfElements, startIndex, returnCode); } - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } void BauSystemB::propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t objectIndex, @@ -783,9 +765,6 @@ void BauSystemB::propertyValueWrite(ObjectType objectType, uint8_t objectInstanc obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); else numberOfElements = 0; - - if(_unloadStarted != 0) - _unloadStarted = millis(); // reset unload timer } Memory& BauSystemB::memory() diff --git a/src/knx/bau_systemB.h b/src/knx/bau_systemB.h index e86f35b..576dac7 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -130,6 +130,4 @@ class BauSystemB : protected BusAccessUnit BeforeRestartCallback _beforeRestart = 0; FunctionPropertyCallback _functionProperty = 0; FunctionPropertyCallback _functionPropertyState = 0; - - unsigned long _unloadStarted = 0; }; diff --git a/src/knx/bau_systemB_device.cpp b/src/knx/bau_systemB_device.cpp index 2a27590..a852d4f 100644 --- a/src/knx/bau_systemB_device.cpp +++ b/src/knx/bau_systemB_device.cpp @@ -49,23 +49,7 @@ void BauSystemBDevice::loop() #ifdef USE_DATASECURE _appLayer.loop(); #endif - - if(_unloadStarted == 0) - { - if(_addrTable.getWasUnloaded() - || _assocTable.getWasUnloaded() - || _groupObjTable.getWasUnloaded()) - { - _unloadStarted = millis(); - } - } else if(millis() - _unloadStarted > 5000) - { - writeMemory(); - _unloadStarted = 0; - _addrTable.unsetWasundloaded(); - _assocTable.unsetWasundloaded(); - _groupObjTable.unsetWasundloaded(); - } + _memory.loop(); } void BauSystemBDevice::sendNextGroupTelegram() diff --git a/src/knx/memory.cpp b/src/knx/memory.cpp index 23a737a..4ee9cc5 100644 --- a/src/knx/memory.cpp +++ b/src/knx/memory.cpp @@ -204,6 +204,7 @@ void Memory::clearMemory() { _platform.writeNonVolatileMemory(0, 0xFF, _metadataSize); _platform.commitNonVolatileMemory(); + _saveTimeout = millis(); } void Memory::addSaveRestore(SaveRestore* obj) @@ -305,6 +306,10 @@ void Memory::freeMemory(uint8_t* ptr) void Memory::writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data) { + if(_saveTimeout != 0) + { + _saveTimeout = millis(); + } _platform.writeNonVolatileMemory(relativeAddress, data, size); } @@ -541,3 +546,13 @@ VersionCheckCallback Memory::versionCheckCallback() { return _versionCheckCallback; } + +void Memory::loop() +{ + if(_saveTimeout != 0 && millis() - _saveTimeout > 5000) + { + println("saveMemory timeout"); + _saveTimeout = 0; + writeMemory(); + } +} \ No newline at end of file diff --git a/src/knx/memory.h b/src/knx/memory.h index 30ba9b1..0b0e983 100644 --- a/src/knx/memory.h +++ b/src/knx/memory.h @@ -46,6 +46,7 @@ class Memory void clearMemory(); void addSaveRestore(SaveRestore* obj); void addSaveRestore(TableObject* obj); + void loop(); uint8_t* allocMemory(size_t size); void freeMemory(uint8_t* ptr); @@ -82,4 +83,5 @@ class Memory MemoryBlock* _freeList = nullptr; MemoryBlock* _usedList = nullptr; uint16_t _metadataSize = 6 + LEN_HARDWARE_TYPE; // accounting for 3x pushWord and pushByteArray of length LEN_HARDWARE_TYPE + unsigned long _saveTimeout = 0; }; diff --git a/src/knx/table_object.cpp b/src/knx/table_object.cpp index 826077f..cef83be 100644 --- a/src/knx/table_object.cpp +++ b/src/knx/table_object.cpp @@ -58,11 +58,6 @@ void TableObject::loadState(LoadState newState) beforeStateChange(newState); _state = newState; - - if(newState == LS_UNLOADED) - { - _wasUnloaded = true; - } } @@ -416,14 +411,4 @@ void TableObject::initializeDynTableProperties(size_t propertiesSize, Property** memcpy(allProperties + propertyCount, ownProperties, sizeof(ownProperties)); InterfaceObject::initializeProperties(sizeof(allProperties), allProperties); -} - -bool TableObject::getWasUnloaded() -{ - return _wasUnloaded; -} - -void TableObject::unsetWasundloaded() -{ - _wasUnloaded = false; } \ No newline at end of file diff --git a/src/knx/table_object.h b/src/knx/table_object.h index 463db5e..914bb2e 100644 --- a/src/knx/table_object.h +++ b/src/knx/table_object.h @@ -35,9 +35,6 @@ class TableObject: public InterfaceObject static void beforeTablesUnloadCallback(BeforeTablesUnloadCallback func); static BeforeTablesUnloadCallback beforeTablesUnloadCallback(); - bool getWasUnloaded(); - void unsetWasundloaded(); - protected: /** * This method is called before the interface object enters a new ::LoadState. @@ -94,6 +91,4 @@ class TableObject: public InterfaceObject * The size of the memory block cannot be used because it is changed during alignment to page size. */ uint32_t _size = 0; - - bool _wasUnloaded = false; };