From 1b03bfb3eaf89e99b20835da1d4b199abbbd5882 Mon Sep 17 00:00:00 2001 From: Peter Dragun Date: Thu, 6 Apr 2023 11:48:16 +0200 Subject: [PATCH] feat(monitor): flush terminal detection seq --- tools/idf_monitor_base/constants.py | 3 +++ tools/idf_monitor_base/serial_handler.py | 15 ++++++++++++--- tools/test_idf_monitor/tests/in2f1.txt | 2 +- tools/test_idf_monitor/tests/in2f2.txt | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/idf_monitor_base/constants.py b/tools/idf_monitor_base/constants.py index 139c390d94..4afd5e8756 100644 --- a/tools/idf_monitor_base/constants.py +++ b/tools/idf_monitor_base/constants.py @@ -19,6 +19,9 @@ CTRL_X = '\x18' CTRL_L = '\x0c' CTRL_RBRACKET = '\x1d' # Ctrl+] +# VT100 escape sequences +CONSOLE_STATUS_QUERY = b'\x1b[5n' + # Command parsed from console inputs CMD_STOP = 1 CMD_RESET = 2 diff --git a/tools/idf_monitor_base/serial_handler.py b/tools/idf_monitor_base/serial_handler.py index b3a71f64a2..827cb28f78 100644 --- a/tools/idf_monitor_base/serial_handler.py +++ b/tools/idf_monitor_base/serial_handler.py @@ -16,9 +16,9 @@ from .chip_specific_config import get_chip_config from .console_parser import ConsoleParser, prompt_next_action # noqa: F401 from .console_reader import ConsoleReader # noqa: F401 from .constants import (CMD_APP_FLASH, CMD_ENTER_BOOT, CMD_MAKE, CMD_OUTPUT_TOGGLE, CMD_RESET, CMD_STOP, - CMD_TOGGLE_LOGGING, CMD_TOGGLE_TIMESTAMPS, PANIC_DECODE_DISABLE, PANIC_END, PANIC_IDLE, - PANIC_READING, PANIC_STACK_DUMP, PANIC_START) -from .coredump import CoreDump + CMD_TOGGLE_LOGGING, CMD_TOGGLE_TIMESTAMPS, CONSOLE_STATUS_QUERY, PANIC_DECODE_DISABLE, + PANIC_END, PANIC_IDLE, PANIC_READING, PANIC_STACK_DUMP, PANIC_START) +from .coredump import CoreDump # noqa: F401 from .exceptions import SerialStopException from .gdbhelper import GDBHelper from .line_matcher import LineMatcher @@ -106,6 +106,11 @@ class SerialHandler: self.logger.handle_possible_pc_address_in_line(line) check_gdb_stub_and_run(line) self._force_line_print = False + + if self._last_line_part.startswith(CONSOLE_STATUS_QUERY): + self.logger.print(CONSOLE_STATUS_QUERY) + self._last_line_part = self._last_line_part[len(CONSOLE_STATUS_QUERY):] + # Now we have the last part (incomplete line) in _last_line_part. By # default we don't touch it and just wait for the arrival of the rest # of the line. But after some time when we didn't received it we need @@ -255,6 +260,10 @@ class SerialHandlerNoElf(SerialHandler): self.compare_elf_sha256(line.decode(errors='ignore')) self._force_line_print = False + if self._last_line_part.startswith(CONSOLE_STATUS_QUERY): + self.logger.print(CONSOLE_STATUS_QUERY) + self._last_line_part = self._last_line_part[len(CONSOLE_STATUS_QUERY):] + force_print_or_matched = any(( self._force_line_print, (finalize_line and line_matcher.match(self._last_line_part.decode(errors='ignore'))) diff --git a/tools/test_idf_monitor/tests/in2f1.txt b/tools/test_idf_monitor/tests/in2f1.txt index a1831593ee..fa593b2802 100644 --- a/tools/test_idf_monitor/tests/in2f1.txt +++ b/tools/test_idf_monitor/tests/in2f1.txt @@ -9,7 +9,7 @@ I (793) mdf_device_handle: [mdf_device_init_handle, 908]:silicon revision : 0 I (801) mdf_device_handle: [mdf_device_init_handle, 910]:flash : 4 MB external I (810) mdf_device_handle: [mdf_device_init_handle, 911]:*************************************************** -E (45488) mesh: [esp_mesh_push_to_nwk_queue,5360] null args +E (45488) mesh: [esp_mesh_push_to_nwk_queue,5360] null args I (50495) mdf_device_handle: [mdf_show_sysinfo_timercb, 73]:parent: 00:00:00:00:00:00, mac:30:ae:a4:00:43:84, layer: -1, free heap: 87712, compile time: May 26 2018 00:22:11 I (55495) mdf_device_handle: [mdf_show_sysinfo_timercb, 73]:parent: 20:a6:80:98:dc:b4, mac:30:ae:a4:00:43:84, layer: 1, free heap: 88452, compile time: May 26 2018 00:22:11 I (60495) mdf_device_handle: [mdf_show_sysinfo_timercb, 73]:parent: 20:a6:80:98:dc:b4, mac:30:ae:a4:00:43:84, layer: 1, free heap: 71792, compile time: May 26 2018 00:22:11 diff --git a/tools/test_idf_monitor/tests/in2f2.txt b/tools/test_idf_monitor/tests/in2f2.txt index d9e3880721..f123d93e91 100644 --- a/tools/test_idf_monitor/tests/in2f2.txt +++ b/tools/test_idf_monitor/tests/in2f2.txt @@ -1,5 +1,5 @@ D (318) vfs: esp_vfs_register_fd_range is successful for range <54; 64) and VFS ID 1 -D (59342) vfs: esp_vfs_select starts with nfds = 55 +D (59342) vfs: esp_vfs_select starts with nfds = 55 D (59343) vfs: FDs in readfds = D (59343) vfs: 54 D (59355) vfs: calling socket_select with the following FDs