Skip to content

Commit e0a3a60

Browse files
committed
Merge branch 'feature/add_time_info_to_idf_monitor' into 'master'
Add time information to idf monitor See merge request sdk/ESP8266_RTOS_SDK!358
2 parents a53f016 + f6db55c commit e0a3a60

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

components/esptool_py/Kconfig.projbuild

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,10 @@ config MONITOR_BAUD
205205
default 2000000 if MONITOR_BAUD_2MB
206206
default MONITOR_BAUD_OTHER_VAL if MONITOR_BAUD_OTHER
207207

208+
config ESPTOOLPY_ENABLE_TIME
209+
bool "Enable monitor time information"
210+
default n
211+
help
212+
Enable this option, time string will be added at the head of serial input data line.
213+
208214
endmenu

components/esptool_py/Makefile.projbuild

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# Component support for esptool.py. Doesn't do much by itself,
22
# components have their own flash targets that can use these variables.
3+
34
ESPPORT ?= $(CONFIG_ESPTOOLPY_PORT)
45
ESPBAUD ?= $(CONFIG_ESPTOOLPY_BAUD)
56
ESPFLASHMODE ?= $(CONFIG_ESPTOOLPY_FLASHMODE)
67
ESPFLASHFREQ ?= $(CONFIG_ESPTOOLPY_FLASHFREQ)
78
ESPFLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE)
89

10+
ifdef CONFIG_ESPTOOLPY_ENABLE_TIME
11+
ENABLE_TIME := y
12+
else
13+
ENABLE_TIME := n
14+
endif
15+
916
CONFIG_ESPTOOLPY_COMPRESSED ?=
1017

1118
PYTHON ?= $(call dequote,$(CONFIG_PYTHON))
@@ -92,7 +99,7 @@ endif
9299
simple_monitor: $(call prereq_if_explicit,%flash)
93100
$(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw $(ESPPORT) $(MONITORBAUD)
94101

95-
MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_TOOLPREFIX) --make "$(MAKE)"
102+
MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_TOOLPREFIX) --make "$(MAKE)" --enable-time $(ENABLE_TIME)
96103

97104
monitor: $(call prereq_if_explicit,%flash)
98105
$(summary) MONITOR

tools/idf_monitor.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def red_print(message):
8383

8484
DEFAULT_TOOLCHAIN_PREFIX = "xtensa-esp32-elf-"
8585

86+
def get_time_stamp():
87+
ct = time.time()
88+
local_time = time.localtime(ct)
89+
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
90+
data_secs = (ct - long(ct)) * 1000
91+
time_stamp = "%s.%03d" % (data_head, data_secs)
92+
return time_stamp
93+
8694
class StoppableThread(object):
8795
"""
8896
Provide a Thread-like class which can be 'cancelled' via a subclass-provided
@@ -218,7 +226,7 @@ class Monitor(object):
218226
219227
Main difference is that all event processing happens in the main thread, not the worker threads.
220228
"""
221-
def __init__(self, serial_instance, elf_file, make="make", toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX, eol="CRLF"):
229+
def __init__(self, serial_instance, elf_file, make="make", toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX, eol="CRLF", enable_time='n'):
222230
super(Monitor, self).__init__()
223231
self.event_queue = queue.Queue()
224232
self.console = miniterm.Console()
@@ -245,6 +253,7 @@ def getkey_patched(self):
245253
self.toolchain_prefix = toolchain_prefix
246254
self.menu_key = CTRL_T
247255
self.exit_key = CTRL_RBRACKET
256+
self.enable_time = enable_time
248257

249258
self.translate_eol = {
250259
"CRLF": lambda c: c.replace(b"\n", b"\r\n"),
@@ -299,8 +308,13 @@ def handle_serial_input(self, data):
299308
# this may need to be made more efficient, as it pushes out a byte
300309
# at a time to the console
301310
for b in data:
302-
self.console.write_bytes(b)
303311
if b == b'\n': # end of line
312+
self._read_line += '\n'
313+
if self.enable_time == 'y':
314+
s_out = get_time_stamp() + ": " + self._read_line
315+
else:
316+
s_out = self._read_line
317+
self.console.write_bytes(s_out)
304318
self.handle_serial_input_line(self._read_line.strip())
305319
self._read_line = b""
306320
else:
@@ -466,6 +480,12 @@ def main():
466480
'elf_file', help='ELF file of application',
467481
type=argparse.FileType('rb'))
468482

483+
parser.add_argument(
484+
'--enable-time',
485+
help='Serial port device',
486+
default=False
487+
)
488+
469489
args = parser.parse_args()
470490

471491
if args.port.startswith("/dev/tty."):
@@ -491,7 +511,7 @@ def main():
491511
except KeyError:
492512
pass # not running a make jobserver
493513

494-
monitor = Monitor(serial_instance, args.elf_file.name, args.make, args.toolchain_prefix, args.eol)
514+
monitor = Monitor(serial_instance, args.elf_file.name, args.make, args.toolchain_prefix, args.eol, args.enable_time)
495515

496516
yellow_print('--- idf_monitor on {p.name} {p.baudrate} ---'.format(
497517
p=serial_instance))

0 commit comments

Comments
 (0)