-
Notifications
You must be signed in to change notification settings - Fork 2
/
mydu.py
184 lines (168 loc) · 5.09 KB
/
mydu.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
# -*- coding: utf-8 -*-
import sys
import gc
import time
try:
import msvcrt
def kbhit():
return msvcrt.kbhit()
def getch():
return msvcrt.getwch()
except ImportError:
print("Assuming on ESP")
import uselect
def kbhit():
spoll=uselect.poll()
spoll.register(sys.stdin,uselect.POLLIN)
kbch = sys.stdin.read(1) if spoll.poll(0) else None
spoll.unregister(sys.stdin)
return(kbch)
def getch():
while True:
tmp= sys.stdin.read(1)
if tmp is not None:
return tmp
try:
from i2ct import i2ct
i2=i2ct()
print ("Available Slaves:", i2.con.scan())
except ImportError:
print("no i2ct")
from duclas import cserv
from duclas import ccon
username="targon"
rigname = "None"
myCons=[]
serv=cserv()
def newCon(targ,tarnam):
myCons.append(ccon(targ,tarnam,serv.pool_address, serv.pool_port,rigname,username))
def get_config():
global rigname
conf=open("conf.txt",'r')
rigname=conf.readline().rstrip()
print (rigname)
for l in conf.readlines():
s=l.rstrip().split(" ",1)
print (s[1]+"<")
newCon(int(s[0]),s[1])
def overview():
print("cons",len(myCons))
now=time.ticks_ms()
for c in myCons:
tim=time.ticks_diff(now,c.jobStartTim)
print (c.target, c.getSlStat(),c.sta,c.reqAnz,'/',c.reqAnzTop,"sin", tim)
def info():
gc.collect()
print ("Available Slaves:", i2.con.scan())
print("Mem Alloc",gc.mem_alloc(),'Free',gc.mem_free())
print("Rigname",rigname, 'with',len(myCons),"Cons:")
for c in myCons:
c.coninfo()
def loop(top=0):
global myCons
allbusy=0 #counter subsequent loops
zings=0 # jobs terminated
ms='?'
now=time.ticks_ms()
for c in myCons: # in case of break
c.jobStartTim=now
if top==0: #run unlimited
c.reqAnzTop=0
else: #run top jobs (pi)
c.reqAnz=0
c.reqAnzTop=top
while True:
allbusy=allbusy+1
zings=1
for c in myCons:
ms=c.mach()
if ms != 'B':
allbusy=0
if ms != 'Z':
zings=0
time.sleep(0.05) #let other tasks run
if zings>0:
print("Zinged")
break
if kbhit() is not None:
break
if allbusy>0:
#print("All Bus ",allbusy)
gc.collect() # something useful
time.sleep(0.1)
print("Loop Done")
def menu():
global myCons
inpAkt=False
inp=0
myc=0
print (username+", welcome to mydu.")
if len(myCons)==0: #re-running config would duplicate cons
get_config()
loop()
while True:
if not inpAkt: print(rigname,">",end='')
ch = getch()
if ((ch >= '0') and (ch <= '9')):
if (inpAkt) :
inp = inp * 10 + (ord(ch) - 48);
else:
inpAkt = True;
inp = ord(ch) - 48;
print(ch,end='')
else:
print(ch)
inpAkt=False
try:
if ch=="a":
myc=inp
print("myc=",myc)
elif ch=="c":
myCons[inp].conn()
elif ch=="d":
myCons[inp].close()
elif ch=="D":
for c in myCons:
c.close()
elif ch=="e":
myCons[inp].close()
myCons.pop(inp)
elif ch=="h":
myCons[inp].sendRate = not myCons[inp].sendRate
print ("sendRate ",myCons[inp].sendRate)
elif ch=="i":
info()
elif ch=="l":
loop(0)
elif ch=="m":
myCons[inp].mach()
elif ch=="o":
overview()
elif ch=="q":
print (myCons[inp].getSlStat())
elif ch=="s":
get_config()
elif ch=="u":
myCons[inp].statReset()
print ("stats reset for",inp)
elif ch=="w":
inp=myCons[myc].getResult()
print ("inp",inp)
elif ch=="x":
for c in myCons:
c.close()
print ("Thanks for using mydu")
return
elif ch=="y":
loop(inp)
elif ch=="z":
for c in myCons:
c.reqAnzTop=c.reqAnz+inp
print ("Zinging")
loop()
else:
print("else"+str(ord(ch)))
except Exception as inst:
print ("menu Exception "+str(inst))
raise #remove when perfect
menu()