1
|
#!/bin/sh
|
2
|
#CAN Bus loopback test script
|
3
|
#Gregory Dias
|
4
|
#Last modified 5/14/2014
|
5
|
|
6
|
if [ $# -lt 1 ]
|
7
|
then
|
8
|
echo "Please specify a bitrate (bits/second)"
|
9
|
exit 1
|
10
|
fi
|
11
|
|
12
|
case $1 in
|
13
|
''|*[!0-9]*) echo "Please specify an integer bitrate";exit 1;;
|
14
|
*) BITRATE=$1 ;;
|
15
|
esac
|
16
|
|
17
|
#BITRATE=$1
|
18
|
|
19
|
if [[ $BITRATE -lt 10000 && $BITRATE -gt 1000000 ]]
|
20
|
then
|
21
|
echo "Please specify a bitrate in the range of 10Kbits to 1Mbits"
|
22
|
echo "in a numerical format. (EX: 500Kbits is 500000)"
|
23
|
exit 1
|
24
|
fi
|
25
|
|
26
|
echo "CAN Bus loopback test script - V1"
|
27
|
echo
|
28
|
echo "Configuring devices with bitrate $BITRATE..."
|
29
|
echo
|
30
|
canconfig can0 stop
|
31
|
canconfig can1 stop
|
32
|
|
33
|
canconfig can0 bitrate $BITRATE
|
34
|
canconfig can1 bitrate $BITRATE
|
35
|
|
36
|
canconfig can0 start
|
37
|
canconfig can1 start
|
38
|
|
39
|
echo
|
40
|
echo "Test 1: can1 -> can0"
|
41
|
echo "============================"
|
42
|
#read from can0, write from can1
|
43
|
|
44
|
candump can0 > can0.out &
|
45
|
CAN0_PID=$!
|
46
|
|
47
|
cansend can1 -i 0x00 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 --loop=15
|
48
|
sleep 2
|
49
|
cansend can1 -i 0x88 0x88 0x77 0x66 0x55 0x44 0x33 0x22 0x11 --loop=15
|
50
|
sleep 2
|
51
|
|
52
|
kill $CAN0_PID
|
53
|
|
54
|
#send one last message to ensure candump is closed (odd)
|
55
|
cansend can1 -i 0xAA
|
56
|
|
57
|
WC=`wc -l can0.out | awk '{print $1}'`
|
58
|
LOOP1COUNT=0
|
59
|
LOOP2COUNT=0
|
60
|
|
61
|
while read LINE
|
62
|
do
|
63
|
if [ "$LINE" == "<0x000> [8] 11 22 33 44 55 66 77 88" ]
|
64
|
then
|
65
|
LOOP1COUNT=`expr $LOOP1COUNT + 1`
|
66
|
fi
|
67
|
if [ "$LINE" == "<0x088> [8] 88 77 66 55 44 33 22 11" ]
|
68
|
then
|
69
|
LOOP2COUNT=`expr $LOOP2COUNT + 1`
|
70
|
fi
|
71
|
if [ "$LINE" == "<0x0aa> [0]" ]
|
72
|
then
|
73
|
WC=`expr $WC - 2`
|
74
|
fi
|
75
|
done < can0.out
|
76
|
|
77
|
if [ $WC -eq `expr $LOOP1COUNT + $LOOP2COUNT` ]
|
78
|
then
|
79
|
CAN0R="PASS"
|
80
|
CAN1W="PASS"
|
81
|
else
|
82
|
CAN0R="FAIL"
|
83
|
CAN1W="FAIL"
|
84
|
fi
|
85
|
|
86
|
if [ $WC -eq 0 ]
|
87
|
then
|
88
|
CAN0R="FAIL"
|
89
|
CAN1W="FAIL"
|
90
|
fi
|
91
|
|
92
|
echo
|
93
|
echo "Test 2: can0 -> can1"
|
94
|
echo "============================"
|
95
|
|
96
|
#read from can1, write from can0
|
97
|
|
98
|
candump can1 > can1.out &
|
99
|
CAN1_PID=$!
|
100
|
|
101
|
cansend can0 -i 0xFF 0x99 0xAA 0xBB 0xCC 0xDD 0xEE 0xFF 0x00 --loop=15
|
102
|
sleep 2
|
103
|
cansend can0 -i 0x22 0x00 0xFF 0xEE 0xDD 0xCC 0xBB 0xAA 0x99 --loop=15
|
104
|
sleep 2
|
105
|
|
106
|
kill $CAN1_PID
|
107
|
|
108
|
#send one last message to ensure candump is closed
|
109
|
cansend can0 -i 0x33
|
110
|
|
111
|
WC=`wc -l can1.out | awk '{print $1}'`
|
112
|
LOOP1COUNT=0
|
113
|
LOOP2COUNT=0
|
114
|
|
115
|
while read LINE
|
116
|
do
|
117
|
if [ "$LINE" == "<0x0ff> [8] 99 aa bb cc dd ee ff 00" ]
|
118
|
then
|
119
|
LOOP1COUNT=`expr $LOOP1COUNT + 1`
|
120
|
fi
|
121
|
if [ "$LINE" == "<0x022> [8] 00 ff ee dd cc bb aa 99" ]
|
122
|
then
|
123
|
LOOP2COUNT=`expr $LOOP2COUNT + 1`
|
124
|
fi
|
125
|
if [ "$LINE" == "<0x033> [0]" ]
|
126
|
then
|
127
|
WC=`expr $WC - 2`
|
128
|
fi
|
129
|
done < can1.out
|
130
|
|
131
|
if [ $WC -eq `expr $LOOP1COUNT + $LOOP2COUNT` ]
|
132
|
then
|
133
|
CAN1R="PASS"
|
134
|
CAN0W="PASS"
|
135
|
else
|
136
|
CAN1R="FAIL"
|
137
|
CAN0W="FAIL"
|
138
|
fi
|
139
|
|
140
|
if [ $WC -eq 0 ]
|
141
|
then
|
142
|
CAN1R="FAIL"
|
143
|
CAN0W="FAIL"
|
144
|
fi
|
145
|
|
146
|
echo
|
147
|
echo "Test results:"
|
148
|
echo "can0: Read - $CAN0R | Write - $CAN0W"
|
149
|
echo "can1: Read - $CAN1R | Write - $CAN1W"
|
150
|
|
151
|
#cleanup
|
152
|
rm can[0-1].out
|
153
|
|
154
|
echo
|
155
|
echo done.
|
156
|
|