@@ -83,6 +83,14 @@ def red_print(message):
83
83
84
84
DEFAULT_TOOLCHAIN_PREFIX = "xtensa-esp32-elf-"
85
85
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
+
86
94
class StoppableThread (object ):
87
95
"""
88
96
Provide a Thread-like class which can be 'cancelled' via a subclass-provided
@@ -218,7 +226,7 @@ class Monitor(object):
218
226
219
227
Main difference is that all event processing happens in the main thread, not the worker threads.
220
228
"""
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' ):
222
230
super (Monitor , self ).__init__ ()
223
231
self .event_queue = queue .Queue ()
224
232
self .console = miniterm .Console ()
@@ -245,6 +253,7 @@ def getkey_patched(self):
245
253
self .toolchain_prefix = toolchain_prefix
246
254
self .menu_key = CTRL_T
247
255
self .exit_key = CTRL_RBRACKET
256
+ self .enable_time = enable_time
248
257
249
258
self .translate_eol = {
250
259
"CRLF" : lambda c : c .replace (b"\n " , b"\r \n " ),
@@ -299,8 +308,13 @@ def handle_serial_input(self, data):
299
308
# this may need to be made more efficient, as it pushes out a byte
300
309
# at a time to the console
301
310
for b in data :
302
- self .console .write_bytes (b )
303
311
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 )
304
318
self .handle_serial_input_line (self ._read_line .strip ())
305
319
self ._read_line = b""
306
320
else :
@@ -466,6 +480,12 @@ def main():
466
480
'elf_file' , help = 'ELF file of application' ,
467
481
type = argparse .FileType ('rb' ))
468
482
483
+ parser .add_argument (
484
+ '--enable-time' ,
485
+ help = 'Serial port device' ,
486
+ default = False
487
+ )
488
+
469
489
args = parser .parse_args ()
470
490
471
491
if args .port .startswith ("/dev/tty." ):
@@ -491,7 +511,7 @@ def main():
491
511
except KeyError :
492
512
pass # not running a make jobserver
493
513
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 )
495
515
496
516
yellow_print ('--- idf_monitor on {p.name} {p.baudrate} ---' .format (
497
517
p = serial_instance ))
0 commit comments