Skip to content

Commit dde7f03

Browse files
authored
Merge pull request #25 from karlfl/Use_All_Mask_Filter_Pairs
Use all mask filter pairs
2 parents 284a7f0 + 3d89b02 commit dde7f03

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

adafruit_mcp2515/__init__.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,20 @@ def _create_mask(self, match):
782782
else:
783783
mask = STDID_BOTTOM_11_MASK
784784

785+
# has this mask already been loaded?
786+
for index, existing_mask in enumerate(self._masks_in_use):
787+
if mask == existing_mask:
788+
self._dbg("Mask Found", index, existing_mask)
789+
return index
790+
785791
masks_used = len(self._masks_in_use)
786792
if masks_used < len(MASKS):
787793
next_mask_index = masks_used
788794

789795
self._set_mask_register(next_mask_index, mask, match.extended)
790-
self._masks_in_use.append(MASKS[next_mask_index])
796+
# Append the actual mask to the 'in use' array so later we can
797+
# find it to use again
798+
self._masks_in_use.append(mask)
791799
return next_mask_index
792800

793801
raise RuntimeError("No Masks Available")
@@ -875,25 +883,39 @@ def listen(self, matches=None, *, timeout: float = 10):
875883
Creating a listener is an expensive operation and can interfere with reception of messages
876884
by other listeners.
877885
878-
There is an implementation-defined maximum number of listeners and limit to the complexity of
879-
the filters.
886+
There is an implementation-defined maximum number of listeners and limit to the complexity \
887+
of the filters.
888+
889+
If the hardware cannot support all the requested matches, a ValueError is raised. Note \
890+
that generally there are some number of hardware filters shared among all fifos.
880891
881-
If the hardware cannot support all the requested matches, a ValueError is raised. Note that \
882-
generally there are some number of hardware filters shared among all fifos.
892+
A message can be received by at most one Listener. If more than one listener matches a \
893+
message, it is undefined which one actually receives it.
883894
884-
A message can be received by at most one Listener. If more than one listener matches a message,\
885-
it is undefined which one actually receives it.
895+
The MCP2515 has space for 2 masks (RXM0/RXM1) and 6 filters (RXMF0-RXMF5). \
896+
Mask RXM0 is paired with 2 filters (RXF0-1) and mask RXM1 is paired with 4 filters \
897+
(RXF2-5). Read the MCP2515 datasheet for more details on masks and filters.
886898
887-
An empty filter list causes all messages to be accepted.
899+
You can use up to 6 matches (match = mask & filter) in the array. \
900+
The order of the match objects in the array matters. \
901+
The first unique mask will be placed in RXM0 and can be paired with up to 2 filters. \
902+
The second unique mask will be placed in RXM1 and can be paired with up to 4 filters. \
903+
When no mask is defined in the match object, an 'exact match' mask of all 1's will be \
904+
used. You can use the same mask in multiple matches, however if there are more than \
905+
2 unique masks in the matches array, a RuntimeError will be raised. \
906+
Similarly if there are more than 2 filters used with the first unique mask or \
907+
more than 4 filters used with the second unique mask a RuntimeError will be raised.
888908
889-
Timeout dictates how long ``receive()`` will block.
909+
An empty matches array causes all messages to be accepted.
890910
891911
Args:
892-
match (Optional[Sequence[Match]], optional): [description]. Defaults to None.
893-
timeout (float, optional): [description]. Defaults to 10.
912+
matches ([canio.Match], optional): ID patterns used to restrict the packets received. \
913+
Defaults to None.
914+
timeout (float, optional): dictates how long ``receive()`` will block. Defaults to 10.
894915
895916
Returns:
896-
Listener: [description]
917+
`canio.Listener`: Listener object used to receive CANio packets based on the arguments \
918+
passed into ``listen()``
897919
"""
898920
if matches is None:
899921
matches = []

0 commit comments

Comments
 (0)