knx icon indicating copy to clipboard operation
knx copied to clipboard

Permanently unload device

Open thewhobox opened this issue 8 months ago • 10 comments

First attempt to fix permanently unloading a device according to thelsing/knx #144

thewhobox avatar May 12 '25 13:05 thewhobox

It's not yet tested.

It just marks tables as "wasUnloaded". The loop in bau_systemB_device (and coupler) checks this and saves the time. If the timeout reaches 5s it will call writeMemory(). If the device receives a memoryWrite/propertyWrite/routingTableWrite/... it will reset the timeout so it may not effect the parametration of the device.

@Phil1pp could you test it?

thewhobox avatar May 12 '25 13:05 thewhobox

The timeout and the write is working, however it keeps triggering the write every 5000ms. Some kind of writeDone or resetting of the WasUnloaded bits is missing.

Phil1pp avatar May 12 '25 19:05 Phil1pp

I resetted the flag WasUnloaded. Should now only trigger once.

thewhobox avatar May 13 '25 11:05 thewhobox

It looks good now. Thanks a lot. I did several tests for unloading with and without physical address. The unload was persistant after a device restart. Also loading the application again was without a problem.

Phil1pp avatar May 13 '25 19:05 Phil1pp

Thanks for your testing.

@thelsing what do you think about the solution?

thewhobox avatar May 15 '25 09:05 thewhobox

My first idea would be to add the timeout to the Memory class instead. So on "ClearMemory" one would set a timeout and do a writeMemory after it's reached. This seems to be a bit more centralized if we clear memory for some other reason.

Does this seam reasonable?

thelsing avatar May 19 '25 09:05 thelsing

This would also be a good idea. I moved it to the Memory Class.

I also added a reset of the timeout if there is write access to the memory. This will prevent write memory while the ets wants to load the application into the device (since it unloads every table before).

thewhobox avatar May 19 '25 10:05 thewhobox

After you last change it doesn't work anymore because _saveTimeout is never set. clearMemory() was just recently added by me and isn't involved in the unloading process.

You probably still have to check if TableObject state changed to LS_UNLOADED.

Phil1pp avatar May 19 '25 19:05 Phil1pp

Okay, i now moved it to freeMemory(). Whis will be called when the TableState changes from loaded to unloaded. (and also when the table gets allocated but was not a nullptr)

https://github.com/thewhobox/knx/blob/9ebf5a572b73c7258f045758b7dc8b4ffaf151ec/src/knx/table_object.cpp#L253

thewhobox avatar May 27 '25 09:05 thewhobox

I tested it again and it's working fine now. Thx thewhobox

Phil1pp avatar May 27 '25 15:05 Phil1pp

It's a bit less obvious how this works than I'd like it to be, but it's good enough to merge.

thelsing avatar Jul 21 '25 17:07 thelsing