diff --git a/can/io/trc.py b/can/io/trc.py index a498da992..f568f93a5 100644 --- a/can/io/trc.py +++ b/can/io/trc.py @@ -76,6 +76,8 @@ def _extract_header(self): file_version = line.split("=")[1] if file_version == "1.1": self.file_version = TRCFileVersion.V1_1 + elif file_version == "1.3": + self.file_version = TRCFileVersion.V1_3 elif file_version == "2.0": self.file_version = TRCFileVersion.V2_0 elif file_version == "2.1": @@ -121,6 +123,8 @@ def _extract_header(self): self._parse_cols = self._parse_msg_v1_0 elif self.file_version == TRCFileVersion.V1_1: self._parse_cols = self._parse_cols_v1_1 + elif self.file_version == TRCFileVersion.V1_3: + self._parse_cols = self._parse_cols_v1_3 elif self.file_version in [TRCFileVersion.V2_0, TRCFileVersion.V2_1]: self._parse_cols = self._parse_cols_v2_x else: @@ -161,6 +165,24 @@ def _parse_msg_v1_1(self, cols: List[str]) -> Optional[Message]: msg.is_rx = cols[2] == "Rx" return msg + def _parse_msg_v1_3(self, cols: List[str]) -> Optional[Message]: + arbit_id = cols[4] + + msg = Message() + if isinstance(self.start_time, datetime): + msg.timestamp = ( + self.start_time + timedelta(milliseconds=float(cols[1])) + ).timestamp() + else: + msg.timestamp = float(cols[1]) / 1000 + msg.arbitration_id = int(arbit_id, 16) + 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)]) + msg.is_rx = cols[3] == "Rx" + return msg + def _parse_msg_v2_x(self, cols: List[str]) -> Optional[Message]: type_ = cols[self.columns["T"]] bus = self.columns.get("B", None) @@ -203,6 +225,14 @@ def _parse_cols_v1_1(self, cols: List[str]) -> Optional[Message]: logger.info("TRCReader: Unsupported type '%s'", dtype) return None + def _parse_cols_v1_3(self, cols: List[str]) -> Optional[Message]: + dtype = cols[3] + if dtype in ("Tx", "Rx"): + return self._parse_msg_v1_3(cols) + else: + logger.info("TRCReader: Unsupported type '%s'", dtype) + return None + def _parse_cols_v2_x(self, cols: List[str]) -> Optional[Message]: dtype = cols[self.columns["T"]] if dtype in ["DT", "FD", "FB"]: diff --git a/test/data/test_CanMessage_V1_3.trc b/test/data/test_CanMessage_V1_3.trc new file mode 100644 index 000000000..5b0bf060a --- /dev/null +++ b/test/data/test_CanMessage_V1_3.trc @@ -0,0 +1,32 @@ +;$FILEVERSION=1.3 +;$STARTTIME=44548.6028595139 +; +; C:\test.trc +; Start time: 18.12.2021 14:28:07.062.0 +; Generated by PCAN-Explorer v5.4.0 +;------------------------------------------------------------------------------- +; Bus Name Connection Protocol Bit rate +; 1 PCAN Untitled@pcan_usb CAN 500 kbit/s +; 2 PTCAN PCANLight_USB_16@pcan_usb CAN +;------------------------------------------------------------------------------- +; Message Number +; | Time Offset (ms) +; | | Bus +; | | | Type +; | | | | ID (hex) +; | | | | | Reserved +; | | | | | | Data Length Code +; | | | | | | | Data Bytes (hex) ... +; | | | | | | | | +; | | | | | | | | +;---+-- ------+------ +- --+-- ----+--- +- -+-- -+ -- -- -- -- -- -- -- + 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 diff --git a/test/logformats_test.py b/test/logformats_test.py index a7e75d7c8..71d392aa8 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -939,6 +939,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_1", "test_CanMessage_V2_1.trc", True), ] )