def main(assist, ipv4_host, port, color, fpv, bci2000, speech, mapl, mapr): try: Console.disable_quick_edit() file = None keyboard = False bci = False listen = None listen_th = None sock = sckt.socket(sckt.AF_INET, sckt.SOCK_DGRAM) sock.connect(('8.8.8.8', 80)) p_ip = sock.getsockname()[0] tcp_c = TCPClient(ipv4_host, port) if tcp_c.join() and input(MSG_READY).lower() == 'y': if bci2000: inbuff = queue.Queue() file = FParse(inbuff) file.read(bci2000) bci = True elif speech: listen = threading.Event() inbuff = queue.Queue() listen_th = threading.Thread(target=speech2txt, args=(inbuff, listen), daemon=True) listen_th.start() else: keyboard = True inbuff = None GameCtrl.init(tcp_c, color, fpv, keyboard, assist, inbuff, file, speech, bci, mapl, mapr, listen) GameCtrl.start() except KeyboardInterrupt: pass if listen_th: listen_th.join(1) print(MSG_CLOSE, flush=True) Console.enable_quick_edit()
Logger.log_game("Shutting down Motion Tracking") if motion_thread is not None: motion_thread.exit_handler() motion_thread.join() Logger.log_game("Shut down Motion Tracking") # GAME Logger.log_game("Shutting down game") if game_thread is not None: game_thread.shutdown() game_thread.join() Logger.log_game("Shut down game") # SPI if useSPI: Logger.log_spi("Shutting down spi-server") if spi_thread is not None: spi_thread.shutdown() spi_thread.join() Logger.log_spi("Shut down spi-server") # TCP-SERVER Logger.log_tcp("Shutting down tcp-server") if tcp_thread is not None: tcp_thread.shutdown() tcp_thread.join() Logger.log_tcp("Shut down tcp-server") Logger.log("Shutting down") exit(0)
class ConnectionManager(QtCore.QObject): result = QtCore.pyqtSignal(bool) def __init__(self, incomming_q, outgoing_q): super(ConnectionManager, self).__init__() self.in_q = incomming_q self.out_q = outgoing_q self.tcpClient = None self.comClient = None def __del__(self): if self.tcpClient is not None: self.tcpClient.join() if self.comClient is not None: self.comClient.join() @QtCore.pyqtSlot() def check(self): if self.tcpClient and not self.tcpClient.isAlive(): self.tcpClient = None Logger.getInstance().error("WiFi connection closed unexpectedly") self.result.emit(False) if self.comClient and not self.comClient.isAlive(): self.comClient = None Logger.getInstance().error("COM connection closed unexpectedly") self.result.emit(False) @QtCore.pyqtSlot(tuple) def connect(self, parameters): self.stopAll() if parameters[0] == "WiFi": try: self.tcpClient = TCPClient( (str(parameters[1]), int(parameters[2])), self.out_q, self.in_q) except Exception as e: self.tcpClient = None Logger.getInstance().error("Cannot start WiFi connection: " + str(e)) else: self.tcpClient.start() Logger.getInstance().info("Connected to WiFi server") elif parameters[0] == "COM": try: self.comClient = COMClient(str(parameters[1]), int(parameters[2]), self.out_q, self.in_q) except Exception as e: self.comClient = None Logger.getInstance().error("Cannot start serial connection: " + str(e)) else: self.comClient.start() Logger.getInstance().info("Connected to COM server") if self.comClient or self.tcpClient: self.result.emit(True) else: self.result.emit(False) @QtCore.pyqtSlot() def setup(self): self.runTimer = QtCore.QTimer() self.runTimer.timeout.connect(self.check) self.runTimer.start(100) def stopAll(self): if self.tcpClient is not None: self.tcpClient.join() self.tcpClient = None Logger.getInstance().info("Stopping TCP Client") if self.comClient is not None: self.comClient.join() self.comClient = None Logger.getInstance().info("Stopping COM Client")