moved timeout to memory class

This commit is contained in:
Mike 2025-05-19 12:21:26 +02:00
parent 3c73cdca5e
commit 5878458a41
No known key found for this signature in database
8 changed files with 23 additions and 60 deletions

5
examples/knx-demo/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@ -164,9 +164,6 @@ void BauSystemB::memoryRoutingTableWriteIndication(Priority priority, HopCountTy
if (_deviceObj.verifyMode()) if (_deviceObj.verifyMode())
memoryRoutingTableReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); 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, 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()) if (_deviceObj.verifyMode())
memoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress, data); 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, 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); _memory.writeMemory(memoryAddress, number, data);
applicationLayer().memoryExtWriteResponse(AckRequested, priority, hopType, asap, secCtrl, ReturnCodes::Success, number, memoryAddress, _memory.toAbsolute(memoryAddress)); 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) 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()) if (_deviceObj.verifyMode())
userMemoryReadIndication(priority, hopType, asap, secCtrl, number, memoryAddress); 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, 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); obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements);
propertyValueReadIndication(priority, hopType, asap, secCtrl, objectIndex, propertyId, numberOfElements, startIndex); 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, 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); 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, 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); obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements);
else else
numberOfElements = 0; numberOfElements = 0;
if(_unloadStarted != 0)
_unloadStarted = millis(); // reset unload timer
} }
Memory& BauSystemB::memory() Memory& BauSystemB::memory()

View File

@ -130,6 +130,4 @@ class BauSystemB : protected BusAccessUnit
BeforeRestartCallback _beforeRestart = 0; BeforeRestartCallback _beforeRestart = 0;
FunctionPropertyCallback _functionProperty = 0; FunctionPropertyCallback _functionProperty = 0;
FunctionPropertyCallback _functionPropertyState = 0; FunctionPropertyCallback _functionPropertyState = 0;
unsigned long _unloadStarted = 0;
}; };

View File

@ -49,23 +49,7 @@ void BauSystemBDevice::loop()
#ifdef USE_DATASECURE #ifdef USE_DATASECURE
_appLayer.loop(); _appLayer.loop();
#endif #endif
_memory.loop();
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();
}
} }
void BauSystemBDevice::sendNextGroupTelegram() void BauSystemBDevice::sendNextGroupTelegram()

View File

@ -204,6 +204,7 @@ void Memory::clearMemory()
{ {
_platform.writeNonVolatileMemory(0, 0xFF, _metadataSize); _platform.writeNonVolatileMemory(0, 0xFF, _metadataSize);
_platform.commitNonVolatileMemory(); _platform.commitNonVolatileMemory();
_saveTimeout = millis();
} }
void Memory::addSaveRestore(SaveRestore* obj) 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) void Memory::writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data)
{ {
if(_saveTimeout != 0)
{
_saveTimeout = millis();
}
_platform.writeNonVolatileMemory(relativeAddress, data, size); _platform.writeNonVolatileMemory(relativeAddress, data, size);
} }
@ -541,3 +546,13 @@ VersionCheckCallback Memory::versionCheckCallback()
{ {
return _versionCheckCallback; return _versionCheckCallback;
} }
void Memory::loop()
{
if(_saveTimeout != 0 && millis() - _saveTimeout > 5000)
{
println("saveMemory timeout");
_saveTimeout = 0;
writeMemory();
}
}

View File

@ -46,6 +46,7 @@ class Memory
void clearMemory(); void clearMemory();
void addSaveRestore(SaveRestore* obj); void addSaveRestore(SaveRestore* obj);
void addSaveRestore(TableObject* obj); void addSaveRestore(TableObject* obj);
void loop();
uint8_t* allocMemory(size_t size); uint8_t* allocMemory(size_t size);
void freeMemory(uint8_t* ptr); void freeMemory(uint8_t* ptr);
@ -82,4 +83,5 @@ class Memory
MemoryBlock* _freeList = nullptr; MemoryBlock* _freeList = nullptr;
MemoryBlock* _usedList = nullptr; MemoryBlock* _usedList = nullptr;
uint16_t _metadataSize = 6 + LEN_HARDWARE_TYPE; // accounting for 3x pushWord and pushByteArray of length LEN_HARDWARE_TYPE uint16_t _metadataSize = 6 + LEN_HARDWARE_TYPE; // accounting for 3x pushWord and pushByteArray of length LEN_HARDWARE_TYPE
unsigned long _saveTimeout = 0;
}; };

View File

@ -58,11 +58,6 @@ void TableObject::loadState(LoadState newState)
beforeStateChange(newState); beforeStateChange(newState);
_state = 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)); memcpy(allProperties + propertyCount, ownProperties, sizeof(ownProperties));
InterfaceObject::initializeProperties(sizeof(allProperties), allProperties); InterfaceObject::initializeProperties(sizeof(allProperties), allProperties);
}
bool TableObject::getWasUnloaded()
{
return _wasUnloaded;
}
void TableObject::unsetWasundloaded()
{
_wasUnloaded = false;
} }

View File

@ -35,9 +35,6 @@ class TableObject: public InterfaceObject
static void beforeTablesUnloadCallback(BeforeTablesUnloadCallback func); static void beforeTablesUnloadCallback(BeforeTablesUnloadCallback func);
static BeforeTablesUnloadCallback beforeTablesUnloadCallback(); static BeforeTablesUnloadCallback beforeTablesUnloadCallback();
bool getWasUnloaded();
void unsetWasundloaded();
protected: protected:
/** /**
* This method is called before the interface object enters a new ::LoadState. * 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. * The size of the memory block cannot be used because it is changed during alignment to page size.
*/ */
uint32_t _size = 0; uint32_t _size = 0;
bool _wasUnloaded = false;
}; };