def analyze_message(self, message): self.console.text = ''.join( ('CMD: ', message, '\n', self.console.text)) # GET ================================================================== if message == port_protocol.PortInfo.GET_PORT: return UART.port elif message == port_protocol.PortInfo.GET_PORT_STATE: if self.is_share: return port_protocol.PortState.SHARE elif UART.is_open: return port_protocol.PortState.OPEN else: return port_protocol.PortState.CLOSE # CMD ================================================================== elif message == port_protocol.PortCommand.CMD_OPEN_PORT: if not self.is_share: UART.run() return 'OPEN' else: return 'PORT IS OCCUPIED' ######################################################################## elif message == port_protocol.PortCommand.CMD_CLOSE_PORT: if not self.is_share: UART.stop() return 'STOP' else: return 'PORT IS OCCUPIED' ######################################################################## elif message == port_protocol.PortCommand.CMD_SHARE_PORT: if not self.is_share: self.is_share = True self.uuid = str(uuid1()) UART.stop() return self.uuid else: return 'PORT IS OCCUPIED' ######################################################################## elif port_protocol.PortCommand.CMD_RETURN_PORT in message: if self.is_share: uuid_key = message.split()[-1] if uuid_key == self.uuid: self.is_share = False UART.run() return 'RETURN' else: return 'ERROR' else: return 'ERROR' # ERR ================================================================== else: return 'ERROR'
def baudrate_update(self, baudrate=None, shift=None): if baudrate in BAUDRATE: UART.baudrate = baudrate UART.stop() UART.run() if shift: i = BAUDRATE.index(UART.baudrate) i = 0 if i + 1 >= len(BAUDRATE) else i + 1 UART.baudrate = BAUDRATE[i] UART.stop() UART.run() self.menu.menu_items[-3].text = '[F4] Baudrate ' + str(UART.baudrate)
def key_uart_open(self, event=None): UART.run()
def baudrate_update(self, baudrate=None, shift=None): if baudrate in BAUDRATE: UART.baudrate = baudrate UART.stop() UART.run() if shift: i = BAUDRATE.index(UART.baudrate) i = 0 if i + 1 >= len(BAUDRATE) else i + 1 UART.baudrate = BAUDRATE[i] UART.stop() UART.run() self.menu.menu_items[-3].text = '[F4] Baudrate ' + str(UART.baudrate) def run(self): prompt_toolkit.eventloop.use_asyncio_event_loop() asyncio.get_event_loop().run_until_complete( self.app.run_async().to_asyncio_future()) if __name__ == '__main__': UART.__init__(args.port, args.baudrate, delay=args.delay) UART.run() tui = TUI() server = PortServer(tui.console) asyncio.ensure_future(read(tui.console)) server.run() tui.run()