-
Notifications
You must be signed in to change notification settings - Fork 638
Adding CAN FD 64 frame support to blf reader #568
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,13 @@ class BLFParseError(Exception): | |
# valid data bytes, data | ||
CAN_FD_MSG_STRUCT = struct.Struct("<HBBLLBBB5x64s") | ||
|
||
# channel, dlc, valid payload length of data, tx count, arbitration id, | ||
# frame length, flags, bit rate used in arbitration phase, | ||
# bit rate used in data phase, time offset of brs field, | ||
# time offset of crc delimiter field, bit count, direction, | ||
# offset if extDataOffset is used, crc | ||
CAN_FD_MSG_64_STRUCT = struct.Struct("<BBBBLLLLLLLHBBL") | ||
|
||
# channel, length, flags, ecc, position, dlc, frame length, id, flags ext, data | ||
CAN_ERROR_EXT_STRUCT = struct.Struct("<HHLBBBxLLH2x8s") | ||
|
||
|
@@ -81,6 +88,7 @@ class BLFParseError(Exception): | |
CAN_MESSAGE2 = 86 | ||
GLOBAL_MARKER = 96 | ||
CAN_FD_MESSAGE = 100 | ||
CAN_FD_MESSAGE_64 = 101 | ||
|
||
NO_COMPRESSION = 0 | ||
ZLIB_DEFLATE = 2 | ||
|
@@ -91,6 +99,12 @@ class BLFParseError(Exception): | |
BRS = 0x2 | ||
ESI = 0x4 | ||
|
||
# CAN FD 64 Flags | ||
REMOTE_FLAG_64 = 0x0010 | ||
EDL_64 = 0x1000 | ||
BRS_64 = 0x2000 | ||
ESI_64 = 0x4000 | ||
|
||
TIME_TEN_MICS = 0x00000001 | ||
TIME_ONE_NANS = 0x00000002 | ||
|
||
|
@@ -236,6 +250,29 @@ def __iter__(self): | |
data=can_data[:length], | ||
channel=channel - 1) | ||
yield msg | ||
elif obj_type == CAN_FD_MESSAGE_64: | ||
( | ||
channel, dlc, _, _, can_id, _, fd_flags | ||
) = CAN_FD_MSG_64_STRUCT.unpack_from(data, pos)[:7] | ||
length = dlc2len(dlc) | ||
can_data = struct.unpack_from( | ||
"<{}s".format(length), | ||
data, | ||
pos + CAN_FD_MSG_64_STRUCT.size | ||
)[0] | ||
msg = Message( | ||
timestamp=timestamp, | ||
arbitration_id=can_id & 0x1FFFFFFF, | ||
is_extended_id=bool(can_id & CAN_MSG_EXT), | ||
is_remote_frame=bool(fd_flags & REMOTE_FLAG_64), | ||
is_fd=bool(fd_flags & EDL_64), | ||
bitrate_switch=bool(fd_flags & BRS_64), | ||
error_state_indicator=bool(fd_flags & ESI_64), | ||
dlc=length, | ||
data=can_data[:length], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be more efficient something like this instead of unpacking the raw data above: data_offset = pos + CAN_FD_MSG_64_STRUCT.size
data[data_offset:data_offset + length] Also I've realized it should really be the valid payload length and not the DLC to support remote frames correctly, but it is more of a sanity thing. |
||
channel=channel - 1 | ||
) | ||
yield msg | ||
elif obj_type == CAN_ERROR_EXT: | ||
(channel, _, _, _, _, dlc, _, can_id, _, | ||
can_data) = CAN_ERROR_EXT_STRUCT.unpack_from(data, pos) | ||
|
@@ -247,6 +284,8 @@ def __iter__(self): | |
data=can_data[:dlc], | ||
channel=channel - 1) | ||
yield msg | ||
# else: | ||
# LOG.warning("Unknown object type (%d)", obj_type) | ||
felixdivo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
pos = next_pos | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.