Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions can/interfaces/seeedstudio/seeedstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
frame_type="STD",
operation_mode="normal",
bitrate=500000,
can_filters = [{"can_id": 0x00, "can_mask": 0x00}],
**kwargs,
):
"""
Expand All @@ -79,12 +80,18 @@ def __init__(
:param str frame_type:
STD or EXT, to select standard or extended messages

:param operation_mode
:param operation_mode:
normal, loopback, silent or loopback_and_silent.

:param bitrate
:param bitrate:
CAN bus bit rate, selected from available list.

:param can_filters:
A list of can filter dictionaries. For the SeeedBus interface,
this list must not contain more than one filter.
Each filter is a dict with 'can_id', 'can_mask'.
Defaults to No filter (i.e [{"can_id": 0x00, "can_mask": 0x00}]).

:raises can.CanInitializationError: If the given parameters are invalid.
:raises can.CanInterfaceNotImplementedError: If the serial module is not installed.
"""
Expand All @@ -93,12 +100,21 @@ def __init__(
raise can.CanInterfaceNotImplementedError(
"the serial module is not installed"
)

if len(can_filters) > 1:
raise can.CanInitializationError(
f"The SeeedBus interface only supports one hardware filter, "
f"but {len(can_filters)} were provided."
)

# Get the first (and only) filter in can_filters
hw_filter = can_filters[0]

self.bit_rate = bitrate
self.frame_type = frame_type
self.op_mode = operation_mode
self.filter_id = bytearray([0x00, 0x00, 0x00, 0x00])
self.mask_id = bytearray([0x00, 0x00, 0x00, 0x00])
self.filter_id = struct.pack('<I', hw_filter['can_id'])
self.mask_id = struct.pack('<I', hw_filter['can_mask'])
self._can_protocol = CanProtocol.CAN_20

if not channel:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1995.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added hardware filter support for SeeedBus during initialization.
17 changes: 16 additions & 1 deletion doc/interfaces/seeedstudio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Configuration
timeout=0.1,
frame_type='STD',
operation_mode='normal',
bitrate=500000)
bitrate=500000,
can_filters = [dict(can_id = 0x00, can_mask = 0x00)])

CHANNEL
The serial port created by the USB device when connected.
Expand Down Expand Up @@ -75,3 +76,17 @@ BITRATE
- 20000
- 10000
- 5000

CAN_FILTERS
A list of can filter dictionaries. Defaults to the value
``[{"can_id": 0x00, "can_mask": 0x00}]`` (i.e. no filtering).
An example filter: ``[{"can_id": 0x11, "can_mask": 0x21}]``

**Hardware Limitation:** The Seeed Studio device only supports
a single hardware filter. This list must contain at most
one filter dictionary. A ``can.CanInitializationError`` will be
raised if more than one filter is provided.

Each filter dictionary should have the following keys:
- ``can_id``: The CAN ID to filter on.
- ``can_mask``: The mask to apply to the ID.