Socket-CAN virtual bus

大城市里の小女人 提交于 2019-12-06 01:57:16

问题


How can I create several virtual sockets and link them together to create a virtual bus?

I want to simulate an application in which many nodes communicate to each other via CAN.


回答1:


All you need is cangw tool from can-utils. Create two virtual interfaces:

ip link add dev vcan0 type vcan
ip link add dev vcan1 type vcan
ip link set up vcan0
ip link set up vcan1

Create routing rule, so that all packets coming to vcan0 will be sent to vcan1:

cangw -A -s vcan0 -d vcan1 -e

Listen to vcan1 in one terminal:

candump vcan1

And send packet from another terminal:

cansend vcan0 123#0011

You'll see, that candump will get this CAN packet:

vcan1  123   [2]  00 11


来源:https://stackoverflow.com/questions/33574256/socket-can-virtual-bus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!