Skip to content

Conversation

@varunpenumudi
Copy link
Contributor

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:

  • Added the can_filters parameter to SeeedBus.__init__.
  • The implementation validates that only one filter is provided, raising a can.CanInitializationError if more are given, in accordance with the SeedBus protocol limitation.
  • Updated the seeedstudio.rst documentation to reflect the new parameter and its usage
  • Added a news fragment for the changelog.

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.

if can_filters is None:
can_filters = [{"can_id": 0x00, "can_mask": 0x00}]

if len(can_filters) > 1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the software fallback of python-can if the user passes multiple filters. Check the implementation in BusABC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Idea will implement it

- Updated the __init__ function in SeedBus
- Implemented software fallback, if the user passes multiple filters in can_filters dict.
@varunpenumudi
Copy link
Contributor Author

varunpenumudi commented Oct 19, 2025

I have completed the re-implementation of the can_filters for SeeedBus, incorporating the software fallback mechanism.

@varunpenumudi
Copy link
Contributor Author

Also updated the changelog and done all the tox tests

@zariiii9003
Copy link
Collaborator

The _recv_internal method should also be updated. It returns a message and a boolean value:

2. a bool that is True if message filtering has already

If you are using hardware filtering, you should return True, for software filtering return False. You can add an attribute self._is_filtered and return that in in _recv_internal

@zariiii9003
Copy link
Collaborator

Ignore the pylint errors, i assume they are caused by the new wrapt version.

- updated _recv_internal method of SeedBus to return also the Boolean value based on whether hw filter is enabled or not
@varunpenumudi
Copy link
Contributor Author

The _recv_internal method should also be updated. It returns a message and a boolean value:

2. a bool that is True if message filtering has already

If you are using hardware filtering, you should return True, for software filtering return False. You can add an attribute self._is_filtered and return that in in _recv_internal

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

@varunpenumudi
Copy link
Contributor Author

Again, except that lint error all the tests were passed.

Copy link
Collaborator

@zariiii9003 zariiii9003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you 👍

@zariiii9003 zariiii9003 merged commit b4d5094 into hardbyte:main Oct 21, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants