使用SocketCAN编写自定义CAN协议

时间:2015-07-28 19:37:38

标签: linux beagleboneblack can-bus socketcan

我试图为SocketCAN编写一个稍微修改过的CAN协议。 SocketCAN文档有一个简短的部分:

5.3 writing own CAN protocol modules

To implement a new protocol in the protocol family PF_CAN a new
protocol has to be defined in include/linux/can.h .
The prototypes and definitions to use the SocketCAN core can be
accessed by including include/linux/can/core.h .
In addition to functions that register the CAN protocol and the
CAN device notifier chain there are functions to subscribe CAN
frames received by CAN interfaces and to send CAN frames:

can_rx_register   - subscribe CAN frames from a specific interface
can_rx_unregister - unsubscribe CAN frames from a specific interface
can_send          - transmit a CAN frame (optional with local loopback)

For details see the kerneldoc documentation in net/can/af_can.c or
the source code of net/can/raw.c or net/can/bcm.c .

https://www.kernel.org/doc/Documentation/networking/can.txt

问题是我无法找到这里引用的一些文件。我不熟悉Linux内核,所以我不知道我是否在错误的地方找工作。我可以找到include/linux/can.h和目录include/linux/can/,但那里没有core.h个文件。此外,我无法找到引用的net/目录。

其他信息:

  • 我能够发送和接收原始CAN帧,所以我相信我已正确设置SocketCAN

  • 目录的内容(core.h应该在哪里):

     beaglebone:~# ls /usr/include/linux/can/
     bcm.h  error.h  gw.h  netlink.h  raw.h
    
  • 我在BeagleBone Black上使用Debian(我不确定我的系统的嵌入性是否有所作为)

如果有人可以帮我指出我应该寻找这些文件的地方,我会非常感激。

非常感谢!

1 个答案:

答案 0 :(得分:0)

CAN协议是在硬件中实现的;尝试使不符合标准的数据包无法与兼容的硬件一起使用。