SeedBus: Added can_filters parameter in SeedBus.__init__ method#1999
SeedBus: Added can_filters parameter in SeedBus.__init__ method#1999zariiii9003 merged 4 commits intohardbyte:mainfrom
Conversation
| if can_filters is None: | ||
| can_filters = [{"can_id": 0x00, "can_mask": 0x00}] | ||
|
|
||
| if len(can_filters) > 1: |
There was a problem hiding this comment.
You could use the software fallback of python-can if the user passes multiple filters. Check the implementation in BusABC.
There was a problem hiding this comment.
Good Idea will implement it
- Updated the __init__ function in SeedBus - Implemented software fallback, if the user passes multiple filters in can_filters dict.
|
I have completed the re-implementation of the can_filters for SeeedBus, incorporating the software fallback mechanism. |
|
Also updated the changelog and done all the tox tests |
|
The Line 169 in efd4de5 If you are using hardware filtering, you should return |
|
Ignore the pylint errors, i assume they are caused by the new |
- updated _recv_internal method of SeedBus to return also the Boolean value based on whether hw filter is enabled or not
Sorry, I haven't observed this, now i also updated the _recv_internal method of SeedBus to return the boolean of whether message i already filtered by hardware or to be filtered by software |
|
Again, except that lint error all the tests were passed. |
zariiii9003
left a comment
There was a problem hiding this comment.
Looks good, thank you 👍
This pull request resolves issue #1995 by adding support for configuring the hardware acceptance filter and mask during SeeedBus initialization.
Previously, setting a hardware filter was not possible directly through the init call of SeedBus. Users had to use a workaround by manually overwriting internal attributes (filter_id, mask_id) and re-calling the internal init_frame() method after the bus was already created. This process was unintuitive, broke encapsulation, and was prone to errors.
This PR implements the standard can_filters parameter in the SeeedBus.init method, adhering to the BusABC interface. This allows users to set a hardware filter cleanly in a single step upon bus creation.
Key Changes:
SeeedBus.__init__.Note: This change is fully backward-compatible. If can_filters is not provided or None, the bus defaults to the previous behavior of accepting all messages.
Testing
I have personally tested this feature on a Waveshare USB to CAN Adapter (Model A), which uses the same serial protocol, and can confirm that it works as expected for both default (no filter) and filtered modes.