mcu: Raise a command_error on a command timeout event

Raise a printer.command_error() instead of an mcu.error() if a query
command does not succeed.  That error is less likely to result in an
unhandled exception error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-02-21 22:09:51 -05:00
parent 3fc72da9ae
commit 0bdee6bc04
1 changed files with 6 additions and 4 deletions

View File

@ -358,18 +358,20 @@ class RetryAsyncCommand:
query_time = self.reactor.monotonic() query_time = self.reactor.monotonic()
if query_time > first_query_time + self.TIMEOUT_TIME: if query_time > first_query_time + self.TIMEOUT_TIME:
self.serial.register_response(None, self.name, self.oid) self.serial.register_response(None, self.name, self.oid)
raise error("Timeout on wait for '%s' response" % (self.name,)) raise serialhdl.error("Timeout on wait for '%s' response"
% (self.name,))
self.serial.raw_send(cmd, minclock, minclock, cmd_queue) self.serial.raw_send(cmd, minclock, minclock, cmd_queue)
# Wrapper around query commands # Wrapper around query commands
class CommandQueryWrapper: class CommandQueryWrapper:
def __init__(self, serial, msgformat, respformat, oid=None, def __init__(self, serial, msgformat, respformat, oid=None,
cmd_queue=None, is_async=False): cmd_queue=None, is_async=False, error=serialhdl.error):
self._serial = serial self._serial = serial
self._cmd = serial.get_msgparser().lookup_command(msgformat) self._cmd = serial.get_msgparser().lookup_command(msgformat)
serial.get_msgparser().lookup_command(respformat) serial.get_msgparser().lookup_command(respformat)
self._response = respformat.split()[0] self._response = respformat.split()[0]
self._oid = oid self._oid = oid
self._error = error
self._xmit_helper = serialhdl.SerialRetryCommand self._xmit_helper = serialhdl.SerialRetryCommand
if is_async: if is_async:
self._xmit_helper = RetryAsyncCommand self._xmit_helper = RetryAsyncCommand
@ -383,7 +385,7 @@ class CommandQueryWrapper:
try: try:
return xh.get_response(cmd, self._cmd_queue, minclock, reqclock) return xh.get_response(cmd, self._cmd_queue, minclock, reqclock)
except serialhdl.error as e: except serialhdl.error as e:
raise error(str(e)) raise self._error(str(e))
# Wrapper around command sending # Wrapper around command sending
class CommandWrapper: class CommandWrapper:
@ -688,7 +690,7 @@ class MCU:
def lookup_query_command(self, msgformat, respformat, oid=None, def lookup_query_command(self, msgformat, respformat, oid=None,
cq=None, is_async=False): cq=None, is_async=False):
return CommandQueryWrapper(self._serial, msgformat, respformat, oid, return CommandQueryWrapper(self._serial, msgformat, respformat, oid,
cq, is_async) cq, is_async, self._printer.command_error)
def try_lookup_command(self, msgformat): def try_lookup_command(self, msgformat):
try: try:
return self.lookup_command(msgformat) return self.lookup_command(msgformat)