Skip to content

Commit 8bff24a

Browse files
author
Eduard Bröcker
committed
fix for issue #596
cope with signals without receiver
1 parent 25a8725 commit 8bff24a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/canmatrix/formats/dbc.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,15 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
551551
db.frames.append(frame)
552552
add_frame_by_id(frame)
553553
elif decoded.startswith("SG_ "):
554+
original_line = l
555+
if decoded.strip().endswith(r'"'):
556+
decoded += r" Vector__XXX"
557+
original_line += b" Vector__XXX"
554558
pattern = r"^SG_ +(\w+) *: *(\d+)\|(\d+)@(\d+)([\+|\-]) *\(([0-9.+\-eE]+), *([0-9.+\-eE]+)\) *\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(.*)\" +(.*)"
555559
regexp = re.compile(pattern)
556560
temp = regexp.match(decoded)
557561
regexp_raw = re.compile(pattern.encode(dbc_import_encoding))
558-
temp_raw = regexp_raw.match(l)
562+
temp_raw = regexp_raw.match(original_line)
559563
if temp:
560564
receiver = [b.strip() for b in temp.group(11).split(',')]
561565

@@ -587,7 +591,7 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
587591
regexp = re.compile(pattern)
588592
regexp_raw = re.compile(pattern.encode(dbc_import_encoding))
589593
temp = regexp.match(decoded)
590-
temp_raw = regexp_raw.match(l)
594+
temp_raw = regexp_raw.match(original_line)
591595
receiver = [b.strip() for b in temp.group(12).split(',')]
592596
multiplex = temp.group(2) # type: str
593597

src/canmatrix/tests/test_dbc.py

+8
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,11 @@ def test_float_cycle_time():
508508
assert matrix.frames[0].cycle_time == 100
509509

510510

511+
def test_without_ecu():
512+
dbc = io.BytesIO(textwrap.dedent(u'''\
513+
BO_ 17 Frame_1: 8 Vector__XXX
514+
SG_ A_B_C_D_E: 39|16@0+ (0.01,0) [0|655.35] "km/h"
515+
''').encode('utf-8'))
516+
517+
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
518+
matrix.frames[0].signals[0].name == "A_B_C_D_E"

src/canmatrix/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def decode_number(value, float_factory): # type(string) -> (int)
114114
:param value: string input value
115115
:return: integer
116116
"""
117-
117+
if value is None:
118+
return 0
118119
value = value.strip()
119120

120121
if '.' in value:

0 commit comments

Comments
 (0)