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