Exemplo n.º 1
0
    def find_serial(self):
        injector_serial, injector_device = next(
            ((path, device) for path, device in find_serial('CP2102').items()
             if (device.hwid or device.device) not in self.initial_devices),
            (None, None),
        )
        if injector_serial:
            self.sleep()
            self.sleep()
            self.sleep()
            self.logger.info("Opening %s", injector_serial)

            try:
                self.injector: Optional[serial.Serial] = serial.Serial(
                    port=injector_serial,
                    baudrate=115200,
                    xonxoff=True,
                    timeout=1)
            except Exception as e:
                self.logger.error("Failed to open, %s", e)
                return

            self.sleep()
            self.sleep()
            self.sleep()
            self.read_config()
Exemplo n.º 2
0
    def __init__(self, mock=False, run=True) -> None:
        super().__init__('injector_node')

        self.command_publisher = messenger.Publisher('/command',
                                                     messenger.Messages.string)

        self.strategy_listener = messenger.Listener('/strategy',
                                                    messenger.Messages.string)
        self.canbus_listener = messenger.Listener('/canbus_message',
                                                  messenger.Messages.string)
        self.settings_listener = messenger.Listener(
            '/settings_changed',
            messenger.Messages.string,
            callback=self.refresh_settings)
        self.recognition_listener = messenger.Listener(
            '/recognition', messenger.Messages.string)

        self.config = ConfigManager.get_value('game')
        self.mock = mock

        self.initial_devices = set(
            (dev.hwid or dev.device) for dev in find_serial('CP2102').values())
        self.logger.info("existing devices %s", list(self.initial_devices))
        self.injector: Optional[serial.Serial] = None

        if run:
            self.loop(3)
Exemplo n.º 3
0
    def __init__(self, mock=False, run=True, silent=True) -> None:
        super().__init__('remoterf',
                         existing_loggers=['remoterf', 'config_manager'])

        self.silent = silent
        self.mock = mock

        path = next(iter(find_serial('FT232R').keys()), None)

        self.ser = serial.Serial(path, timeout=1)
        if run:
            self.run()
Exemplo n.º 4
0
    def try_reconnect(self):
        if self.motor_serial:
            self.motor_serial.close()
        self.motor_serial = None
        while self.motor_serial is None:
            controller_serial = next(iter(find_serial(self.descriptor)), None)
            logger.info("Opening %s", controller_serial)

            if not controller_serial:
                logger.error('Reconnect serial device not found!')
                sleep(1)
                continue

            try:
                self.motor_serial = serial.Serial(
                    port=controller_serial,
                    baudrate=115200, timeout=0.01)
            except Exception as e:
                logger.error('Reconnect failed: %s', e)
                sleep(1)
Exemplo n.º 5
0
    def reconnect(self):
        while True:
            zubax = set(find_serial('zubax').keys())
            if len(zubax) != 1:
                logger.error(f"Zubax controller not determined, {zubax}")
                sleep(1)
                continue

            serial_device = next(iter(zubax), None)
            print(serial_device)
            logger.info(f"Zubax controller determined, {zubax}")
            try:
                self.node: Optional[uavcan.node.Node] = uavcan.make_node(
                    serial_device,
                    node_id=10,
                    bitrate=1000000,
                )

                # setup
                node_monitor = uavcan.app.node_monitor.NodeMonitor(self.node)
                dynamic_node_id_allocator = uavcan.app.dynamic_node_id.CentralizedServer(
                    self.node, node_monitor)

                # Waiting for at least one other node to appear online (our local node is already online).
                while len(
                        dynamic_node_id_allocator.get_allocation_table()) <= 1:
                    logger.error('Waiting for other nodes to become online...')
                    self.node.spin(timeout=1)

                # how fast can we blast this?
                self.node.periodic(0.05, self.update)
                self.node.add_handler(uavcan.equipment.esc.Status, self.listen)
                logger.info('New zubax node: %s', serial_device)
                return
            except Exception as e:
                logger.error("Opening zubax failed %s", e)
                sleep(1)
                continue
Exemplo n.º 6
0
    def try_reconnect(self):
        if self.motor_serial:
            self.motor_serial.close()
        self.motor_serial = None
        for i in range(10):
            if self.motor_serial is not None:
                break
            controller_serial = next(iter(find_serial('CP2102')), None)
            logger.info("Opening %s", controller_serial)

            if not controller_serial:
                logger.error('Reconnect serial device not found!')
                sleep(1)
                continue

            try:
                self.motor_serial = serial.Serial(port=controller_serial,
                                                  baudrate=115200,
                                                  xonxoff=True,
                                                  timeout=0.01)
            except Exception as e:
                logger.error('Reconnect failed: %s', e)
                sleep(1)