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