added timeout for unloading to write memory

This commit is contained in:
Mike 2025-05-12 15:22:29 +02:00
parent 649adeaf53
commit d15cda5a15
No known key found for this signature in database
6 changed files with 66 additions and 0 deletions

View File

@ -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()

View File

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

View File

@ -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()

View File

@ -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()

View File

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

View File

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