Skip to content

Draft: WOM-390: SCU lib caches node IDs to JSON file after scanning server

Jarrett Engelbrecht requested to merge wom-390-cache-nodes into main

This MR introduces non-breaking API changes to SCU lib and changes to the GUI.

SCU can be instantiated with an optional use_nodes_cache bool argument - default 'False'. If set to 'True', SCU checks for any existing caches for the server it's connecting to, and uses it to recreate the Node objects with its unique ID, without scanning the server tree again with asyncio coroutines. This significantly speeds-up subsequent reconnects to the same server.

For a root node, such as PLC_PRG, a dict of servers with a generation timestamp and nested dict of node names (paths), their ID string representation and node class integer (node with children, attribute or method) is stored as a JSON file in the user's cache directory. In Linux, the path would be /home/<username>/.cache/DiSQ/PLC_PRG.json, and in Windows \Users\<username>\AppData\Local\SKAO\DiSQ\Cache. Example snippet of the JSON:

{
    "opc.tcp://127.0.0.1:4840/OPCUA/SimpleServer - v3.1": {
        "timestamp": "2024-07-02 10:31:31"
        "node_ids": {
            "Azimuth": [
                "ns=2;s=Azimuth",
                1
            ],
            "Azimuth.ErrorStatus": [
                "ns=2;s=Azimuth_ErrorStatus",
                1
            ],
...

For the GUI, a checkbox has been added next to the connect button to control when to use the cache and when to regenerate it by scanning a server. After establishing a connection, the stored timestamp of the cache is also displayed (or the current time if it was just regenerated):

image.png-image.png

Edited by Jarrett Engelbrecht

Merge request reports