dronecan / pydronecan

python DroneCAN code generation, interface and utilities
MIT License
40 stars 42 forks source link

fixed load_dsdl problem #66

Closed FelixEL closed 2 months ago

FelixEL commented 4 months ago

load_dsdl overwrites dictionaries:

DATATYPES = {}
TYPENAMES = {}

this is described in: https://github.com/dronecan/pydronecan/issues/65

this is very big problem when loading custom definitions of DSDL files. It loads files during initialization (works) but every consecutive execution of load_dsdl breaks previous link.

How to reproduce (minimal example): Please note that "./external_dependencies/custom" contains uavcan definitions

import dronecan
from dronecan import uavcan

def main():
    node = dronecan.make_node(can_device_name="PCAN_USBBUS1",
                              node_id=127,
                              bitrate=125000)

    node_monitor = dronecan.app.node_monitor.NodeMonitor(node)

    node.add_handler(uavcan.protocol.NodeStatus, node_status_callback)
    allocator = dronecan.app.dynamic_node_id.CentralizedServer(
        node, node_monitor)

    while len(node_monitor.get_all_node_id()) < 1:
        print("waiting for nodes", node_monitor.get_all_node_id())
        node.spin(timeout=1)

    types = dronecan.load_dsdl(
        "./external_dependencies/custom")

    node.spin() 
FelixEL commented 4 months ago

@tridge and @bugobliterator - It would be great if you could approve it and merge to master before next release to PyPI. Before fix invocation of load_dsdl function was overwriting old subscribers without re-subscribing once again.

This is quite crucial bugfix as otherwise there is no way to add custom DSDL definitions using load_dsdl function.

tridge commented 2 months ago

sorry, needed to revert as it broke CI