From d15cda5a155ddacec2c9f99903e80a8cbaf17ae3 Mon Sep 17 00:00:00 2001 From: Mike <45664417+thewhobox@users.noreply.github.com> Date: Mon, 12 May 2025 15:22:29 +0200 Subject: [PATCH 1/6] added timeout for unloading to write memory --- src/knx/bau_systemB.cpp | 21 +++++++++++++++++++++ src/knx/bau_systemB.h | 2 ++ src/knx/bau_systemB_coupler.cpp | 11 +++++++++++ src/knx/bau_systemB_device.cpp | 18 ++++++++++++++++++ src/knx/table_object.cpp | 10 ++++++++++ src/knx/table_object.h | 4 ++++ 6 files changed, 66 insertions(+) diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index b727148..f76e512 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -164,6 +164,9 @@ void BauSystemB::memoryRoutingTableWriteIndication(Priority priority, HopCountTy if (_deviceObj.verifyMode()) memoryRoutingTableReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); + + if(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, @@ -173,6 +176,9 @@ void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, if (_deviceObj.verifyMode()) memoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); + + if(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } void BauSystemB::memoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, @@ -193,6 +199,9 @@ 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(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } void BauSystemB::memoryExtReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, uint32_t memoryAddress) @@ -252,6 +261,9 @@ void BauSystemB::userMemoryWriteIndication(Priority priority, HopCountType hopTy if (_deviceObj.verifyMode()) userMemoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress); + + if(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } void BauSystemB::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t objectIndex, @@ -311,6 +323,9 @@ void BauSystemB::propertyValueWriteIndication(Priority priority, HopCountType ho obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); propertyValueReadIndication(priority, hopType, asap, secCtrl, objectIndex, propertyId, numberOfElements, startIndex); + + if(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } void BauSystemB::propertyValueExtWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, ObjectType objectType, uint8_t objectInstance, @@ -329,6 +344,9 @@ void BauSystemB::propertyValueExtWriteIndication(Priority priority, HopCountType { applicationLayer().propertyValueExtWriteConResponse(AckRequested, priority, hopType, asap, secCtrl, objectType, objectInstance, propertyId, numberOfElements, startIndex, returnCode); } + + if(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } void BauSystemB::propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t objectIndex, @@ -765,6 +783,9 @@ void BauSystemB::propertyValueWrite(ObjectType objectType, uint8_t objectInstanc obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); else numberOfElements = 0; + + if(_unloadStartet != 0) + _unloadStartet = millis(); // reset unload timer } Memory& BauSystemB::memory() diff --git a/src/knx/bau_systemB.h b/src/knx/bau_systemB.h index 576dac7..2574ffc 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -130,4 +130,6 @@ class BauSystemB : protected BusAccessUnit BeforeRestartCallback _beforeRestart = 0; FunctionPropertyCallback _functionProperty = 0; FunctionPropertyCallback _functionPropertyState = 0; + + unsigned long _unloadStartet = 0; }; diff --git a/src/knx/bau_systemB_coupler.cpp b/src/knx/bau_systemB_coupler.cpp index e71164f..984ef42 100644 --- a/src/knx/bau_systemB_coupler.cpp +++ b/src/knx/bau_systemB_coupler.cpp @@ -33,6 +33,17 @@ void BauSystemBCoupler::loop() #ifdef USE_DATASECURE _appLayer.loop(); #endif + +#ifdef USE_DATASECURE + if(_unloadStartet == 0 && _secIfObj.getWasUnloaded()) + { + _unloadStartet = millis(); + } else if(millis() - _unloadStartet > 5000) + { + writeMemory(); + _unloadStartet = 0; + } +#endif } bool BauSystemBCoupler::configured() diff --git a/src/knx/bau_systemB_device.cpp b/src/knx/bau_systemB_device.cpp index 872d677..c59bcf4 100644 --- a/src/knx/bau_systemB_device.cpp +++ b/src/knx/bau_systemB_device.cpp @@ -49,6 +49,24 @@ void BauSystemBDevice::loop() #ifdef USE_DATASECURE _appLayer.loop(); #endif + + if(_unloadStartet == 0) + { + if(_addrTable.getWasUnloaded() + || _assocTable.getWasUnloaded() + || _groupObjTable.getWasUnloaded() +#ifdef USE_DATASECURE + || _secIfObj.getWasUnloaded() +#endif + ) + { + _unloadStartet = millis(); + } + } else if(millis() - _unloadStartet > 5000) + { + writeMemory(); + _unloadStartet = 0; + } } void BauSystemBDevice::sendNextGroupTelegram() diff --git a/src/knx/table_object.cpp b/src/knx/table_object.cpp index cef83be..12b9222 100644 --- a/src/knx/table_object.cpp +++ b/src/knx/table_object.cpp @@ -58,6 +58,11 @@ void TableObject::loadState(LoadState newState) beforeStateChange(newState); _state = newState; + + if(newState == LS_UNLOADED) + { + _wasUnloaded = true; + } } @@ -411,4 +416,9 @@ void TableObject::initializeDynTableProperties(size_t propertiesSize, Property** memcpy(allProperties + propertyCount, ownProperties, sizeof(ownProperties)); InterfaceObject::initializeProperties(sizeof(allProperties), allProperties); +} + +bool TableObject::getWasUnloaded() +{ + return _wasUnloaded; } \ No newline at end of file diff --git a/src/knx/table_object.h b/src/knx/table_object.h index 914bb2e..da8f4f3 100644 --- a/src/knx/table_object.h +++ b/src/knx/table_object.h @@ -35,6 +35,8 @@ class TableObject: public InterfaceObject static void beforeTablesUnloadCallback(BeforeTablesUnloadCallback func); static BeforeTablesUnloadCallback beforeTablesUnloadCallback(); + bool getWasUnloaded(); + protected: /** * This method is called before the interface object enters a new ::LoadState. @@ -91,4 +93,6 @@ 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; }; From 1feac3927c8d1782ec5e349410cd25590d6baea6 Mon Sep 17 00:00:00 2001 From: Mike <45664417+thewhobox@users.noreply.github.com> Date: Mon, 12 May 2025 15:31:04 +0200 Subject: [PATCH 2/6] removed check for secIfObj --- src/knx/bau_systemB_coupler.cpp | 11 ----------- src/knx/bau_systemB_device.cpp | 6 +----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/knx/bau_systemB_coupler.cpp b/src/knx/bau_systemB_coupler.cpp index 984ef42..e71164f 100644 --- a/src/knx/bau_systemB_coupler.cpp +++ b/src/knx/bau_systemB_coupler.cpp @@ -33,17 +33,6 @@ void BauSystemBCoupler::loop() #ifdef USE_DATASECURE _appLayer.loop(); #endif - -#ifdef USE_DATASECURE - if(_unloadStartet == 0 && _secIfObj.getWasUnloaded()) - { - _unloadStartet = millis(); - } else if(millis() - _unloadStartet > 5000) - { - writeMemory(); - _unloadStartet = 0; - } -#endif } bool BauSystemBCoupler::configured() diff --git a/src/knx/bau_systemB_device.cpp b/src/knx/bau_systemB_device.cpp index c59bcf4..7996768 100644 --- a/src/knx/bau_systemB_device.cpp +++ b/src/knx/bau_systemB_device.cpp @@ -54,11 +54,7 @@ void BauSystemBDevice::loop() { if(_addrTable.getWasUnloaded() || _assocTable.getWasUnloaded() - || _groupObjTable.getWasUnloaded() -#ifdef USE_DATASECURE - || _secIfObj.getWasUnloaded() -#endif - ) + || _groupObjTable.getWasUnloaded()) { _unloadStartet = millis(); } From 5c3ae41ea1d9def61468b9324cd12f02c09dcdc4 Mon Sep 17 00:00:00 2001 From: Mike <45664417+thewhobox@users.noreply.github.com> Date: Mon, 12 May 2025 16:28:50 +0200 Subject: [PATCH 3/6] fix: typo --- src/knx/bau_systemB.cpp | 28 ++++++++++++++-------------- src/knx/bau_systemB.h | 2 +- src/knx/bau_systemB_device.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index f76e512..36ef4ed 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -165,8 +165,8 @@ void BauSystemB::memoryRoutingTableWriteIndication(Priority priority, HopCountTy if (_deviceObj.verifyMode()) memoryRoutingTableReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + if(_unloadStarted != 0) + _unloadStarted = millis(); // reset unload timer } void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, @@ -177,8 +177,8 @@ void BauSystemB::memoryWriteIndication(Priority priority, HopCountType hopType, if (_deviceObj.verifyMode()) memoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + if(_unloadStarted != 0) + _unloadStarted = millis(); // reset unload timer } void BauSystemB::memoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t number, @@ -200,8 +200,8 @@ void BauSystemB::memoryExtWriteIndication(Priority priority, HopCountType hopTyp applicationLayer().memoryExtWriteResponse(AckRequested, priority, hopType, asap, secCtrl, ReturnCodes::Success, number, memoryAddress, _memory.toAbsolute(memoryAddress)); - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + 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) @@ -262,8 +262,8 @@ void BauSystemB::userMemoryWriteIndication(Priority priority, HopCountType hopTy if (_deviceObj.verifyMode()) userMemoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress); - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + if(_unloadStarted != 0) + _unloadStarted = millis(); // reset unload timer } void BauSystemB::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t objectIndex, @@ -324,8 +324,8 @@ void BauSystemB::propertyValueWriteIndication(Priority priority, HopCountType ho propertyValueReadIndication(priority, hopType, asap, secCtrl, objectIndex, propertyId, numberOfElements, startIndex); - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + 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, @@ -345,8 +345,8 @@ void BauSystemB::propertyValueExtWriteIndication(Priority priority, HopCountType applicationLayer().propertyValueExtWriteConResponse(AckRequested, priority, hopType, asap, secCtrl, objectType, objectInstance, propertyId, numberOfElements, startIndex, returnCode); } - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + if(_unloadStarted != 0) + _unloadStarted = millis(); // reset unload timer } void BauSystemB::propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, const SecurityControl& secCtrl, uint8_t objectIndex, @@ -784,8 +784,8 @@ void BauSystemB::propertyValueWrite(ObjectType objectType, uint8_t objectInstanc else numberOfElements = 0; - if(_unloadStartet != 0) - _unloadStartet = millis(); // reset unload timer + 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 2574ffc..e86f35b 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -131,5 +131,5 @@ class BauSystemB : protected BusAccessUnit FunctionPropertyCallback _functionProperty = 0; FunctionPropertyCallback _functionPropertyState = 0; - unsigned long _unloadStartet = 0; + unsigned long _unloadStarted = 0; }; diff --git a/src/knx/bau_systemB_device.cpp b/src/knx/bau_systemB_device.cpp index 7996768..67f6394 100644 --- a/src/knx/bau_systemB_device.cpp +++ b/src/knx/bau_systemB_device.cpp @@ -50,18 +50,18 @@ void BauSystemBDevice::loop() _appLayer.loop(); #endif - if(_unloadStartet == 0) + if(_unloadStarted == 0) { if(_addrTable.getWasUnloaded() || _assocTable.getWasUnloaded() || _groupObjTable.getWasUnloaded()) { - _unloadStartet = millis(); + _unloadStarted = millis(); } - } else if(millis() - _unloadStartet > 5000) + } else if(millis() - _unloadStarted > 5000) { writeMemory(); - _unloadStartet = 0; + _unloadStarted = 0; } } From 3c73cdca5eea15b6945b6c0e75b1685bd3f58b93 Mon Sep 17 00:00:00 2001 From: Mike <45664417+thewhobox@users.noreply.github.com> Date: Tue, 13 May 2025 13:25:06 +0200 Subject: [PATCH 4/6] fix: reset flag wasUnloaded --- src/knx/bau_systemB_device.cpp | 3 +++ src/knx/table_object.cpp | 5 +++++ src/knx/table_object.h | 1 + 3 files changed, 9 insertions(+) diff --git a/src/knx/bau_systemB_device.cpp b/src/knx/bau_systemB_device.cpp index 67f6394..2a27590 100644 --- a/src/knx/bau_systemB_device.cpp +++ b/src/knx/bau_systemB_device.cpp @@ -62,6 +62,9 @@ void BauSystemBDevice::loop() { writeMemory(); _unloadStarted = 0; + _addrTable.unsetWasundloaded(); + _assocTable.unsetWasundloaded(); + _groupObjTable.unsetWasundloaded(); } } diff --git a/src/knx/table_object.cpp b/src/knx/table_object.cpp index 12b9222..826077f 100644 --- a/src/knx/table_object.cpp +++ b/src/knx/table_object.cpp @@ -421,4 +421,9 @@ void TableObject::initializeDynTableProperties(size_t propertiesSize, Property** 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 da8f4f3..463db5e 100644 --- a/src/knx/table_object.h +++ b/src/knx/table_object.h @@ -36,6 +36,7 @@ class TableObject: public InterfaceObject static BeforeTablesUnloadCallback beforeTablesUnloadCallback(); bool getWasUnloaded(); + void unsetWasundloaded(); protected: /** From 5878458a41cb5f303e774bf3c5215047906778af Mon Sep 17 00:00:00 2001 From: Mike <45664417+thewhobox@users.noreply.github.com> Date: Mon, 19 May 2025 12:21:26 +0200 Subject: [PATCH 5/6] moved timeout to memory class --- examples/knx-demo/.gitignore | 5 +++++ src/knx/bau_systemB.cpp | 21 --------------------- src/knx/bau_systemB.h | 2 -- src/knx/bau_systemB_device.cpp | 18 +----------------- src/knx/memory.cpp | 15 +++++++++++++++ src/knx/memory.h | 2 ++ src/knx/table_object.cpp | 15 --------------- src/knx/table_object.h | 5 ----- 8 files changed, 23 insertions(+), 60 deletions(-) create mode 100644 examples/knx-demo/.gitignore 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; }; From 9ebf5a572b73c7258f045758b7dc8b4ffaf151ec Mon Sep 17 00:00:00 2001 From: Mike <45664417+thewhobox@users.noreply.github.com> Date: Tue, 27 May 2025 11:02:49 +0200 Subject: [PATCH 6/6] moved timeout for memory to freeMemory --- src/knx/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/knx/memory.cpp b/src/knx/memory.cpp index 4ee9cc5..fe08a92 100644 --- a/src/knx/memory.cpp +++ b/src/knx/memory.cpp @@ -204,7 +204,6 @@ void Memory::clearMemory() { _platform.writeNonVolatileMemory(0, 0xFF, _metadataSize); _platform.commitNonVolatileMemory(); - _saveTimeout = millis(); } void Memory::addSaveRestore(SaveRestore* obj) @@ -302,6 +301,7 @@ void Memory::freeMemory(uint8_t* ptr) removeFromUsedList(block); addToFreeList(block); + _saveTimeout = millis(); } void Memory::writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data)