附件为C测试程序
描述
该程序实现了通过 socketcan 接口的 CAN 通信测试,适用于Neardi Linux 平台
- can0: 每隔 3 秒发送一次消息 006#ED99999999999999。
- can1: 接收到消息后立即回复 007#EE88888888888888。
运行
sudo ./neardi_can_test 3000 //3秒,单位:毫秒
执行结果
neardi@LPA3568:~/can$ ./neardi_can_test 3000
[2024-08-29 10:27:51] [neardi] Message sent from can0: ID = 6, Data = ED 99 99 99 99 99 99 99
[2024-08-29 10:27:51] [neardi] Received message from can1: ID = 6, Data = ED 99 99 99 99 99 99 99
[2024-08-29 10:27:51] [neardi] Reply sent from can1: ID = 7, Data = EE 88 88 88 88 88 88 88
--------------------------------------------------
[2024-08-29 10:27:54] [neardi] Message sent from can0: ID = 6, Data = ED 99 99 99 99 99 99 99
[2024-08-29 10:27:54] [neardi] Received message from can1: ID = 6, Data = ED 99 99 99 99 99 99 99
[2024-08-29 10:27:54] [neardi] Reply sent from can1: ID = 7, Data = EE 88 88 88 88 88 88 88
编译
若需修改源码并重新编译,使用以下命令
gcc -o neardi_can_test neardi_can_test.c -lpthread