Project

General

Profile

MCAN » cantest.sh

Joshua Bourgeot, 06/20/2024 01:51 PM

 
1
#!/bin/sh
2
#CAN Bus loopback test script
3
#Gregory Dias
4
#Last modified 5/14/2014
5
#Updated 6/12/24 - Joshua Bourgeot
6

    
7
echo
8

    
9
echo "Test 1: mcu_mcan1 -> mcu_mcan0"
10

    
11
echo "============================"
12

    
13
#read from mcu_mcan0, write from mcu_mcan1
14

    
15
candump mcu_mcan0 > mcu_mcan0.out &
16
CAN0_PID=$!
17

    
18
for i in {1..15}
19
do
20
	cansend mcu_mcan1 000#11.22.33.44.55.66.77.88
21
	sleep 2
22
done
23

    
24
for i in {1..15}
25
do
26
	cansend mcu_mcan1 088#88.77.66.55.44.33.22.11
27
	sleep 2
28
done
29

    
30
kill $CAN0_PID
31

    
32
WC=`wc -l mcu_mcan0.out | awk '{print $1}'`
33

    
34
LOOP1COUNT=0
35

    
36
LOOP2COUNT=0
37

    
38
while read LINE
39
do
40
	if [ "$LINE" == "mcu_mcan0  000   [8]  11 22 33 44 55 66 77 88" ]
41
	then
42
		LOOP1COUNT=`expr $LOOP1COUNT + 1`
43
	fi
44

    
45
	if [ "$LINE" == "mcu_mcan0  088   [8]  88 77 66 55 44 33 22 11" ]
46
	then
47
		LOOP2COUNT=`expr $LOOP2COUNT + 1`
48
	fi
49

    
50
done < mcu_mcan0.out
51

    
52
if [ $WC -eq `expr $LOOP1COUNT + $LOOP2COUNT` ]
53
then
54
	CAN0R="PASS"
55
	CAN1W="PASS"
56
else
57
	CAN0R="FAIL"
58
	CAN1W="FAIL"
59
fi
60

    
61
if [ $WC -eq 0 ]
62
then
63
	CAN0R="FAIL"
64
	CAN1W="FAIL"
65
fi
66

    
67
echo
68
echo "Test 2: mcu_mcan0 -> mcu_mcan1"
69
echo "============================"
70

    
71
#read from mcu_mcan1, write from mcu_mcan0
72
candump mcu_mcan1 > mcu_mcan1.out &
73

    
74
CAN1_PID=$!
75

    
76
for i in {1..15}
77
do
78
	cansend mcu_mcan1 0FF#FF.99.AA.BB.CC.DD.EE.FF.00
79
	sleep 2
80
done
81

    
82
for i in {1..15}
83
do
84
	cansend mcu_mcan1 088#22.00.FF.EE.DD.CC.BB.AA.99 
85
	sleep 2
86
done
87

    
88
kill $CAN1_PID
89

    
90

    
91
WC=`wc -l mcu_mcan1.out | awk '{print $1}'`
92

    
93
LOOP1COUNT=0
94

    
95
LOOP2COUNT=0
96

    
97
while read LINE
98

    
99
do
100
        if [ "$LINE" == "mcu_mcan1  0FF   [8]  FF 99 AA BB CC DD EE FF" ]
101
        then
102
                LOOP1COUNT=`expr $LOOP1COUNT + 1`
103
        fi
104

    
105
        if [ "$LINE" == "mcu_mcan1  0FF   [8]  FF 99 AA BB CC DD EE FF" ]
106
        then
107
                LOOP2COUNT=`expr $LOOP2COUNT + 1`
108
        fi
109

    
110
        if [ "$LINE" == "<0x033> [0]" ]
111
        then
112
                WC=`expr $WC - 2`
113
        fi
114
done < mcu_mcan1.out
115

    
116
if [ $WC -eq `expr $LOOP1COUNT + $LOOP2COUNT` ]
117
then
118
	CAN1R="PASS"
119
	CAN0W="PASS"
120
else
121
	CAN1R="FAIL"
122
	CAN0W="FAIL"
123
fi
124

    
125
if [ $WC -eq 0 ]
126
then
127
	CAN1R="FAIL"
128
	CAN0W="FAIL"
129
fi
130

    
131
echo 
132
echo "Test results:"
133
echo "mcu_mcan0: Read - $CAN0R | Write - $CAN0W"
134
echo "mcu_mcan1: Read - $CAN1R | Write - $CAN1W"
135

    
136
#cleanup
137
rm mcu_mcan0.out
138
rm mcu_mcan1.out
139
echo
140
echo done.
141

    
(3-3/3) Go to top
Add picture from clipboard (Maximum size: 1 GB)