diff --git a/can/io/trc.py b/can/io/trc.py index a498da992..5d548e832 100644 --- a/can/io/trc.py +++ b/can/io/trc.py @@ -121,6 +121,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_msg_v1_3 elif self.file_version in [TRCFileVersion.V2_0, TRCFileVersion.V2_1]: self._parse_cols = self._parse_cols_v2_x else: @@ -161,6 +163,25 @@ 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 = 1 + 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" + msg.bus = int(cols[2]) + return msg + def _parse_msg_v2_x(self, cols: List[str]) -> Optional[Message]: type_ = cols[self.columns["T"]] bus = self.columns.get("B", None) diff --git a/can/message.py b/can/message.py index c26733087..04a2cfa3e 100644 --- a/can/message.py +++ b/can/message.py @@ -38,6 +38,7 @@ class Message: # pylint: disable=too-many-instance-attributes; OK for a datacla "is_remote_frame", "is_error_frame", "channel", + "bus", "dlc", "data", "is_fd", @@ -55,6 +56,7 @@ def __init__( # pylint: disable=too-many-locals, too-many-arguments is_remote_frame: bool = False, is_error_frame: bool = False, channel: Optional[typechecking.Channel] = None, + bus: Optional[int] = None, dlc: Optional[int] = None, data: Optional[typechecking.CanData] = None, is_fd: bool = False, @@ -83,6 +85,7 @@ def __init__( # pylint: disable=too-many-locals, too-many-arguments self.is_remote_frame = is_remote_frame self.is_error_frame = is_error_frame self.channel = channel + self.bus = bus self.is_fd = is_fd self.is_rx = is_rx self.bitrate_switch = bitrate_switch