-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindCCU.py
180 lines (166 loc) · 4.97 KB
/
findCCU.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
import itertools
from subprocess import Popen,PIPE,STDOUT
class Ring:
def __init__(self,n):
self.inA = True
self.outA = True
self.CCUs = []
for i in range(0,n):
self.CCUs.append(True)
return
def setCCU(self,i,b):
if i >= len(self.CCUs): return
self.CCUs[i] = b
return
def setInA(self,b):
self.inA = b
return
def setOutA(self,b):
self.outA = b
return
def makeRing(sequence,mode):
ring = Ring(len(sequence))
for i,b in enumerate(sequence):
ring.setCCU(i,b)
if mode == 1:
ring.setInA(False)
elif mode == 2:
ring.setOutA(False)
elif mode == 3:
ring.setInA(False)
ring.setOutA(False)
return ring
def compareCCUs(hasCCUs,foundCCUs):
#print hasCCUs,foundCCUs
if len(hasCCUs) != len(foundCCUs): return -3
for ccu in hasCCUs:
if ccu not in foundCCUs: return -4
return 0
def testRedundancy(redundancy,adapterslotN,fecN,ringN,hasCCUs,nMissing):
lineRed = "ProgramTest.exe -adapterslot %d -fec %d -ring %d %s" % (adapterslotN,fecN,ringN,redundancy,)
lineReset = "ProgramTest.exe -adapterslot %d -fec %d -ring %d -reset" % (adapterslotN,fecN,ringN,)
lineScan = "ProgramTest.exe -adapterslot %d -fec %d -ring %d -scanCCU" % (adapterslotN,fecN,ringN,)
p = Popen(lineReset.split(),stdout=PIPE,stdin=PIPE,stderr=PIPE)
stdout_reset = p.communicate(input='')
nRed = 0
nRedGood = 0
while True:
if redundancy.strip() == "-redundancy FEC-A-A": break
p = Popen(lineRed.split(),stdout=PIPE,stdin=PIPE,stderr=PIPE)
stdout_red = p.communicate(input='')
if "FEC SR0 = 0x5c80" in stdout_red[0]:
nRedGood += 1
continue
if nRedGood > nMissing+2: break
if nRed > 10: return -1
nRed += 1
nScan = 0
foundCCUs = []
while True:
p = Popen(lineScan.split(),stdout=PIPE,stdin=PIPE,stderr=PIPE)
stdout_scan = p.communicate(input='')
if not "ERROR" in stdout_scan[1]:
splt = stdout_scan[0].split("CCU ")
for line in splt:
if "found" in line:
splt2 = line.split(" found")
if '0x7e' not in splt2[0]: foundCCUs.append(splt2[0])
break
nScan += 1
if nScan > 10: return -2
goodCCUlist = compareCCUs(hasCCUs,foundCCUs)
if goodCCUlist != 0: return goodCCUlist
p = Popen(lineReset.split(),stdout=PIPE,stdin=PIPE,stderr=PIPE)
stdout_reset = p.communicate(input='')
return 0
def checkRing(ring):
if len(ring.CCUs) < 2: return False
if ring.inA and not ring.CCUs[0]: return False
if not ring.inA and not (ring.CCUs[0] or ring.CCUs[1]): return False
if ring.outA and ring.CCUs[-1]: return False
if ring.outA and not ring.CCUs[-2]: return False
if not ring.outA and not ring.CCUs[-1]: return False
for i in range(0,len(ring.CCUs)-2):
if not ring.CCUs[i] and not ring.CCUs[i+1]: return False
return True
def whichCCUs(ring,ccus):
hasCCUs = []
for ii,ccu in enumerate(ccus):
if ring.CCUs[ii]:
hasCCUs.append(ccu)
return hasCCUs
def printRedundancyCommand(ccus,ring):
outputline = "-redundancy FEC-"
#print ring.inA,ring.outA,len(ring.CCUs)
if ring.outA:
outputline += "A-"
else:
outputline += "B-"
if ring.inA:
outputline += "A "
else:
outputline += "B "
for ii,address in enumerate(ccus):
ccuin = "A"
ccuout = "A"
if not ring.CCUs[ii]: continue
if ii == 0 and not ring.inA:
ccuin = "B"
if ii > 0 and not ring.CCUs[ii-1]:
ccuin = "B"
if not ring.CCUs[ii+1]:
ccuout = "B"
if ii+1 == len(ccus) and not ring.outA:
ccuout = "B"
elif ii+1 == len(ccus) and ring.outA:
ccuout = "A"
if ccuin == "A" and ccuout == "A": continue
outputline += address+"-"+ccuin+"-"+ccuout+" "
dummyind = ii+1
if ring.CCUs[dummyind] and not ring.CCUs[dummyind-1]:
outputline += "0x7e-B-A"
return outputline
def analyzeRing(ring,ccuAnalysis,test):
for ii,nbad in ccuAnalysis.iteritems():
if not ring.CCUs[ii]:
if test != 0: ccuAnalysis[ii][0] = ccuAnalysis[ii][0] + 1
else: ccuAnalysis[ii][1] = ccuAnalysis[ii][1] + 1
return
def main():
#
#ccus = ["0x1","0x2","0x48","0x55","0x41","0xd","0x16","0x56"]
ccus = ["0x1","0x2","0x60","0x5f","0x68","0x2d","0x1b"]
#ccus = ["0x1","0x2","0x76","0xe","0x22"]
fecN=4
ringN=7
adapterN=1
#ccus = ["0x6f","0x5f","0x7b","0x3f"]
ccuAnalysis = dict()
for ii,ccu in enumerate(ccus): ccuAnalysis[ii] = [0,0]
sequences = itertools.product((True,False),repeat = len(ccus)+1)
nBad = 0
for sequence in sequences:
for j in range(0,4):
ring = makeRing(sequence,j)
if checkRing(ring):
hasCCUs = whichCCUs(ring,ccus)
redundancy = printRedundancyCommand(ccus,ring)
line = "ProgramTest.exe -adapterslot %d -fec %d -ring %d %s" % (adapterN,fecN,ringN,redundancy,)
test = testRedundancy(redundancy,adapterN,fecN,ringN,hasCCUs,len(ccus)-len(hasCCUs))
print test,line
if test != 0:
nBad += 1
analyzeRing(ring,ccuAnalysis,test)
print nBad
for ii,ccu in enumerate(ccus): print ccu,ccuAnalysis[ii]
#for i in range(1,9):
# nGood = 0
# sequences = itertools.product((True,False),repeat = i+1)
# for sequence in sequences:
#print sequence
# for j in range(0,4):
# if checkRing(makeRing(sequence,j)): nGood += 1
# print i,nGood
return
if __name__ == "__main__":
main()