From 461ed4cb80ad23f7395621fbe6010d9ac9a7aaa5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 20 Jun 2019 22:08:38 -0400 Subject: [PATCH] serialhdl: Add a get_msgparser() method Signed-off-by: Kevin O'Connor --- klippy/console.py | 8 ++++---- klippy/mcu.py | 14 +++++++------- klippy/serialhdl.py | 2 ++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/klippy/console.py b/klippy/console.py index dfb4262f..1610c4d0 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -53,7 +53,7 @@ class KeyboardReader: self.output(help_txt) self.output("="*20 + " attempting to connect " + "="*20) self.ser.connect() - msgparser = self.ser.msgparser + msgparser = self.ser.get_msgparser() self.output("Loaded %d commands (%s / %s)" % ( len(msgparser.messages_by_id), msgparser.version, msgparser.build_versions)) @@ -72,8 +72,8 @@ class KeyboardReader: sys.stdout.flush() def handle_default(self, params): tdiff = params['#receive_time'] - self.start_time - self.output("%07.3f: %s" % ( - tdiff, self.ser.msgparser.format_params(params))) + msg = self.ser.get_msgparser().format_params(params) + self.output("%07.3f: %s" % (tdiff, msg)) def handle_output(self, params): tdiff = params['#receive_time'] - self.start_time self.output("%07.3f: %s: %s" % (tdiff, params['#name'], params['#msg'])) @@ -137,7 +137,7 @@ class KeyboardReader: self.clocksync.stats(curtime)])) def command_LIST(self, parts): self.update_evals(self.reactor.monotonic()) - mp = self.ser.msgparser + mp = self.ser.get_msgparser() out = "Available mcu commands:" out += "\n ".join([""] + sorted([ mp.messages_by_id[i].msgformat for i in mp.command_ids])) diff --git a/klippy/mcu.py b/klippy/mcu.py index ff8ed23b..cb07658f 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -544,7 +544,7 @@ class MCU: self._config_cmds.insert(0, "allocate_oids count=%d" % ( self._oid_count,)) # Resolve pin names - mcu_type = self._serial.msgparser.get_constant('MCU') + mcu_type = self._serial.get_msgparser().get_constant('MCU') ppins = self._printer.lookup_object('pins') reserved_pins = ppins.get_reserved_pins(self._name) pin_resolver = pins.PinResolver(mcu_type, reserved_pins) @@ -616,7 +616,7 @@ class MCU: self._check_restart("enable power") self._serial.connect() self._clocksync.connect(self._serial) - msgparser = self._serial.msgparser + msgparser = self._serial.get_msgparser() name = self._name log_info = [ "Loaded MCU '%s' %d commands (%s / %s)" % ( @@ -689,16 +689,16 @@ class MCU: def try_lookup_command(self, msgformat): try: return self.lookup_command(msgformat) - except self._serial.msgparser.error as e: + except self._serial.get_msgparser().error as e: return None def lookup_command_id(self, msgformat): - return self._serial.msgparser.lookup_command(msgformat).msgid + return self._serial.get_msgparser().lookup_command(msgformat).msgid def get_enumerations(self): - return self._serial.msgparser.get_enumerations() + return self._serial.get_msgparser().get_enumerations() def get_constants(self): - return self._serial.msgparser.get_constants() + return self._serial.get_msgparser().get_constants() def get_constant_float(self, name): - return self._serial.msgparser.get_constant_float(name) + return self._serial.get_msgparser().get_constant_float(name) def print_time_to_clock(self, print_time): return self._clocksync.print_time_to_clock(print_time) def clock_to_print_time(self, clock): diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index e0548e37..82748b70 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -116,6 +116,8 @@ class SerialReader: self.ffi_lib.serialqueue_get_stats( self.serialqueue, self.stats_buf, len(self.stats_buf)) return self.ffi_main.string(self.stats_buf) + def get_msgparser(self): + return self.msgparser # Serial response callbacks def register_response(self, callback, name, oid=None): with self.lock: