Beispiel #1
0
    def _on_timer(self) -> None:
        self._restart_timer()
        if self.get_result() is not None:
            self.close()
            return

        msg: typing.Any = None
        try:
            if self._presentation.transport.protocol_parameters.mtu > self._MTU_THRESHOLD:
                msg = NodeIDAllocationData_2(node_id=ID(
                    self._preferred_node_id),
                                             unique_id=self._local_unique_id)
            else:
                msg = NodeIDAllocationData_1(
                    unique_id_hash=_make_pseudo_unique_id(
                        self._local_unique_id))

            if self._pub is None or self._pub.dtype != type(msg):
                if self._pub is not None:
                    self._pub.close()
                self._pub = self._presentation.make_publisher_with_fixed_subject_id(
                    type(msg))
                self._pub.priority = self.DEFAULT_PRIORITY

            _logger.debug('Publishing allocation request %s', msg)
            self._pub.publish_soon(msg)
        except Exception as ex:
            _logger.exception(f'Could not send allocation request {msg}: {ex}')
Beispiel #2
0
 def _respond_v1(self, priority: pyuavcan.transport.Priority,
                 unique_id_hash: int, allocated_node_id: int) -> None:
     msg = NodeIDAllocationData_1(unique_id_hash=unique_id_hash,
                                  allocated_node_id=[ID(allocated_node_id)])
     _logger.info('Publishing allocation response v1: %s', msg)
     self._pub1.priority = priority
     self._pub1.publish_soon(msg)
 def _respond_v2(self, priority: pyuavcan.transport.Priority, unique_id: bytes, allocated_node_id: int) -> None:
     msg = NodeIDAllocationData_2(
         node_id=ID(allocated_node_id),
         unique_id=unique_id,
     )
     _logger.info("Publishing allocation response v2: %s", msg)
     self._pub2.priority = priority
     self._pub2.publish_soon(msg)