diff --git a/can/io/trc.py b/can/io/trc.py index a07a53a4d..e1eaa077c 100644 --- a/can/io/trc.py +++ b/can/io/trc.py @@ -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]: @@ -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 @@ -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 @@ -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"} @@ -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) diff --git a/test/data/test_CanMessage_V1_0_BUS1.trc b/test/data/test_CanMessage_V1_0_BUS1.trc index 8985db188..c3905ae47 100644 --- a/test/data/test_CanMessage_V1_0_BUS1.trc +++ b/test/data/test_CanMessage_V1_0_BUS1.trc @@ -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: ; ~~~~~~~~~~~~~~~~~~~~~ @@ -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 \ No newline at end of file diff --git a/test/data/test_CanMessage_V1_1.trc b/test/data/test_CanMessage_V1_1.trc index 5a02cd59b..9a9cc7574 100644 --- a/test/data/test_CanMessage_V1_1.trc +++ b/test/data/test_CanMessage_V1_1.trc @@ -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 diff --git a/test/data/test_CanMessage_V1_3.trc b/test/data/test_CanMessage_V1_3.trc index 5b0bf060a..96db1748c 100644 --- a/test/data/test_CanMessage_V1_3.trc +++ b/test/data/test_CanMessage_V1_3.trc @@ -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) @@ -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 diff --git a/test/data/test_CanMessage_V2_0_BUS1.trc b/test/data/test_CanMessage_V2_0_BUS1.trc index cf2384df0..c1af8abc1 100644 --- a/test/data/test_CanMessage_V2_0_BUS1.trc +++ b/test/data/test_CanMessage_V2_0_BUS1.trc @@ -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 @@ -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 \ No newline at end of file diff --git a/test/data/test_CanMessage_V2_1.trc b/test/data/test_CanMessage_V2_1.trc index 55ceefaf1..0d259f084 100644 --- a/test/data/test_CanMessage_V2_1.trc +++ b/test/data/test_CanMessage_V2_1.trc @@ -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 @@ -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 \ No newline at end of file diff --git a/test/logformats_test.py b/test/logformats_test.py index f3fe485b2..e9db47af3 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -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), ] ) @@ -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), @@ -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)