-
Notifications
You must be signed in to change notification settings - Fork 0
/
can.py
78 lines (63 loc) · 1.97 KB
/
can.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from socketcan import CanRawSocket, CanFrame
CAN_CHANNEL = 'can0'
class LEDCan:
def __init__(self, channel) -> None:
self.can = CanRawSocket(interface=channel)
# Led Left
def Left(self) -> int:
msg = CanFrame(can_id=516, data=bytes([0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
self.can.send(msg)
return 0
# Led Right
def Right(self) -> int:
msg = CanFrame(can_id=516, data=bytes([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
self.can.send(msg)
return 0
# Led Hazzard
def Hazzard(self) -> int:
msg = CanFrame(can_id=516, data=bytes([0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
self.can.send(msg)
return 0
def Non(self) -> int:
msg = CanFrame(can_id=516, data=bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
self.can.send(msg)
return 0
def TestNone(self) -> int:
import time
msg = CanFrame(can_id=0x201, data=bytes([1, 12, 0, 0, 0]))
self.can.send(msg)
# time.sleep(0.1)
msg = CanFrame(can_id=0x200, data=bytes([0]))
self.can.send(msg)
return 0
def TestLeft(self) -> int:
import time
msg = CanFrame(can_id=0x201, data=bytes([1, 12, 0, 0, 100]))
self.can.send(msg)
# time.sleep(0.1)
msg = CanFrame(can_id=0x200, data=bytes([0]))
self.can.send(msg)
return 0
def TestRight(self) -> int:
import time
msg = CanFrame(can_id=0x201, data=bytes([1, 12, 0, 100, 0]))
self.can.send(msg)
# time.sleep(0.1)
msg = CanFrame(can_id=0x200, data=bytes([0]))
self.can.send(msg)
return 0
def test(led):
# test
import time
print('test Left')
led.Left()
time.sleep(1)
print('test Right')
led.Right()
time.sleep(1)
print('test Hazzard')
led.Hazzard()
time.sleep(1)
if __name__ == '__main__':
led = LEDCan(channel=CAN_CHANNEL)
test(led)