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 ability to read and write FlexRayVFrReceiveMsgEx in BLF #1757

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions can/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
)
from .listener import AsyncBufferedReader, BufferedReader, Listener, RedirectReader
from .message import Message
from .flexray_message import FlexRayVFrReceiveMsgEx
from .notifier import Notifier
from .thread_safe_bus import ThreadSafeBus
from .util import set_logging_level
Expand Down
48 changes: 48 additions & 0 deletions can/flexray_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
This module contains the implementation of :class:`can.FlexRayVFrReceiveMsgEx`.
"""

class FlexRayVFrReceiveMsgEx:
"""
The :class:`~can.FlexRayVFrReceiveMsgEx` object is used to represent Flexray message.
"""

__slots__ = [
"timestamp", "is_flexray",
"channel", "version", "channelMask", "_dir", "clientIndexFlexRayVFrReceiveMsgEx",
"clusterNo", "frameId", "headerCrc1", "headerCrc2", "byteCount", "dataCount",
"cycle", "tag", "_data", "frameFlags", "appParameter", "frameCrc", "frameLengthNs",
"frameId1", "pduOffset", "blfLogMask", "reservedFlexRayVFrReceiveMsgEx1"
]

def __init__(
self, timestamp, is_flexray, channel, version, channelMask, _dir,
clientIndexFlexRayVFrReceiveMsgEx, clusterNo, frameId, headerCrc1, headerCrc2,
byteCount, dataCount, cycle, tag, _data, frameFlags, appParameter, frameCrc,
frameLengthNs, frameId1, pduOffset, blfLogMask, reservedFlexRayVFrReceiveMsgEx1
) -> None:
"""Create FlexRayVFrReceiveMsgEx object"""
self.timestamp = timestamp
self.is_flexray = is_flexray
self.channel = channel
self.version = version
self.channelMask = channelMask
self._dir = _dir
self.clientIndexFlexRayVFrReceiveMsgEx = clientIndexFlexRayVFrReceiveMsgEx
self.clusterNo = clusterNo
self.frameId = frameId
self.headerCrc1 = headerCrc1
self.headerCrc2 = headerCrc2
self.byteCount = byteCount
self.dataCount = dataCount
self.cycle = cycle
self.tag = tag
self._data = _data
self.frameFlags = frameFlags
self.appParameter = appParameter
self.frameCrc = frameCrc
self.frameLengthNs = frameLengthNs
self.frameId1 = frameId1
self.pduOffset = pduOffset
self.blfLogMask = blfLogMask
self.reservedFlexRayVFrReceiveMsgEx1 = reservedFlexRayVFrReceiveMsgEx1
52 changes: 52 additions & 0 deletions can/io/blf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Any, BinaryIO, Generator, List, Optional, Tuple, Union, cast

from ..message import Message
from ..flexray_message import FlexRayVFrReceiveMsgEx
from ..typechecking import StringPathLike
from ..util import channel2int, dlc2len, len2dlc
from .generic import BinaryIOMessageReader, FileIOMessageWriter
Expand Down Expand Up @@ -76,6 +77,11 @@ class BLFParseError(Exception):
# group name length, marker name length, description length
GLOBAL_MARKER_STRUCT = struct.Struct("<LLL3xBLLL12x")

# channel, version, channelMask, dir, clientIndexFlexRayVFrReceiveMsgEx,
# clusterNo, frameId, headerCrc1, headerCrc2, byteCount, dataCount,
# cycle, tag, data, frameFlags, appParameter, frameCrc, frameLengthNs,
# frameId1, pduOffset, blfLogMask, reservedFlexRayVFrReceiveMsgEx1
FR_RCVMESSAGE_EX_STRUCT = struct.Struct("<HHHHLLHHHHHHLLLLLLHHH26x32s")

CAN_MESSAGE = 1
LOG_CONTAINER = 10
Expand All @@ -84,6 +90,7 @@ class BLFParseError(Exception):
GLOBAL_MARKER = 96
CAN_FD_MESSAGE = 100
CAN_FD_MESSAGE_64 = 101
FR_RCVMESSAGE_EX = 66

NO_COMPRESSION = 0
ZLIB_DEFLATE = 2
Expand Down Expand Up @@ -221,6 +228,7 @@ def _parse_data(self, data):
unpack_can_fd_64_msg = CAN_FD_MSG_64_STRUCT.unpack_from
can_fd_64_msg_size = CAN_FD_MSG_64_STRUCT.size
unpack_can_error_ext = CAN_ERROR_EXT_STRUCT.unpack_from
unpack_fr_rcvmsg_ex = FR_RCVMESSAGE_EX_STRUCT.unpack_from

start_timestamp = self.start_timestamp
max_pos = len(data)
Expand Down Expand Up @@ -351,6 +359,22 @@ def _parse_data(self, data):
data=data[pos : pos + valid_bytes],
channel=channel - 1,
)
elif obj_type == FR_RCVMESSAGE_EX:
(
channel, version, channelMask, _dir, clientIndexFlexRayVFrReceiveMsgEx,
clusterNo, frameId, headerCrc1, headerCrc2, byteCount, dataCount,
cycle, tag, _data, frameFlags, appParameter, frameCrc, frameLengthNs,
frameId1, pduOffset, blfLogMask, reservedFlexRayVFrReceiveMsgEx1
) = unpack_fr_rcvmsg_ex(data, pos)
if blfLogMask != 0:
# channel add 10 to distinguish flexray channel from can/canfd
yield FlexRayVFrReceiveMsgEx(
timestamp, True,
channel+10, version, channelMask, _dir, clientIndexFlexRayVFrReceiveMsgEx,
clusterNo, frameId, headerCrc1, headerCrc2, byteCount, dataCount,
cycle, tag, _data, frameFlags, appParameter, frameCrc, frameLengthNs,
frameId1, pduOffset, blfLogMask, reservedFlexRayVFrReceiveMsgEx1
)

pos = next_pos

Expand Down Expand Up @@ -450,6 +474,34 @@ def on_message_received(self, msg):
# Many interfaces start channel numbering at 0 which is invalid
channel += 1

if getattr(msg, "is_flexray", False):
data = FR_RCVMESSAGE_EX_STRUCT.pack(
msg.channel - 10,
msg.version,
msg.channelMask,
msg._dir,
msg.clientIndexFlexRayVFrReceiveMsgEx,
msg.clusterNo,
msg.frameId,
msg.headerCrc1,
msg.headerCrc2,
msg.byteCount,
msg.dataCount,
msg.cycle,
msg.tag,
msg._data,
msg.frameFlags,
msg.appParameter,
msg.frameCrc,
msg.frameLengthNs,
msg.frameId1,
msg.pduOffset,
msg.blfLogMask,
msg.reservedFlexRayVFrReceiveMsgEx1
)
self._add_object(FR_RCVMESSAGE_EX, data, msg.timestamp)
return

arb_id = msg.arbitration_id
if msg.is_extended_id:
arb_id |= CAN_MSG_EXT
Expand Down