hardbyte / hardbyte/python-can

Filters not working properly (socketcan on rPi with MCP 2515 hat

Đang mở
#1,846 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Describe the bug
For my aplication I need to set filters dynamically, changing them every second or so. The bus I'm working on is quite crowded and I am runing into issues where blocked IDs are still read after the filter is set, I suppose these messages come from the RX buffer.

### To Reproduce
`import os
import can
import time

os.system('sudo ip link set can0 type can bitrate 500000')
os.system('sudo ifconfig can0 up')

can0 = can.interface.Bus(channel='can0', bustype='socketcan') # socketcan_native

print("setup ok")

timeout = 999.0
start_time = time.time()
filterchanged = False

while time.time() - start_time < timeout:
msg = can0.recv(0.1)
if time.time() - start_time > 3 and filterchanged == False:
time.sleep(2)
can0.set_filters([{"can_id" : 0x200, "can_mask" : 0xFFF, "extended" : False}])
filterchanged = True
print("filter changed")
if msg is not None:
print("Received message on can0:", msg)
else:
print('Timeout occurred, no message.')
can0.shutdown()
os.system('sudo ifconfig can0 down')`

While this code is running on the rPi, i'm sending random messages on IDs 0x100 and 0x200. As we can see on the screenshot of the terminal, messages with the ID 0x100 are still read after the filter is set up.

![Screenshot from 2024-08-28 16-02-02](https://github.com/user-attachments/assets/7f90969a-f679-4a85-bec9-1c4f1982dd1c)

### Expected behavior
I expect messages to be filtered right away.

### Additional context

OS and version: rPi os 12
Python version: 3.11.2
python-can version:
python-can interface/s (if applicable): MCP2515 2ch hat from waveshare

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.