##// END OF EJS Templates
imanay -
r233:234
parent child
Show More
@@ -1,110 +1,110
1 import library3
1 import library3
2 import os.path
2 import os.path
3
3
4 class ABSClient(object):
4 class ABSClient(object):
5
5
6 def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000):
6 def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000):
7
7
8 self.ipSource = ipSource
8 self.ipSource = ipSource
9 self.iDSource = iDSource
9 self.iDSource = iDSource
10 self.ipDestino = ipDestino
10 self.ipDestino = ipDestino
11 self.iDDestino = iDDestino
11 self.iDDestino = iDDestino
12 self.portDestino = portDestino
12 self.portDestino = portDestino
13
13
14 self.createObjects()
14 self.createObjects()
15
15
16 def createObjects(self):
16 def createObjects(self):
17
17
18 self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino)
18 self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino)
19 #self.wFiles = library3.FilesStuff()
19 #self.wFiles = library3.FilesStuff()
20
20
21 def __ConnectionWithCentralControl(self, cmd, data):
21 def __ConnectionWithCentralControl(self, cmd, data):
22
22
23 self.commObj.open_socket()
23 self.commObj.open_socket()
24 self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino)
24 self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino)
25 ipSource, ipDestino, cmd, output = self.commObj.waitData()
25 ipSource, ipDestino, cmd, output = self.commObj.waitData()
26 self.commObj.close_socket()
26 self.commObj.close_socket()
27
27
28 return output
28 return output
29
29
30 # def abs2ControlModuleFormatFile(self, filename):
30 # def abs2ControlModuleFormatFile(self, filename):
31 #
31 #
32 # #From matriz to control module format
32 # #From matriz to control module format
33 # self.wFiles.toCentralControlFormat(filename)
33 # self.wFiles.toCentralControlFormat(filename)
34 # FileName = "CentralControlFormat.txt"
34 # FileName = "CentralControlFormat.txt"
35 # F_Obj = open(FileName,"r")
35 # F_Obj = open(FileName,"r")
36 # FileList = F_Obj.readlines()
36 # FileList = F_Obj.readlines()
37 # F_Obj.close()
37 # F_Obj.close()
38 # FileStr = "".join(FileList)
38 # FileStr = "".join(FileList)
39 #
39 #
40 # return FileStr
40 # return FileStr
41
41
42 def sendFile(self, filename):
42 def sendFile(self, filename):
43
43
44 data = self.__readFile(filename)
44 data = self.__readFile(filename)
45 answer = self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
45 answer = self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
46 return answer
46 return answer
47
47
48 def readFile(self, filename):
48 def readFile(self):
49
49
50 data = "optional"
50 data = "optional"
51 file = self.__ConnectionWithCentralControl(cmd = "GETF", data = data)
51 file = self.__ConnectionWithCentralControl(cmd = "GETF", data = data)
52
52
53 return file
53 return file
54
54
55 def changeBeam(self, newBeam):
55 def changeBeam(self, newBeam):
56
56
57 answer = self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
57 answer = self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
58 return answer
58 return answer
59
59
60 def __writeFile(self, filename, data):
60 def __writeFile(self, filename, data):
61
61
62 fobj = open(filename,"w")
62 fobj = open(filename,"w")
63 fobj.writelines(data)
63 fobj.writelines(data)
64 fobj.close()
64 fobj.close()
65
65
66 def __readFile(self, filename):
66 def __readFile(self, filename):
67
67
68 fobj = open(filename,"r")
68 fobj = open(filename,"r")
69 listData = fobj.readlines()
69 listData = fobj.readlines()
70 fobj.close()
70 fobj.close()
71 tmp = "".join(listData)
71 tmp = "".join(listData)
72 #Adding filename to the begining of the data
72 #Adding filename to the begining of the data
73 newfilename = os.path.split(filename)[1]
73 newfilename = os.path.split(filename)[1]
74 #data = filename + '\n' + tmp
74 #data = filename + '\n' + tmp
75 data = newfilename + '\n' + tmp
75 data = newfilename + '\n' + tmp
76 return data
76 return data
77
77
78
78
79 def getControlModuleStatus(self, data):
79 def getControlModuleStatus(self, data):
80
80
81 bits = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
81 bits = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
82 #self.__writeFile("report.txt", data)
82 #self.__writeFile("report.txt", data)
83
83
84 print "Report:\n"
84 print "Report:\n"
85 print "======:\n"
85 print "======:\n"
86 print bits
86 print bits
87
87
88 def getControlModulePhase(self, opt, u = "50", pw = "10"):
88 def getControlModulePhase(self, opt, u = "50", pw = "10"):
89
89
90 if opt == '0':
90 if opt == '0':
91 data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/')
91 data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/')
92 elif opt == '1':
92 elif opt == '1':
93 data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/')
93 data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/')
94 elif opt == '2':
94 elif opt == '2':
95 data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/')
95 data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/')
96 else:
96 else:
97 data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/')
97 data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/')
98 # self.__writeFile("report.txt", data)
98 # self.__writeFile("report.txt", data)
99
99
100 def getConnectionStatus(self):
100 def getConnectionStatus(self):
101
101
102 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
102 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
103 self.__writeFile("connection_status.txt", data)
103 self.__writeFile("connection_status.txt", data)
104
104
105 if __name__ == '__main__':
105 if __name__ == '__main__':
106
106
107 filename = "experimento1.abs"
107 filename = "experimento1.abs"
108
108
109 absObj = ABSClient()
109 absObj = ABSClient()
110 print absObj.sendFile(filename)
110 print absObj.sendFile(filename)
@@ -1,435 +1,437
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 self.ipSource = ipSource
12 self.ipSource = ipSource
13 self.ipDestino = ipDestino
13 self.ipDestino = ipDestino
14 self.portDestino = portDestino
14 self.portDestino = portDestino
15
15
16 self.ipDestino2 = ipDestino2
16 self.ipDestino2 = ipDestino2
17 self.portDestino2 = portDestino2
17 self.portDestino2 = portDestino2
18
18
19 self.tx_buffer = "default"
19 self.tx_buffer = "default"
20 self.rx_buffer = rx_buffer
20 self.rx_buffer = rx_buffer
21 self.enaModules = []
21 self.enaModules = []
22 self.bits = []
22 self.bits = []
23 self.phase = []
23 self.phase = []
24 self.txFile = []
24 self.txFile = []
25 self.rxFile = []
25 self.rxFile = []
26
26
27 self.createObjects()
27 self.createObjects()
28
28
29 print "Checking control modules, please wait ..."
29 print "Checking control modules, please wait ..."
30 self.enaModules = self.checkAntenna()
30 self.enaModules = self.checkAntenna()
31 print '\nThis modules are present : ' + str(self.enaModules) + '\n'
31 print '\nThis modules are present : ' + str(self.enaModules) + '\n'
32 # print "Starting automatic control module status."
32 # print "Starting automatic control module status."
33 self.__StartingAutomaticControlModules()
33 self.__StartingAutomaticControlModules()
34 # self.__AutomaticControlModules()
34 # self.__AutomaticControlModules()
35
35
36 def createObjects(self):
36 def createObjects(self):
37
37
38 asServer = True
38 asServer = True
39 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
39 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
40 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
40 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
41 self.wFiles = library3.FilesStuff()
41 self.wFiles = library3.FilesStuff()
42
42
43 def waitRequest(self):
43 def waitRequest(self):
44
44
45 #Using rx buffer
45 #Using rx buffer
46 # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
46 # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
47 ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData()
47 ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData()
48
48
49 if cmd == "SNDF":
49 if cmd == "SNDF":
50 datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer)
50 datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer)
51
51
52 if cmd == "GETF":
52 if cmd == "GETF":
53 datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
53 datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
54
54
55 if cmd == "CHGB":
55 if cmd == "CHGB":
56 datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer)
56 datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer)
57
57
58 if cmd == "ANST":
58 if cmd == "ANST":
59 datarpta = self.__getControlModuleStatus_old(cmd = cmd, rx_buffer = rx_buffer)
59 datarpta = self.__getControlModuleStatus_old(cmd = cmd, rx_buffer = rx_buffer)
60
60
61 if cmd == "BGPH":
61 if cmd == "BGPH":
62 datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer)
62 datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer)
63
63
64 if cmd == "LWPH":
64 if cmd == "LWPH":
65 datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
65 datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
66
66
67 if cmd == "NTST":
67 if cmd == "NTST":
68 datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer)
68 datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer)
69
69
70 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
70 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
71
71
72 def __checkModule(self, address):
72 def __checkModule(self, address):
73
73
74 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
74 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
75 status = os.system(cmd)
75 status = os.system(cmd)
76
76
77 if status == 256:
77 if status == 256:
78 return False
78 return False
79
79
80 return True
80 return True
81
81
82 def __writeReport(self, enaModules):
82 def __writeReport(self, enaModules):
83
83
84 status_array = ["Status of modules\n"]
84 status_array = ["Status of modules\n"]
85 status_array.append("----------------\n")
85 status_array.append("----------------\n")
86
86
87 for address in range(1,65):
87 for address in range(1,65):
88 if address in enaModules:
88 if address in enaModules:
89 status_array.append("192.168.1." + str(address) + " [1 1]\n")
89 status_array.append("192.168.1." + str(address) + " [1 1]\n")
90 else:
90 else:
91 status_array.append("192.168.1." + str(address) + " [0 0]\n")
91 status_array.append("192.168.1." + str(address) + " [0 0]\n")
92
92
93 filename = "module_status.txt"
93 filename = "module_status.txt"
94 self.__writeFile(filename,status_array)
94 self.__writeFile(filename,status_array)
95 # f = open("module_status.txt","w")
95 # f = open("module_status.txt","w")
96 # f.writelines(status_array)
96 # f.writelines(status_array)
97 # f.close()
97 # f.close()
98
98
99
99
100 def __CreateFile(self, filename):
100 def __CreateFile(self, filename):
101
101
102 fobj = open(filename,"w")
102 fobj = open(filename,"w")
103 fobj.close()
103 fobj.close()
104
104
105 def __writeNewFile(self, filename, data):
105 def __writeNewFile(self, filename, data):
106
106
107 fobj = open(filename,"w")
107 fobj = open(filename,"w")
108 fobj.writelines(data)
108 fobj.writelines(data)
109 fobj.close()
109 fobj.close()
110
110
111 def __writeFile(self, filename, data):
111 def __writeFile(self, filename, data):
112
112
113 fobj = open(filename,"a")
113 fobj = open(filename,"a")
114 fobj.writelines(data)
114 fobj.writelines(data)
115 fobj.close()
115 fobj.close()
116
116
117 def __checkAntenna(self):
117 def __checkAntenna(self):
118
118
119 """
119 """
120 Direccion de los modulos de las antenas:
120 Direccion de los modulos de las antenas:
121
121
122 Norte : 01-16
122 Norte : 01-16
123 Este : 17-32
123 Este : 17-32
124 Oeste: : 33-48
124 Oeste: : 33-48
125 Sur : 49-64
125 Sur : 49-64
126
126
127 """
127 """
128
128
129 enaModules2 = []
129 enaModules2 = []
130
130
131 for address in range(1,65):
131 for address in range(1,65):
132 if self.checkModule(address):
132 if self.checkModule(address):
133 enaModules2.append(address)
133 enaModules2.append(address)
134
134
135 self.__writeReport(enaModules2)
135 self.__writeReport(enaModules2)
136 return enaModules2
136 return enaModules2
137
137
138 def checkModule(self, arg, queue):
138 def checkModule(self, arg, queue):
139 cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null"
139 cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null"
140 status = os.system(cmd)
140 status = os.system(cmd)
141 if status == 256:
141 if status == 256:
142 result = "failed"
142 result = "failed"
143 else:
143 else:
144 result = "ok"
144 result = "ok"
145 queue.put({arg: result})
145 queue.put({arg: result})
146
146
147 def checkAntenna(self):
147 def checkAntenna(self):
148
148
149 iD = range(1,65)
149 iD = range(1,65)
150 q = Queue.Queue()
150 q = Queue.Queue()
151 threads = []
151 threads = []
152 tOut = []
152 tOut = []
153 modules = []
153 modules = []
154
154
155 for argument in iD:
155 for argument in iD:
156 t = Thread(target=self.checkModule, args=(argument, q))
156 t = Thread(target=self.checkModule, args=(argument, q))
157 t.start()
157 t.start()
158 threads.append(t)
158 threads.append(t)
159
159
160 for t in threads:
160 for t in threads:
161 t.join()
161 t.join()
162
162
163 for _ in range(len(iD)):
163 for _ in range(len(iD)):
164 tOut.append(q.get())
164 tOut.append(q.get())
165
165
166 for i in tOut:
166 for i in tOut:
167 if i.values()[0] == 'ok':
167 if i.values()[0] == 'ok':
168 modules.append(i.keys()[0])
168 modules.append(i.keys()[0])
169
169
170 return modules
170 return modules
171
171
172 def __ConnectionWithControlModules(self,data,cmd,id):
172 def __ConnectionWithControlModules(self,data,cmd,id):
173
173
174 self.commClientObj.open_socket()
174 self.commClientObj.open_socket()
175 ip = "192.168.1." + str(id)
175 ip = "192.168.1." + str(id)
176 self.commClientObj.sendData(cmd, data, ip)
176 self.commClientObj.sendData(cmd, data, ip)
177 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
177 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
178 self.commClientObj.close_socket()
178 self.commClientObj.close_socket()
179
179
180 return tmp
180 return tmp
181
181
182 def abs2ControlModuleFormatFile(self, filename):
182 def abs2ControlModuleFormatFile(self, filename):
183
183
184 #From matriz to control module format
184 #From matriz to control module format
185 self.wFiles.toCentralControlFormat(filename)
185 self.wFiles.toCentralControlFormat(filename)
186 FileName = "CentralControlFormat.txt"
186 FileName = "CentralControlFormat.txt"
187 F_Obj = open(FileName,"r")
187 F_Obj = open(FileName,"r")
188 FileList = F_Obj.readlines()
188 FileList = F_Obj.readlines()
189 F_Obj.close()
189 F_Obj.close()
190 FileStr = "".join(FileList)
190 FileStr = "".join(FileList)
191
191
192 return FileStr
192 return FileStr
193
193
194 def __All2Blocks(self,input):
194 def __All2Blocks(self,input):
195
195
196 rx_frame_lst = input.split('\n',2)
196 rx_frame_lst = input.split('\n',2)
197
197
198 header = rx_frame_lst[0] + "\n"
198 header = rx_frame_lst[0] + "\n"
199 control_modules_str = rx_frame_lst[2]
199 control_modules_str = rx_frame_lst[2]
200 control_modules_lst = control_modules_str.split("------\n")
200 control_modules_lst = control_modules_str.split("------\n")
201
201
202 return header, control_modules_lst
202 return header, control_modules_lst
203
203
204
204
205 def __sendFile2Modules(self,cmd, rx_buffer):
205 def __sendFile2Modules(self,cmd, rx_buffer):
206
206
207 # rx_buffer_lst = self.rx_buffer.split('\n',1)
207 # rx_buffer_lst = self.rx_buffer.split('\n',1)
208 rx_buffer_lst = rx_buffer.split('\n',1)
208 rx_buffer_lst = rx_buffer.split('\n',1)
209 #Getting the filename from the begining of data
209 #Getting the filename from the begining of data
210 filename = rx_buffer_lst[0]
210 filename = rx_buffer_lst[0]
211 tmp = rx_buffer_lst[1]
211 tmp = rx_buffer_lst[1]
212 self.__writeFile(filename,tmp)
212 self.__writeFile(filename,tmp)
213 data = self.abs2ControlModuleFormatFile(filename)
213 data = self.abs2ControlModuleFormatFile(filename)
214 #Needed for the loop
214 #Needed for the loop
215 header, control_modules_lst = self.__All2Blocks(data)
215 header, control_modules_lst = self.__All2Blocks(data)
216 correct = 0
216 correct = 0
217
217
218 for id in range(1,65):
218 for id in range(1,65):
219
219
220 if id not in self.enaModules:
220 if id not in self.enaModules:
221 continue
221 continue
222
222
223 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
223 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
224 correct = correct + 1
224 correct = correct + 1
225
225
226 if correct == len(self.enaModules):
226 if correct == len(self.enaModules):
227 rpta = "OK"
227 rpta = "OK"
228 else:
228 else:
229 rpta = "Failure"
229 rpta = "Failure"
230
230
231 return rpta
231 return rpta
232
232
233 def __getFileFromModules(self, cmd, rx_buffer):
233 def __getFileFromModules(self, cmd, rx_buffer):
234
234
235 for id in range(1,65):
235 for id in range(1,65):
236 if id not in self.enaModules:
236 if id not in self.enaModules:
237 continue
237 continue
238
238
239 file = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
239 file = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
240 del self.rxFile[id-1]
240 del self.rxFile[id-1]
241 self.rxFile.insert(id-1, file)
241 self.rxFile.insert(id-1, file)
242
243 return self.rxFile
242
244
243 def __changeBeam(self, cmd, rx_buffer):
245 def __changeBeam(self, cmd, rx_buffer):
244
246
245 correct = 0
247 correct = 0
246 # enaModules = self.checkAntenna()
248 # enaModules = self.checkAntenna()
247 # enaModules = [11,12,13,14]
249 # enaModules = [11,12,13,14]
248
250
249 for id in range(1,65):
251 for id in range(1,65):
250 if id not in self.enaModules:
252 if id not in self.enaModules:
251 continue
253 continue
252
254
253 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
255 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
254 correct = correct + 1
256 correct = correct + 1
255
257
256 if correct == len(self.enaModules):
258 if correct == len(self.enaModules):
257 rpta = "OK"
259 rpta = "OK"
258 else:
260 else:
259 rpta = "Failure"
261 rpta = "Failure"
260
262
261 return rpta
263 return rpta
262
264
263 def __getControlModuleStatus(self, cmd, rx_buffer):
265 def __getControlModuleStatus(self, cmd, rx_buffer):
264
266
265 # all_blocks = ""
267 # all_blocks = ""
266 # all_blocks = []
268 # all_blocks = []
267 # enaModules = self.checkAntenna()
269 # enaModules = self.checkAntenna()
268 # enaModules = [11,12,13,14]
270 # enaModules = [11,12,13,14]
269
271
270 for id in range(1,65):
272 for id in range(1,65):
271 if id not in self.enaModules:
273 if id not in self.enaModules:
272 continue
274 continue
273
275
274 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
276 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
275 del self.bits[id-1]
277 del self.bits[id-1]
276 self.bits.insert(id-1, bits)
278 self.bits.insert(id-1, bits)
277
279
278 # all_blocks.append(one_block)
280 # all_blocks.append(one_block)
279 #Using tx buffer
281 #Using tx buffer
280
282
281 return self.bits
283 return self.bits
282
284
283 def __getControlModuleBigPhase(self, cmd, rx_buffer):
285 def __getControlModuleBigPhase(self, cmd, rx_buffer):
284
286
285 # all_blocks = ""
287 # all_blocks = ""
286 all_blocks = []
288 all_blocks = []
287 # enaModules = self.checkAntenna()
289 # enaModules = self.checkAntenna()
288 # enaModules = [11,12,13,14]
290 # enaModules = [11,12,13,14]
289
291
290 for id in range(1,65):
292 for id in range(1,65):
291 if id not in self.enaModules:
293 if id not in self.enaModules:
292 continue
294 continue
293
295
294 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
296 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
295
297
296 # all_blocks = all_blocks + one_block
298 # all_blocks = all_blocks + one_block
297 all_blocks.append(one_block)
299 all_blocks.append(one_block)
298 #Using tx buffer
300 #Using tx buffer
299 return all_blocks
301 return all_blocks
300
302
301 def __getControlModuleLowPhase(self, cmd, rx_buffer):
303 def __getControlModuleLowPhase(self, cmd, rx_buffer):
302
304
303 # all_blocks = ""
305 # all_blocks = ""
304 # all_blocks = []
306 # all_blocks = []
305 # enaModules = self.checkAntenna()
307 # enaModules = self.checkAntenna()
306 # enaModules = [11,12,13,14]
308 # enaModules = [11,12,13,14]
307
309
308 for id in range(1,65):
310 for id in range(1,65):
309 if id not in self.enaModules:
311 if id not in self.enaModules:
310 continue
312 continue
311
313
312 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
314 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
313 del self.phase[id-1]
315 del self.phase[id-1]
314 self.phase.insert(id-1, phase)
316 self.phase.insert(id-1, phase)
315 # all_blocks = all_blocks + one_block
317 # all_blocks = all_blocks + one_block
316 # all_blocks.append(one_block)
318 # all_blocks.append(one_block)
317 #Using tx buffer
319 #Using tx buffer
318 # return all_blocks
320 # return all_blocks
319
321
320 def __getConnectionStatus(self, cmd, rx_buffer):
322 def __getConnectionStatus(self, cmd, rx_buffer):
321
323
322 ena = self.checkAntenna()
324 ena = self.checkAntenna()
323 print ena
325 print ena
324 self.enaModules = ena
326 self.enaModules = ena
325
327
326 blockLst = []
328 blockLst = []
327
329
328 for id in range(1,65):
330 for id in range(1,65):
329 if id not in self.enaModules:
331 if id not in self.enaModules:
330 continue
332 continue
331
333
332 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
334 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
333 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
335 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
334 #Using tx buffer
336 #Using tx buffer
335 all_blocks = "".join(blockLst)
337 all_blocks = "".join(blockLst)
336
338
337 return all_blocks
339 return all_blocks
338
340
339 def getConnectionStatus(self, cmd):
341 def getConnectionStatus(self, cmd):
340
342
341 ena = self.checkAntenna()
343 ena = self.checkAntenna()
342 self.enaModules = ena
344 self.enaModules = ena
343
345
344 blockLst = []
346 blockLst = []
345
347
346 for id in range(1,65):
348 for id in range(1,65):
347 if id not in self.enaModules:
349 if id not in self.enaModules:
348 continue
350 continue
349
351
350 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
352 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
351 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
353 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
352 #Using tx buffer
354 #Using tx buffer
353 self.tx_buffer = "".join(blockLst)
355 self.tx_buffer = "".join(blockLst)
354 print self.tx_buffer
356 print self.tx_buffer
355
357
356 return self.tx_buffer
358 return self.tx_buffer
357
359
358 def __getControlModuleStatus_old(self, cmd, rx_buffer):
360 def __getControlModuleStatus_old(self, cmd, rx_buffer):
359
361
360 all_blocks = ""
362 all_blocks = ""
361 # enaModules = self.checkAntenna()
363 # enaModules = self.checkAntenna()
362 # enaModules = [11,12,13,14]
364 # enaModules = [11,12,13,14]
363
365
364 for id in range(1,65):
366 for id in range(1,65):
365 if id not in self.enaModules:
367 if id not in self.enaModules:
366 continue
368 continue
367
369
368 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
370 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
369
371
370 all_blocks = all_blocks + one_block
372 all_blocks = all_blocks + one_block
371 #Using tx buffer
373 #Using tx buffer
372 print all_blocks
374 print all_blocks
373 self.tx_buffer = all_blocks
375 self.tx_buffer = all_blocks
374
376
375 return all_blocks
377 return all_blocks
376
378
377 def __StartingAutomaticControlModules(self):
379 def __StartingAutomaticControlModules(self):
378
380
379 #Starting file
381 #Starting file
380 self.__CreateFile("Monitoring.txt")
382 self.__CreateFile("Monitoring.txt")
381 # data = "MOD.\t BITS\t\t PHASE\n"
383 # data = "MOD.\t BITS\t\t PHASE\n"
382 # self.__writeFile("Monitoring.txt", data)
384 # self.__writeFile("Monitoring.txt", data)
383 #Starting lists
385 #Starting lists
384 self.txFile = list("------\n------\n------\n" for i in range(64))
386 self.txFile = list("------\n------\n------\n" for i in range(64))
385 self.rxFile = list("------\n------\n------\n" for i in range(64))
387 self.rxFile = list("------\n------\n------\n" for i in range(64))
386 self.bits = list("------\n------\n------\n" for i in range(64))
388 self.bits = list("------\n------\n------\n" for i in range(64))
387 self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64))
389 self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64))
388
390
389 def __AutomaticControlModules(self):
391 def __AutomaticControlModules(self):
390
392
391 # cmd = "GETF"
393 # cmd = "GETF"
392 # rx_buffer = "experimento1.ab1" + "\n"
394 # rx_buffer = "experimento1.ab1" + "\n"
393 # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
395 # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
394 #
396 #
395 # print self.rxFile
397 # print self.rxFile
396
398
397 cmd = "ANST"
399 cmd = "ANST"
398 rx_buffer = "1"
400 rx_buffer = "1"
399 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
401 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
400
402
401 cmd = "LWPH"
403 cmd = "LWPH"
402 rx_buffer = "0"
404 rx_buffer = "0"
403 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
405 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
404 print "Saving file..."
406 print "Saving file..."
405
407
406
408
407 print self.bits
409 print self.bits
408 print self.phase
410 print self.phase
409
411
410 self.__WritingMonitoringFile()
412 self.__WritingMonitoringFile()
411
413
412 threading.Timer(60, self.__AutomaticControlModules).start()
414 threading.Timer(60, self.__AutomaticControlModules).start()
413
415
414 def __WritingMonitoringFile(self):
416 def __WritingMonitoringFile(self):
415 filename = "Monitoring.txt"
417 filename = "Monitoring.txt"
416 data = '===============================' + '\n'
418 data = '===============================' + '\n'
417 self.__writeFile(filename, data)
419 self.__writeFile(filename, data)
418 data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime())
420 data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime())
419 self.__writeFile(filename, data)
421 self.__writeFile(filename, data)
420 data = "MOD.\t BITS\t\t PHASE\n"
422 data = "MOD.\t BITS\t\t PHASE\n"
421 self.__writeFile(filename, data)
423 self.__writeFile(filename, data)
422 data = '===============================' + '\n'
424 data = '===============================' + '\n'
423 self.__writeFile(filename, data)
425 self.__writeFile(filename, data)
424 for i in range(64):
426 for i in range(64):
425 tmp = self.bits[i].split('\n',3)
427 tmp = self.bits[i].split('\n',3)
426 self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2])
428 self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2])
427 tmp = self.phase[i].split('\n',3)
429 tmp = self.phase[i].split('\n',3)
428 self.__writeFile(filename, '\t\t' + tmp[2] + '\n')
430 self.__writeFile(filename, '\t\t' + tmp[2] + '\n')
429
431
430 if __name__ == '__main__':
432 if __name__ == '__main__':
431
433
432 absObj = ABSServer()
434 absObj = ABSServer()
433
435
434 while 1:
436 while 1:
435 absObj.waitRequest() No newline at end of file
437 absObj.waitRequest()
@@ -1,39 +1,28
1
1
2 import optparse, os, sys
2 import optparse, os, sys
3
3
4 pathFile = os.path.dirname(os.path.abspath(__file__))
4 pathFile = os.path.dirname(os.path.abspath(__file__))
5 sys.path.append(os.path.split(pathFile)[0])
5 sys.path.append(os.path.split(pathFile)[0])
6
6
7 from bin.client3 import ABSClient
7 from bin.client3 import ABSClient
8
8
9 class readFile(object):
9 class readFile(object):
10
10
11 def __init__(self):
11 def __init__(self):
12 self.output = ""
12 self.output = ""
13
13
14 def execute(self, filename):
14 def execute(self):
15 if os.path.exists(filename):
15 absObj = ABSClient(ipDestino="10.10.20.27")
16 #absObj = ABSClient(ipDestino="10.10.10.97")
16 self.output = absObj.readFile()
17 absObj = ABSClient(ipDestino="10.10.20.27")
18 self.output = absObj.readFile(filename)
19 #pass
20 else:
21 print "No file"
22
17
23 def getOutput(self):
18 def getOutput(self):
24 return self.output
19 return self.output
25
20
26 usage = "::::::::::::\n"
21 usage = "::::::::::::\n"
27
22
28 if __name__ == '__main__':
23 if __name__ == '__main__':
29
24
30 parser = optparse.OptionParser(usage=usage)
25 app = readFile()
31
26 app.execute()
32 parser.add_option("-f", "--filename", dest="filename", type="string", default="", help="Filename")
33
27
34 (options, args) = parser.parse_args()
28 print app.output
35
36 filename = options.filename
37
38 app = readFile()
39 app.execute(filename)
General Comments 0
You need to be logged in to leave comments. Login now