mcu: Raise config_error (not protocol error) on pin enumeration errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
31fcd491fd
commit
ecbfa76242
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import sys, os, zlib, logging, math
|
import sys, os, zlib, logging, math
|
||||||
import serialhdl, pins, chelper, clocksync
|
import serialhdl, msgproto, pins, chelper, clocksync
|
||||||
|
|
||||||
class error(Exception):
|
class error(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -548,17 +548,26 @@ class MCU:
|
||||||
raise error("MCU '%s' CRC does not match config" % (self._name,))
|
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')
|
self.register_response(self._handle_starting, 'starting')
|
||||||
if prev_crc is None:
|
try:
|
||||||
logging.info("Sending MCU '%s' printer configuration...",
|
if prev_crc is None:
|
||||||
self._name)
|
logging.info("Sending MCU '%s' printer configuration...",
|
||||||
for c in self._config_cmds:
|
self._name)
|
||||||
|
for c in self._config_cmds:
|
||||||
|
self._serial.send(c)
|
||||||
|
else:
|
||||||
|
for c in self._restart_cmds:
|
||||||
|
self._serial.send(c)
|
||||||
|
# Transmit init messages
|
||||||
|
for c in self._init_cmds:
|
||||||
self._serial.send(c)
|
self._serial.send(c)
|
||||||
else:
|
except msgproto.enumeration_error as e:
|
||||||
for c in self._restart_cmds:
|
enum_name, enum_value = e.get_enum_params()
|
||||||
self._serial.send(c)
|
if enum_name == 'pin':
|
||||||
# Transmit init messages
|
# Raise pin name errors as a config error (not a protocol error)
|
||||||
for c in self._init_cmds:
|
raise self._printer.config_error(
|
||||||
self._serial.send(c)
|
"Pin '%s' is not a valid pin name on mcu '%s'"
|
||||||
|
% (enum_value, self._name))
|
||||||
|
raise
|
||||||
def _send_get_config(self):
|
def _send_get_config(self):
|
||||||
get_config_cmd = self.lookup_query_command(
|
get_config_cmd = self.lookup_query_command(
|
||||||
"get_config",
|
"get_config",
|
||||||
|
|
|
@ -86,12 +86,14 @@ class PT_progmem_buffer(PT_string):
|
||||||
class PT_buffer(PT_string):
|
class PT_buffer(PT_string):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
MessageTypes = {
|
class enumeration_error(error):
|
||||||
'%u': PT_uint32(), '%i': PT_int32(),
|
def __init__(self, enum_name, value):
|
||||||
'%hu': PT_uint16(), '%hi': PT_int16(),
|
self.enum_name = enum_name
|
||||||
'%c': PT_byte(),
|
self.value = value
|
||||||
'%s': PT_string(), '%.*s': PT_progmem_buffer(), '%*s': PT_buffer(),
|
error.__init__(self, "Unknown value '%s' in enumeration '%s'"
|
||||||
}
|
% (value, enum_name))
|
||||||
|
def get_enum_params(self):
|
||||||
|
return self.enum_name, self.value
|
||||||
|
|
||||||
class Enumeration:
|
class Enumeration:
|
||||||
is_int = False
|
is_int = False
|
||||||
|
@ -105,8 +107,7 @@ class Enumeration:
|
||||||
def encode(self, out, v):
|
def encode(self, out, v):
|
||||||
tv = self.enums.get(v)
|
tv = self.enums.get(v)
|
||||||
if tv is None:
|
if tv is None:
|
||||||
raise error("Unknown value '%s' in enumeration '%s'"
|
raise enumeration_error(self.enum_name, v)
|
||||||
% (v, self.enum_name))
|
|
||||||
self.pt.encode(out, tv)
|
self.pt.encode(out, tv)
|
||||||
def parse(self, s, pos):
|
def parse(self, s, pos):
|
||||||
v, pos = self.pt.parse(s, pos)
|
v, pos = self.pt.parse(s, pos)
|
||||||
|
@ -115,6 +116,13 @@ class Enumeration:
|
||||||
tv = "?%d" % (v,)
|
tv = "?%d" % (v,)
|
||||||
return tv, pos
|
return tv, pos
|
||||||
|
|
||||||
|
MessageTypes = {
|
||||||
|
'%u': PT_uint32(), '%i': PT_int32(),
|
||||||
|
'%hu': PT_uint16(), '%hi': PT_int16(),
|
||||||
|
'%c': PT_byte(),
|
||||||
|
'%s': PT_string(), '%.*s': PT_progmem_buffer(), '%*s': PT_buffer(),
|
||||||
|
}
|
||||||
|
|
||||||
# Lookup the message types for a format string
|
# Lookup the message types for a format string
|
||||||
def lookup_params(msgformat, enumerations={}):
|
def lookup_params(msgformat, enumerations={}):
|
||||||
out = []
|
out = []
|
||||||
|
|
Loading…
Reference in New Issue