Esempio n. 1
0
    def __init__(self,
                 serial_instance,
                 elf_file,
                 make="make",
                 toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,
                 eol="CRLF"):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(
                self.console.byte_output)

        self.serial = serial_instance
        self.console_reader = ConsoleReader(self.console, self.event_queue)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        self.make = make
        self.toolchain_prefix = toolchain_prefix
        self.menu_key = CTRL_T
        self.exit_key = CTRL_RBRACKET

        self.translate_eol = {
            "CRLF": lambda c: c.replace(b"\n", b"\r\n"),
            "CR": lambda c: c.replace(b"\n", b"\r"),
            "LF": lambda c: c.replace(b"\r", b"\n"),
        }[eol]

        # internal state
        self._pressed_menu_key = False
        self._read_line = b""
        self._gdb_buffer = b""
Esempio n. 2
0
    def __init__(self,
                 serial_instance,
                 elf_file,
                 print_filter,
                 make="make",
                 encrypted=False,
                 toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,
                 eol="CRLF"):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.cmd_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr, decode_output=True)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(
                self.console.byte_output)

        if StrictVersion(serial.VERSION) < StrictVersion('3.3.0'):
            # Use Console.getkey implementation from 3.3.0 (to be in sync with the ConsoleReader._cancel patch above)
            def getkey_patched(self):
                c = self.enc_stdin.read(1)
                if c == chr(0x7f):
                    c = chr(
                        8)  # map the BS key (which yields DEL) to backspace
                return c

            self.console.getkey = types.MethodType(getkey_patched,
                                                   self.console)

        socket_mode = serial_instance.port.startswith(
            "socket://"
        )  # testing hook - data from serial can make exit the monitor
        self.serial = serial_instance
        self.console_parser = ConsoleParser(eol)
        self.console_reader = ConsoleReader(self.console, self.event_queue,
                                            self.cmd_queue,
                                            self.console_parser, socket_mode)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        if not os.path.exists(make):
            self.make = shlex.split(
                make
            )  # allow for possibility the "make" arg is a list of arguments (for idf.py)
        else:
            self.make = make
        self.encrypted = encrypted
        self.toolchain_prefix = toolchain_prefix

        # internal state
        self._last_line_part = b""
        self._gdb_buffer = b""
        self._pc_address_buffer = b""
        self._line_matcher = LineMatcher(print_filter)
        self._invoke_processing_last_line_timer = None
        self._force_line_print = False
        self._output_enabled = True
        self._serial_check_exit = socket_mode
        self._log_file = None
Esempio n. 3
0
    def __init__(
            self,
            serial_instance,  # type: serial.Serial
            elf_file,  # type: str
            print_filter,  # type: str
            make='make',  # type: str
            encrypted=False,  # type: bool
            toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,  # type: str
            eol='CRLF',  # type: str
            decode_coredumps=COREDUMP_DECODE_INFO,  # type: str
            decode_panic=PANIC_DECODE_DISABLE,  # type: str
            target='esp32',  # type: str
            websocket_client=None,  # type: WebSocketClient
            enable_address_decoding=True,  # type: bool
            timestamps=False,  # type: bool
            timestamp_format=''  # type: str
    ):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()  # type: queue.Queue
        self.cmd_queue = queue.Queue()  # type: queue.Queue
        self.console = miniterm.Console()

        sys.stderr = get_converter(sys.stderr, decode_output=True)
        self.console.output = get_converter(self.console.output)
        self.console.byte_output = get_converter(self.console.byte_output)

        # testing hook - data from serial can make exit the monitor
        socket_mode = serial_instance.port.startswith('socket://')
        self.serial = serial_instance

        self.console_parser = ConsoleParser(eol)
        self.console_reader = ConsoleReader(self.console, self.event_queue,
                                            self.cmd_queue,
                                            self.console_parser, socket_mode)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file

        # allow for possibility the "make" arg is a list of arguments (for idf.py)
        self.make = make if os.path.exists(make) else shlex.split(
            make)  # type: Any[Union[str, List[str]], str]
        self.target = target

        self._line_matcher = LineMatcher(print_filter)
        self.gdb_helper = GDBHelper(toolchain_prefix, websocket_client,
                                    self.elf_file, self.serial.port,
                                    self.serial.baudrate)
        self.logger = Logger(self.elf_file, self.console, timestamps,
                             timestamp_format, b'', enable_address_decoding,
                             toolchain_prefix)
        self.coredump = CoreDump(decode_coredumps, self.event_queue,
                                 self.logger, websocket_client, self.elf_file)
        self.serial_handler = SerialHandler(b'', socket_mode, self.logger,
                                            decode_panic, PANIC_IDLE, b'',
                                            target, False, False, self.serial,
                                            encrypted)

        # internal state
        self._invoke_processing_last_line_timer = None  # type: Optional[threading.Timer]
Esempio n. 4
0
    def __init__(self,
                 serial_instance,
                 elf_file,
                 print_filter,
                 make="make",
                 toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,
                 eol="CRLF"):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr, decode_output=True)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(
                self.console.byte_output)

        if StrictVersion(serial.VERSION) < StrictVersion('3.3.0'):
            # Use Console.getkey implementation from 3.3.0 (to be in sync with the ConsoleReader._cancel patch above)
            def getkey_patched(self):
                c = self.enc_stdin.read(1)
                if c == chr(0x7f):
                    c = chr(
                        8)  # map the BS key (which yields DEL) to backspace
                return c

            self.console.getkey = types.MethodType(getkey_patched,
                                                   self.console)

        socket_mode = serial_instance.port.startswith(
            "socket://"
        )  # testing hook - data from serial can make exit the monitor
        self.serial = serial_instance
        self.console_reader = ConsoleReader(self.console, self.event_queue,
                                            socket_mode)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        self.make = make
        self.toolchain_prefix = toolchain_prefix
        self.menu_key = CTRL_T
        self.exit_key = CTRL_RBRACKET

        self.translate_eol = {
            "CRLF": lambda c: c.replace("\n", "\r\n"),
            "CR": lambda c: c.replace("\n", "\r"),
            "LF": lambda c: c.replace("\r", "\n"),
        }[eol]

        # internal state
        self._pressed_menu_key = False
        self._last_line_part = b""
        self._gdb_buffer = b""
        self._pc_address_buffer = b""
        self._line_matcher = LineMatcher(print_filter)
        self._invoke_processing_last_line_timer = None
        self._force_line_print = False
        self._output_enabled = True
        self._serial_check_exit = socket_mode
Esempio n. 5
0
    def __init__(self,
                 serial_instance,
                 elf_file,
                 print_filter,
                 make="make",
                 toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,
                 eol="CRLF"):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(
                self.console.byte_output)

        if StrictVersion(serial.VERSION) < StrictVersion('3.3.0'):
            # Use Console.getkey implementation from 3.3.0 (to be in sync with the ConsoleReader._cancel patch above)
            def getkey_patched(self):
                c = self.enc_stdin.read(1)
                if c == unichr(0x7f):
                    c = unichr(
                        8)  # map the BS key (which yields DEL) to backspace
                return c

            self.console.getkey = types.MethodType(getkey_patched,
                                                   self.console)

        self.serial = serial_instance
        self.console_reader = ConsoleReader(self.console, self.event_queue)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        if not os.path.exists(make):
            self.make = shlex.split(
                make
            )  # allow for possibility the "make" arg is a list of arguments (for idf.py)
        else:
            self.make = make
        self.toolchain_prefix = toolchain_prefix
        self.menu_key = CTRL_T
        self.exit_key = CTRL_RBRACKET

        self.translate_eol = {
            "CRLF": lambda c: c.replace(b"\n", b"\r\n"),
            "CR": lambda c: c.replace(b"\n", b"\r"),
            "LF": lambda c: c.replace(b"\r", b"\n"),
        }[eol]

        # internal state
        self._pressed_menu_key = False
        self._last_line_part = b""
        self._gdb_buffer = b""
        self._pc_address_buffer = b""
        self._line_matcher = LineMatcher(print_filter)
        self._invoke_processing_last_line_timer = None
        self._force_line_print = False
        self._output_enabled = True
Esempio n. 6
0
    def __init__(self,
                 serial_instance,
                 elf_file,
                 make="make",
                 toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,
                 eol="CRLF",
                 enable_time='n',
                 enable_savelog='n'):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(
                self.console.byte_output)

        if StrictVersion(serial.VERSION) < StrictVersion('3.3.0'):
            # Use Console.getkey implementation from 3.3.0 (to be in sync with the ConsoleReader._cancel patch above)
            def getkey_patched(self):
                c = self.enc_stdin.read(1)
                if c == unichr(0x7f):
                    c = unichr(
                        8)  # map the BS key (which yields DEL) to backspace
                return c

            self.console.getkey = types.MethodType(getkey_patched,
                                                   self.console)

        self.serial = serial_instance
        self.console_reader = ConsoleReader(self.console, self.event_queue)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        self.make = make
        self.toolchain_prefix = toolchain_prefix
        self.menu_key = CTRL_T
        self.exit_key = CTRL_RBRACKET
        self.enable_time = enable_time
        self.enable_savelog = enable_savelog
        self.next_line = True
        if self.enable_savelog == 'y':
            self.log_file = esp_openlog(
                os.path.splitext(os.path.basename(self.elf_file))[0])

        self.translate_eol = {
            "CRLF": lambda c: c.replace(b"\n", b"\r\n"),
            "CR": lambda c: c.replace(b"\n", b"\r"),
            "LF": lambda c: c.replace(b"\r", b"\n"),
        }[eol]

        # internal state
        self._pressed_menu_key = False
        self._read_line = b""
        self._gdb_buffer = b""
Esempio n. 7
0
    def __init__(self, serial_instance, elf_file, make="make", toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX, eol="CRLF"):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(self.console.byte_output)

        if StrictVersion(serial.VERSION) < StrictVersion('3.3.0'):
            # Use Console.getkey implementation from 3.3.0 (to be in sync with the ConsoleReader._cancel patch above)
            def getkey_patched(self):
                c = self.enc_stdin.read(1)
                if c == unichr(0x7f):
                    c = unichr(8)    # map the BS key (which yields DEL) to backspace
                return c

            self.console.getkey = types.MethodType(getkey_patched, self.console)

        self.serial = serial_instance
        self.console_reader = ConsoleReader(self.console, self.event_queue)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        self.make = make
        self.toolchain_prefix = toolchain_prefix
        self.menu_key = CTRL_T
        self.exit_key = CTRL_RBRACKET

        self.log_converter = LogConverter()
        try:
            file_name = 'log_text.json'
            if not os.path.isfile(file_name):
                self.console.write('Cannot find file log_text.json')
            else:
                self.log_converter.LoadJson(file_name)
        except:
            self.console.write("CWD: " + os.getcwd() + '\n')
            self.console.write('\nFailed to load log_text.json. LogConverter unavailable\n')

        self.translate_eol = {
            "CRLF": lambda c: c.replace(b"\n", b"\r\n"),
            "CR":   lambda c: c.replace(b"\n", b"\r"),
            "LF":   lambda c: c.replace(b"\r", b"\n"),
        }[eol]

        # internal state
        self._pressed_menu_key = False
        self._read_line = b""
        self._gdb_buffer = b""
Esempio n. 8
0
    def __init__(self, serial_instance, eol="CRLF", send_data=b'None', test_algorithms=[P.ALGO_TEST], send_data_byte_size = 2):
        super(FadMonitor, self).__init__()
        self.event_queue = queue.Queue()
        self.cmd_queue = queue.Queue()
        self.console = miniterm.Console() 

        self.serial = serial_instance
        self.console_parser = ConsoleParser(eol)
        self.console_reader = com_tools.ConsoleReader(self.console, self.event_queue, self.cmd_queue, self.console_parser)
        self.serial_reader = com_tools.SerialReader(self.serial, self.event_queue)
        self.packet_handler = FadSerialPacketHandler(send_data, test_algorithms, send_data_byte_size)

        self._last_line_part = b''
        self._invoke_processing_last_line_timer = None
        self._receiving_packet = False
        self._packet_buffer = b''
Esempio n. 9
0
    def __init__(self, serial_instance, elf_file, make="make"):
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()
        self.console = miniterm.Console()
        if os.name == 'nt':
            sys.stderr = ANSIColorConverter(sys.stderr)
            self.console.output = ANSIColorConverter(self.console.output)
            self.console.byte_output = ANSIColorConverter(
                self.console.byte_output)

        self.serial = serial_instance
        self.console_reader = ConsoleReader(self.console, self.event_queue)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        self.make = make
        self.menu_key = CTRL_T
        self.exit_key = CTRL_RBRACKET

        # internal state
        self._pressed_menu_key = False
        self._read_line = b""
        self._gdb_buffer = b""
Esempio n. 10
0
    def __init__(self,
                 serial_instance,
                 elf_file,
                 print_filter,
                 make='make',
                 encrypted=False,
                 toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,
                 eol='CRLF',
                 decode_coredumps=COREDUMP_DECODE_INFO,
                 decode_panic=PANIC_DECODE_DISABLE,
                 target='esp32',
                 websocket_client=None,
                 enable_address_decoding=True):
        # type: (serial.Serial, str, str, str, bool, str, str, str, str, str, WebSocketClient, bool) -> None
        super(Monitor, self).__init__()
        self.event_queue = queue.Queue()  # type: queue.Queue
        self.cmd_queue = queue.Queue()  # type: queue.Queue
        self.console = miniterm.Console()
        self.enable_address_decoding = enable_address_decoding

        sys.stderr = get_converter(sys.stderr, decode_output=True)
        self.console.output = get_converter(self.console.output)
        self.console.byte_output = get_converter(self.console.byte_output)

        socket_mode = serial_instance.port.startswith(
            'socket://'
        )  # testing hook - data from serial can make exit the monitor
        self.serial = serial_instance

        self.console_parser = ConsoleParser(eol)
        self.console_reader = ConsoleReader(self.console, self.event_queue,
                                            self.cmd_queue,
                                            self.console_parser, socket_mode)
        self.serial_reader = SerialReader(self.serial, self.event_queue)
        self.elf_file = elf_file
        if not os.path.exists(make):
            # allow for possibility the "make" arg is a list of arguments (for idf.py)
            self.make = shlex.split(make)  # type: Union[str, List[str]]
        else:
            self.make = make
        self.encrypted = encrypted
        self.toolchain_prefix = toolchain_prefix
        self.websocket_client = websocket_client
        self.target = target

        # internal state
        self._last_line_part = b''
        self._gdb_buffer = b''
        self._pc_address_buffer = b''
        self._line_matcher = LineMatcher(print_filter)
        self._invoke_processing_last_line_timer = None  # type: Optional[threading.Timer]
        self._force_line_print = False
        self._output_enabled = True
        self._serial_check_exit = socket_mode
        self._log_file = None  # type: Optional[BinaryIO]
        self._decode_coredumps = decode_coredumps
        self._reading_coredump = COREDUMP_IDLE
        self._coredump_buffer = b''
        self._decode_panic = decode_panic
        self._reading_panic = PANIC_IDLE
        self._panic_buffer = b''
Esempio n. 11
0
    def __init__(
            self,
            serial_instance,  # type: serial.Serial
            elf_file,  # type: str
            print_filter,  # type: str
            make='make',  # type: str
            encrypted=False,  # type: bool
            reset=True,  # type: bool
            toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX,  # type: str
            eol='CRLF',  # type: str
            decode_coredumps=COREDUMP_DECODE_INFO,  # type: str
            decode_panic=PANIC_DECODE_DISABLE,  # type: str
            target='esp32',  # type: str
            websocket_client=None,  # type: Optional[WebSocketClient]
            enable_address_decoding=True,  # type: bool
            timestamps=False,  # type: bool
            timestamp_format='',  # type: str
            force_color=False  # type: bool
    ):
        self.event_queue = queue.Queue()  # type: queue.Queue
        self.cmd_queue = queue.Queue()  # type: queue.Queue
        self.console = miniterm.Console()
        # if the variable is set ANSI will be printed even if we do not print to terminal
        sys.stderr = get_converter(sys.stderr,
                                   decode_output=True,
                                   force_color=force_color)
        self.console.output = get_converter(self.console.output,
                                            force_color=force_color)
        self.console.byte_output = get_converter(self.console.byte_output,
                                                 force_color=force_color)

        self.elf_file = elf_file or ''
        self.elf_exists = os.path.exists(self.elf_file)
        self.logger = Logger(self.elf_file, self.console, timestamps,
                             timestamp_format, b'', enable_address_decoding,
                             toolchain_prefix)

        self.coredump = CoreDump(decode_coredumps, self.event_queue,
                                 self.logger, websocket_client,
                                 self.elf_file) if self.elf_exists else None

        # allow for possibility the "make" arg is a list of arguments (for idf.py)
        self.make = make if os.path.exists(make) else shlex.split(
            make)  # type: Any[Union[str, List[str]], str]
        self.target = target

        # testing hook - data from serial can make exit the monitor
        if isinstance(self, SerialMonitor):
            socket_mode = serial_instance.port.startswith('socket://')
            self.serial = serial_instance
            self.serial_reader = SerialReader(self.serial, self.event_queue,
                                              reset)

            self.gdb_helper = GDBHelper(
                toolchain_prefix, websocket_client, self.elf_file,
                self.serial.port,
                self.serial.baudrate) if self.elf_exists else None

        else:
            socket_mode = False
            self.serial = subprocess.Popen([self.elf_file],
                                           stdin=subprocess.PIPE,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.STDOUT)
            self.serial_reader = LinuxReader(self.serial, self.event_queue)

            self.gdb_helper = None

        cls = SerialHandler if self.elf_exists else SerialHandlerNoElf
        self.serial_handler = cls(b'', socket_mode, self.logger, decode_panic,
                                  PANIC_IDLE, b'', target, False, False,
                                  self.serial, encrypted, reset, self.elf_file)

        self.console_parser = ConsoleParser(eol)
        self.console_reader = ConsoleReader(self.console, self.event_queue,
                                            self.cmd_queue,
                                            self.console_parser, socket_mode)

        self._line_matcher = LineMatcher(print_filter)

        # internal state
        self._invoke_processing_last_line_timer = None  # type: Optional[threading.Timer]