Skip to content

Add TRCReader RTR frames support #1953

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions can/io/trc.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ def _parse_msg_v1_0(self, cols: tuple[str, ...]) -> Optional[Message]:
msg.is_extended_id = len(arbit_id) > 4
msg.channel = 1
msg.dlc = int(cols[3])
msg.data = bytearray([int(cols[i + 4], 16) for i in range(msg.dlc)])
if len(cols) > 4 and cols[4] == "RTR":
msg.is_remote_frame = True
else:
msg.data = bytearray([int(cols[i + 4], 16) for i in range(msg.dlc)])
return msg

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

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

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

def _parse_cols_v2_x(self, cols: tuple[str, ...]) -> Optional[Message]:
dtype = cols[self.columns["T"]]
if dtype in {"DT", "FD", "FB", "FE", "BI"}:
if dtype in {"DT", "FD", "FB", "FE", "BI", "RR"}:
return self._parse_msg_v2_x(cols)
else:
logger.info("TRCReader: Unsupported type '%s'", dtype)
Expand Down
7 changes: 4 additions & 3 deletions test/data/test_CanMessage_V1_0_BUS1.trc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
;##########################################################################
; C:\Users\User\Desktop\python-can\test\data\test_CanMessage_V1_0_BUS1.trc
; C:\NewFileName_BUS1.trc
;
; CAN activities imported from C:\Users\User\Desktop\python-can\test\data\test_CanMessage_V1_1.trc
; CAN activities imported from C:\test_CanMessage_V1_1.trc
; Start time: 18.12.2021 14:28:07.062
; PCAN-Net: N/A
; Generated by PEAK-Converter Version 2.2.4.136
; Generated by PEAK-Converter Version 3.0.4.594
;
; Columns description:
; ~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -26,3 +26,4 @@
9) 20798 00000100 8 00 00 00 00 00 00 00 00
10) 20956 00000100 8 00 00 00 00 00 00 00 00
11) 21097 00000100 8 00 00 00 00 00 00 00 00
12) 48937 0704 1 RTR
3 changes: 2 additions & 1 deletion test/data/test_CanMessage_V1_1.trc
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
8) 20592.7 Tx 00000100 8 00 00 00 00 00 00 00 00
9) 20798.6 Tx 00000100 8 00 00 00 00 00 00 00 00
10) 20956.0 Tx 00000100 8 00 00 00 00 00 00 00 00
11) 21097.1 Tx 00000100 8 00 00 00 00 00 00 00 00
11) 21097.1 Tx 00000100 8 00 00 00 00 00 00 00 00
12) 48937.6 Rx 0704 1 RTR
35 changes: 19 additions & 16 deletions test/data/test_CanMessage_V1_3.trc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
;$FILEVERSION=1.3
;$STARTTIME=44548.6028595139
; C:\NewFileName_V1_3.trc
;
; C:\test.trc
; Start time: 18.12.2021 14:28:07.062.0
; Generated by PCAN-Explorer v5.4.0
; Start time: 18.12.2021 14:28:07.062.1
;
; Generated by PEAK-Converter Version 3.0.4.594
; Data imported from C:\test_CanMessage_V1_1.trc
;-------------------------------------------------------------------------------
; Bus Name Connection Protocol Bit rate
; 1 PCAN Untitled@pcan_usb CAN 500 kbit/s
; 2 PTCAN PCANLight_USB_16@pcan_usb CAN
; Bus Name Connection Protocol
; N/A N/A N/A CAN
;-------------------------------------------------------------------------------
; Message Number
; | Time Offset (ms)
Expand All @@ -20,13 +21,15 @@
; | | | | | | | |
; | | | | | | | |
;---+-- ------+------ +- --+-- ----+--- +- -+-- -+ -- -- -- -- -- -- --
1) 17535.4 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
2) 17700.3 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
3) 17873.8 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
4) 19295.4 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
5) 19500.6 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
6) 19705.2 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
7) 20592.7 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
8) 20798.6 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
9) 20956.0 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
10) 21097.1 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
1) 17535.400 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
2) 17540.300 1 Warng FFFFFFFF - 4 00 00 00 08 BUSHEAVY
3) 17700.300 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
4) 17873.800 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
5) 19295.400 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
6) 19500.600 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
7) 19705.200 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
8) 20592.700 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
9) 20798.600 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
10) 20956.000 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
11) 21097.100 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
12) 48937.600 1 Rx 0704 - 1 RTR
11 changes: 6 additions & 5 deletions test/data/test_CanMessage_V2_0_BUS1.trc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
;$STARTTIME=44548.6028595139
;$COLUMNS=N,O,T,I,d,l,D
;
; C:\Users\User\Desktop\python-can\test\data\test_CanMessage_V2_0_BUS1.trc
; C:\test_CanMessage_V2_0_BUS1.trc
; Start time: 18.12.2021 14:28:07.062.001
; Generated by PEAK-Converter Version 2.2.4.136
; Data imported from C:\Users\User\Desktop\python-can\test\data\test_CanMessage_V1_1.trc
; Generated by PEAK-Converter Version 3.0.4.594
; Data imported from C:\test_CanMessage_V1_1.trc
;-------------------------------------------------------------------------------
; Connection Bit rate
; N/A N/A
; N/A N/A
;-------------------------------------------------------------------------------
; Message Time Type ID Rx/Tx
; Number Offset | [hex] | Data Length
; | [ms] | | | | Data [hex] ...
; | | | | | | |
; | | | | | | |
;---+-- ------+------ +- --+----- +- +- +- -- -- -- -- -- -- --
1 17535.400 DT 00000100 Tx 8 00 00 00 00 00 00 00 00
2 17540.300 ST Rx 00 00 00 08
Expand All @@ -26,3 +26,4 @@
9 20798.600 DT 00000100 Tx 8 00 00 00 00 00 00 00 00
10 20956.000 DT 00000100 Tx 8 00 00 00 00 00 00 00 00
11 21097.100 DT 00000100 Tx 8 00 00 00 00 00 00 00 00
12 48937.600 RR 0704 Rx 1
11 changes: 6 additions & 5 deletions test/data/test_CanMessage_V2_1.trc
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
;$STARTTIME=44548.6028595139
;$COLUMNS=N,O,T,B,I,d,R,L,D
;
; C:\Users\User\Desktop\python-can\test\data\test_CanMessage_V2_1.trc
; C:\test_CanMessage_V2_1.trc
; Start time: 18.12.2021 14:28:07.062.001
; Generated by PEAK-Converter Version 2.2.4.136
; Data imported from C:\Users\User\Desktop\python-can\test\data\test_CanMessage_V1_1.trc
; Generated by PEAK-Converter Version 3.0.4.594
; Data imported from C:\test_CanMessage_V1_1.trc
;-------------------------------------------------------------------------------
; Bus Name Connection Protocol
; N/A N/A N/A N/A
; N/A N/A N/A N/A
;-------------------------------------------------------------------------------
; Message Time Type ID Rx/Tx
; Number Offset | Bus [hex] | Reserved
; | [ms] | | | | | Data Length Code
; | | | | | | | | Data [hex] ...
; | | | | | | | | |
; | | | | | | | | |
;---+-- ------+------ +- +- --+----- +- +- +--- +- -- -- -- -- -- -- --
1 17535.400 DT 1 00000100 Tx - 8 00 00 00 00 00 00 00 00
2 17540.300 ST 1 - Rx - 4 00 00 00 08
Expand All @@ -27,3 +27,4 @@
9 20798.600 DT 1 00000100 Tx - 8 00 00 00 00 00 00 00 00
10 20956.000 DT 1 00000100 Tx - 8 00 00 00 00 00 00 00 00
11 21097.100 DT 1 00000100 Tx - 8 00 00 00 00 00 00 00 00
12 48937.600 RR 1 0704 Rx - 1
16 changes: 16 additions & 0 deletions test/logformats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ def test_can_message(self):
("V1_0", "test_CanMessage_V1_0_BUS1.trc", False),
("V1_1", "test_CanMessage_V1_1.trc", True),
("V1_3", "test_CanMessage_V1_3.trc", True),
("V2_0", "test_CanMessage_V2_0_BUS1.trc", True),
("V2_1", "test_CanMessage_V2_1.trc", True),
]
)
Expand Down Expand Up @@ -1029,6 +1030,20 @@ def msg_ext(timestamp):
msg.is_rx = False
return msg

def msg_rtr(timestamp):
msg = can.Message(
timestamp=timestamp + start_time,
arbitration_id=0x704,
is_extended_id=False,
is_remote_frame=True,
channel=1,
dlc=1,
data=[],
)
if is_rx_support:
msg.is_rx = True
return msg

expected_messages = [
msg_ext(17.5354),
msg_ext(17.7003),
Expand All @@ -1040,6 +1055,7 @@ def msg_ext(timestamp):
msg_ext(20.7986),
msg_ext(20.9560),
msg_ext(21.0971),
msg_rtr(48.9376),
]
actual = self._read_log_file(filename)
self.assertMessagesEqual(actual, expected_messages)
Expand Down