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

オープン
#1,846 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
linux, python, raspberry-pi

調査の方向性

issue に記載されている MCP2515 Raspberry Pi セットアップを使用し、再現コードの socketcan Bus セットアップ、recv ループ、set_filters 呼び出しから始めます。フィルター変更後も受信パスにすでにあるフレームが残るかどうかを調査し、フィルタリングが直ちにどのように動作すべきかを判断します。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時間
マージ済み PR(30日)
42

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hardbyte/python-can のほかの issue

hardbyte/python-can の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。