Skip to content

Commit 71e5e19

Browse files
authored
Fix is_rx for receive_own_messages for Kvaser (#1908)
* Enable LOCAL_TXACK to fix is_rx for Kvaser * Add missing constant definition * Update comment
1 parent b323e77 commit 71e5e19

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

can/interfaces/kvaser/canlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,15 @@ def __init__(
554554
1,
555555
)
556556

557+
# enable canMSG_LOCAL_TXACK flag in received messages
558+
559+
canIoCtlInit(
560+
self._read_handle,
561+
canstat.canIOCTL_SET_LOCAL_TXACK,
562+
ctypes.byref(ctypes.c_byte(local_echo)),
563+
1,
564+
)
565+
557566
if self.single_handle:
558567
log.debug("We don't require separate handles to the bus")
559568
self._write_handle = self._read_handle
@@ -671,6 +680,7 @@ def _recv_internal(self, timeout=None):
671680
is_remote_frame = bool(flags & canstat.canMSG_RTR)
672681
is_error_frame = bool(flags & canstat.canMSG_ERROR_FRAME)
673682
is_fd = bool(flags & canstat.canFDMSG_FDF)
683+
is_rx = not bool(flags & canstat.canMSG_LOCAL_TXACK)
674684
bitrate_switch = bool(flags & canstat.canFDMSG_BRS)
675685
error_state_indicator = bool(flags & canstat.canFDMSG_ESI)
676686
msg_timestamp = timestamp.value * TIMESTAMP_FACTOR
@@ -682,6 +692,7 @@ def _recv_internal(self, timeout=None):
682692
is_error_frame=is_error_frame,
683693
is_remote_frame=is_remote_frame,
684694
is_fd=is_fd,
695+
is_rx=is_rx,
685696
bitrate_switch=bitrate_switch,
686697
error_state_indicator=error_state_indicator,
687698
channel=self.channel,

can/interfaces/kvaser/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def CANSTATUS_SUCCESS(status):
6363
canMSG_ERROR_FRAME = 0x0020
6464
canMSG_TXACK = 0x0040
6565
canMSG_TXRQ = 0x0080
66+
canMSG_LOCAL_TXACK = 0x1000_0000
6667

6768
canFDMSG_FDF = 0x010000
6869
canFDMSG_BRS = 0x020000
@@ -195,6 +196,7 @@ def CANSTATUS_SUCCESS(status):
195196
canIOCTL_GET_USB_THROTTLE = 29
196197
canIOCTL_SET_BUSON_TIME_AUTO_RESET = 30
197198
canIOCTL_SET_LOCAL_TXECHO = 32
199+
canIOCTL_SET_LOCAL_TXACK = 46
198200
canIOCTL_PREFER_EXT = 1
199201
canIOCTL_PREFER_STD = 2
200202
canIOCTL_CLEAR_ERROR_COUNTERS = 5

0 commit comments

Comments
 (0)