在J1939协议中使用带有socketcan的python,似乎recvfrom()在数据超过8个字节时没有返回接口。在 J1939 协议中,当数据字节数超过 8 个时,会发送多个 CAN 报文,因为一条 CAN 报文最多只能容纳 8 个数据字节。
使用下面的程序,我看到接口返回 8 个数据字节,但不是 9 个数据字节。
是 Python 的问题还是内核的问题?如果这确实是一个错误,我们如何才能找到合适的开发人员?
谢谢你。
#!/usr/bin/env python3
import socket
send_socket = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_J1939)
interface = "vcan0"
send_socket_src_name = socket.J1939_NO_NAME
send_socket_src_pgn = socket.J1939_NO_PGN
send_socket_src_addr = 0x80
send_socket_src_sck_addr = (interface, send_socket_src_name, send_socket_src_pgn, send_socket_src_addr)
send_socket.bind(send_socket_src_sck_addr)
send_socket_dest_name = socket.J1939_NO_NAME
send_socket_dest_pgn = 0x2300
send_socket_dest_addr = 0x81
send_socket_dest_sck_addr = (interface, send_socket_dest_name, send_socket_dest_pgn, send_socket_dest_addr)
send_socket_data_8_bytes = b'\x01\x02\x03\x04\x05\x06\x07\x08'
send_socket_data_9_bytes = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09'
receive_socket = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_J1939)
receive_socket_src_name = socket.J1939_NO_NAME
receive_socket_src_pgn = socket.J1939_NO_PGN
receive_socket_src_addr = 0x81
receive_socket_src_sck_addr = (interface, receive_socket_src_name, receive_socket_src_pgn, receive_socket_src_addr)
receive_socket.bind(receive_socket_src_sck_addr)
send_socket.sendto(send_socket_data_8_bytes, send_socket_dest_sck_addr)
(data, sock_addr) = receive_socket.recvfrom(128)
(interface, src_name, src_pgn, src_addr) = sock_addr
print(f"interface for 8 data bytes:{interface}")
send_socket.sendto(send_socket_data_9_bytes, send_socket_dest_sck_addr)
(data, sock_addr) = receive_socket.recvfrom(128)
(interface, src_name, src_pgn, src_addr) = sock_addr
print(f"interface for 9 data bytes:{interface}")
receive_socket.close()
send_socket.close()
这是输出:
interface for 8 data bytes:vcan0
interface for 9 data bytes: