Skip to content

Commit a35ab98

Browse files
authored
Add TX/RX message direction to socketcan (#780)
1 parent f4c2cff commit a35ab98

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

can/interfaces/socketcan/socketcan.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ def capture_message(
509509
# Fetching the Arb ID, DLC and Data
510510
try:
511511
if get_channel:
512-
cf, addr = sock.recvfrom(CANFD_MTU)
512+
cf, _, msg_flags, addr = sock.recvmsg(CANFD_MTU)
513513
channel = addr[0] if isinstance(addr, tuple) else addr
514514
else:
515-
cf = sock.recv(CANFD_MTU)
515+
cf, _, msg_flags, _ = sock.recvmsg(CANFD_MTU)
516516
channel = None
517517
except socket.error as exc:
518518
raise can.CanError("Error receiving: %s" % exc)
@@ -539,6 +539,9 @@ def capture_message(
539539
bitrate_switch = bool(flags & CANFD_BRS)
540540
error_state_indicator = bool(flags & CANFD_ESI)
541541

542+
# Section 4.7.1: MSG_DONTROUTE: set when the received frame was created on the local host.
543+
is_rx = not bool(msg_flags & socket.MSG_DONTROUTE)
544+
542545
if is_extended_frame_format:
543546
# log.debug("CAN: Extended")
544547
# TODO does this depend on SFF or EFF?
@@ -555,6 +558,7 @@ def capture_message(
555558
is_remote_frame=is_remote_transmission_request,
556559
is_error_frame=is_error_frame,
557560
is_fd=is_fd,
561+
is_rx=is_rx,
558562
bitrate_switch=bitrate_switch,
559563
error_state_indicator=error_state_indicator,
560564
dlc=can_dlc,

0 commit comments

Comments
 (0)