Skip to content

Commit 6a15ac8

Browse files
HenrikSolverdpgeorge
authored andcommitted
tests: Added and adapted CAN tests for extended messages
1 parent 5046368 commit 6a15ac8

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

tests/pyb/can.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
from pyb import CAN
22

3-
can = CAN(1)
3+
can = CAN(1, CAN.LOOPBACK)
44
print(can)
5-
can.init(CAN.LOOPBACK)
65
print(can.any(0))
76
can.send('abcd', 123)
87
print(can.any(0))
98
print(can.recv(0))
9+
10+
can.send('abcd', -1)
11+
print(can.recv(0))
12+
13+
can.send('abcd', 0x7FF + 1)
14+
print(can.recv(0))
15+
16+
#Test too long message
17+
try:
18+
can.send('abcdefghi', 0x7FF)
19+
except ValueError:
20+
print('passed')
21+
else:
22+
print('failed')
23+
24+
del can
25+
26+
#Testing extended IDs
27+
can = CAN(1, CAN.LOOPBACK, extframe = True)
28+
print(can)
29+
30+
try:
31+
can.send('abcde', 0x7FF + 1)
32+
except ValueError:
33+
print('failed')
34+
else:
35+
r = can.recv(0)
36+
if r[0] == 0x7FF+1 and r[3] == b'abcde':
37+
print('passed')
38+
else:
39+
print('failed, wrong data received')
40+
41+
42+
print('end')

tests/pyb/can.py.exp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
CAN(1)
1+
CAN(1, LOOPBACK, False)
22
False
33
True
44
(123, 0, 0, b'abcd')
5+
(2047, 0, 0, b'abcd')
6+
(0, 0, 0, b'abcd')
7+
passed
8+
CAN(1, LOOPBACK, True)
9+
passed
10+
end

0 commit comments

Comments
 (0)