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