Using CAN port » cantest-echo.sh
1 |
#!/bin/sh
|
---|---|
2 |
#CAN Bus echo test script
|
3 |
#Gregory Dias
|
4 |
#Last modified 5/22/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 echo test script - V1" |
27 |
echo
|
28 |
echo "Configuring can0 with bitrate $BITRATE..." |
29 |
echo
|
30 |
canconfig $2 stop
|
31 |
|
32 |
canconfig $2 bitrate $BITRATE |
33 |
|
34 |
canconfig $2 start
|
35 |
|
36 |
echo
|
37 |
echo "Testing can1..." |
38 |
echo "============================" |
39 |
#using canecho on another devkit (or similar device) this script
|
40 |
#will be witing to see identical messages with an incremented id
|
41 |
|
42 |
#set up canread for file output
|
43 |
candump $2 > can1.out & |
44 |
CAN1_PID=$! |
45 |
|
46 |
sleep 1
|
47 |
|
48 |
cansend $2 -i 0x00 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 --loop=15 |
49 |
sleep 2
|
50 |
cansend $2 -i 0x88 0x88 0x77 0x66 0x55 0x44 0x33 0x22 0x11 --loop=15 |
51 |
sleep 2
|
52 |
|
53 |
kill $CAN1_PID |
54 |
|
55 |
#send one last message to ensure candump is closed (odd,
|
56 |
#canread must block when waiting for a read)
|
57 |
cansend $2 -i 0xAA |
58 |
|
59 |
WC=`wc -l can1.out | awk '{print $1}'` |
60 |
let WC=($WC-2)/2 |
61 |
LOOP1COUNT=0 |
62 |
LOOP2COUNT=0 |
63 |
|
64 |
while read LINE |
65 |
do
|
66 |
if [ "$LINE" == "<0x001> [8] 11 22 33 44 55 66 77 88" ] |
67 |
then
|
68 |
LOOP1COUNT=`expr $LOOP1COUNT + 1` |
69 |
fi
|
70 |
if [ "$LINE" == "<0x089> [8] 88 77 66 55 44 33 22 11" ] |
71 |
then
|
72 |
LOOP2COUNT=`expr $LOOP2COUNT + 1` |
73 |
fi
|
74 |
done < can1.out
|
75 |
|
76 |
echo $WC |
77 |
echo $LOOP1COUNT $LOOP2COUNT |
78 |
|
79 |
if [ $WC -eq `expr $LOOP1COUNT + $LOOP2COUNT` ] |
80 |
then
|
81 |
CAN1="PASS" |
82 |
else
|
83 |
CAN1="FAIL" |
84 |
fi
|
85 |
|
86 |
echo "Test results:" |
87 |
echo "can1: $CAN1" |
88 |
|
89 |
#cleanup
|
90 |
#rm can1.out
|
91 |
|
92 |
echo
|
93 |
echo done. |
94 |
|
- « Previous
- 1
- 2
- Next »