##// END OF EJS Templates
automatic check of the antenna
imanay -
r149:150
parent child
Show More
@@ -1,314 +1,325
1 import os
1 import os
2 import library3
2 import library3
3 import time
3 import time
4 import threading
4
5
5 class ABSServer:
6 class ABSServer:
6
7
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
8 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
8
9
9 self.ipSource = ipSource
10 self.ipSource = ipSource
10 self.ipDestino = ipDestino
11 self.ipDestino = ipDestino
11 self.portDestino = portDestino
12 self.portDestino = portDestino
12
13
13 self.ipDestino2 = ipDestino2
14 self.ipDestino2 = ipDestino2
14 self.portDestino2 = portDestino2
15 self.portDestino2 = portDestino2
15
16
16 self.tx_buffer = "default"
17 self.tx_buffer = "default"
17 # self.rx_buffer = "default"
18 # self.rx_buffer = "default"
18 self.rx_buffer = rx_buffer
19 self.rx_buffer = rx_buffer
19 self.enaModules = []
20 self.enaModules = []
20
21
21 self.createObjects()
22 self.createObjects()
22
23
24 print "Checking control modules, please wait ..."
23 self.enaModules = self.checkAntenna()
25 self.enaModules = self.checkAntenna()
26 print "Starting automatic control module status."
27 self.__AutomaticControlModules()
24
28
25 def createObjects(self):
29 def createObjects(self):
26
30
27 asServer = True
31 asServer = True
28 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
32 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
29 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
33 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
30 self.wFiles = library3.FilesStuff()
34 self.wFiles = library3.FilesStuff()
31
35
32 def waitRequest(self):
36 def waitRequest(self):
33
37
34 #Using rx buffer
38 #Using rx buffer
35 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
39 # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
40 ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData()
36
41
37 if cmd == "SNDF":
42 if cmd == "SNDF":
38 datarpta = self.__sendFile2Modules(cmd = cmd)
43 datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer)
39
44
40 if cmd == "CHGB":
45 if cmd == "CHGB":
41 datarpta = self.__changeBeam(cmd = cmd)
46 datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer)
42
47
43 if cmd == "ANST":
48 if cmd == "ANST":
44 self.__getControlModuleStatus(cmd = cmd)
49 datarpta = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
45 #Using tx buffer
46 datarpta = self.tx_buffer
47
50
48 if cmd == "BGPH":
51 if cmd == "BGPH":
49 self.__getControlModuleBigPhase(cmd = cmd)
52 datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer)
50 #Using tx buffer
51 datarpta = self.tx_buffer
52
53
53 if cmd == "LWPH":
54 if cmd == "LWPH":
54 self.__getControlModuleLowPhase(cmd = cmd)
55 datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
55 #Using tx buffer
56 datarpta = self.tx_buffer
57
56
58 if cmd == "NTST":
57 if cmd == "NTST":
59 #Using tx buffer
58 datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer)
60 datarpta = self.__getConnectionStatus(cmd = cmd)
61
59
62 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
60 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
63
61
64 def checkModule(self, address):
62 def checkModule(self, address):
65
63
66 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
64 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
67 status = os.system(cmd)
65 status = os.system(cmd)
68
66
69 if status == 256:
67 if status == 256:
70 return False
68 return False
71
69
72 return True
70 return True
73
71
74 def __writeReport(self, enaModules):
72 def __writeReport(self, enaModules):
75
73
76 status_array = ["Status of modules\n"]
74 status_array = ["Status of modules\n"]
77 status_array.append("----------------\n")
75 status_array.append("----------------\n")
78
76
79 for address in range(1,65):
77 for address in range(1,65):
80 if address in enaModules:
78 if address in enaModules:
81 status_array.append("192.168.1." + str(address) + " [1 1]\n")
79 status_array.append("192.168.1." + str(address) + " [1 1]\n")
82 else:
80 else:
83 status_array.append("192.168.1." + str(address) + " [0 0]\n")
81 status_array.append("192.168.1." + str(address) + " [0 0]\n")
84
82
85 filename = "module_status.txt"
83 filename = "module_status.txt"
86 self.__writeFile(filename,status_array)
84 self.__writeFile(filename,status_array)
87 # f = open("module_status.txt","w")
85 # f = open("module_status.txt","w")
88 # f.writelines(status_array)
86 # f.writelines(status_array)
89 # f.close()
87 # f.close()
90
88
91
89
92 def __writeFile(self, filename, data):
90 def __writeFile(self, filename, data):
93
91
94 fobj = open(filename,"w")
92 fobj = open(filename,"w")
95 fobj.writelines(data)
93 fobj.writelines(data)
96 fobj.close()
94 fobj.close()
97
95
98 def checkAntenna(self):
96 def checkAntenna(self):
99
97
100 """
98 """
101 Direccion de los modulos de las antenas:
99 Direccion de los modulos de las antenas:
102
100
103 Norte : 01-16
101 Norte : 01-16
104 Este : 17-32
102 Este : 17-32
105 Oeste: : 33-48
103 Oeste: : 33-48
106 Sur : 49-64
104 Sur : 49-64
107
105
108 """
106 """
109
107
110 enaModules2 = []
108 enaModules2 = []
111
109
112 for address in range(1,65):
110 for address in range(1,65):
113 if self.checkModule(address):
111 if self.checkModule(address):
114 enaModules2.append(address)
112 enaModules2.append(address)
115
113
116 self.__writeReport(enaModules2)
114 self.__writeReport(enaModules2)
117 return enaModules2
115 return enaModules2
118
116
119 def __ConnectionWithControlModules(self,data,cmd,id):
117 def __ConnectionWithControlModules(self,data,cmd,id):
120
118
121 self.commClientObj.open_socket()
119 self.commClientObj.open_socket()
122 ip = "192.168.1." + str(id)
120 ip = "192.168.1." + str(id)
123 self.commClientObj.sendData(cmd, data, ip)
121 self.commClientObj.sendData(cmd, data, ip)
124 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
122 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
125 self.commClientObj.close_socket()
123 self.commClientObj.close_socket()
126
124
127 return tmp
125 return tmp
128
126
129 def abs2ControlModuleFormatFile(self, filename):
127 def abs2ControlModuleFormatFile(self, filename):
130
128
131 #From matriz to control module format
129 #From matriz to control module format
132 self.wFiles.toCentralControlFormat(filename)
130 self.wFiles.toCentralControlFormat(filename)
133 FileName = "CentralControlFormat.txt"
131 FileName = "CentralControlFormat.txt"
134 F_Obj = open(FileName,"r")
132 F_Obj = open(FileName,"r")
135 FileList = F_Obj.readlines()
133 FileList = F_Obj.readlines()
136 F_Obj.close()
134 F_Obj.close()
137 FileStr = "".join(FileList)
135 FileStr = "".join(FileList)
138
136
139 return FileStr
137 return FileStr
140
138
141 def __All2Blocks(self,input):
139 def __All2Blocks(self,input):
142
140
143 rx_frame_lst = input.split('\n',2)
141 rx_frame_lst = input.split('\n',2)
144
142
145 header = rx_frame_lst[0] + "\n"
143 header = rx_frame_lst[0] + "\n"
146 control_modules_str = rx_frame_lst[2]
144 control_modules_str = rx_frame_lst[2]
147 control_modules_lst = control_modules_str.split("------\n")
145 control_modules_lst = control_modules_str.split("------\n")
148
146
149 return header, control_modules_lst
147 return header, control_modules_lst
150
148
151
149
152 def __sendFile2Modules(self,cmd):
150 def __sendFile2Modules(self,cmd, rx_buffer):
153
151
154 rx_buffer_lst = self.rx_buffer.split('\n',1)
152 # rx_buffer_lst = self.rx_buffer.split('\n',1)
153 rx_buffer_lst = rx_buffer.split('\n',1)
155 #Getting the filename from the begining of data
154 #Getting the filename from the begining of data
156 filename = rx_buffer_lst[0]
155 filename = rx_buffer_lst[0]
157 tmp = rx_buffer_lst[1]
156 tmp = rx_buffer_lst[1]
158 self.__writeFile(filename,tmp)
157 self.__writeFile(filename,tmp)
159 data = self.abs2ControlModuleFormatFile(filename)
158 data = self.abs2ControlModuleFormatFile(filename)
160 #Needed for the loop
159 #Needed for the loop
161 header, control_modules_lst = self.__All2Blocks(data)
160 header, control_modules_lst = self.__All2Blocks(data)
162 correct = 0
161 correct = 0
163
162
164 for id in range(1,65):
163 for id in range(1,65):
165
164
166 if id not in self.enaModules:
165 if id not in self.enaModules:
167 continue
166 continue
168
167
169 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
168 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
170 correct = correct + 1
169 correct = correct + 1
171
170
172 if correct == len(self.enaModules):
171 if correct == len(self.enaModules):
173 rpta = "OK"
172 rpta = "OK"
174 else:
173 else:
175 rpta = "Failure"
174 rpta = "Failure"
176
175
177 return rpta
176 return rpta
178
177
179 def __changeBeam(self, cmd):
178 def __changeBeam(self, cmd, rx_buffer):
180
179
181 correct = 0
180 correct = 0
182 # enaModules = self.checkAntenna()
181 # enaModules = self.checkAntenna()
183 # enaModules = [11,12,13,14]
182 # enaModules = [11,12,13,14]
184
183
185 for id in range(1,65):
184 for id in range(1,65):
186 if id not in self.enaModules:
185 if id not in self.enaModules:
187 continue
186 continue
188
187
189 if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK":
188 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
190 correct = correct + 1
189 correct = correct + 1
191
190
192 if correct == len(self.enaModules):
191 if correct == len(self.enaModules):
193 rpta = "OK"
192 rpta = "OK"
194 else:
193 else:
195 rpta = "Failure"
194 rpta = "Failure"
196
195
197 return rpta
196 return rpta
198
197
199 def __getControlModuleStatus(self, cmd):
198 def __getControlModuleStatus(self, cmd, rx_buffer):
200
199
201 all_blocks = ""
200 all_blocks = ""
202 # enaModules = self.checkAntenna()
201 # enaModules = self.checkAntenna()
203 # enaModules = [11,12,13,14]
202 # enaModules = [11,12,13,14]
204
203
205 for id in range(1,65):
204 for id in range(1,65):
206 if id not in self.enaModules:
205 if id not in self.enaModules:
207 continue
206 continue
208
207
209 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
208 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
210
209
211 all_blocks = all_blocks + one_block
210 all_blocks = all_blocks + one_block
212 #Using tx buffer
211 #Using tx buffer
213 print all_blocks
212
214 self.tx_buffer = all_blocks
213 return all_blocks
215
214
216 def __getControlModuleBigPhase(self, cmd):
215 def __getControlModuleBigPhase(self, cmd, rx_buffer):
217
216
218 all_blocks = ""
217 all_blocks = ""
219 # enaModules = self.checkAntenna()
218 # enaModules = self.checkAntenna()
220 # enaModules = [11,12,13,14]
219 # enaModules = [11,12,13,14]
221
220
222 for id in range(1,65):
221 for id in range(1,65):
223 if id not in self.enaModules:
222 if id not in self.enaModules:
224 continue
223 continue
225
224
226 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
225 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
227
226
228 all_blocks = all_blocks + one_block
227 all_blocks = all_blocks + one_block
229 #Using tx buffer
228 #Using tx buffer
230 print all_blocks
229 return all_blocks
231 self.tx_buffer = all_blocks
230
232
231 def __getControlModuleLowPhase(self, cmd, rx_buffer):
233 def __getControlModuleLowPhase(self, cmd):
234
232
235 all_blocks = ""
233 all_blocks = ""
236 # enaModules = self.checkAntenna()
234 # enaModules = self.checkAntenna()
237 # enaModules = [11,12,13,14]
235 # enaModules = [11,12,13,14]
238
236
239 for id in range(1,65):
237 for id in range(1,65):
240 if id not in self.enaModules:
238 if id not in self.enaModules:
241 continue
239 continue
242
240
243 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
241 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
244
242
245 all_blocks = all_blocks + one_block
243 all_blocks = all_blocks + one_block
246 #Using tx buffer
244 #Using tx buffer
247 print all_blocks
245 return all_blocks
248 self.tx_buffer = all_blocks
246
249
247 def __getConnectionStatus(self, cmd, rx_buffer):
250 def __getConnectionStatus(self, cmd):
251
248
252 ena = self.checkAntenna()
249 ena = self.checkAntenna()
253 print ena
250 print ena
254 self.enaModules = ena
251 self.enaModules = ena
255
252
256 blockLst = []
253 blockLst = []
257
254
258 for id in range(1,65):
255 for id in range(1,65):
259 if id not in self.enaModules:
256 if id not in self.enaModules:
260 continue
257 continue
261
258
259 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
260 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
261 #Using tx buffer
262 all_blocks = "".join(blockLst)
263
264 return all_blocks
265
266 def getConnectionStatus(self, cmd):
267
268 ena = self.checkAntenna()
269 self.enaModules = ena
270
271 blockLst = []
272
273 for id in range(1,65):
274 if id not in self.enaModules:
275 continue
276
262 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
277 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
263 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
278 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
264 #Using tx buffer
279 #Using tx buffer
265 self.tx_buffer = "".join(blockLst)
280 self.tx_buffer = "".join(blockLst)
266 print self.tx_buffer
281 print self.tx_buffer
267
282
268 return self.tx_buffer
283 return self.tx_buffer
269
270 def getConnectionStatus(self, cmd):
271
272 ena = self.checkAntenna()
273 self.enaModules = ena
274
275 blockLst = []
276
277 for id in range(1,65):
278 if id not in self.enaModules:
279 continue
280
281 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
282 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
283 #Using tx buffer
284 self.tx_buffer = "".join(blockLst)
285 print self.tx_buffer
286
287 return self.tx_buffer
288
284
289 def getControlModuleStatus(self, cmd):
285 def getControlModuleStatus(self, cmd):
290
286
291 all_blocks = ""
287 all_blocks = ""
292 # enaModules = self.checkAntenna()
288 # enaModules = self.checkAntenna()
293 # enaModules = [11,12,13,14]
289 # enaModules = [11,12,13,14]
294
290
295 for id in range(1,65):
291 for id in range(1,65):
296 if id not in self.enaModules:
292 if id not in self.enaModules:
297 continue
293 continue
298
294
299 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
295 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
300
296
301 all_blocks = all_blocks + one_block
297 all_blocks = all_blocks + one_block
302 #Using tx buffer
298 #Using tx buffer
303 print all_blocks
299 print all_blocks
304 self.tx_buffer = all_blocks
300 self.tx_buffer = all_blocks
305
301
306 return all_blocks
302 return all_blocks
303
304 def __AutomaticControlModules(self):
305
306 cmd = "ANST"
307 rx_buffer = "1"
308 tmp1 = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
309
310 cmd = "LWPH"
311 rx_buffer = "0"
312 tmp2 = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
313 print "getting this: "
314 print tmp1
315 print tmp2
316
317 threading.Timer(30, self.__AutomaticControlModules).start()
307
318
308
319
309 if __name__ == '__main__':
320 if __name__ == '__main__':
310
321
311 absObj = ABSServer()
322 absObj = ABSServer()
312
323
313 while 1:
324 while 1:
314 absObj.waitRequest() No newline at end of file
325 absObj.waitRequest()
@@ -1,8 +1,12
1 import file
1 import file
2 from client3 import *
2 from client3 import *
3 import sys
3
4
4 ns = "4"
5
6 absObj = ABSClient(ipDestino="10.10.10.97")
5 absObj = ABSClient(ipDestino="10.10.10.97")
7 #absObj = ABSClient()
6 #absObj = ABSClient()
8 absObj.getControlModuleStatus(ns) No newline at end of file
7 if len(sys.argv) == 2:
8 # ns = "4"
9 ns = sys.argv[1]
10 absObj.getControlModuleStatus(ns)
11 else:
12 print "Only one argument needed." No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now