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; };