Skip to content

Commit ffb14a3

Browse files
authored
Add trc 1.3 read support (#1753)
1 parent d40915c commit ffb14a3

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

can/io/trc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def _extract_header(self):
7676
file_version = line.split("=")[1]
7777
if file_version == "1.1":
7878
self.file_version = TRCFileVersion.V1_1
79+
elif file_version == "1.3":
80+
self.file_version = TRCFileVersion.V1_3
7981
elif file_version == "2.0":
8082
self.file_version = TRCFileVersion.V2_0
8183
elif file_version == "2.1":
@@ -121,6 +123,8 @@ def _extract_header(self):
121123
self._parse_cols = self._parse_msg_v1_0
122124
elif self.file_version == TRCFileVersion.V1_1:
123125
self._parse_cols = self._parse_cols_v1_1
126+
elif self.file_version == TRCFileVersion.V1_3:
127+
self._parse_cols = self._parse_cols_v1_3
124128
elif self.file_version in [TRCFileVersion.V2_0, TRCFileVersion.V2_1]:
125129
self._parse_cols = self._parse_cols_v2_x
126130
else:
@@ -161,6 +165,24 @@ def _parse_msg_v1_1(self, cols: List[str]) -> Optional[Message]:
161165
msg.is_rx = cols[2] == "Rx"
162166
return msg
163167

168+
def _parse_msg_v1_3(self, cols: List[str]) -> Optional[Message]:
169+
arbit_id = cols[4]
170+
171+
msg = Message()
172+
if isinstance(self.start_time, datetime):
173+
msg.timestamp = (
174+
self.start_time + timedelta(milliseconds=float(cols[1]))
175+
).timestamp()
176+
else:
177+
msg.timestamp = float(cols[1]) / 1000
178+
msg.arbitration_id = int(arbit_id, 16)
179+
msg.is_extended_id = len(arbit_id) > 4
180+
msg.channel = int(cols[2])
181+
msg.dlc = int(cols[6])
182+
msg.data = bytearray([int(cols[i + 7], 16) for i in range(msg.dlc)])
183+
msg.is_rx = cols[3] == "Rx"
184+
return msg
185+
164186
def _parse_msg_v2_x(self, cols: List[str]) -> Optional[Message]:
165187
type_ = cols[self.columns["T"]]
166188
bus = self.columns.get("B", None)
@@ -203,6 +225,14 @@ def _parse_cols_v1_1(self, cols: List[str]) -> Optional[Message]:
203225
logger.info("TRCReader: Unsupported type '%s'", dtype)
204226
return None
205227

228+
def _parse_cols_v1_3(self, cols: List[str]) -> Optional[Message]:
229+
dtype = cols[3]
230+
if dtype in ("Tx", "Rx"):
231+
return self._parse_msg_v1_3(cols)
232+
else:
233+
logger.info("TRCReader: Unsupported type '%s'", dtype)
234+
return None
235+
206236
def _parse_cols_v2_x(self, cols: List[str]) -> Optional[Message]:
207237
dtype = cols[self.columns["T"]]
208238
if dtype in ["DT", "FD", "FB"]:

test/data/test_CanMessage_V1_3.trc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;$FILEVERSION=1.3
2+
;$STARTTIME=44548.6028595139
3+
;
4+
; C:\test.trc
5+
; Start time: 18.12.2021 14:28:07.062.0
6+
; Generated by PCAN-Explorer v5.4.0
7+
;-------------------------------------------------------------------------------
8+
; Bus Name Connection Protocol Bit rate
9+
; 1 PCAN Untitled@pcan_usb CAN 500 kbit/s
10+
; 2 PTCAN PCANLight_USB_16@pcan_usb CAN
11+
;-------------------------------------------------------------------------------
12+
; Message Number
13+
; | Time Offset (ms)
14+
; | | Bus
15+
; | | | Type
16+
; | | | | ID (hex)
17+
; | | | | | Reserved
18+
; | | | | | | Data Length Code
19+
; | | | | | | | Data Bytes (hex) ...
20+
; | | | | | | | |
21+
; | | | | | | | |
22+
;---+-- ------+------ +- --+-- ----+--- +- -+-- -+ -- -- -- -- -- -- --
23+
1) 17535.4 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
24+
2) 17700.3 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
25+
3) 17873.8 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
26+
4) 19295.4 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
27+
5) 19500.6 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
28+
6) 19705.2 1 Tx 0000 - 8 00 00 00 00 00 00 00 00
29+
7) 20592.7 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
30+
8) 20798.6 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
31+
9) 20956.0 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00
32+
10) 21097.1 1 Tx 00000100 - 8 00 00 00 00 00 00 00 00

test/logformats_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ def test_can_message(self):
939939
[
940940
("V1_0", "test_CanMessage_V1_0_BUS1.trc", False),
941941
("V1_1", "test_CanMessage_V1_1.trc", True),
942+
("V1_3", "test_CanMessage_V1_3.trc", True),
942943
("V2_1", "test_CanMessage_V2_1.trc", True),
943944
]
944945
)

0 commit comments

Comments
 (0)