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