0
点赞
收藏
分享

微信扫一扫

一个测试Can的脚本

星河出山 2022-03-11 阅读 66
linux

设备上有2路can,将这2路canH,canL连到一起

首先写一个单次测试的脚本,

ifconfig can1 down
ifconfig can0 down
ip link set can1 up type can bitrate 125000 triple-sampling on
ip link set can0 up type can bitrate 125000 triple-sampling on
ifconfig can1 up
ifconfig can0 up

if [ -e /root/result/can0.txt ]
then
        rm -fr /root/result/can0.txt
fi
if [ -e /root/result/can1.txt ]
then
        rm -fr /root/result/can1.txt
fi

candump can$1 >  /root/result/can$1.txt &
sleep 1
cansend can$2 123#1234567812345678
sleep 1

cannum=`cat /root/result/can$1.txt | wc -l`
if [ $cannum -eq 1 ]
then
        echo -e "\e[1;36m can$2 ->can$1 is  OK    \e[0m"
        echo "can$2->can$1 is OK" >> /root/result/result.txt
else
        echo -e "\e[1;31m  can$2->can$1 is failed    \e[0m"
        echo "can$2->can$1  is failed" >> /root/result/result.txt
fi
ifconfig can1 down
ifconfig can0 down

可以使用 can.sh 1 0 或者can.sh 0 1 ,让其中一路can发送,另外一路接收。

然后编写脚本自动执行上面的脚本;

while true
do
echo -e "\e[1;32m    `date +%T`   can test     \e[0m"
echo -e "\e[1;32m -----------------------------\e[0m"
/root/hardtest/shell/a40i_hardtest/can.sh 1 0
if [ $? -eq 0 ]
then
	echo "run can.sh 1 0  is OK" | tee -a /root/result/result.txt
else
	echo "run can.sh 1 0  is failed" | tee -a /root/result/result.txt
fi
/root/hardtest/shell/a40i_hardtest/can.sh 0 1
if [ $? -eq 0 ]
then
	echo "run can.sh 0 1  is OK"  | tee -a /root/result/result.txt
else
	echo "run can.sh 0 1  is failed" | tee -a /root/result/result.txt
fi
done

这样就可以一直进行测试了

举报

相关推荐

0 条评论