##// END OF EJS Templates
Monitoring test
imanay -
r251:252
parent child
Show More
@@ -1,517 +1,584
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.__writeFile(filename,tmp)
217 data = self.abs2ControlModuleFormatFile(filename)
217 data = self.abs2ControlModuleFormatFile(filename)
218 #Needed for the loop
218 #Needed for the loop
219 header, control_modules_lst = self.__All2Blocks(data)
219 header, control_modules_lst = self.__All2Blocks(data)
220 correct = 0
220 correct = 0
221
221
222 for id in range(1,65):
222 for id in range(1,65):
223
223
224 if id not in self.enaModules:
224 if id not in self.enaModules:
225 continue
225 continue
226
226
227 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
227 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
228 correct = correct + 1
228 correct = correct + 1
229
229
230 if correct == len(self.enaModules):
230 if correct == len(self.enaModules):
231 rpta = "OK"
231 rpta = "OK"
232 else:
232 else:
233 rpta = "Failure"
233 rpta = "Failure"
234
234
235 return rpta
235 return rpta
236
236
237 def __getFileFromModules(self, cmd, rx_buffer):
237 def __getFileFromModules(self, cmd, rx_buffer):
238
238
239 for id in range(1,65):
239 for id in range(1,65):
240 if id not in self.enaModules:
240 if id not in self.enaModules:
241 continue
241 continue
242
242
243 file = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
243 file = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
244 del self.rxFile[id-1]
244 del self.rxFile[id-1]
245 self.rxFile.insert(id-1, file)
245 self.rxFile.insert(id-1, file)
246
246
247 return self.rxFile
247 return self.rxFile
248
248
249 def __changeBeam(self, cmd, rx_buffer):
249 def __changeBeam(self, cmd, rx_buffer):
250
250
251 correct = 0
251 correct = 0
252 # enaModules = self.checkAntenna()
252 # enaModules = self.checkAntenna()
253 # enaModules = [11,12,13,14]
253 # enaModules = [11,12,13,14]
254
254
255 for id in range(1,65):
255 for id in range(1,65):
256 if id not in self.enaModules:
256 if id not in self.enaModules:
257 continue
257 continue
258
258
259 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
259 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
260 correct = correct + 1
260 correct = correct + 1
261
261
262 if correct == len(self.enaModules):
262 if correct == len(self.enaModules):
263 rpta = "OK"
263 rpta = "OK"
264 else:
264 else:
265 rpta = "Failure"
265 rpta = "Failure"
266
266
267 return rpta
267 return rpta
268
268
269 def __getControlModuleStatus(self, cmd, rx_buffer):
269 def __getControlModuleStatus(self, cmd, rx_buffer):
270
270
271 # all_blocks = ""
271 # all_blocks = ""
272 # all_blocks = []
272 # all_blocks = []
273 # enaModules = self.checkAntenna()
273 # enaModules = self.checkAntenna()
274 # enaModules = [11,12,13,14]
274 # enaModules = [11,12,13,14]
275
275
276 for id in range(1,65):
276 for id in range(1,65):
277 if id not in self.enaModules:
277 if id not in self.enaModules:
278 continue
278 continue
279
279
280 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
280 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
281 del self.bits[id-1]
281 del self.bits[id-1]
282 self.bits.insert(id-1, bits)
282 self.bits.insert(id-1, bits)
283
283
284 # all_blocks.append(one_block)
284 # all_blocks.append(one_block)
285 #Using tx buffer
285 #Using tx buffer
286
286
287 return self.bits
287 return self.bits
288
288
289 def __getControlModuleStatus_new(self, cmd, type):
289 def __getControlModuleStatus_new(self, cmd, type):
290
290
291 cm_lst = self.__gettingDataFromControlModules(self, cmd, rx_buffer = type)
291 cm_lst = self.__gettingDataFromControlModules(self, cmd, rx_buffer = type)
292 out_lst = self.__processingCMdata(in_data = cm_lst, type = type)
292 out_str = self.__processingCMdata(in_data = cm_lst, type = type)
293
293
294 return "".join(lst_out)
294 return out_str
295
295
296 def __gettingDataFromControlModules(self, cmd, rx_buffer):
296 def __gettingDataFromControlModules(self, cmd, rx_buffer):
297
297
298 for id in range(1,65):
298 for id in range(1,65):
299 if id not in self.enaModules:
299 if id not in self.enaModules:
300 continue
300 continue
301
301
302 cm = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
302 cm = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
303 del self.test[id-1]
303 del self.test[id-1]
304 self.test.insert(id-1, cm)
304 self.test.insert(id-1, cm)
305
305
306 return self.test
306 return self.test
307
307
308 def __processingCMdata(self,in_data, type):
308 def __processingCMdata(self,in_data, type):
309
309
310 if (type == "0") or (type == "1") or (type == "2"):
310 if (type == "0") or (type == "1") or (type == "2"):
311 out_str = "".join(in_data)
311 out_str = "".join(in_data)
312 elif type == "3":
312 elif type == "3":
313 out_str = TwoComparation(in_lst = in_data)
313 out_str = TwoComparation(in_lst = in_data)
314 else:
314 else:
315 out_str = ThreeComparation(in_lst = in_data)
315 out_str = ThreeComparation(in_lst = in_data)
316
316
317 return out_str
317 return out_str
318
318
319 def __TwoComparation(self, in_lst):
319 def __TwoComparation(self, in_lst):
320
320
321 cm_up =[]
321
322 cm_dw =[]
322 file = []
323 relay_up =[]
323 relay = []
324 relay_dw =[]
324 status = []
325
325 mode = '0'
326 for i in in_lst:
326 cnt = 0
327 if len(i) == 8:
327
328 relay_up.append("-")
328 if mode == '0':
329 relay_dw.append("-")
329
330 cm_up.append("-")
330 for i in in_lst:
331 cm_dw.append("-")
331 if len(i) == 8:
332 continue
332 file.append("xxxxxx")
333 relay_up.append(i[14:17])
333 relay.append("xxxxxx")
334 relay_dw.append(i[17:20])
334 else:
335 cm_up.append(i[21:24])
335 file.append(i[14:20])
336 cm_dw.append(i[24:27])
336 relay.append(i[21:27])
337
337 #Loop to generate a status
338 comp_up = []
338 for i in range(64):
339 comp_dw = []
339 if file[i] == "xxxxxx":
340
340 status.append("xx")
341 continue
342
343 if cmp(file[i],relay[i]) == 0:
344 cnt = cnt + 1
345
346 if cmp(file[i][0:3],relay[i][0:3]) == 0:
347 cnt = cnt + 1
348
349 if cmp(file[i][3:6],relay[i][3:6]) == 0:
350 cnt = cnt + 2
351
352 if cnt == 4:
353 status.append("00")
354 elif cnt == 0:
355 status.append("11")
356 elif cnt == 1:
357 status.append("11")
358 else:
359 status.append("01")
360
361 else:
362
363 cm_up =[]
364 cm_dw =[]
365 relay_up =[]
366 relay_dw =[]
367
368 for i in in_lst:
369 if len(i) == 8:
370 relay_up.append("-")
371 relay_dw.append("-")
372 cm_up.append("-")
373 cm_dw.append("-")
374 continue
375 relay_up.append(i[14:17])
376 relay_dw.append(i[17:20])
377 cm_up.append(i[21:24])
378 cm_dw.append(i[24:27])
379
380 comp_up = []
381 comp_dw = []
382
383 for i in range(64):
384 if len(relay_up == 1):
385 comp_up.append('x')
386 else:
387 if cmp(relay_up[i], cm_up[i]) == 0:
388 comp_up.append('0')
389 else:
390 comp_up.append('1')
391
392 for i in range(64):
393 if len(relay_dw == 1):
394 comp_dw.append('x')
395 else:
396 if cmp(relay_dw[i], cm_dw[i]) == 0:
397 comp_dw.append('0')
398 else:
399 comp_dw.append('1')
400
401 # Example:
402 # comp_up = [1,0,x,1,1,1 ..,1,0,1,x]
403 #
404 print comp_up
405 print comp_dw
406
407 #Doing final format
408 return self.__FinalFormat(data1 = file, data2 = relay, data3 = status)
409
410 def __FinalFormat(self,data1,data2,data3):
411
412 header = "Device\tFile\tRelay\tStatus\n"
413 body = ""
341 for i in range(64):
414 for i in range(64):
342 if len(relay_up == 1):
415 if i<9:
343 comp_up.append('x')
416 device = "CM0" + str(i+1)
344 else:
417 else:
345 if cmp(relay_up[i], cm_up[i]) == 0:
418 device = "CM" + str(i+1)
346 comp_up.append('0')
347 else:
348 comp_up.append('1')
349
350 for i in range(len(relay_dw)):
351 comp_dw.append('x')
352 if cmp(relay_dw[i], cm_dw[i]) == 0:
353 comp_dw.append('0')
354 else:
355 comp_dw.append('1')
356
419
357 print comp_up
420 line = device + '\t' + data1[i] + '\t' + data2[i] + '\t' + data3[i] + '\n'
358 print comp_dw
421 body = body + line
359
422
360
423 report = header + body
424
425 return report
426
361 def __ThreeComparation(self, in_lst):
427 def __ThreeComparation(self, in_lst):
362 pass
428 pass
363
429
364 def __getControlModuleBigPhase(self, cmd, rx_buffer):
430 def __getControlModuleBigPhase(self, cmd, rx_buffer):
365
431
366 # all_blocks = ""
432 # all_blocks = ""
367 all_blocks = []
433 all_blocks = []
368 # enaModules = self.checkAntenna()
434 # enaModules = self.checkAntenna()
369 # enaModules = [11,12,13,14]
435 # enaModules = [11,12,13,14]
370
436
371 for id in range(1,65):
437 for id in range(1,65):
372 if id not in self.enaModules:
438 if id not in self.enaModules:
373 continue
439 continue
374
440
375 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
441 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
376
442
377 # all_blocks = all_blocks + one_block
443 # all_blocks = all_blocks + one_block
378 all_blocks.append(one_block)
444 all_blocks.append(one_block)
379 #Using tx buffer
445 #Using tx buffer
380 return all_blocks
446 return all_blocks
381
447
382 def __getControlModuleLowPhase(self, cmd, rx_buffer):
448 def __getControlModuleLowPhase(self, cmd, rx_buffer):
383
449
384 # all_blocks = ""
450 # all_blocks = ""
385 # all_blocks = []
451 # all_blocks = []
386 # enaModules = self.checkAntenna()
452 # enaModules = self.checkAntenna()
387 # enaModules = [11,12,13,14]
453 # enaModules = [11,12,13,14]
388
454
389 for id in range(1,65):
455 for id in range(1,65):
390 if id not in self.enaModules:
456 if id not in self.enaModules:
391 continue
457 continue
392
458
393 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
459 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
394 del self.phase[id-1]
460 del self.phase[id-1]
395 self.phase.insert(id-1, phase)
461 self.phase.insert(id-1, phase)
396 # all_blocks = all_blocks + one_block
462 # all_blocks = all_blocks + one_block
397 # all_blocks.append(one_block)
463 # all_blocks.append(one_block)
398 #Using tx buffer
464 #Using tx buffer
399 # return all_blocks
465 # return all_blocks
400
466
401 def __getConnectionStatus(self, cmd, rx_buffer):
467 def __getConnectionStatus(self, cmd, rx_buffer):
402
468
403 ena = self.checkAntenna()
469 ena = self.checkAntenna()
404 print ena
470 print ena
405 self.enaModules = ena
471 self.enaModules = ena
406
472
407 blockLst = []
473 blockLst = []
408
474
409 for id in range(1,65):
475 for id in range(1,65):
410 if id not in self.enaModules:
476 if id not in self.enaModules:
411 continue
477 continue
412
478
413 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
479 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
414 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
480 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
415 #Using tx buffer
481 #Using tx buffer
416 all_blocks = "".join(blockLst)
482 all_blocks = "".join(blockLst)
417
483
418 return all_blocks
484 return all_blocks
419
485
420 def getConnectionStatus(self, cmd):
486 def getConnectionStatus(self, cmd):
421
487
422 ena = self.checkAntenna()
488 ena = self.checkAntenna()
423 self.enaModules = ena
489 self.enaModules = ena
424
490
425 blockLst = []
491 blockLst = []
426
492
427 for id in range(1,65):
493 for id in range(1,65):
428 if id not in self.enaModules:
494 if id not in self.enaModules:
429 continue
495 continue
430
496
431 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
497 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
432 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
498 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
433 #Using tx buffer
499 #Using tx buffer
434 self.tx_buffer = "".join(blockLst)
500 self.tx_buffer = "".join(blockLst)
435 print self.tx_buffer
501 print self.tx_buffer
436
502
437 return self.tx_buffer
503 return self.tx_buffer
438
504
439 def __getControlModuleStatus_old(self, cmd, rx_buffer):
505 def __getControlModuleStatus_old(self, cmd, rx_buffer):
440
506
441 all_blocks = ""
507 all_blocks = ""
442 # enaModules = self.checkAntenna()
508 # enaModules = self.checkAntenna()
443 # enaModules = [11,12,13,14]
509 # enaModules = [11,12,13,14]
444
510
445 for id in range(1,65):
511 for id in range(1,65):
446 if id not in self.enaModules:
512 if id not in self.enaModules:
447 continue
513 continue
448
514
449 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
515 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
450
516
451 all_blocks = all_blocks + one_block
517 all_blocks = all_blocks + one_block
452 #Using tx buffer
518 #Using tx buffer
453 print all_blocks
519 print all_blocks
454 self.tx_buffer = all_blocks
520 self.tx_buffer = all_blocks
455
521
456 return all_blocks
522 return all_blocks
457
523
458 def __StartingAutomaticControlModules(self):
524 def __StartingAutomaticControlModules(self):
459
525
460 #Starting file
526 #Starting file
461 self.__CreateFile("Monitoring.txt")
527 self.__CreateFile("Monitoring.txt")
462 # data = "MOD.\t BITS\t\t PHASE\n"
528 # data = "MOD.\t BITS\t\t PHASE\n"
463 # self.__writeFile("Monitoring.txt", data)
529 # self.__writeFile("Monitoring.txt", data)
464 #Starting lists
530 #Starting lists
465 self.txFile = list("------\n------\n------\n" for i in range(64))
531 self.txFile = list("------\n------\n------\n" for i in range(64))
466 self.rxFile = list("------\n------\n------\n" for i in range(64))
532 self.rxFile = list("------\n------\n------\n" for i in range(64))
467 self.bits = list("------\n------\n------\n" for i in range(64))
533 self.bits = list("------\n------\n------\n" for i in range(64))
468 self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64))
534 self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64))
469 self.test = list("------\n" for i in range(64))
535 self.test = list("------\n" for i in range(64))
470
536
471 def __AutomaticControlModules(self):
537 def __AutomaticControlModules(self):
472
538
473 # cmd = "GETF"
539 # cmd = "GETF"
474 # rx_buffer = "experimento1.ab1" + "\n"
540 # rx_buffer = "experimento1.ab1" + "\n"
475 # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
541 # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
476 #
542 #
477 # print self.rxFile
543 # print self.rxFile
478
544
479 cmd = "ANST"
545 cmd = "ANST"
480 rx_buffer = "1"
546 rx_buffer = "1"
481 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
547 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
482
548
483 cmd = "LWPH"
549 cmd = "LWPH"
484 rx_buffer = "0"
550 rx_buffer = "0"
485 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
551 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
486 print "Saving file..."
552 print "Saving file..."
487
553
488
554
489 print self.bits
555 print self.bits
490 print self.phase
556 print self.phase
491
557
492 self.__WritingMonitoringFile()
558 self.__WritingMonitoringFile()
493
559
494 threading.Timer(60, self.__AutomaticControlModules).start()
560 threading.Timer(60, self.__AutomaticControlModules).start()
495
561
496 def __WritingMonitoringFile(self):
562 def __WritingMonitoringFile(self):
497 filename = "Monitoring.txt"
563 filename = "Monitoring.txt"
498 data = '===============================' + '\n'
564 data = '===============================' + '\n'
499 self.__writeFile(filename, data)
565 self.__writeFile(filename, data)
500 data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime())
566 data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime())
501 self.__writeFile(filename, data)
567 self.__writeFile(filename, data)
502 data = "MOD.\t BITS\t\t PHASE\n"
568 data = "MOD.\t BITS\t\t PHASE\n"
503 self.__writeFile(filename, data)
569 self.__writeFile(filename, data)
504 data = '===============================' + '\n'
570 data = '===============================' + '\n'
505 self.__writeFile(filename, data)
571 self.__writeFile(filename, data)
506 for i in range(64):
572 for i in range(64):
507 tmp = self.bits[i].split('\n',3)
573 tmp = self.bits[i].split('\n',3)
508 self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2])
574 self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2])
509 tmp = self.phase[i].split('\n',3)
575 tmp = self.phase[i].split('\n',3)
510 self.__writeFile(filename, '\t\t' + tmp[2] + '\n')
576 self.__writeFile(filename, '\t\t' + tmp[2] + '\n')
577
511
578
512 if __name__ == '__main__':
579 if __name__ == '__main__':
513
580
514 absObj = ABSServer()
581 absObj = ABSServer()
515
582
516 while 1:
583 while 1:
517 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