ilya1725
ilya1725

Reputation: 4968

Send one-shot message using SocketCAN

Is it possible to send a "one-shot" CAN message using SocketCAN? This is basically a message that does not expect an acknowledgement back from the receiver. The protocol allows this ACK bit not to be set.

Upvotes: 4

Views: 12297

Answers (2)

Fusho
Fusho

Reputation: 1467

The CAN frame will be retransmitted again and again until a bus error is detected (bus off). This is done by the CAN peripheral (it is part of the spec, search for "retransmission"), SocketCan does not know anything about that.

SocketCan allows you to subscribe to different error notifications on the bus/controller. In general, CAN peripherals/drivers implement the signaling of a subset of these errors only. If you are lucky, you could be able to subscribe (see 4.1.2) for notifications and react accordingly.

Upvotes: 0

evadeflow
evadeflow

Reputation: 4944

I'm not sure what you mean by "one-shot", but I send single CAN frames all the time using the cansend utility from can-utils, like this:

$ cansend can0 135#02080426A10D112A

I've also written C programs that do the same using an AF_CAN socket. (You can basically crib from cansend.c to figure out how.)

Regarding retransmission of messages, this doesn't happen with cansend:

$ timeout 20s tcpdump -i can0 -w out.pcap &                                                                                                                                               
[1] 16509
tcpdump: listening on can0, link-type CAN_SOCKETCAN (CAN-bus with SocketCAN headers), capture size 262144 bytes

$ cansend can0 135#02080426A10D112A

$ 1 packet captured
0 packets received by filter
0 packets dropped by kernel

[1]  + 16509 exit 124   timeout 20s tcpdump -i can0 -w out.pcap

In the sequence above, there are no consumers online, so nobody ACKs the message, but I still only capture a single packet on can0. It seems safe to conclude that the SocketCAN stack isn't 'automagically' trying to re-send the message in the background after cansend exits.

Upvotes: 2

Related Questions