Skip to content

Commit 9aa5db7

Browse files
authored
[WIP] [ARXML] can_fd info (potentional fix for #410) (#418)
* potentional fix for #410 * [ARXML] can-fd recogintion * add baudrate attributes
1 parent 35893aa commit 9aa5db7

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/canmatrix/canmatrix.py

+3
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,9 @@ class CanMatrix(object):
14391439
env_vars = attr.ib(factory=dict) # type: typing.MutableMapping[str, typing.MutableMapping]
14401440
signals = attr.ib(factory=list) # type: typing.MutableSequence[Signal]
14411441

1442+
baudrate = attr.ib(default=0) # type:int
1443+
fd_baudrate = attr.ib(default=0) # type:int
1444+
14421445
load_errors = attr.ib(factory=list) # type: typing.MutableSequence[Exception]
14431446

14441447
def __iter__(self): # type: () -> typing.Iterator[Frame]

src/canmatrix/formats/arxml.py

+26
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,15 @@ def dump(dbs, f, **options):
215215
pdu_triggering_ref = create_sub_element(pdu_triggering_ref_conditional, 'PDU-TRIGGERING-REF')
216216
pdu_triggering_ref.set('DEST', 'PDU-TRIGGERING')
217217

218+
218219
if frame.arbitration_id.extended is False:
219220
create_sub_element(can_frame_triggering, 'CAN-ADDRESSING-MODE', 'STANDARD')
220221
else:
221222
create_sub_element(can_frame_triggering, 'CAN-ADDRESSING-MODE', 'EXTENDED')
223+
224+
if frame.is_fd:
225+
create_sub_element(can_frame_triggering, 'CAN-FRAME-RX-BEHAVIOR', "CAN-FD")
226+
create_sub_element(can_frame_triggering, 'CAN-FRAME-RX-BEHAVIOR', "CAN-FD")
222227
create_sub_element(can_frame_triggering, 'IDENTIFIER', str(frame.arbitration_id.id))
223228

224229
pdu_triggering_ref.text = "/Cluster/CAN/IPDUTRIGG_{0}".format(frame.name)
@@ -1324,6 +1329,10 @@ def get_frame(frame_triggering, root_or_cache, multiplex_translation, ns, float_
13241329
# type: (_Element, _DocRoot, dict, str, typing.Callable) -> typing.Union[canmatrix.Frame, None]
13251330
global pdu_frame_mapping
13261331
address_mode = get_child(frame_triggering, "CAN-ADDRESSING-MODE", root_or_cache, ns)
1332+
frame_rx_behaviour_elem = get_child(frame_triggering, "CAN-FRAME-RX-BEHAVIOR", root_or_cache, ns)
1333+
frame_tx_behaviour_elem = get_child(frame_triggering, "CAN-FRAME-TX-BEHAVIOR", root_or_cache, ns)
1334+
is_fd_elem = get_child(frame_triggering, "CAN-FD-FRAME-SUPPORT", root_or_cache, ns)
1335+
13271336
arb_id = get_child(frame_triggering, "IDENTIFIER", root_or_cache, ns)
13281337
frame_elem = get_child(frame_triggering, "FRAME", root_or_cache, ns)
13291338

@@ -1378,6 +1387,13 @@ def get_frame(frame_triggering, root_or_cache, multiplex_translation, ns, float_
13781387
else:
13791388
new_frame.arbitration_id = canmatrix.ArbitrationId(arbitration_id, extended=False)
13801389

1390+
if (frame_rx_behaviour_elem is not None and frame_rx_behaviour_elem.text == 'CAN-FD') or \
1391+
(frame_tx_behaviour_elem is not None and frame_tx_behaviour_elem.text == 'CAN-FD') or \
1392+
(is_fd_elem is not None and is_fd_elem.text == 'TRUE'):
1393+
new_frame.is_fd = True
1394+
else:
1395+
new_frame.is_fd = False
1396+
13811397
timing_spec = get_child(pdu, "I-PDU-TIMING-SPECIFICATION", root_or_cache, ns)
13821398
if timing_spec is None:
13831399
timing_spec = get_child(pdu, "I-PDU-TIMING-SPECIFICATIONS", root_or_cache, ns)
@@ -1669,10 +1685,19 @@ def load(file, **options):
16691685
bus_name = ""
16701686
else:
16711687
speed = get_child(cc, "SPEED", search_point, ns)
1688+
baudrate_elem = cc.find(".//" + ns + "BAUDRATE")
1689+
fd_baudrate_elem = cc.find(".//" + ns + "CAN-FD-BAUDRATE")
1690+
1691+
speed = baudrate_elem is speed is None
1692+
16721693
logger.debug("Busname: " + get_element_name(cc, ns))
16731694

16741695
bus_name = get_element_name(cc, ns)
16751696
if speed is not None:
1697+
db.baudrate = speed
1698+
if fd_baudrate_elem is not None:
1699+
db.fd_baudrate = fd_baudrate_elem.text
1700+
16761701
logger.debug(" Speed: " + speed.text)
16771702

16781703
physical_channels = cc.find('.//' + ns + "PHYSICAL-CHANNELS") # type: _Element
@@ -1681,6 +1706,7 @@ def load(file, **options):
16811706

16821707
nm_lower_id = get_child(cc, "NM-LOWER-CAN-ID", search_point, ns)
16831708

1709+
16841710
physical_channel = get_child(physical_channels, "PHYSICAL-CHANNEL", search_point, ns)
16851711
if physical_channel is None:
16861712
physical_channel = get_child(physical_channels, "CAN-PHYSICAL-CHANNEL", search_point, ns)

src/canmatrix/tests/test_canmatrix.py

+7
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,10 @@ def test_effective_cycle_time():
10071007
sig1.cycle_time = 0
10081008
sig2.cycle_time = 0
10091009
assert frame.effective_cycle_time == 0
1010+
1011+
def test_baudrate():
1012+
cm = canmatrix.CanMatrix()
1013+
cm.baudrate = 500000
1014+
assert cm.baudrate == 500000
1015+
cm.fd_baudrate = 1000000
1016+
assert cm.fd_baudrate == 1000000

0 commit comments

Comments
 (0)