@@ -392,28 +392,24 @@ def set_filters(self, can_filters=None):
392392
393393 A filter matches, when ``<received_can_id> & can_mask == can_id & can_mask``
394394 """
395+ can_id = 0
396+ can_mask = 0
397+
395398 if not can_filters :
396- # Disable all filters
399+ log . info ( 'Filtering has been disabled' )
397400 self .sw_filters = []
398- canSetAcceptanceFilter (self ._read_handle , 0 , 0 , 0 )
399- canSetAcceptanceFilter (self ._read_handle , 0 , 0 , 1 )
400401 elif len (can_filters ) == 1 :
401- # Standard messages
402- canSetAcceptanceFilter (self ._read_handle ,
403- can_filters [0 ]['can_id' ],
404- can_filters [0 ]['can_mask' ],
405- 0 )
406- # Extended messages
407- canSetAcceptanceFilter (self ._read_handle ,
408- can_filters [0 ]['can_id' ],
409- can_filters [0 ]['can_mask' ],
410- 1 )
402+ can_id = can_filters [0 ]['can_id' ]
403+ can_mask = can_filters [0 ]['can_mask' ]
404+ log .info ('canlib is filtering on ID 0x%X, mask 0x%X' , can_id , can_mask )
411405 self .sw_filters = []
412406 elif len (can_filters ) > 1 :
407+ log .info ('Filtering is handled in Python' )
413408 self .sw_filters = can_filters
414- # Disable HW filtering
415- canSetAcceptanceFilter (self ._read_handle , 0 , 0 , 0 )
416- canSetAcceptanceFilter (self ._read_handle , 0 , 0 , 1 )
409+
410+ # Set filters for both std and ext IDs
411+ for ext in (0 , 1 ):
412+ canSetAcceptanceFilter (self ._read_handle , can_id , can_mask , ext )
417413
418414 def flush_tx_buffer (self ):
419415 """
@@ -461,7 +457,7 @@ def _is_filter_match(self, arb_id):
461457 (or if SW filtering is not used).
462458 """
463459 if not self .sw_filters :
464- # Filtering done on HW or driver level
460+ # Filtering done on HW or driver level or no filtering
465461 return True
466462 for can_filter in self .sw_filters :
467463 if not (arb_id ^ can_filter ['can_id' ]) & can_filter ['can_mask' ]:
0 commit comments