Skip to content

Commit 5ffe5d8

Browse files
committed
possible fix for issue #535
1 parent 63670c5 commit 5ffe5d8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/canmatrix/formats/dbc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
932932
ecu.name = ecu.attributes.get("SystemNodeLongSymbol")[1:-1]
933933
ecu.del_attribute("SystemNodeLongSymbol")
934934
for frame in db.frames:
935-
frame.cycle_time = int(frame.attributes.get("GenMsgCycleTime", 0))
935+
frame.cycle_time = int(float(frame.attributes.get("GenMsgCycleTime", 0)))
936936
if frame.attributes.get("SystemMessageLongSymbol", None) is not None:
937937
frame.name = frame.attributes.get("SystemMessageLongSymbol")[1:-1]
938938
frame.del_attribute("SystemMessageLongSymbol")

src/canmatrix/tests/test_dbc.py

+18
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,21 @@ def test_escaped_quotes():
489489
assert matrix.frames[0].signals[0].values[2] == r'string with "escaped" double quotes'
490490

491491

492+
def test_float_cycle_time():
493+
dbc = io.BytesIO(textwrap.dedent(u'''\
494+
BO_ 17 Frame_1: 8 Vector__XXX
495+
SG_ sig2 : 8|8@1- (1,0) [0|0] "" Vector__XXX
496+
SG_ sig1 : 0|8@1- (1,0) [0|0] "" Vector__XXX
497+
498+
499+
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 3600000;
500+
BA_ "GenMsgCycleTime" BO_ 17 100.0;
501+
''').encode('utf-8'))
502+
503+
504+
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
505+
506+
assert matrix.frames[0].cycle_time == 100
507+
assert matrix.frames[0].signal_by_name("sig1").cycle_time == 10
508+
assert matrix.frames[0].signal_by_name("sig2").cycle_time == 20
509+

0 commit comments

Comments
 (0)