aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/msgproto.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-06-09 15:02:56 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-06-09 18:58:26 -0400
commitecbfa762425b81031357c68158fb5939f6d24675 (patch)
tree6c3b33734e714f7f3bc988e8f495c1f4fd8070bd /klippy/msgproto.py
parent31fcd491fd9fd99f81599558b5256cfaaa078da0 (diff)
downloadkutter-ecbfa762425b81031357c68158fb5939f6d24675.tar.gz
kutter-ecbfa762425b81031357c68158fb5939f6d24675.tar.xz
kutter-ecbfa762425b81031357c68158fb5939f6d24675.zip
mcu: Raise config_error (not protocol error) on pin enumeration errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/msgproto.py')
-rw-r--r--klippy/msgproto.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/klippy/msgproto.py b/klippy/msgproto.py
index cdecd8e7..7391a6f4 100644
--- a/klippy/msgproto.py
+++ b/klippy/msgproto.py
@@ -86,12 +86,14 @@ class PT_progmem_buffer(PT_string):
class PT_buffer(PT_string):
pass
-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(),
-}
+class enumeration_error(error):
+ def __init__(self, enum_name, value):
+ self.enum_name = enum_name
+ self.value = value
+ 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:
is_int = False
@@ -105,8 +107,7 @@ class Enumeration:
def encode(self, out, v):
tv = self.enums.get(v)
if tv is None:
- raise error("Unknown value '%s' in enumeration '%s'"
- % (v, self.enum_name))
+ raise enumeration_error(self.enum_name, v)
self.pt.encode(out, tv)
def parse(self, s, pos):
v, pos = self.pt.parse(s, pos)
@@ -115,6 +116,13 @@ class Enumeration:
tv = "?%d" % (v,)
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
def lookup_params(msgformat, enumerations={}):
out = []