Skip to content

Commit

Permalink
possible fix for #490 (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker authored Sep 20, 2020
1 parent f72a8d6 commit 10da46d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/canmatrix/formats/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
db.frames.append(frame)
add_frame_by_id(frame)
elif decoded.startswith("SG_ "):
pattern = r"^SG_ +(\w+) *: *(\d+)\|(\d+)@(\d+)([\+|\-]) +\(([0-9.+\-eE]+), *([0-9.+\-eE]+)\) +\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(.*)\" +(.*)"
pattern = r"^SG_ +(\w+) *: *(\d+)\|(\d+)@(\d+)([\+|\-]) *\(([0-9.+\-eE]+), *([0-9.+\-eE]+)\) *\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(.*)\" +(.*)"
regexp = re.compile(pattern)
temp = regexp.match(decoded)
regexp_raw = re.compile(pattern.encode(dbc_import_encoding))
Expand Down Expand Up @@ -577,7 +577,7 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
frame.add_signal(temp_signal)
# db.frames.addSignalToLastFrame(tempSig)
else:
pattern = r"^SG_ +(.+?) +(.+?) *: *(\d+)\|(\d+)@(\d+)([\+|\-]) +\(([0-9.+\-eE]+),([0-9.+\-eE]+)\) +\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(.*)\" +(.*)"
pattern = r"^SG_ +(.+?) +(.+?) *: *(\d+)\|(\d+)@(\d+)([\+|\-]) *\(([0-9.+\-eE]+),([0-9.+\-eE]+)\) *\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(.*)\" +(.*)"
regexp = re.compile(pattern)
regexp_raw = re.compile(pattern.encode(dbc_import_encoding))
temp = regexp.match(decoded)
Expand Down
9 changes: 9 additions & 0 deletions src/canmatrix/tests/test_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,12 @@ def test_signal_inital_value():
outdbc = io.BytesIO()
canmatrix.formats.dump(matrix, outdbc, "dbc")
assert 'BA_ "GenSigStartValue" SG_ 17 sig1 2.7;' in outdbc.getvalue().decode('utf8')

def test_missing_space():
dbc = io.BytesIO(textwrap.dedent(u'''\
BO_ 17 Frame_1: 8 Vector__XXX
SG_ sig1 : 0|8@1-(1,0)[0|0] "" Vector__XXX
''').encode('utf-8'))
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
assert matrix.frames[0].signals[0].name == "sig1"

0 comments on commit 10da46d

Please sign in to comment.