SeeedBus: Allow setting hardware filter/mask during Bus Init
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- python
- Ambito
- embedded-iot, networking
Direzione di ricerca
Inizia da SeeedBus.init e dal percorso interno init_frame() descritto nell’issue. Traccia come filter_id e mask_id vengono attualmente inizializzati e inviati all’hardware, quindi verifica che i valori opzionali configurino il filtro durante la costruzione, mentre i valori omessi mantengano il comportamento attuale senza filtro.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Main Problem
I don't like that the SeeedBus interface does not allow for the configuration of the hardware acceptance filter and mask during the bus initialization.
My use case involves a bootloader flasher client that communicates with a device over the CAN bus. The client sends a message with one CAN ID and needs to listen only for a response on another specific CAN ID. To achieve this efficiently, I need to use the hardware filter. The current implementation forces me to create the bus object, then manually change its internal attributes (filter_id, mask_id), and then re-call the internal init_frame() method. This workflow is not intuitive and feels like a workaround.
Current Alternative
The only alternative at the moment is to manually re-configure the bus after it has been created. This involves the following steps:
import struct
# 1. Create the bus with default (disabled) filters
bus = can.interface.Bus(interface='seeedstudio', channel='/dev/ttyUSB0')
# 2. Manually overwrite the internal attributes
bus.filter_id = struct.pack('<I', 0x456 << 21)
bus.mask_id = struct.pack('<I', 0xFFFFFFFF)
# 3. Call the internal init_frame() method again to send the new config to the hardware
bus.init_frame()
This is not an ideal solution because it is recalling init_frame() method again after it is called in init, and is little more complicated.
Want to change Like this
I would like to have filter_id and mask_id added as optional keyword arguments to the SeeedBus.init method. This would allow the hardware filter to be configured cleanly and directly when the bus is created.
Example of the desired usage:
Python
# Initialize the bus to only accept messages with ID 0x456
bus = can.interface.Bus(
interface='seeedstudio',
channel='/dev/ttyUSB0',
bitrate=500000,
frame_type='STD',
filter_id=0x456,
mask_id=0xFFFFFFFF
)
# The bus is now ready to use with the hardware filter active.
msg = bus.recv()
Note: If the filter_id and mask_id arguments are not provided, they will default to 0x00. This maintains the current behavior where the filter is disabled and all CAN IDs are received, ensuring the change is fully backward-compatible.
# Initialize the bus
# Filter ID, Mask ID here defaults to 0x00 so no filtering of can messages
bus = can.interface.Bus(
interface='seeedstudio',
channel='/dev/ttyUSB0',
bitrate=500000,
frame_type='STD',
)
# The bus is now ready to use with the hardware filter active.
msg = bus.recv()
This feature request originated from my work on a project using a Waveshare USB to CAN Adapter (Model A). This device works perfectly with the seeedstudio interface as it uses the same serial protocol. The lack of an initial filtering mechanism was the primary challenge I faced.
Adding this feature would be a significant improvement for any application that needs to use hardware filtering with Seeed Studio or compatible devices. I am currently working on this feature by cloning the repo, making the changes, and am prepared to submit a pull request to resolve this issue.
- Lingua principale
- Python
- Stelle
- 1.6k
- Fork
- 697
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di hardbyte/python-can
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
hardbyte/python-can#2103 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
hardbyte/python-can#2077 · 1 commento · 1 reazione ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
hardbyte/python-can#1922 · 1 reazione ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
hardbyte/python-can#2102 ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
hardbyte/python-can#2092 ·
Tutte le issue di hardbyte/python-can
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
canonical/paas-charm#368 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
addition to tracking list Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
StevenBlack/hosts#3256 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
qualcomm/qai-appbuilder#275 ·