mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-21 09:05:59 +08:00
feat(tools): Add time information to idf monitor
This commit is contained in:
@ -205,4 +205,10 @@ config MONITOR_BAUD
|
||||
default 2000000 if MONITOR_BAUD_2MB
|
||||
default MONITOR_BAUD_OTHER_VAL if MONITOR_BAUD_OTHER
|
||||
|
||||
config ESPTOOLPY_ENABLE_TIME
|
||||
bool "Enable monitor time information"
|
||||
default n
|
||||
help
|
||||
Enable this option, time string will be added at the head of serial input data line.
|
||||
|
||||
endmenu
|
||||
|
@ -1,11 +1,18 @@
|
||||
# Component support for esptool.py. Doesn't do much by itself,
|
||||
# components have their own flash targets that can use these variables.
|
||||
|
||||
ESPPORT ?= $(CONFIG_ESPTOOLPY_PORT)
|
||||
ESPBAUD ?= $(CONFIG_ESPTOOLPY_BAUD)
|
||||
ESPFLASHMODE ?= $(CONFIG_ESPTOOLPY_FLASHMODE)
|
||||
ESPFLASHFREQ ?= $(CONFIG_ESPTOOLPY_FLASHFREQ)
|
||||
ESPFLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE)
|
||||
|
||||
ifdef CONFIG_ESPTOOLPY_ENABLE_TIME
|
||||
ENABLE_TIME := y
|
||||
else
|
||||
ENABLE_TIME := n
|
||||
endif
|
||||
|
||||
CONFIG_ESPTOOLPY_COMPRESSED ?=
|
||||
|
||||
PYTHON ?= $(call dequote,$(CONFIG_PYTHON))
|
||||
@ -92,7 +99,7 @@ endif
|
||||
simple_monitor: $(call prereq_if_explicit,%flash)
|
||||
$(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw $(ESPPORT) $(MONITORBAUD)
|
||||
|
||||
MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_TOOLPREFIX) --make "$(MAKE)"
|
||||
MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_TOOLPREFIX) --make "$(MAKE)" --enable-time $(ENABLE_TIME)
|
||||
|
||||
monitor: $(call prereq_if_explicit,%flash)
|
||||
$(summary) MONITOR
|
||||
|
@ -83,6 +83,14 @@ MATCH_PCADDR = re.compile(r'0x4[0-9a-f]{7}', re.IGNORECASE)
|
||||
|
||||
DEFAULT_TOOLCHAIN_PREFIX = "xtensa-esp32-elf-"
|
||||
|
||||
def get_time_stamp():
|
||||
ct = time.time()
|
||||
local_time = time.localtime(ct)
|
||||
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
|
||||
data_secs = (ct - long(ct)) * 1000
|
||||
time_stamp = "%s.%03d" % (data_head, data_secs)
|
||||
return time_stamp
|
||||
|
||||
class StoppableThread(object):
|
||||
"""
|
||||
Provide a Thread-like class which can be 'cancelled' via a subclass-provided
|
||||
@ -218,7 +226,7 @@ class Monitor(object):
|
||||
|
||||
Main difference is that all event processing happens in the main thread, not the worker threads.
|
||||
"""
|
||||
def __init__(self, serial_instance, elf_file, make="make", toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX, eol="CRLF"):
|
||||
def __init__(self, serial_instance, elf_file, make="make", toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX, eol="CRLF", enable_time='n'):
|
||||
super(Monitor, self).__init__()
|
||||
self.event_queue = queue.Queue()
|
||||
self.console = miniterm.Console()
|
||||
@ -245,6 +253,7 @@ class Monitor(object):
|
||||
self.toolchain_prefix = toolchain_prefix
|
||||
self.menu_key = CTRL_T
|
||||
self.exit_key = CTRL_RBRACKET
|
||||
self.enable_time = enable_time
|
||||
|
||||
self.translate_eol = {
|
||||
"CRLF": lambda c: c.replace(b"\n", b"\r\n"),
|
||||
@ -299,8 +308,13 @@ class Monitor(object):
|
||||
# this may need to be made more efficient, as it pushes out a byte
|
||||
# at a time to the console
|
||||
for b in data:
|
||||
self.console.write_bytes(b)
|
||||
if b == b'\n': # end of line
|
||||
self._read_line += '\n'
|
||||
if self.enable_time == 'y':
|
||||
s_out = get_time_stamp() + ": " + self._read_line
|
||||
else:
|
||||
s_out = self._read_line
|
||||
self.console.write_bytes(s_out)
|
||||
self.handle_serial_input_line(self._read_line.strip())
|
||||
self._read_line = b""
|
||||
else:
|
||||
@ -466,6 +480,12 @@ def main():
|
||||
'elf_file', help='ELF file of application',
|
||||
type=argparse.FileType('rb'))
|
||||
|
||||
parser.add_argument(
|
||||
'--enable-time',
|
||||
help='Serial port device',
|
||||
default=False
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.port.startswith("/dev/tty."):
|
||||
@ -491,7 +511,7 @@ def main():
|
||||
except KeyError:
|
||||
pass # not running a make jobserver
|
||||
|
||||
monitor = Monitor(serial_instance, args.elf_file.name, args.make, args.toolchain_prefix, args.eol)
|
||||
monitor = Monitor(serial_instance, args.elf_file.name, args.make, args.toolchain_prefix, args.eol, args.enable_time)
|
||||
|
||||
yellow_print('--- idf_monitor on {p.name} {p.baudrate} ---'.format(
|
||||
p=serial_instance))
|
||||
|
Reference in New Issue
Block a user