Skip to content
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

add parser for TRC 1.3 format #1727

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 23 additions & 0 deletions can/io/trc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def _extract_header(self):
file_version = line.split("=")[1]
if file_version == "1.1":
self.file_version = TRCFileVersion.V1_1
if 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":
Expand Down Expand Up @@ -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_msg_v1_3
elif self.file_version in [TRCFileVersion.V2_0, TRCFileVersion.V2_1]:
self._parse_cols = self._parse_cols_v2_x
else:
Expand Down Expand Up @@ -161,6 +165,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)
Expand Down
3 changes: 3 additions & 0 deletions can/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading