Skip to content

Add TX/RX message direction to socketcan #780

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 4 commits into from
Apr 4, 2020
Merged
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
8 changes: 6 additions & 2 deletions can/interfaces/socketcan/socketcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,10 @@ def capture_message(
# Fetching the Arb ID, DLC and Data
try:
if get_channel:
cf, addr = sock.recvfrom(CANFD_MTU)
cf, _, msg_flags, addr = sock.recvmsg(CANFD_MTU)
channel = addr[0] if isinstance(addr, tuple) else addr
else:
cf = sock.recv(CANFD_MTU)
cf, _, msg_flags, _ = sock.recvmsg(CANFD_MTU)
channel = None
except socket.error as exc:
raise can.CanError("Error receiving: %s" % exc)
Expand All @@ -539,6 +539,9 @@ def capture_message(
bitrate_switch = bool(flags & CANFD_BRS)
error_state_indicator = bool(flags & CANFD_ESI)

# Section 4.7.1: MSG_DONTROUTE: set when the received frame was created on the local host.
is_rx = not bool(msg_flags & socket.MSG_DONTROUTE)

if is_extended_frame_format:
# log.debug("CAN: Extended")
# TODO does this depend on SFF or EFF?
Expand All @@ -555,6 +558,7 @@ def capture_message(
is_remote_frame=is_remote_transmission_request,
is_error_frame=is_error_frame,
is_fd=is_fd,
is_rx=is_rx,
bitrate_switch=bitrate_switch,
error_state_indicator=error_state_indicator,
dlc=can_dlc,
Expand Down