Exemplo n.º 1
0
    def __init__(self,
                 can_driver,
                 node_id=None,
                 node_status_interval=None,
                 mode=None,
                 node_info=None,
                 **_extras):
        """
        It is recommended to use make_node() rather than instantiating this type directly.

        :param can_driver: CAN bus driver object. Calling close() on a node object closes its driver instance.

        :param node_id: Node ID of the current instance. Defaults to None, which enables passive mode.

        :param node_status_interval: NodeStatus broadcasting interval. Defaults to DEFAULT_NODE_STATUS_INTERVAL.

        :param mode: Initial operating mode (INITIALIZATION, OPERATIONAL, etc.); defaults to INITIALIZATION.

        :param node_info: Structure of type uavcan.protocol.GetNodeInfo.Response, responded with when the local
                          node is queried for its node info.
        """
        super(Node, self).__init__()

        self._handler_dispatcher = HandlerDispatcher(self)

        self._can_driver = can_driver
        self._node_id = node_id

        self._transfer_manager = transport.TransferManager()
        self._outstanding_requests = {}
        self._outstanding_request_callbacks = {}
        self._next_transfer_ids = collections.defaultdict(int)

        self.start_time_monotonic = time.monotonic()

        # Hooks
        self._transfer_hook_dispatcher = TransferHookDispatcher()

        # NodeStatus publisher
        self.health = uavcan.protocol.NodeStatus(
        ).HEALTH_OK  # @UndefinedVariable
        self.mode = uavcan.protocol.NodeStatus(
        ).MODE_INITIALIZATION if mode is None else mode  # @UndefinedVariable
        self.vendor_specific_status_code = 0

        node_status_interval = node_status_interval or DEFAULT_NODE_STATUS_INTERVAL
        self.periodic(node_status_interval, self._send_node_status)

        # GetNodeInfo server
        def on_get_node_info(e):
            logger.debug('GetNodeInfo request from %r',
                         e.transfer.source_node_id)
            self._fill_node_status(self.node_info.status)
            return self.node_info

        self.node_info = node_info or uavcan.protocol.GetNodeInfo.Response(
        )  # @UndefinedVariable
        self.add_handler(uavcan.protocol.GetNodeInfo,
                         on_get_node_info)  # @UndefinedVariable
Exemplo n.º 2
0
 def __init__(self, handlers, node_id=127):
     self.can = None
     self.transfer_manager = transport.TransferManager()
     self.handlers = handlers
     self.node_id = node_id
     self.outstanding_requests = {}
     self.outstanding_request_callbacks = {}
     self.outstanding_request_timestamps = {}
     self.next_transfer_ids = collections.defaultdict(int)
     self.node_info = {}