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

未关闭
#1,846 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
linux, python, raspberry-pi

调研方向

从复现中的 socketcan 总线设置、recv 循环和 set_filters 调用开始,使用 issue 中描述的 MCP2515 Raspberry Pi 设置。调查接收路径中已经存在的帧在过滤器更改后是否仍然保留,并确定过滤应如何立即生效;完成的标准是应用 0x200 过滤器后,不再出现报告的 0x100 帧。

由索引模型根据 Issue 内容生成。

描述

bug
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

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

主要语言
Python
星标
1.6k
派生
715
平均合并
2 天 4 小时
30 天内合并 PR
42

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hardbyte/python-can 的其他 Issue

查看 hardbyte/python-can 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。