使用 socketCAN 确认消息被发送到 CAN 总线

Confirmation that the message was sent to the CAN bus using socketCAN

我想确认我的消息已经通过 socketCAN 库保存在 CAN 总线上。 socketCAN 文档描述了使用 recvmsg() 函数时的这种可能性,我对其实现有疑问。

我要实现的功能是确认我的消息在仲裁过程中获胜

我想提到 recvmsg(2) 你参考了 SocketCAN 文档的以下段落:

MSG_CONFIRM: set when the frame was sent via the socket it is received on.
      This flag can be interpreted as a 'transmission confirmation' when the
      CAN driver supports the echo of frames on driver level, see 3.2 and 6.2.
      In order to receive such messages, CAN_RAW_RECV_OWN_MSGS must be set.

这里的关键词是“当 CAN driver支持driver level的帧回显,所以首先要确保,接下来需要开启相应的flags。最后,这样的确认有与 仲裁无关 。当帧失去仲裁时,一旦总线空闲,控制器就会尝试 re-transmit 它。

我想你可以在你的电脑上使用命令"candump can0/can1",它会显示在给定的 CAN 接口上接收到的 CAN 数据包。

Usage: candump [options] <CAN interface>+
  (use CTRL-C to terminate candump)

Options: -t <type>   (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)
         -c          (increment color mode level)
         -i          (binary output - may exceed 80 chars/line)
         -a          (enable additional ASCII output)
     -b <can>    (bridge mode - send received frames to <can>)
     -B <can>    (bridge mode - like '-b' with disabled loopback)
     -u <usecs>  (delay bridge forwarding by <usecs> microseconds)
     -l          (log CAN-frames into file. Sets '-s 2' by default)
     -L          (use log file format on stdout)
     -n <count>  (terminate after receiption of <count> CAN frames)
     -r <size>   (set socket receive buffer to <size>)