Workaround for typo & whitespace in Malyan M115 responses

NAME. instead of NAME:, whitespace between key and value component.
This commit is contained in:
Gina Häußge committed 2018-04-11 11:12:56 +02:00
1 parent 75de062b55
commit 6f224bd825
2 files changed
+28 -5

No files matched your search

+14 -4
View File
@@ -192,7 +192,7 @@ Groups will be as follows:
* ``value``: reported position value
"""
regex_firmware_splitter = re.compile("\s*([A-Z0-9_]+):")
regex_firmware_splitter = re.compile("\s*([A-Z0-9_]+):\s*")
"""Regex to use for splitting M115 responses."""
regex_resend_linenumber = re.compile("(N|N:)?(?P<n>%s)" % regex_int_pattern)
@@ -1662,7 +1662,7 @@ class MachineCom(object):
pass
##~~ firmware name & version
elif "NAME:" in line:
elif "NAME:" in line or line.startswith("NAME."):
# looks like a response to M115
data = parse_firmware_line(line)
firmware_name = data.get("FIRMWARE_NAME")
@@ -1672,7 +1672,11 @@ class MachineCom(object):
# report its firmware name properly in response to M115. Wonderful - why stick to established
# protocol when you can do your own thing, right?
#
# Example: NAME: Malyan VER: 2.9 MODEL: M200 HW: HA02
# Examples:
#
# NAME: Malyan VER: 2.9 MODEL: M200 HW: HA02
# NAME. Malyan VER: 3.8 MODEL: M100 HW: HB02
# NAME. Malyan VER: 3.7 MODEL: M300 HW: HG01
#
# We do a bit of manual fiddling around here to circumvent that issue and get ourselves a
# reliable firmware name (NAME + VER) out of the Malyan M115 response.
@@ -4013,10 +4017,16 @@ def parse_firmware_line(line):
dict: a dictionary with the parsed data
"""
if line.startswith("NAME."):
# Good job Malyan. Why use a : when you can also just use a ., right? Let's revert that.
line = list(line)
line[4] = ":"
line = "".join(line)
result = dict()
split_line = regex_firmware_splitter.split(line.strip())[1:] # first entry is empty start of trimmed string
for key, value in chunks(split_line, 2):
result[key] = value
result[key] = value.strip()
return result
def parse_capability_line(line):
+14 -1
View File
@@ -259,7 +259,20 @@ class TestCommHelpers(unittest.TestCase):
@data(
("KEY1:Value 1 FIRMWARE_NAME:Some Firmware With Spaces KEY2:Value 2",
dict(KEY1="Value 1", KEY2="Value 2", FIRMWARE_NAME="Some Firmware With Spaces"))
dict(KEY1="Value 1", KEY2="Value 2", FIRMWARE_NAME="Some Firmware With Spaces")),
("NAME: Malyan VER: 2.9 MODEL: M200 HW: HA02",
dict(NAME="Malyan", VER="2.9", MODEL="M200", HW="HA02")),
("NAME. Malyan VER: 3.8 MODEL: M100 HW: HB02",
dict(NAME="Malyan", VER="3.8", MODEL="M100", HW="HB02")),
("NAME. Malyan VER: 3.7 MODEL: M300 HW: HG01",
dict(NAME="Malyan", VER="3.7", MODEL="M300", HW="HG01")),
("FIRMWARE_NAME:Marlin 1.1.0 From Archive SOURCE_CODE_URL:http:// ... PROTOCOL_VERSION:1.0 MACHINE_TYPE:www.cxsw3d.com EXTRUDER_COUNT:1 UUID:00000000-0000-0000-0000-000000000000",
dict(FIRMWARE_NAME="Marlin 1.1.0 From Archive",
SOURCE_CODE_URL="http:// ...",
PROTOCOL_VERSION="1.0",
MACHINE_TYPE="www.cxsw3d.com",
EXTRUDER_COUNT="1",
UUID="00000000-0000-0000-0000-000000000000"))
)
@unpack
def test_parse_firmware_line(self, line, expected):