From 4bf1b042b1accc234db81b2c50079a2d3dbab31f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 16 May 2018 09:27:50 -0400 Subject: [PATCH] console: Report timestamp on each read message Signed-off-by: Kevin O'Connor --- klippy/console.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/klippy/console.py b/klippy/console.py index 59dffc59..01272828 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -33,6 +33,7 @@ class KeyboardReader: def __init__(self, ser, reactor): self.ser = ser self.reactor = reactor + self.start_time = reactor.monotonic() self.clocksync = clocksync.ClockSync(self.reactor) self.fd = sys.stdin.fileno() util.set_nonblock(self.fd) @@ -60,6 +61,7 @@ class KeyboardReader: ["%s=%s" % (k, v) for k, v in msgparser.config.items()]))) self.clocksync.connect(self.ser) self.ser.handle_default = self.handle_default + self.ser.register_callback(self.handle_output, '#output') self.mcu_freq = msgparser.get_constant_float('CLOCK_FREQ') mcu_type = msgparser.get_constant('MCU') self.pins = pins.PinResolver(mcu_type, validate_aliases=False) @@ -70,7 +72,12 @@ class KeyboardReader: sys.stdout.write("%s\n" % (msg,)) sys.stdout.flush() def handle_default(self, params): - self.output(self.ser.msgparser.format_params(params)) + tdiff = params['#receive_time'] - self.start_time + self.output("%07.3f: %s" % ( + tdiff, self.ser.msgparser.format_params(params))) + def handle_output(self, params): + tdiff = params['#receive_time'] - self.start_time + self.output("%07.3f: %s: %s" % (tdiff, params['#name'], params['#msg'])) def handle_suppress(self, params): pass def update_evals(self, eventtime):