-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender_test.py
83 lines (73 loc) · 2.4 KB
/
sender_test.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
79
80
81
82
83
import protocol
import construct
import sender
import logging, time
import random
def binx(x, digits=0):
oct2bin = ['000','001','010','011','100','101','110','111']
binstring = [oct2bin[int(n)] for n in oct(x)]
return ''.join(binstring).lstrip('0').zfill(digits)
# set up logging to file - see previous section for more details
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%d.%m.%y %H:%M:%s',
filename='sender.log',
filemode='a')
container = construct.Container(
frametype = 'CAN_MSG',
priority = 'REGULAR',
subnet = 'ZERO',
protocol = 'LED',
receiver = 'ADDR_LED',
sender = 'ADDR_GW',
mode = 'COLOR',
length = 7,
leds = [1,1,1,1],
colormode = 'RGB',
time1 = 0,
color1 = 255,
color2 = 255,
color3 = 255,
)
try:
s = sender.Sender()
#s.sendMessage(container)
time.sleep(0.5)
# while(1):
# s.setAllColorRGB(0,0,0)
# time.sleep(0.1)
# s.setAllColorRGB(255,255,255)
# time.sleep(0.1)
while(1):
rand_time = random.randint(60,240)
time.sleep(rand_time)
color = random.randint(0,255)
container.color1 = color
color = random.randint(0,255)
container.color2 = color
color = random.randint(0,255)
container.color3 = color
s.sendMessage(container)
time.sleep(0.05)
container.color1 = 0
container.color2 = 0
container.color3 = 0
s.sendMessage(container)
# while(1):
# leds = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
# for led in leds:
# container.leds = led
# color = random.randint(0,255)
# container.color1 = color
# color = random.randint(0,255)
# container.color2 = color
# color = random.randint(0,255)
# container.color3 = color
# s.sendMessage(container)
# time.sleep(0.25)
except KeyboardInterrupt:
print 'Keyboard Interrupt'
print 'Killing server crap'
time.sleep(2)
s.stop()
print 'Killed server crap'