diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-06-21 19:35:34 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-06-21 21:42:20 -0400 |
commit | e202a8802b31495622a47178459481540f314b7c (patch) | |
tree | 3f44e6c7412ab8f07836f8583dc267b52d426b71 /klippy/mcu.py | |
parent | cc3666aa78d76b17c2c2292d409f90acfb2b976b (diff) | |
download | kutter-e202a8802b31495622a47178459481540f314b7c.tar.gz kutter-e202a8802b31495622a47178459481540f314b7c.tar.xz kutter-e202a8802b31495622a47178459481540f314b7c.zip |
mcu: Move SerialCommand from serialhdl.py to mcu.py
Move the serial command wrapper class from serialhdl.py to mcu.py.
This will allow that class to better support higher level
functionality.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/mcu.py')
-rw-r--r-- | klippy/mcu.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py index 2facba0a..b10a9c99 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -424,6 +424,25 @@ class MCU_adc: if self._callback is not None: self._callback(last_read_time, last_value) +# Wrapper around command sending +class CommandWrapper: + def __init__(self, mcu, serial, cmd, cmd_queue): + self._mcu = mcu + self._serial = serial + self._cmd = cmd + self._cmd_queue = cmd_queue + def send(self, data=(), minclock=0, reqclock=0): + cmd = self._cmd.encode(data) + self._serial.raw_send(cmd, minclock, reqclock, self._cmd_queue) + def send_with_response(self, data=(), response=None, response_oid=None): + cmd = self._cmd.encode(data) + try: + src = serialhdl.SerialRetryCommand(self._serial, cmd, + response, response_oid) + return src.get_response() + except serialhdl.error as e: + raise error(str(e)) + class MCU: error = error def __init__(self, config, clocksync): @@ -688,7 +707,10 @@ class MCU: def alloc_command_queue(self): return self._serial.alloc_command_queue() def lookup_command(self, msgformat, cq=None): - return self._serial.lookup_command(msgformat, cq) + if cq is None: + cq = self._serial.get_default_command_queue() + cmd = self._serial.get_msgparser().lookup_command(msgformat) + return CommandWrapper(self, self._serial, cmd, cq) def try_lookup_command(self, msgformat): try: return self.lookup_command(msgformat) |