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

Abierto
#1,846 0 comentarios 2 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
linux, python, raspberry-pi

Línea de trabajo

Comienza con la configuración del bus socketcan, el bucle recv y la llamada a set_filters en la reproducción, utilizando la configuración de MCP2515 en Raspberry Pi descrita en la issue. Investiga si los frames que ya están en la ruta de recepción permanecen después de cambiar los filtros y determina cómo debe comportarse el filtrado inmediatamente; se considera terminado cuando los frames 0x100 reportados ya no aparecen después de aplicar el filtro 0x200.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
1.6k
Forks
715
Merge medio
2 d 4 h
PR fusionados (30 d)
42

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hardbyte/python-can

Todos los issues de hardbyte/python-can

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.