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