Skip to content

Commit

Permalink
Fix is_rx for receive_own_messages for Kvaser (#1908)
Browse files Browse the repository at this point in the history
* Enable LOCAL_TXACK to fix is_rx for Kvaser

* Add missing constant definition

* Update comment
  • Loading branch information
btRooke authored Feb 2, 2025
1 parent b323e77 commit 71e5e19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions can/interfaces/kvaser/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,15 @@ def __init__(
1,
)

# enable canMSG_LOCAL_TXACK flag in received messages

canIoCtlInit(
self._read_handle,
canstat.canIOCTL_SET_LOCAL_TXACK,
ctypes.byref(ctypes.c_byte(local_echo)),
1,
)

if self.single_handle:
log.debug("We don't require separate handles to the bus")
self._write_handle = self._read_handle
Expand Down Expand Up @@ -671,6 +680,7 @@ def _recv_internal(self, timeout=None):
is_remote_frame = bool(flags & canstat.canMSG_RTR)
is_error_frame = bool(flags & canstat.canMSG_ERROR_FRAME)
is_fd = bool(flags & canstat.canFDMSG_FDF)
is_rx = not bool(flags & canstat.canMSG_LOCAL_TXACK)
bitrate_switch = bool(flags & canstat.canFDMSG_BRS)
error_state_indicator = bool(flags & canstat.canFDMSG_ESI)
msg_timestamp = timestamp.value * TIMESTAMP_FACTOR
Expand All @@ -682,6 +692,7 @@ def _recv_internal(self, timeout=None):
is_error_frame=is_error_frame,
is_remote_frame=is_remote_frame,
is_fd=is_fd,
is_rx=is_rx,
bitrate_switch=bitrate_switch,
error_state_indicator=error_state_indicator,
channel=self.channel,
Expand Down
2 changes: 2 additions & 0 deletions can/interfaces/kvaser/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def CANSTATUS_SUCCESS(status):
canMSG_ERROR_FRAME = 0x0020
canMSG_TXACK = 0x0040
canMSG_TXRQ = 0x0080
canMSG_LOCAL_TXACK = 0x1000_0000

canFDMSG_FDF = 0x010000
canFDMSG_BRS = 0x020000
Expand Down Expand Up @@ -195,6 +196,7 @@ def CANSTATUS_SUCCESS(status):
canIOCTL_GET_USB_THROTTLE = 29
canIOCTL_SET_BUSON_TIME_AUTO_RESET = 30
canIOCTL_SET_LOCAL_TXECHO = 32
canIOCTL_SET_LOCAL_TXACK = 46
canIOCTL_PREFER_EXT = 1
canIOCTL_PREFER_STD = 2
canIOCTL_CLEAR_ERROR_COUNTERS = 5
Expand Down

0 comments on commit 71e5e19

Please sign in to comment.