-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
executable file
·193 lines (179 loc) · 4.79 KB
/
run.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/python
RRDPATH="/root/rrds/"
import curses
import time
import importlib
import threading
def startports():
startport("Stookhok","05",RRDPATH,19200)
startport("Stookkelder","14",RRDPATH,19200)
startport("Bar","13",RRDPATH,19200)
startport("Brandhok","11",RRDPATH,19200)
startport("Wifi",None,RRDPATH,None)
startport("Kassasounds",None,RRDPATH,None)
startport("Doorsounds",None,RRDPATH,None)
startport("Mqtt",None,RRDPATH,None)
startport("Onewire","OW",RRDPATH,9600)
startport("Sidedoor","01","/root/software",19200)
startport("1Door","18","/root/software",38400)
myobjs={}
mythreads={}
names={}
def startport(mod,port,RRDPATH,speed):
global myobjs,mythreads,enableports,lines,line,lastseen
pi=len(enableports)
enableports.append(pi)
lines[pi]=[]
lines[pi].append("Hello")
line[pi]=""
lastseen[pi]=0
if mod=="Onewire":
mymod=importlib.import_module("meten2.MonReader")
myobjs[pi]=mymod.OneWireReader(None if port==None else "/dev/monitor/P"+port,RRDPATH,speed,lines[pi])
else:
mymod=importlib.import_module("meten2."+mod)
myobjs[pi]=mymod.meet(None if port==None else "/dev/monitor/P"+port,RRDPATH,speed,lines[pi])
mythreads[pi]=threading.Thread(name=mod,target=myobjs[pi].start).start()
names[pi]=mod
def paintports():
global stat,ports,names,screen
(y,x)=screen.getmaxyx()
stat.resize(8,x)
stat.erase();
stat.box();
nextline=0
prevstart=0
for i in enableports:
width=len(names[i])+4;
if(3+prevstart+width)>(x-2):
prevstart=0
nextline=1
ports[i] = stat.subwin( 3 , width, 1+nextline*3, 1+prevstart)
prevstart+=width+1
ports[i].box()
ports[i].addstr(1,1,' '+names[i])
ports[i].addstr(0,1,' '+chr(ord('a')+i)+' ')
stat.refresh()
def signal_handler(signal, frame):
curses.endwin()
for x in myobjs:
myobjs[x].stopping=1
sys.exit(0)
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
screen.keypad( 1 ) # delete this line
curses.init_pair(1,curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(2,curses.COLOR_BLACK, curses.COLOR_GREEN)
curses.init_pair(3,curses.COLOR_BLACK, curses.COLOR_RED)
curses.init_pair(4,curses.COLOR_YELLOW, curses.COLOR_BLUE)
curses.init_pair(5,curses.COLOR_BLACK, curses.COLOR_YELLOW)
highlightText = curses.color_pair( 1 )
normalText = curses.color_pair(1)
#screen.border( 0 )
curses.curs_set( 0 )
stat = curses.newwin( 8, 120, 0, 0 )
stat.bkgd(curses.color_pair(4))
stat.box()
linex=0
liney=0
def resizeoutp():
global screen,linex,liney
(y,x)=screen.getmaxyx()
linex=x-2
liney=y-2-8
outp.resize(y-8,x)
outp.box()
outp.refresh()
outp = curses.newwin( 0, 2, 8, 0 )
outp.bkgd(curses.color_pair(4))
outp.keypad( 1 )
outp.box()
resizeoutp()
enableports=[]
lastseen={}
ports={}
lines={}
line={}
prevactiveport=-1
activeport=0
screen.refresh() # delete this line
stat.refresh()
outp.refresh()
outp.nodelay(1)
x=0
def setactiveport():
global prevactiveport,activeport,enableports
for i in enableports:
if i!=activeport:
status=None
if myobjs[i].timelast>time.time()-60:
status=True
ports[i].bkgd( curses.color_pair(2) if status else curses.color_pair(3))
#if i in enableports and lastseen[i]+60<time.time():
# ports[activeport].bkgd( curses.color_pair(3))
ports[i].refresh()
ports[activeport].bkgd( curses.color_pair(5))
ports[activeport].refresh()
startports()
paintports()
olines=None
ofline=None
try:
while x != 27:
setactiveport()
if lines[activeport]!=olines:
outp.erase();
outp.box()
olines=lines[activeport]
else:
if len(lines[activeport]) > 0 and ofline!=lines[activeport][-1]:
outp.erase();
outp.box()
ofline=lines[activeport][-1]
ln=0
for myline in lines[activeport][-liney:]:
ln+=1
if line==liney: break;
try:
outp.addstr( ln,1, myline[:linex],curses.color_pair(1) )
except:
pass
ln+=1
try:
outp.addstr( ln,1, line[activeport],curses.color_pair(1) )
except:
pass
outp.refresh() # delete this line
x = outp.getch()
if x>=ord('a') and x<ord('a')+24 and x-ord('a') in enableports:
activeport=x-ord('a')
elif x==12:
resizeoutp()
paintports()
screen.touchwin()
screen.refresh()
elif x==ord('z'):
if x in enableports:
del enableports[enableports.index(x)]
else:
enableports.append(x)
elif x<127 and x>0:
if myobjs[activeport].ser:
myobjs[activeport].ser.write(chr(x))
elif x==curses.KEY_RESIZE:
resizeoutp()
paintports()
time.sleep(0.2)
except:
curses.endwin()
for x in myobjs:
myobjs[x].stopping=1
import traceback
print traceback.format_exc()
try:
curses.endwin()
except:
pass
exit()