Skip to content

Commit 8a09725

Browse files
author
Pierre-Luc Tessier Gagné
committed
Adding CAN FD 64 frame support to blf reader
1 parent 3dd1184 commit 8a09725

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

can/io/blf.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class BLFParseError(Exception):
6666
# valid data bytes, data
6767
CAN_FD_MSG_STRUCT = struct.Struct("<HBBLLBBB5x64s")
6868

69+
# channel, dlc, valid payload length of data, tx count, arbitration id,
70+
# frame length, flags, bit rate used in arbitration phase,
71+
# bit rate used in data phase, time offset of brs field,
72+
# time offset of crc delimiter field, bit count, direction,
73+
# offset if extDataOffset is used, crc
74+
CAN_FD_MSG_64_STRUCT = struct.Struct("<BBBBLLLLLLLHBBL")
75+
6976
# channel, length, flags, ecc, position, dlc, frame length, id, flags ext, data
7077
CAN_ERROR_EXT_STRUCT = struct.Struct("<HHLBBBxLLH2x8s")
7178

@@ -81,6 +88,7 @@ class BLFParseError(Exception):
8188
CAN_MESSAGE2 = 86
8289
GLOBAL_MARKER = 96
8390
CAN_FD_MESSAGE = 100
91+
CAN_FD_MESSAGE_64 = 101
8492

8593
NO_COMPRESSION = 0
8694
ZLIB_DEFLATE = 2
@@ -91,6 +99,12 @@ class BLFParseError(Exception):
9199
BRS = 0x2
92100
ESI = 0x4
93101

102+
# CAN FD 64 Flags
103+
REMOTE_FLAG_64 = 0x0010
104+
EDL_64 = 0x1000
105+
BRS_64 = 0x2000
106+
ESI_64 = 0x4000
107+
94108
TIME_TEN_MICS = 0x00000001
95109
TIME_ONE_NANS = 0x00000002
96110

@@ -236,6 +250,29 @@ def __iter__(self):
236250
data=can_data[:length],
237251
channel=channel - 1)
238252
yield msg
253+
elif obj_type == CAN_FD_MESSAGE_64:
254+
(
255+
channel, dlc, _, _, can_id, _, fd_flags
256+
) = CAN_FD_MSG_64_STRUCT.unpack_from(data, pos)[:7]
257+
length = dlc2len(dlc)
258+
can_data = struct.unpack_from(
259+
"<{}s".format(length),
260+
data,
261+
pos + CAN_FD_MSG_64_STRUCT.size
262+
)[0]
263+
msg = Message(
264+
timestamp=timestamp,
265+
arbitration_id=can_id & 0x1FFFFFFF,
266+
is_extended_id=bool(can_id & CAN_MSG_EXT),
267+
is_remote_frame=bool(fd_flags & REMOTE_FLAG_64),
268+
is_fd=bool(fd_flags & EDL_64),
269+
bitrate_switch=bool(fd_flags & BRS_64),
270+
error_state_indicator=bool(fd_flags & ESI_64),
271+
dlc=length,
272+
data=can_data[:length],
273+
channel=channel - 1
274+
)
275+
yield msg
239276
elif obj_type == CAN_ERROR_EXT:
240277
(channel, _, _, _, _, dlc, _, can_id, _,
241278
can_data) = CAN_ERROR_EXT_STRUCT.unpack_from(data, pos)
@@ -247,6 +284,8 @@ def __iter__(self):
247284
data=can_data[:dlc],
248285
channel=channel - 1)
249286
yield msg
287+
# else:
288+
# LOG.warning("Unknown object type (%d)", obj_type)
250289

251290
pos = next_pos
252291

0 commit comments

Comments
 (0)