Permanently unload device
First attempt to fix permanently unloading a device according to thelsing/knx #144
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?
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.
I resetted the flag WasUnloaded. Should now only trigger once.
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.
Thanks for your testing.
@thelsing what do you think about the solution?
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?
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).
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.
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
I tested it again and it's working fine now. Thx thewhobox
It's a bit less obvious how this works than I'd like it to be, but it's good enough to merge.