reference
https://processors.wiki.ti.com/index.php/AM335X_DCAN_Driver_Guide#CAN_Utilities
http://velep.com/archives/1181.html
Linux 提供了SocketCAN 接口
s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
//创建 SocketCAN 套接字
基于 SocketCAN 的 can-utils 工具套件
can utility
canutils build is depends on libsocketcan binaries so build libsocketcan first then proceed to canutils
Source for canutils are available at http://git.pengutronix.de/?p=tools/canutils.git;a=shortlog;h=refs/heads/master
Source for libsocketcan is available at http://www.pengutronix.de/software/libsocketcan/download/libsocketcan-0.0.8.tar.bz2
#can网络开启/关闭
ip link set can0 down
关闭can0 网络
#设置波特率
ip link set can0 up type can bitrate 800000
设置can0的波特率为800kbps,CAN波特率最大值为1Mbps,CAN-FD波特率最大值为10Mbps.
#发送数据(默认ID)
cansend can0 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
发送默认ID为0x1的can标准帧,数据为0x11 22 33 44 55 66 77 88
#发送数据(指定ID)
cansend can0 -i 0x800 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 -e
-i表示CAN_ID
-e 表示扩展帧,CAN_ID最大29bit,标准帧CAN_ID最大11bit
#--loop 表示发送20个包 $ cansend can0 -i 0xFFFFF 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 -e --loop=20
Transmit 20 packets of 8 bytes each with same extended packet id number as 0xFFFFF
#
$ candump can0
Packet reception can be achieve by using candump utility
#Statistics of CAN device can be seen from these commands
$ ip -d -s link show can0
Below command also used to know the details
$ cat /proc/net/can/stats