Skip to content

Commit 99967bd

Browse files
committed
Definition-Names can now contain spaces
fix for #330
1 parent f798364 commit 99967bd

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/canmatrix/formats/dbc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
761761
substring = decoded[7:].strip()
762762
define_type = substring[:3]
763763
substring = substring[3:].strip()
764-
pattern = r"^\"([A-Za-z0-9\-_]+)\" +(.+);"
764+
pattern = r"^\"([A-Za-z0-9\-_\ ]+)\" +(.+);"
765765
regexp = re.compile(pattern)
766766
regexp_raw = re.compile(pattern.encode(dbcImportEncoding))
767767
temp = regexp.match(substring)

src/canmatrix/tests/test_copy.py

+23
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,26 @@ def test_copy_ecu_without_frames():
5151
assert len(matrix1.frames) == 1
5252
assert len(matrix1.ecus) == 1
5353
assert matrix1.ecu_by_name("ECU") is not None
54+
55+
56+
def test_copy_ecu_with_attributes():
57+
matrix1 = canmatrix.canmatrix.CanMatrix()
58+
frame1 = canmatrix.canmatrix.Frame("Frame1", arbitration_id=1)
59+
frame1.add_signal(canmatrix.canmatrix.Signal("SomeSignal"))
60+
matrix1.add_frame(frame1)
61+
62+
matrix2 = canmatrix.canmatrix.CanMatrix()
63+
frame2 = canmatrix.canmatrix.Frame("Frame2", arbitration_id=2, transmitters= ["ECU"])
64+
matrix2.add_frame(frame2)
65+
matrix2.update_ecu_list()
66+
matrix2.add_ecu_defines("Node Address", "INT 0 255")
67+
matrix2.add_ecu_defines("attrib", "STRING")
68+
matrix2.ecu_by_name("ECU").add_attribute("attrib", "attribValue")
69+
matrix2.ecu_by_name("ECU").add_attribute("Node Address", 42)
70+
71+
canmatrix.copy.copy_ecu("ECU", matrix2, matrix1)
72+
73+
assert len(matrix1.frames) == 1
74+
assert len(matrix1.ecus) == 1
75+
assert matrix1.ecu_by_name("ECU") is not None
76+
assert matrix1.ecu_by_name("ECU").attribute("Node Address") == 42

src/canmatrix/tests/test_dbc.py

+12
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,15 @@ def test_braces_in_attributes():
227227
BA_ "Signal Age [ms]" SG_ 20 sometext 5000;
228228
''').encode('utf-8'))
229229
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
230+
231+
def test_defines_with_spaces():
232+
dbc = io.BytesIO(textwrap.dedent(u'''\
233+
BU_: someOtherEcu
234+
235+
BA_DEF_ BU_ "Node Address" INT 0 255;
236+
BA_ "Node Address" BU_ someOtherEcu 42;
237+
''').encode('utf-8'))
238+
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
239+
assert matrix.ecu_defines["Node Address"].type == "INT"
240+
assert matrix.ecu_defines["Node Address"].min == 0
241+
assert matrix.ecu_defines["Node Address"].max == 255

0 commit comments

Comments
 (0)