Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in simple multiplexing for dbc #816

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,17 @@ def compress(self):
gap_found = True
break

def multiplex_signals(self):
"""Assign multiplexer to signals. When a multiplexor is in the frame."""
multiplexor = self.get_multiplexer
if multiplexor is None:
return

for signal in self.signals:
if signal.is_multiplexer or (signal.muxer_for_signal is not None):
continue
signal.muxer_for_signal = multiplexor.name
signal.mux_val = signal.multiplex

def __str__(self): # type: () -> str
"""Represent the frame by its name only."""
Expand Down
5 changes: 4 additions & 1 deletion src/canmatrix/formats/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,11 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
multiplex = temp.group(2) # type: str

is_complex_multiplexed = False
is_multiplexer = False

if multiplex == 'M':
multiplex = 'Multiplexor'
is_multiplexer = True
elif multiplex.endswith('M'):
is_complex_multiplexed = True
multiplex = multiplex[:-1]
Expand Down Expand Up @@ -632,7 +634,7 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
**extras
)

if is_complex_multiplexed:
if is_complex_multiplexed or is_multiplexer:
temp_signal.is_multiplexer = True
temp_signal.multiplex = 'Multiplexor'

Expand Down Expand Up @@ -989,6 +991,7 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None

db.enum_attribs_to_values()
for frame in db.frames:
frame.multiplex_signals()
if "_FD" in frame.attributes.get("VFrameFormat", ""):
frame.is_fd = True
if "J1939PG" in frame.attributes.get("VFrameFormat", ""):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,20 @@ def test_j1939_frametype():
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
assert matrix.frames[0].is_j1939 == False

def test_multiplex_frame():
dbc = io.BytesIO(textwrap.dedent(u'''\
BU_: someOtherEcu

BO_ 123 someFrame: 8 someOtherEcu
SG_ someSignal m2 : 8|8@1+ (1,0) [0|9] "" CCL_TEST
SG_ someOtherSignal m1 : 8|8@0+ (1,0) [0|9] "" CCL_TEST
SG_ someMultiplexor M : 0|8@1+ (1,0) [0|2] "" CCL_TEST
''').encode('utf-8'))
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
assert matrix.frames[0].is_multiplexed

assert matrix.frames[0].signal_by_name("someSignal").muxer_for_signal == "someMultiplexor"


def test_attributes_with_spaces_before_semicolumn():
dbc = io.BytesIO(textwrap.dedent(u'''\
Expand Down
Loading