##// END OF EJS Templates
Monitoring test
imanay -
r253:254
parent child
Show More
@@ -1,584 +1,584
1 import os No newline at end of file
1 import os
2 import library3 No newline at end of file
2 import library3
3 import time No newline at end of file
3 import time
4 from threading import Thread No newline at end of file
4 from threading import Thread
5 import threading No newline at end of file
5 import threading
6 import Queue No newline at end of file
6 import Queue
7 No newline at end of file
7
8 class ABSServer: No newline at end of file
8 class ABSServer:
9 No newline at end of file
9
10 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"): No newline at end of file
10 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
11 No newline at end of file
11
12 No newline at end of file
12
13 self.ipSource = ipSource No newline at end of file
13 self.ipSource = ipSource
14 self.ipDestino = ipDestino No newline at end of file
14 self.ipDestino = ipDestino
15 self.portDestino = portDestino No newline at end of file
15 self.portDestino = portDestino
16 No newline at end of file
16
17 self.ipDestino2 = ipDestino2 No newline at end of file
17 self.ipDestino2 = ipDestino2
18 self.portDestino2 = portDestino2 No newline at end of file
18 self.portDestino2 = portDestino2
19 No newline at end of file
19
20 self.tx_buffer = "default" No newline at end of file
20 self.tx_buffer = "default"
21 self.rx_buffer = rx_buffer No newline at end of file
21 self.rx_buffer = rx_buffer
22 self.enaModules = [] No newline at end of file
22 self.enaModules = []
23 self.bits = [] No newline at end of file
23 self.bits = []
24 self.phase = [] No newline at end of file
24 self.phase = []
25 self.txFile = [] No newline at end of file
25 self.txFile = []
26 self.rxFile = [] No newline at end of file
26 self.rxFile = []
27 No newline at end of file
27
28 self.createObjects() No newline at end of file
28 self.createObjects()
29 No newline at end of file
29
30 print "Checking control modules, please wait ..." No newline at end of file
30 print "Checking control modules, please wait ..."
31 self.enaModules = self.checkAntenna() No newline at end of file
31 self.enaModules = self.checkAntenna()
32 print '\nThis modules are present : ' + str(self.enaModules) + '\n' No newline at end of file
32 print '\nThis modules are present : ' + str(self.enaModules) + '\n'
33 # print "Starting automatic control module status." No newline at end of file
33 # print "Starting automatic control module status."
34 self.__StartingAutomaticControlModules() No newline at end of file
34 self.__StartingAutomaticControlModules()
35 # self.__AutomaticControlModules() No newline at end of file
35 # self.__AutomaticControlModules()
36 No newline at end of file
36
37 def createObjects(self): No newline at end of file
37 def createObjects(self):
38 No newline at end of file
38
39 asServer = True No newline at end of file
39 asServer = True
40 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) No newline at end of file
40 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
41 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) No newline at end of file
41 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
42 self.wFiles = library3.FilesStuff() No newline at end of file
42 self.wFiles = library3.FilesStuff()
43 No newline at end of file
43
44 def waitRequest(self): No newline at end of file
44 def waitRequest(self):
45 No newline at end of file
45
46 #Using rx buffer No newline at end of file
46 #Using rx buffer
47 # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() No newline at end of file
47 # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
48 ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData() No newline at end of file
48 ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData()
49 No newline at end of file
49
50 if cmd == "SNDF": No newline at end of file
50 if cmd == "SNDF":
51 datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
51 datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer)
52 No newline at end of file
52
53 if cmd == "GETF": No newline at end of file
53 if cmd == "GETF":
54 datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
54 datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
55 No newline at end of file
55
56 if cmd == "CHGB": No newline at end of file
56 if cmd == "CHGB":
57 datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
57 datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer)
58 No newline at end of file
58
59 if cmd == "ANST": No newline at end of file
59 if cmd == "ANST":
60 datarpta = self.__getControlModuleStatus_old(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
60 datarpta = self.__getControlModuleStatus_old(cmd = cmd, rx_buffer = rx_buffer)
61 No newline at end of file
61
62 if cmd == "BGPH": No newline at end of file
62 if cmd == "BGPH":
63 datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
63 datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer)
64 No newline at end of file
64
65 if cmd == "LWPH": No newline at end of file
65 if cmd == "LWPH":
66 datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
66 datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
67 No newline at end of file
67
68 if cmd == "NTST": No newline at end of file
68 if cmd == "NTST":
69 datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
69 datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer)
70 No newline at end of file
70
71 if cmd == "MNTR": No newline at end of file
71 if cmd == "MNTR":
72 datarpta = self.__getControlModuleStatus_new(cmd = cmd, type = rx_buffer) No newline at end of file
72 datarpta = self.__getControlModuleStatus_new(cmd = cmd, type = rx_buffer)
73 No newline at end of file
73
74 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) No newline at end of file
74 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
75 No newline at end of file
75
76 def __checkModule(self, address): No newline at end of file
76 def __checkModule(self, address):
77 No newline at end of file
77
78 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" No newline at end of file
78 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
79 status = os.system(cmd) No newline at end of file
79 status = os.system(cmd)
80 No newline at end of file
80
81 if status == 256: No newline at end of file
81 if status == 256:
82 return False No newline at end of file
82 return False
83 No newline at end of file
83
84 return True No newline at end of file
84 return True
85 No newline at end of file
85
86 def __writeReport(self, enaModules): No newline at end of file
86 def __writeReport(self, enaModules):
87 No newline at end of file
87
88 status_array = ["Status of modules\n"] No newline at end of file
88 status_array = ["Status of modules\n"]
89 status_array.append("----------------\n") No newline at end of file
89 status_array.append("----------------\n")
90 No newline at end of file
90
91 for address in range(1,65): No newline at end of file
91 for address in range(1,65):
92 if address in enaModules: No newline at end of file
92 if address in enaModules:
93 status_array.append("192.168.1." + str(address) + " [1 1]\n") No newline at end of file
93 status_array.append("192.168.1." + str(address) + " [1 1]\n")
94 else: No newline at end of file
94 else:
95 status_array.append("192.168.1." + str(address) + " [0 0]\n") No newline at end of file
95 status_array.append("192.168.1." + str(address) + " [0 0]\n")
96 No newline at end of file
96
97 filename = "module_status.txt" No newline at end of file
97 filename = "module_status.txt"
98 self.__writeFile(filename,status_array) No newline at end of file
98 self.__writeFile(filename,status_array)
99 # f = open("module_status.txt","w") No newline at end of file
99 # f = open("module_status.txt","w")
100 # f.writelines(status_array) No newline at end of file
100 # f.writelines(status_array)
101 # f.close() No newline at end of file
101 # f.close()
102 No newline at end of file
102
103 No newline at end of file
103
104 def __CreateFile(self, filename): No newline at end of file
104 def __CreateFile(self, filename):
105 No newline at end of file
105
106 fobj = open(filename,"w") No newline at end of file
106 fobj = open(filename,"w")
107 fobj.close() No newline at end of file
107 fobj.close()
108 No newline at end of file
108
109 def __writeNewFile(self, filename, data): No newline at end of file
109 def __writeNewFile(self, filename, data):
110 No newline at end of file
110
111 fobj = open(filename,"w") No newline at end of file
111 fobj = open(filename,"w")
112 fobj.writelines(data) No newline at end of file
112 fobj.writelines(data)
113 fobj.close() No newline at end of file
113 fobj.close()
114 No newline at end of file
114
115 def __writeFile(self, filename, data): No newline at end of file
115 def __writeFile(self, filename, data):
116 No newline at end of file
116
117 fobj = open(filename,"a") No newline at end of file
117 fobj = open(filename,"a")
118 fobj.writelines(data) No newline at end of file
118 fobj.writelines(data)
119 fobj.close() No newline at end of file
119 fobj.close()
120 No newline at end of file
120
121 def __checkAntenna(self): No newline at end of file
121 def __checkAntenna(self):
122 No newline at end of file
122
123 """ No newline at end of file
123 """
124 Direccion de los modulos de las antenas: No newline at end of file
124 Direccion de los modulos de las antenas:
125 No newline at end of file
125
126 Norte : 01-16 No newline at end of file
126 Norte : 01-16
127 Este : 17-32 No newline at end of file
127 Este : 17-32
128 Oeste: : 33-48 No newline at end of file
128 Oeste: : 33-48
129 Sur : 49-64 No newline at end of file
129 Sur : 49-64
130 No newline at end of file
130
131 """ No newline at end of file
131 """
132 No newline at end of file
132
133 enaModules2 = [] No newline at end of file
133 enaModules2 = []
134 No newline at end of file
134
135 for address in range(1,65): No newline at end of file
135 for address in range(1,65):
136 if self.checkModule(address): No newline at end of file
136 if self.checkModule(address):
137 enaModules2.append(address) No newline at end of file
137 enaModules2.append(address)
138 No newline at end of file
138
139 self.__writeReport(enaModules2) No newline at end of file
139 self.__writeReport(enaModules2)
140 return enaModules2 No newline at end of file
140 return enaModules2
141 No newline at end of file
141
142 def checkModule(self, arg, queue): No newline at end of file
142 def checkModule(self, arg, queue):
143 cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null" No newline at end of file
143 cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null"
144 status = os.system(cmd) No newline at end of file
144 status = os.system(cmd)
145 if status == 256: No newline at end of file
145 if status == 256:
146 result = "failed" No newline at end of file
146 result = "failed"
147 else: No newline at end of file
147 else:
148 result = "ok" No newline at end of file
148 result = "ok"
149 queue.put({arg: result}) No newline at end of file
149 queue.put({arg: result})
150 No newline at end of file
150
151 def checkAntenna(self): No newline at end of file
151 def checkAntenna(self):
152 No newline at end of file
152
153 iD = range(1,65) No newline at end of file
153 iD = range(1,65)
154 q = Queue.Queue() No newline at end of file
154 q = Queue.Queue()
155 threads = [] No newline at end of file
155 threads = []
156 tOut = [] No newline at end of file
156 tOut = []
157 modules = [] No newline at end of file
157 modules = []
158 No newline at end of file
158
159 for argument in iD: No newline at end of file
159 for argument in iD:
160 t = Thread(target=self.checkModule, args=(argument, q)) No newline at end of file
160 t = Thread(target=self.checkModule, args=(argument, q))
161 t.start() No newline at end of file
161 t.start()
162 threads.append(t) No newline at end of file
162 threads.append(t)
163 No newline at end of file
163
164 for t in threads: No newline at end of file
164 for t in threads:
165 t.join() No newline at end of file
165 t.join()
166 No newline at end of file
166
167 for _ in range(len(iD)): No newline at end of file
167 for _ in range(len(iD)):
168 tOut.append(q.get()) No newline at end of file
168 tOut.append(q.get())
169 No newline at end of file
169
170 for i in tOut: No newline at end of file
170 for i in tOut:
171 if i.values()[0] == 'ok': No newline at end of file
171 if i.values()[0] == 'ok':
172 modules.append(i.keys()[0]) No newline at end of file
172 modules.append(i.keys()[0])
173 No newline at end of file
173
174 return modules No newline at end of file
174 return modules
175 No newline at end of file
175
176 def __ConnectionWithControlModules(self,data,cmd,id): No newline at end of file
176 def __ConnectionWithControlModules(self,data,cmd,id):
177 No newline at end of file
177
178 self.commClientObj.open_socket() No newline at end of file
178 self.commClientObj.open_socket()
179 ip = "192.168.1." + str(id) No newline at end of file
179 ip = "192.168.1." + str(id)
180 self.commClientObj.sendData(cmd, data, ip) No newline at end of file
180 self.commClientObj.sendData(cmd, data, ip)
181 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() No newline at end of file
181 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
182 self.commClientObj.close_socket() No newline at end of file
182 self.commClientObj.close_socket()
183 No newline at end of file
183
184 return tmp No newline at end of file
184 return tmp
185 No newline at end of file
185
186 def abs2ControlModuleFormatFile(self, filename): No newline at end of file
186 def abs2ControlModuleFormatFile(self, filename):
187 No newline at end of file
187
188 #From matriz to control module format No newline at end of file
188 #From matriz to control module format
189 self.wFiles.toCentralControlFormat(filename) No newline at end of file
189 self.wFiles.toCentralControlFormat(filename)
190 FileName = "CentralControlFormat.txt" No newline at end of file
190 FileName = "CentralControlFormat.txt"
191 F_Obj = open(FileName,"r") No newline at end of file
191 F_Obj = open(FileName,"r")
192 FileList = F_Obj.readlines() No newline at end of file
192 FileList = F_Obj.readlines()
193 F_Obj.close() No newline at end of file
193 F_Obj.close()
194 FileStr = "".join(FileList) No newline at end of file
194 FileStr = "".join(FileList)
195 No newline at end of file
195
196 return FileStr No newline at end of file
196 return FileStr
197 No newline at end of file
197
198 def __All2Blocks(self,input): No newline at end of file
198 def __All2Blocks(self,input):
199 No newline at end of file
199
200 rx_frame_lst = input.split('\n',2) No newline at end of file
200 rx_frame_lst = input.split('\n',2)
201 No newline at end of file
201
202 header = rx_frame_lst[0] + "\n" No newline at end of file
202 header = rx_frame_lst[0] + "\n"
203 control_modules_str = rx_frame_lst[2] No newline at end of file
203 control_modules_str = rx_frame_lst[2]
204 control_modules_lst = control_modules_str.split("------\n") No newline at end of file
204 control_modules_lst = control_modules_str.split("------\n")
205 No newline at end of file
205
206 return header, control_modules_lst No newline at end of file
206 return header, control_modules_lst
207 No newline at end of file
207
208 No newline at end of file
208
209 def __sendFile2Modules(self,cmd, rx_buffer): No newline at end of file
209 def __sendFile2Modules(self,cmd, rx_buffer):
210 No newline at end of file
210
211 # rx_buffer_lst = self.rx_buffer.split('\n',1) No newline at end of file
211 # rx_buffer_lst = self.rx_buffer.split('\n',1)
212 rx_buffer_lst = rx_buffer.split('\n',1) No newline at end of file
212 rx_buffer_lst = rx_buffer.split('\n',1)
213 #Getting the filename from the begining of data No newline at end of file
213 #Getting the filename from the begining of data
214 filename = rx_buffer_lst[0] No newline at end of file
214 filename = rx_buffer_lst[0]
215 tmp = rx_buffer_lst[1] No newline at end of file
215 tmp = rx_buffer_lst[1]
216 self.__writeFile(filename,tmp) No newline at end of file
216 self.__writeFile(filename,tmp)
217 data = self.abs2ControlModuleFormatFile(filename) No newline at end of file
217 data = self.abs2ControlModuleFormatFile(filename)
218 #Needed for the loop No newline at end of file
218 #Needed for the loop
219 header, control_modules_lst = self.__All2Blocks(data) No newline at end of file
219 header, control_modules_lst = self.__All2Blocks(data)
220 correct = 0 No newline at end of file
220 correct = 0
221 No newline at end of file
221
222 for id in range(1,65): No newline at end of file
222 for id in range(1,65):
223 No newline at end of file
223
224 if id not in self.enaModules: No newline at end of file
224 if id not in self.enaModules:
225 continue No newline at end of file
225 continue
226 No newline at end of file
226
227 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": No newline at end of file
227 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
228 correct = correct + 1 No newline at end of file
228 correct = correct + 1
229 No newline at end of file
229
230 if correct == len(self.enaModules): No newline at end of file
230 if correct == len(self.enaModules):
231 rpta = "OK" No newline at end of file
231 rpta = "OK"
232 else: No newline at end of file
232 else:
233 rpta = "Failure" No newline at end of file
233 rpta = "Failure"
234 No newline at end of file
234
235 return rpta No newline at end of file
235 return rpta
236 No newline at end of file
236
237 def __getFileFromModules(self, cmd, rx_buffer): No newline at end of file
237 def __getFileFromModules(self, cmd, rx_buffer):
238 No newline at end of file
238
239 for id in range(1,65): No newline at end of file
239 for id in range(1,65):
240 if id not in self.enaModules: No newline at end of file
240 if id not in self.enaModules:
241 continue No newline at end of file
241 continue
242 No newline at end of file
242
243 file = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
243 file = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
244 del self.rxFile[id-1] No newline at end of file
244 del self.rxFile[id-1]
245 self.rxFile.insert(id-1, file) No newline at end of file
245 self.rxFile.insert(id-1, file)
246 No newline at end of file
246
247 return self.rxFile No newline at end of file
247 return self.rxFile
248 No newline at end of file
248
249 def __changeBeam(self, cmd, rx_buffer): No newline at end of file
249 def __changeBeam(self, cmd, rx_buffer):
250 No newline at end of file
250
251 correct = 0 No newline at end of file
251 correct = 0
252 # enaModules = self.checkAntenna() No newline at end of file
252 # enaModules = self.checkAntenna()
253 # enaModules = [11,12,13,14] No newline at end of file
253 # enaModules = [11,12,13,14]
254 No newline at end of file
254
255 for id in range(1,65): No newline at end of file
255 for id in range(1,65):
256 if id not in self.enaModules: No newline at end of file
256 if id not in self.enaModules:
257 continue No newline at end of file
257 continue
258 No newline at end of file
258
259 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK": No newline at end of file
259 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
260 correct = correct + 1 No newline at end of file
260 correct = correct + 1
261 No newline at end of file
261
262 if correct == len(self.enaModules): No newline at end of file
262 if correct == len(self.enaModules):
263 rpta = "OK" No newline at end of file
263 rpta = "OK"
264 else: No newline at end of file
264 else:
265 rpta = "Failure" No newline at end of file
265 rpta = "Failure"
266 No newline at end of file
266
267 return rpta No newline at end of file
267 return rpta
268 No newline at end of file
268
269 def __getControlModuleStatus(self, cmd, rx_buffer): No newline at end of file
269 def __getControlModuleStatus(self, cmd, rx_buffer):
270 No newline at end of file
270
271 # all_blocks = "" No newline at end of file
271 # all_blocks = ""
272 # all_blocks = [] No newline at end of file
272 # all_blocks = []
273 # enaModules = self.checkAntenna() No newline at end of file
273 # enaModules = self.checkAntenna()
274 # enaModules = [11,12,13,14] No newline at end of file
274 # enaModules = [11,12,13,14]
275 No newline at end of file
275
276 for id in range(1,65): No newline at end of file
276 for id in range(1,65):
277 if id not in self.enaModules: No newline at end of file
277 if id not in self.enaModules:
278 continue No newline at end of file
278 continue
279 No newline at end of file
279
280 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
280 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
281 del self.bits[id-1] No newline at end of file
281 del self.bits[id-1]
282 self.bits.insert(id-1, bits) No newline at end of file
282 self.bits.insert(id-1, bits)
283 No newline at end of file
283
284 # all_blocks.append(one_block) No newline at end of file
284 # all_blocks.append(one_block)
285 #Using tx buffer No newline at end of file
285 #Using tx buffer
286 No newline at end of file
286
287 return self.bits No newline at end of file
287 return self.bits
288 No newline at end of file
288
289 def __getControlModuleStatus_new(self, cmd, type): No newline at end of file
289 def __getControlModuleStatus_new(self, cmd, type):
290
290
No newline at end of file
291 cm_lst = self.__gettingDataFromControlModules(cmd = cmd, rx_buffer = type) No newline at end of file
291 cm_lst = self.__gettingDataFromControlModules(self, cmd = cmd, rx_buffer = type) No newline at end of file
292 out_str = self.__processingCMdata(in_data = cm_lst, type = type) No newline at end of file
292 out_str = self.__processingCMdata(in_data = cm_lst, type = type)
293 No newline at end of file
293
294 return out_str No newline at end of file
294 return out_str
295 No newline at end of file
295
296 def __gettingDataFromControlModules(self, cmd, rx_buffer): No newline at end of file
296 def __gettingDataFromControlModules(self, cmd, rx_buffer):
297 No newline at end of file
297
298 for id in range(1,65): No newline at end of file
298 for id in range(1,65):
299 if id not in self.enaModules: No newline at end of file
299 if id not in self.enaModules:
300 continue No newline at end of file
300 continue
301 No newline at end of file
301
302 cm = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
302 cm = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
303 del self.test[id-1] No newline at end of file
303 del self.test[id-1]
304 self.test.insert(id-1, cm) No newline at end of file
304 self.test.insert(id-1, cm)
305 No newline at end of file
305
306 return self.test No newline at end of file
306 return self.test
307 No newline at end of file
307
308 def __processingCMdata(self,in_data, type): No newline at end of file
308 def __processingCMdata(self,in_data, type):
309 No newline at end of file
309
310 if (type == "0") or (type == "1") or (type == "2"): No newline at end of file
310 if (type == "0") or (type == "1") or (type == "2"):
311 out_str = "".join(in_data) No newline at end of file
311 out_str = "".join(in_data)
312 elif type == "3": No newline at end of file
312 elif type == "3":
313 out_str = TwoComparation(in_lst = in_data) No newline at end of file
313 out_str = TwoComparation(in_lst = in_data)
314 else: No newline at end of file
314 else:
315 out_str = ThreeComparation(in_lst = in_data) No newline at end of file
315 out_str = ThreeComparation(in_lst = in_data)
316 No newline at end of file
316
317 return out_str No newline at end of file
317 return out_str
318 No newline at end of file
318
319 def __TwoComparation(self, in_lst): No newline at end of file
319 def __TwoComparation(self, in_lst):
320 No newline at end of file
320
321 No newline at end of file
321
322 file = [] No newline at end of file
322 file = []
323 relay = [] No newline at end of file
323 relay = []
324 status = [] No newline at end of file
324 status = []
325 mode = '0' No newline at end of file
325 mode = '0'
326 cnt = 0 No newline at end of file
326 cnt = 0
327 No newline at end of file
327
328 if mode == '0': No newline at end of file
328 if mode == '0':
329 No newline at end of file
329
330 for i in in_lst: No newline at end of file
330 for i in in_lst:
331 if len(i) == 8: No newline at end of file
331 if len(i) == 8:
332 file.append("xxxxxx") No newline at end of file
332 file.append("xxxxxx")
333 relay.append("xxxxxx") No newline at end of file
333 relay.append("xxxxxx")
334 else: No newline at end of file
334 else:
335 file.append(i[14:20]) No newline at end of file
335 file.append(i[14:20])
336 relay.append(i[21:27]) No newline at end of file
336 relay.append(i[21:27])
337 #Loop to generate a status No newline at end of file
337 #Loop to generate a status
338 for i in range(64): No newline at end of file
338 for i in range(64):
339 if file[i] == "xxxxxx": No newline at end of file
339 if file[i] == "xxxxxx":
340 status.append("xx") No newline at end of file
340 status.append("xx")
341 continue No newline at end of file
341 continue
342 No newline at end of file
342
343 if cmp(file[i],relay[i]) == 0: No newline at end of file
343 if cmp(file[i],relay[i]) == 0:
344 cnt = cnt + 1 No newline at end of file
344 cnt = cnt + 1
345 No newline at end of file
345
346 if cmp(file[i][0:3],relay[i][0:3]) == 0: No newline at end of file
346 if cmp(file[i][0:3],relay[i][0:3]) == 0:
347 cnt = cnt + 1 No newline at end of file
347 cnt = cnt + 1
348 No newline at end of file
348
349 if cmp(file[i][3:6],relay[i][3:6]) == 0: No newline at end of file
349 if cmp(file[i][3:6],relay[i][3:6]) == 0:
350 cnt = cnt + 2 No newline at end of file
350 cnt = cnt + 2
351 No newline at end of file
351
352 if cnt == 4: No newline at end of file
352 if cnt == 4:
353 status.append("00") No newline at end of file
353 status.append("00")
354 elif cnt == 0: No newline at end of file
354 elif cnt == 0:
355 status.append("11") No newline at end of file
355 status.append("11")
356 elif cnt == 1: No newline at end of file
356 elif cnt == 1:
357 status.append("11") No newline at end of file
357 status.append("11")
358 else: No newline at end of file
358 else:
359 status.append("01") No newline at end of file
359 status.append("01")
360 No newline at end of file
360
361 else: No newline at end of file
361 else:
362 No newline at end of file
362
363 cm_up =[] No newline at end of file
363 cm_up =[]
364 cm_dw =[] No newline at end of file
364 cm_dw =[]
365 relay_up =[] No newline at end of file
365 relay_up =[]
366 relay_dw =[] No newline at end of file
366 relay_dw =[]
367 No newline at end of file
367
368 for i in in_lst: No newline at end of file
368 for i in in_lst:
369 if len(i) == 8: No newline at end of file
369 if len(i) == 8:
370 relay_up.append("-") No newline at end of file
370 relay_up.append("-")
371 relay_dw.append("-") No newline at end of file
371 relay_dw.append("-")
372 cm_up.append("-") No newline at end of file
372 cm_up.append("-")
373 cm_dw.append("-") No newline at end of file
373 cm_dw.append("-")
374 continue No newline at end of file
374 continue
375 relay_up.append(i[14:17]) No newline at end of file
375 relay_up.append(i[14:17])
376 relay_dw.append(i[17:20]) No newline at end of file
376 relay_dw.append(i[17:20])
377 cm_up.append(i[21:24]) No newline at end of file
377 cm_up.append(i[21:24])
378 cm_dw.append(i[24:27]) No newline at end of file
378 cm_dw.append(i[24:27])
379 No newline at end of file
379
380 comp_up = [] No newline at end of file
380 comp_up = []
381 comp_dw = [] No newline at end of file
381 comp_dw = []
382 No newline at end of file
382
383 for i in range(64): No newline at end of file
383 for i in range(64):
384 if len(relay_up == 1): No newline at end of file
384 if len(relay_up == 1):
385 comp_up.append('x') No newline at end of file
385 comp_up.append('x')
386 else: No newline at end of file
386 else:
387 if cmp(relay_up[i], cm_up[i]) == 0: No newline at end of file
387 if cmp(relay_up[i], cm_up[i]) == 0:
388 comp_up.append('0') No newline at end of file
388 comp_up.append('0')
389 else: No newline at end of file
389 else:
390 comp_up.append('1') No newline at end of file
390 comp_up.append('1')
391 No newline at end of file
391
392 for i in range(64): No newline at end of file
392 for i in range(64):
393 if len(relay_dw == 1): No newline at end of file
393 if len(relay_dw == 1):
394 comp_dw.append('x') No newline at end of file
394 comp_dw.append('x')
395 else: No newline at end of file
395 else:
396 if cmp(relay_dw[i], cm_dw[i]) == 0: No newline at end of file
396 if cmp(relay_dw[i], cm_dw[i]) == 0:
397 comp_dw.append('0') No newline at end of file
397 comp_dw.append('0')
398 else: No newline at end of file
398 else:
399 comp_dw.append('1') No newline at end of file
399 comp_dw.append('1')
400 No newline at end of file
400
401 # Example: No newline at end of file
401 # Example:
402 # comp_up = [1,0,x,1,1,1 ..,1,0,1,x] No newline at end of file
402 # comp_up = [1,0,x,1,1,1 ..,1,0,1,x]
403 # No newline at end of file
403 #
404 print comp_up No newline at end of file
404 print comp_up
405 print comp_dw No newline at end of file
405 print comp_dw
406 No newline at end of file
406
407 #Doing final format No newline at end of file
407 #Doing final format
408 return self.__FinalFormat(data1 = file, data2 = relay, data3 = status) No newline at end of file
408 return self.__FinalFormat(data1 = file, data2 = relay, data3 = status)
409 No newline at end of file
409
410 def __FinalFormat(self,data1,data2,data3): No newline at end of file
410 def __FinalFormat(self,data1,data2,data3):
411 No newline at end of file
411
412 header = "Device\tFile\tRelay\tStatus\n" No newline at end of file
412 header = "Device\tFile\tRelay\tStatus\n"
413 body = "" No newline at end of file
413 body = ""
414 for i in range(64): No newline at end of file
414 for i in range(64):
415 if i<9: No newline at end of file
415 if i<9:
416 device = "CM0" + str(i+1) No newline at end of file
416 device = "CM0" + str(i+1)
417 else: No newline at end of file
417 else:
418 device = "CM" + str(i+1) No newline at end of file
418 device = "CM" + str(i+1)
419 No newline at end of file
419
420 line = device + '\t' + data1[i] + '\t' + data2[i] + '\t' + data3[i] + '\n' No newline at end of file
420 line = device + '\t' + data1[i] + '\t' + data2[i] + '\t' + data3[i] + '\n'
421 body = body + line No newline at end of file
421 body = body + line
422 No newline at end of file
422
423 report = header + body No newline at end of file
423 report = header + body
424 No newline at end of file
424
425 return report No newline at end of file
425 return report
426 No newline at end of file
426
427 def __ThreeComparation(self, in_lst): No newline at end of file
427 def __ThreeComparation(self, in_lst):
428 pass No newline at end of file
428 pass
429 No newline at end of file
429
430 def __getControlModuleBigPhase(self, cmd, rx_buffer): No newline at end of file
430 def __getControlModuleBigPhase(self, cmd, rx_buffer):
431 No newline at end of file
431
432 # all_blocks = "" No newline at end of file
432 # all_blocks = ""
433 all_blocks = [] No newline at end of file
433 all_blocks = []
434 # enaModules = self.checkAntenna() No newline at end of file
434 # enaModules = self.checkAntenna()
435 # enaModules = [11,12,13,14] No newline at end of file
435 # enaModules = [11,12,13,14]
436 No newline at end of file
436
437 for id in range(1,65): No newline at end of file
437 for id in range(1,65):
438 if id not in self.enaModules: No newline at end of file
438 if id not in self.enaModules:
439 continue No newline at end of file
439 continue
440 No newline at end of file
440
441 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
441 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
442 No newline at end of file
442
443 # all_blocks = all_blocks + one_block No newline at end of file
443 # all_blocks = all_blocks + one_block
444 all_blocks.append(one_block) No newline at end of file
444 all_blocks.append(one_block)
445 #Using tx buffer No newline at end of file
445 #Using tx buffer
446 return all_blocks No newline at end of file
446 return all_blocks
447 No newline at end of file
447
448 def __getControlModuleLowPhase(self, cmd, rx_buffer): No newline at end of file
448 def __getControlModuleLowPhase(self, cmd, rx_buffer):
449 No newline at end of file
449
450 # all_blocks = "" No newline at end of file
450 # all_blocks = ""
451 # all_blocks = [] No newline at end of file
451 # all_blocks = []
452 # enaModules = self.checkAntenna() No newline at end of file
452 # enaModules = self.checkAntenna()
453 # enaModules = [11,12,13,14] No newline at end of file
453 # enaModules = [11,12,13,14]
454 No newline at end of file
454
455 for id in range(1,65): No newline at end of file
455 for id in range(1,65):
456 if id not in self.enaModules: No newline at end of file
456 if id not in self.enaModules:
457 continue No newline at end of file
457 continue
458 No newline at end of file
458
459 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
459 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
460 del self.phase[id-1] No newline at end of file
460 del self.phase[id-1]
461 self.phase.insert(id-1, phase) No newline at end of file
461 self.phase.insert(id-1, phase)
462 # all_blocks = all_blocks + one_block No newline at end of file
462 # all_blocks = all_blocks + one_block
463 # all_blocks.append(one_block) No newline at end of file
463 # all_blocks.append(one_block)
464 #Using tx buffer No newline at end of file
464 #Using tx buffer
465 # return all_blocks No newline at end of file
465 # return all_blocks
466 No newline at end of file
466
467 def __getConnectionStatus(self, cmd, rx_buffer): No newline at end of file
467 def __getConnectionStatus(self, cmd, rx_buffer):
468 No newline at end of file
468
469 ena = self.checkAntenna() No newline at end of file
469 ena = self.checkAntenna()
470 print ena No newline at end of file
470 print ena
471 self.enaModules = ena No newline at end of file
471 self.enaModules = ena
472 No newline at end of file
472
473 blockLst = [] No newline at end of file
473 blockLst = []
474 No newline at end of file
474
475 for id in range(1,65): No newline at end of file
475 for id in range(1,65):
476 if id not in self.enaModules: No newline at end of file
476 if id not in self.enaModules:
477 continue No newline at end of file
477 continue
478 No newline at end of file
478
479 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
479 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
480 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") No newline at end of file
480 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
481 #Using tx buffer No newline at end of file
481 #Using tx buffer
482 all_blocks = "".join(blockLst) No newline at end of file
482 all_blocks = "".join(blockLst)
483 No newline at end of file
483
484 return all_blocks No newline at end of file
484 return all_blocks
485 No newline at end of file
485
486 def getConnectionStatus(self, cmd): No newline at end of file
486 def getConnectionStatus(self, cmd):
487 No newline at end of file
487
488 ena = self.checkAntenna() No newline at end of file
488 ena = self.checkAntenna()
489 self.enaModules = ena No newline at end of file
489 self.enaModules = ena
490 No newline at end of file
490
491 blockLst = [] No newline at end of file
491 blockLst = []
492 No newline at end of file
492
493 for id in range(1,65): No newline at end of file
493 for id in range(1,65):
494 if id not in self.enaModules: No newline at end of file
494 if id not in self.enaModules:
495 continue No newline at end of file
495 continue
496 No newline at end of file
496
497 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) No newline at end of file
497 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
498 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") No newline at end of file
498 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
499 #Using tx buffer No newline at end of file
499 #Using tx buffer
500 self.tx_buffer = "".join(blockLst) No newline at end of file
500 self.tx_buffer = "".join(blockLst)
501 print self.tx_buffer No newline at end of file
501 print self.tx_buffer
502 No newline at end of file
502
503 return self.tx_buffer No newline at end of file
503 return self.tx_buffer
504 No newline at end of file
504
505 def __getControlModuleStatus_old(self, cmd, rx_buffer): No newline at end of file
505 def __getControlModuleStatus_old(self, cmd, rx_buffer):
506 No newline at end of file
506
507 all_blocks = "" No newline at end of file
507 all_blocks = ""
508 # enaModules = self.checkAntenna() No newline at end of file
508 # enaModules = self.checkAntenna()
509 # enaModules = [11,12,13,14] No newline at end of file
509 # enaModules = [11,12,13,14]
510 No newline at end of file
510
511 for id in range(1,65): No newline at end of file
511 for id in range(1,65):
512 if id not in self.enaModules: No newline at end of file
512 if id not in self.enaModules:
513 continue No newline at end of file
513 continue
514 No newline at end of file
514
515 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file
515 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
516 No newline at end of file
516
517 all_blocks = all_blocks + one_block No newline at end of file
517 all_blocks = all_blocks + one_block
518 #Using tx buffer No newline at end of file
518 #Using tx buffer
519 print all_blocks No newline at end of file
519 print all_blocks
520 self.tx_buffer = all_blocks No newline at end of file
520 self.tx_buffer = all_blocks
521 No newline at end of file
521
522 return all_blocks No newline at end of file
522 return all_blocks
523 No newline at end of file
523
524 def __StartingAutomaticControlModules(self): No newline at end of file
524 def __StartingAutomaticControlModules(self):
525 No newline at end of file
525
526 #Starting file No newline at end of file
526 #Starting file
527 self.__CreateFile("Monitoring.txt") No newline at end of file
527 self.__CreateFile("Monitoring.txt")
528 # data = "MOD.\t BITS\t\t PHASE\n" No newline at end of file
528 # data = "MOD.\t BITS\t\t PHASE\n"
529 # self.__writeFile("Monitoring.txt", data) No newline at end of file
529 # self.__writeFile("Monitoring.txt", data)
530 #Starting lists No newline at end of file
530 #Starting lists
531 self.txFile = list("------\n------\n------\n" for i in range(64)) No newline at end of file
531 self.txFile = list("------\n------\n------\n" for i in range(64))
532 self.rxFile = list("------\n------\n------\n" for i in range(64)) No newline at end of file
532 self.rxFile = list("------\n------\n------\n" for i in range(64))
533 self.bits = list("------\n------\n------\n" for i in range(64)) No newline at end of file
533 self.bits = list("------\n------\n------\n" for i in range(64))
534 self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64)) No newline at end of file
534 self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64))
535 self.test = list("------\n" for i in range(64)) No newline at end of file
535 self.test = list("------\n" for i in range(64))
536 No newline at end of file
536
537 def __AutomaticControlModules(self): No newline at end of file
537 def __AutomaticControlModules(self):
538 No newline at end of file
538
539 # cmd = "GETF" No newline at end of file
539 # cmd = "GETF"
540 # rx_buffer = "experimento1.ab1" + "\n" No newline at end of file
540 # rx_buffer = "experimento1.ab1" + "\n"
541 # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
541 # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
542 # No newline at end of file
542 #
543 # print self.rxFile No newline at end of file
543 # print self.rxFile
544 No newline at end of file
544
545 cmd = "ANST" No newline at end of file
545 cmd = "ANST"
546 rx_buffer = "1" No newline at end of file
546 rx_buffer = "1"
547 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
547 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
548 No newline at end of file
548
549 cmd = "LWPH" No newline at end of file
549 cmd = "LWPH"
550 rx_buffer = "0" No newline at end of file
550 rx_buffer = "0"
551 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file
551 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
552 print "Saving file..." No newline at end of file
552 print "Saving file..."
553 No newline at end of file
553
554 No newline at end of file
554
555 print self.bits No newline at end of file
555 print self.bits
556 print self.phase No newline at end of file
556 print self.phase
557 No newline at end of file
557
558 self.__WritingMonitoringFile() No newline at end of file
558 self.__WritingMonitoringFile()
559 No newline at end of file
559
560 threading.Timer(60, self.__AutomaticControlModules).start() No newline at end of file
560 threading.Timer(60, self.__AutomaticControlModules).start()
561 No newline at end of file
561
562 def __WritingMonitoringFile(self): No newline at end of file
562 def __WritingMonitoringFile(self):
563 filename = "Monitoring.txt" No newline at end of file
563 filename = "Monitoring.txt"
564 data = '===============================' + '\n' No newline at end of file
564 data = '===============================' + '\n'
565 self.__writeFile(filename, data) No newline at end of file
565 self.__writeFile(filename, data)
566 data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime()) No newline at end of file
566 data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime())
567 self.__writeFile(filename, data) No newline at end of file
567 self.__writeFile(filename, data)
568 data = "MOD.\t BITS\t\t PHASE\n" No newline at end of file
568 data = "MOD.\t BITS\t\t PHASE\n"
569 self.__writeFile(filename, data) No newline at end of file
569 self.__writeFile(filename, data)
570 data = '===============================' + '\n' No newline at end of file
570 data = '===============================' + '\n'
571 self.__writeFile(filename, data) No newline at end of file
571 self.__writeFile(filename, data)
572 for i in range(64): No newline at end of file
572 for i in range(64):
573 tmp = self.bits[i].split('\n',3) No newline at end of file
573 tmp = self.bits[i].split('\n',3)
574 self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2]) No newline at end of file
574 self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2])
575 tmp = self.phase[i].split('\n',3) No newline at end of file
575 tmp = self.phase[i].split('\n',3)
576 self.__writeFile(filename, '\t\t' + tmp[2] + '\n') No newline at end of file
576 self.__writeFile(filename, '\t\t' + tmp[2] + '\n')
577 No newline at end of file
577
578 No newline at end of file
578
579 if __name__ == '__main__': No newline at end of file
579 if __name__ == '__main__':
580 No newline at end of file
580
581 absObj = ABSServer() No newline at end of file
581 absObj = ABSServer()
582 No newline at end of file
582
583 while 1: No newline at end of file
583 while 1:
584 absObj.waitRequest() No newline at end of file
584 absObj.waitRequest()
General Comments 0
You need to be logged in to leave comments. Login now