@@ -90,17 +90,22 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
9090 self .mask = 0
9191 self .fd = fd
9292 # Get channels masks
93+ self .channel_masks = {}
94+ self .index_to_channel = {}
9395 for channel in self .channels :
9496 hw_type = ctypes .c_uint (0 )
9597 hw_index = ctypes .c_uint (0 )
9698 hw_channel = ctypes .c_uint (0 )
9799 vxlapi .xlGetApplConfig (self ._app_name , channel , hw_type , hw_index ,
98100 hw_channel , vxlapi .XL_BUS_TYPE_CAN )
99101 LOG .debug ('Channel index %d found' , channel )
100- mask = vxlapi .xlGetChannelMask (hw_type .value , hw_index .value ,
102+ idx = vxlapi .xlGetChannelIndex (hw_type .value , hw_index .value ,
101103 hw_channel .value )
102- LOG .debug ('Channel %d, Type: %d, Mask: %d' ,
104+ mask = 1 << idx
105+ LOG .debug ('Channel %d, Type: %d, Mask: 0x%X' ,
103106 hw_channel .value , hw_type .value , mask )
107+ self .channel_masks [channel ] = mask
108+ self .index_to_channel [idx ] = channel
104109 self .mask |= mask
105110
106111 permission_mask = vxlapi .XLaccess ()
@@ -225,6 +230,7 @@ def _recv_internal(self, timeout):
225230 dlc = dlc2len (event .tagData .canRxOkMsg .dlc )
226231 flags = event .tagData .canRxOkMsg .msgFlags
227232 timestamp = event .timeStamp * 1e-9
233+ channel = self .index_to_channel .get (event .chanIndex )
228234 msg = Message (
229235 timestamp = timestamp + self ._time_offset ,
230236 arbitration_id = msg_id & 0x1FFFFFFF ,
@@ -236,7 +242,7 @@ def _recv_internal(self, timeout):
236242 bitrate_switch = bool (flags & vxlapi .XL_CAN_RXMSG_FLAG_BRS ),
237243 dlc = dlc ,
238244 data = event .tagData .canRxOkMsg .data [:dlc ],
239- channel = event . chanIndex )
245+ channel = channel )
240246 return msg , self ._is_filtered
241247 else :
242248 event_count .value = 1
@@ -251,6 +257,7 @@ def _recv_internal(self, timeout):
251257 dlc = event .tagData .msg .dlc
252258 flags = event .tagData .msg .flags
253259 timestamp = event .timeStamp * 1e-9
260+ channel = self .index_to_channel .get (event .chanIndex )
254261 msg = Message (
255262 timestamp = timestamp + self ._time_offset ,
256263 arbitration_id = msg_id & 0x1FFFFFFF ,
@@ -260,7 +267,7 @@ def _recv_internal(self, timeout):
260267 is_fd = False ,
261268 dlc = dlc ,
262269 data = event .tagData .msg .data [:dlc ],
263- channel = event . chanIndex )
270+ channel = channel )
264271 return msg , self ._is_filtered
265272
266273 if end_time is not None and time .time () > end_time :
@@ -286,6 +293,10 @@ def send(self, msg, timeout=None):
286293
287294 flags = 0
288295
296+ # If channel has been specified, try to send only to that one.
297+ # Otherwise send to all channels
298+ mask = self .channel_masks .get (msg .channel , self .mask )
299+
289300 if self .fd :
290301 if msg .is_fd :
291302 flags |= vxlapi .XL_CAN_TXMSG_FLAG_EDL
@@ -306,7 +317,7 @@ def send(self, msg, timeout=None):
306317 XLcanTxEvent .tagData .canMsg .dlc = len2dlc (msg .dlc )
307318 for idx , value in enumerate (msg .data ):
308319 XLcanTxEvent .tagData .canMsg .data [idx ] = value
309- vxlapi .xlCanTransmitEx (self .port_handle , self . mask , message_count , MsgCntSent , XLcanTxEvent )
320+ vxlapi .xlCanTransmitEx (self .port_handle , mask , message_count , MsgCntSent , XLcanTxEvent )
310321
311322 else :
312323 if msg .is_remote_frame :
@@ -322,7 +333,7 @@ def send(self, msg, timeout=None):
322333 xl_event .tagData .msg .flags = flags
323334 for idx , value in enumerate (msg .data ):
324335 xl_event .tagData .msg .data [idx ] = value
325- vxlapi .xlCanTransmit (self .port_handle , self . mask , message_count , xl_event )
336+ vxlapi .xlCanTransmit (self .port_handle , mask , message_count , xl_event )
326337
327338
328339 def flush_tx_buffer (self ):
0 commit comments