timestamping suitable for terminal traces
This commit is contained in:
parent
7859bfab0d
commit
ecd436f926
20
time_stamp.py
Normal file
20
time_stamp.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
# Time stamp CAN messages from the serial stream.
|
||||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import io
|
||||
|
||||
def add_timestamp_to_lines():
|
||||
# Ensure stdin is read with a fallback encoding
|
||||
with io.TextIOWrapper(sys.stdin.buffer, encoding='ISO8859-1', errors='replace') as stdin:
|
||||
for line in stdin:
|
||||
if 'CANMSG' in line or 'CMQ' in line:
|
||||
timestamp = datetime.now().strftime("[%Y-%m-%d %H:%M:%S.%f] ")
|
||||
sys.stdout.write(timestamp + line)
|
||||
#else:
|
||||
#sys.stdout.write(line)
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_timestamp_to_lines()
|
Loading…
Reference in New Issue
Block a user