mcu: Shutdown if a spontaneous restart of an mcu is observed

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-03-22 11:46:09 -04:00
parent 0c9eb519ff
commit eeee2a9a35
1 changed files with 8 additions and 3 deletions

View File

@ -444,6 +444,10 @@ class MCU:
if params['#name'] == 'is_shutdown': if params['#name'] == 'is_shutdown':
prefix = "Previous MCU '%s' shutdown: " % (self._name,) prefix = "Previous MCU '%s' shutdown: " % (self._name,)
self._printer.invoke_async_shutdown(prefix + msg + error_help(msg)) self._printer.invoke_async_shutdown(prefix + msg + error_help(msg))
def _handle_starting(self, params):
if not self._is_shutdown:
self._printer.invoke_async_shutdown("MCU '%s' spontaneous restart"
% (self._name,))
# Connection phase # Connection phase
def _check_restart(self, reason): def _check_restart(self, reason):
start_reason = self._printer.get_start_args().get("start_reason") start_reason = self._printer.get_start_args().get("start_reason")
@ -503,15 +507,16 @@ class MCU:
# Calculate config CRC # Calculate config CRC
config_crc = zlib.crc32('\n'.join(self._config_cmds)) & 0xffffffff config_crc = zlib.crc32('\n'.join(self._config_cmds)) & 0xffffffff
self.add_config_cmd("finalize_config crc=%d" % (config_crc,)) self.add_config_cmd("finalize_config crc=%d" % (config_crc,))
if prev_crc is not None and config_crc != prev_crc:
self._check_restart("CRC mismatch")
raise error("MCU '%s' CRC does not match config" % (self._name,))
# Transmit config messages (if needed) # Transmit config messages (if needed)
self.register_response(self._handle_starting, 'starting')
if prev_crc is None: if prev_crc is None:
logging.info("Sending MCU '%s' printer configuration...", logging.info("Sending MCU '%s' printer configuration...",
self._name) self._name)
for c in self._config_cmds: for c in self._config_cmds:
self._serial.send(c) self._serial.send(c)
elif config_crc != prev_crc:
self._check_restart("CRC mismatch")
raise error("MCU '%s' CRC does not match config" % (self._name,))
# Transmit init messages # Transmit init messages
for c in self._init_cmds: for c in self._init_cmds:
self._serial.send(c) self._serial.send(c)