Skip to content

Commit d0e0680

Browse files
committed
trc reader support for RTR frames parsing
1 parent c62b4ea commit d0e0680

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

can/io/trc.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def _parse_msg_v1_0(self, cols: tuple[str, ...]) -> Optional[Message]:
153153
msg.is_extended_id = len(arbit_id) > 4
154154
msg.channel = 1
155155
msg.dlc = int(cols[3])
156-
msg.data = bytearray([int(cols[i + 4], 16) for i in range(msg.dlc)])
156+
if len(cols) > 4 and cols[4] == "RTR":
157+
msg.is_remote_frame = True
158+
else:
159+
msg.data = bytearray([int(cols[i + 4], 16) for i in range(msg.dlc)])
157160
return msg
158161

159162
def _parse_msg_v1_1(self, cols: tuple[str, ...]) -> Optional[Message]:
@@ -165,7 +168,10 @@ def _parse_msg_v1_1(self, cols: tuple[str, ...]) -> Optional[Message]:
165168
msg.is_extended_id = len(arbit_id) > 4
166169
msg.channel = 1
167170
msg.dlc = int(cols[4])
168-
msg.data = bytearray([int(cols[i + 5], 16) for i in range(msg.dlc)])
171+
if len(cols) > 5 and cols[5] == "RTR":
172+
msg.is_remote_frame = True
173+
else:
174+
msg.data = bytearray([int(cols[i + 5], 16) for i in range(msg.dlc)])
169175
msg.is_rx = cols[2] == "Rx"
170176
return msg
171177

@@ -178,7 +184,10 @@ def _parse_msg_v1_3(self, cols: tuple[str, ...]) -> Optional[Message]:
178184
msg.is_extended_id = len(arbit_id) > 4
179185
msg.channel = int(cols[2])
180186
msg.dlc = int(cols[6])
181-
msg.data = bytearray([int(cols[i + 7], 16) for i in range(msg.dlc)])
187+
if len(cols) > 7 and cols[7] == "RTR":
188+
msg.is_remote_frame = True
189+
else:
190+
msg.data = bytearray([int(cols[i + 7], 16) for i in range(msg.dlc)])
182191
msg.is_rx = cols[3] == "Rx"
183192
return msg
184193

@@ -200,7 +209,8 @@ def _parse_msg_v2_x(self, cols: tuple[str, ...]) -> Optional[Message]:
200209
msg.is_extended_id = len(cols[self.columns["I"]]) > 4
201210
msg.channel = int(cols[bus]) if bus is not None else 1
202211
msg.dlc = dlc
203-
if dlc:
212+
msg.is_remote_frame = type_ in {"RR"}
213+
if dlc and not msg.is_remote_frame:
204214
msg.data = bytearray.fromhex(cols[self.columns["D"]])
205215
msg.is_rx = cols[self.columns["d"]] == "Rx"
206216
msg.is_fd = type_ in {"FD", "FB", "FE", "BI"}
@@ -227,7 +237,7 @@ def _parse_cols_v1_3(self, cols: tuple[str, ...]) -> Optional[Message]:
227237

228238
def _parse_cols_v2_x(self, cols: tuple[str, ...]) -> Optional[Message]:
229239
dtype = cols[self.columns["T"]]
230-
if dtype in {"DT", "FD", "FB", "FE", "BI"}:
240+
if dtype in {"DT", "FD", "FB", "FE", "BI", "RR"}:
231241
return self._parse_msg_v2_x(cols)
232242
else:
233243
logger.info("TRCReader: Unsupported type '%s'", dtype)

test/logformats_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ def test_can_message(self):
990990
("V1_0", "test_CanMessage_V1_0_BUS1.trc", False),
991991
("V1_1", "test_CanMessage_V1_1.trc", True),
992992
("V1_3", "test_CanMessage_V1_3.trc", True),
993+
("V2_0", "test_CanMessage_V2_0_BUS1.trc", True),
993994
("V2_1", "test_CanMessage_V2_1.trc", True),
994995
]
995996
)
@@ -1029,6 +1030,20 @@ def msg_ext(timestamp):
10291030
msg.is_rx = False
10301031
return msg
10311032

1033+
def msg_rtr(timestamp):
1034+
msg = can.Message(
1035+
timestamp=timestamp + start_time,
1036+
arbitration_id=0x704,
1037+
is_extended_id=False,
1038+
is_remote_frame=True,
1039+
channel=1,
1040+
dlc=1,
1041+
data=[],
1042+
)
1043+
if is_rx_support:
1044+
msg.is_rx = True
1045+
return msg
1046+
10321047
expected_messages = [
10331048
msg_ext(17.5354),
10341049
msg_ext(17.7003),
@@ -1040,6 +1055,7 @@ def msg_ext(timestamp):
10401055
msg_ext(20.7986),
10411056
msg_ext(20.9560),
10421057
msg_ext(21.0971),
1058+
msg_rtr(48.9376)
10431059
]
10441060
actual = self._read_log_file(filename)
10451061
self.assertMessagesEqual(actual, expected_messages)

0 commit comments

Comments
 (0)