Skip to content

Commit 1d8aa14

Browse files
committed
Revert "check whether CAN settings were correctly applied (hardbyte#1426)"
This reverts commit cd51ec4.
1 parent 04c8a4d commit 1d8aa14

File tree

2 files changed

+4
-69
lines changed

2 files changed

+4
-69
lines changed

can/interfaces/vector/canlib.py

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __init__(
140140
141141
:raise ~can.exceptions.CanInterfaceNotImplementedError:
142142
If the current operating system is not supported or the driver could not be loaded.
143-
:raise ~can.exceptions.CanInitializationError:
143+
:raise can.exceptions.CanInitializationError:
144144
If the bus could not be set up.
145145
This may or may not be a :class:`~can.interfaces.vector.VectorInitializationError`.
146146
"""
@@ -218,17 +218,15 @@ def __init__(
218218
interface_version,
219219
xldefine.XL_BusTypes.XL_BUS_TYPE_CAN,
220220
)
221-
self.permission_mask = permission_mask.value
222221

223222
LOG.debug(
224223
"Open Port: PortHandle: %d, PermissionMask: 0x%X",
225224
self.port_handle.value,
226225
permission_mask.value,
227226
)
228227

229-
# set CAN settings
230228
for channel in self.channels:
231-
if self._has_init_access(channel):
229+
if permission_mask.value & self.channel_masks[channel]:
232230
if fd:
233231
self._set_bitrate_canfd(
234232
channel=channel,
@@ -244,51 +242,6 @@ def __init__(
244242
elif bitrate:
245243
self._set_bitrate_can(channel=channel, bitrate=bitrate)
246244

247-
# Check CAN settings
248-
for channel in self.channels:
249-
if kwargs.get("_testing", False):
250-
# avoid check if xldriver is mocked for testing
251-
break
252-
253-
bus_params = self._read_bus_params(channel)
254-
if fd:
255-
_canfd = bus_params.canfd
256-
if not all(
257-
[
258-
bus_params.bus_type is xldefine.XL_BusTypes.XL_BUS_TYPE_CAN,
259-
_canfd.can_op_mode
260-
& xldefine.XL_CANFD_BusParams_CanOpMode.XL_BUS_PARAMS_CANOPMODE_CANFD,
261-
_canfd.bitrate == bitrate if bitrate else True,
262-
_canfd.sjw_abr == sjw_abr if bitrate else True,
263-
_canfd.tseg1_abr == tseg1_abr if bitrate else True,
264-
_canfd.tseg2_abr == tseg2_abr if bitrate else True,
265-
_canfd.data_bitrate == data_bitrate if data_bitrate else True,
266-
_canfd.sjw_dbr == sjw_dbr if data_bitrate else True,
267-
_canfd.tseg1_dbr == tseg1_dbr if data_bitrate else True,
268-
_canfd.tseg2_dbr == tseg2_dbr if data_bitrate else True,
269-
]
270-
):
271-
raise CanInitializationError(
272-
f"The requested CAN FD settings could not be set for channel {channel}. "
273-
f"Another application might have set incompatible settings. "
274-
f"These are the currently active settings: {_canfd._asdict()}"
275-
)
276-
else:
277-
_can = bus_params.can
278-
if not all(
279-
[
280-
bus_params.bus_type is xldefine.XL_BusTypes.XL_BUS_TYPE_CAN,
281-
_can.can_op_mode
282-
& xldefine.XL_CANFD_BusParams_CanOpMode.XL_BUS_PARAMS_CANOPMODE_CAN20,
283-
_can.bitrate == bitrate if bitrate else True,
284-
]
285-
):
286-
raise CanInitializationError(
287-
f"The requested CAN settings could not be set for channel {channel}. "
288-
f"Another application might have set incompatible settings. "
289-
f"These are the currently active settings: {_can._asdict()}"
290-
)
291-
292245
# Enable/disable TX receipts
293246
tx_receipts = 1 if receive_own_messages else 0
294247
self.xldriver.xlCanSetChannelMode(self.port_handle, self.mask, tx_receipts, 0)
@@ -387,21 +340,6 @@ def _find_global_channel_idx(
387340
error_code=xldefine.XL_Status.XL_ERR_HW_NOT_PRESENT,
388341
)
389342

390-
def _has_init_access(self, channel: int) -> bool:
391-
return bool(self.permission_mask & self.channel_masks[channel])
392-
393-
def _read_bus_params(self, channel: int) -> "VectorBusParams":
394-
channel_mask = self.channel_masks[channel]
395-
396-
vcc_list = get_channel_configs()
397-
for vcc in vcc_list:
398-
if vcc.channel_mask == channel_mask:
399-
return vcc.bus_params
400-
401-
raise CanInitializationError(
402-
f"Channel configuration for channel {channel} not found."
403-
)
404-
405343
def _set_bitrate_can(
406344
self,
407345
channel: int,

test/test_vector.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def mock_xldriver() -> None:
6262
# backup unmodified values
6363
real_xldriver = canlib.xldriver
6464
real_waitforsingleobject = canlib.WaitForSingleObject
65-
real_has_events = canlib.HAS_EVENTS
6665

6766
# set mock
6867
canlib.xldriver = xldriver_mock
@@ -73,7 +72,6 @@ def mock_xldriver() -> None:
7372
# cleanup
7473
canlib.xldriver = real_xldriver
7574
canlib.WaitForSingleObject = real_waitforsingleobject
76-
canlib.HAS_EVENTS = real_has_events
7775

7876

7977
def test_bus_creation_mocked(mock_xldriver) -> None:
@@ -872,14 +870,13 @@ def xlGetChannelIndex(
872870
def xlOpenPort(
873871
port_handle_p: ctypes.POINTER(xlclass.XLportHandle),
874872
app_name_p: ctypes.c_char_p,
875-
access_mask: int,
876-
permission_mask: xlclass.XLaccess,
873+
access_mask: xlclass.XLaccess,
874+
permission_mask_p: ctypes.POINTER(xlclass.XLaccess),
877875
rx_queue_size: ctypes.c_uint,
878876
xl_interface_version: ctypes.c_uint,
879877
bus_type: ctypes.c_uint,
880878
) -> int:
881879
port_handle_p.value = 0
882-
permission_mask.value = access_mask
883880
return 0
884881

885882

0 commit comments

Comments
 (0)