@@ -1,588 +1,588 | |||
|
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 | from threading import Thread No newline at end of file |
|
5 | 5 | import threading No newline at end of file |
|
6 | 6 | import Queue No newline at end of file |
|
7 | 7 | No newline at end of file |
|
8 | 8 | class ABSServer: No newline at end of file |
|
9 | 9 | No newline at end of file |
|
10 | 10 | 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 |
|
11 | 11 | No newline at end of file |
|
12 | 12 | No newline at end of file |
|
13 | 13 | self.ipSource = ipSource No newline at end of file |
|
14 | 14 | self.ipDestino = ipDestino No newline at end of file |
|
15 | 15 | self.portDestino = portDestino No newline at end of file |
|
16 | 16 | No newline at end of file |
|
17 | 17 | self.ipDestino2 = ipDestino2 No newline at end of file |
|
18 | 18 | self.portDestino2 = portDestino2 No newline at end of file |
|
19 | 19 | No newline at end of file |
|
20 | 20 | self.tx_buffer = "default" No newline at end of file |
|
21 | 21 | self.rx_buffer = rx_buffer No newline at end of file |
|
22 | 22 | self.enaModules = [] No newline at end of file |
|
23 | 23 | self.bits = [] No newline at end of file |
|
24 | 24 | self.phase = [] No newline at end of file |
|
25 | 25 | self.txFile = [] No newline at end of file |
|
26 | 26 | self.rxFile = [] No newline at end of file |
|
27 | 27 | No newline at end of file |
|
28 | 28 | self.createObjects() No newline at end of file |
|
29 | 29 | No newline at end of file |
|
30 | 30 | print "Checking control modules, please wait ..." No newline at end of file |
|
31 | 31 | self.enaModules = self.checkAntenna() No newline at end of file |
|
32 | 32 | print '\nThis modules are present : ' + str(self.enaModules) + '\n' No newline at end of file |
|
33 | 33 | # print "Starting automatic control module status." No newline at end of file |
|
34 | 34 | self.__StartingAutomaticControlModules() No newline at end of file |
|
35 | 35 | # self.__AutomaticControlModules() No newline at end of file |
|
36 | 36 | No newline at end of file |
|
37 | 37 | def createObjects(self): No newline at end of file |
|
38 | 38 | No newline at end of file |
|
39 | 39 | asServer = True No newline at end of file |
|
40 | 40 | self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) No newline at end of file |
|
41 | 41 | self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) No newline at end of file |
|
42 | 42 | self.wFiles = library3.FilesStuff() No newline at end of file |
|
43 | 43 | No newline at end of file |
|
44 | 44 | def waitRequest(self): No newline at end of file |
|
45 | 45 | No newline at end of file |
|
46 | 46 | #Using rx buffer No newline at end of file |
|
47 | 47 | # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() No newline at end of file |
|
48 | 48 | ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData() No newline at end of file |
|
49 | 49 | No newline at end of file |
|
50 | 50 | if cmd == "SNDF": No newline at end of file |
|
51 | 51 | datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
52 | 52 | No newline at end of file |
|
53 | 53 | if cmd == "GETF": No newline at end of file |
|
54 | 54 | datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
55 | 55 | No newline at end of file |
|
56 | 56 | if cmd == "CHGB": No newline at end of file |
|
57 | 57 | datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
58 | 58 | No newline at end of file |
|
59 | 59 | if cmd == "ANST": No newline at end of file |
|
60 | 60 | datarpta = self.__getControlModuleStatus_old(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
61 | 61 | No newline at end of file |
|
62 | 62 | if cmd == "BGPH": No newline at end of file |
|
63 | 63 | datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
64 | 64 | No newline at end of file |
|
65 | 65 | if cmd == "LWPH": No newline at end of file |
|
66 | 66 | datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
67 | 67 | No newline at end of file |
|
68 | 68 | if cmd == "NTST": No newline at end of file |
|
69 | 69 | datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
70 | 70 | No newline at end of file |
|
71 | 71 | if cmd == "MNTR": No newline at end of file |
|
72 | 72 | datarpta = self.__getControlModuleStatus_new(cmd = cmd, type = rx_buffer) No newline at end of file |
|
73 | 73 | No newline at end of file |
|
74 | 74 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) No newline at end of file |
|
75 | 75 | No newline at end of file |
|
76 | 76 | def __checkModule(self, address): No newline at end of file |
|
77 | 77 | No newline at end of file |
|
78 | 78 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" No newline at end of file |
|
79 | 79 | status = os.system(cmd) No newline at end of file |
|
80 | 80 | No newline at end of file |
|
81 | 81 | if status == 256: No newline at end of file |
|
82 | 82 | return False No newline at end of file |
|
83 | 83 | No newline at end of file |
|
84 | 84 | return True No newline at end of file |
|
85 | 85 | No newline at end of file |
|
86 | 86 | def __writeReport(self, enaModules): No newline at end of file |
|
87 | 87 | No newline at end of file |
|
88 | 88 | status_array = ["Status of modules\n"] No newline at end of file |
|
89 | 89 | status_array.append("----------------\n") No newline at end of file |
|
90 | 90 | No newline at end of file |
|
91 | 91 | for address in range(1,65): No newline at end of file |
|
92 | 92 | if address in enaModules: No newline at end of file |
|
93 | 93 | status_array.append("192.168.1." + str(address) + " [1 1]\n") No newline at end of file |
|
94 | 94 | else: No newline at end of file |
|
95 | 95 | status_array.append("192.168.1." + str(address) + " [0 0]\n") No newline at end of file |
|
96 | 96 | No newline at end of file |
|
97 | 97 | filename = "module_status.txt" No newline at end of file |
|
98 | 98 | self.__writeFile(filename,status_array) No newline at end of file |
|
99 | 99 | # f = open("module_status.txt","w") No newline at end of file |
|
100 | 100 | # f.writelines(status_array) No newline at end of file |
|
101 | 101 | # f.close() No newline at end of file |
|
102 | 102 | No newline at end of file |
|
103 | 103 | No newline at end of file |
|
104 | 104 | def __CreateFile(self, filename): No newline at end of file |
|
105 | 105 | No newline at end of file |
|
106 | 106 | fobj = open(filename,"w") No newline at end of file |
|
107 | 107 | fobj.close() No newline at end of file |
|
108 | 108 | No newline at end of file |
|
109 | 109 | def __writeNewFile(self, filename, data): No newline at end of file |
|
110 | 110 | No newline at end of file |
|
111 | 111 | fobj = open(filename,"w") No newline at end of file |
|
112 | 112 | fobj.writelines(data) No newline at end of file |
|
113 | 113 | fobj.close() No newline at end of file |
|
114 | 114 | No newline at end of file |
|
115 | 115 | def __writeFile(self, filename, data): No newline at end of file |
|
116 | 116 | No newline at end of file |
|
117 | 117 | fobj = open(filename,"a") No newline at end of file |
|
118 | 118 | fobj.writelines(data) No newline at end of file |
|
119 | 119 | fobj.close() No newline at end of file |
|
120 | 120 | No newline at end of file |
|
121 | 121 | def __checkAntenna(self): No newline at end of file |
|
122 | 122 | No newline at end of file |
|
123 | 123 | """ No newline at end of file |
|
124 | 124 | Direccion de los modulos de las antenas: No newline at end of file |
|
125 | 125 | No newline at end of file |
|
126 | 126 | Norte : 01-16 No newline at end of file |
|
127 | 127 | Este : 17-32 No newline at end of file |
|
128 | 128 | Oeste: : 33-48 No newline at end of file |
|
129 | 129 | Sur : 49-64 No newline at end of file |
|
130 | 130 | No newline at end of file |
|
131 | 131 | """ No newline at end of file |
|
132 | 132 | No newline at end of file |
|
133 | 133 | enaModules2 = [] No newline at end of file |
|
134 | 134 | No newline at end of file |
|
135 | 135 | for address in range(1,65): No newline at end of file |
|
136 | 136 | if self.checkModule(address): No newline at end of file |
|
137 | 137 | enaModules2.append(address) No newline at end of file |
|
138 | 138 | No newline at end of file |
|
139 | 139 | self.__writeReport(enaModules2) No newline at end of file |
|
140 | 140 | return enaModules2 No newline at end of file |
|
141 | 141 | No newline at end of file |
|
142 | 142 | def checkModule(self, arg, queue): No newline at end of file |
|
143 | 143 | cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null" No newline at end of file |
|
144 | 144 | status = os.system(cmd) No newline at end of file |
|
145 | 145 | if status == 256: No newline at end of file |
|
146 | 146 | result = "failed" No newline at end of file |
|
147 | 147 | else: No newline at end of file |
|
148 | 148 | result = "ok" No newline at end of file |
|
149 | 149 | queue.put({arg: result}) No newline at end of file |
|
150 | 150 | No newline at end of file |
|
151 | 151 | def checkAntenna(self): No newline at end of file |
|
152 | 152 | No newline at end of file |
|
153 | 153 | iD = range(1,65) No newline at end of file |
|
154 | 154 | q = Queue.Queue() No newline at end of file |
|
155 | 155 | threads = [] No newline at end of file |
|
156 | 156 | tOut = [] No newline at end of file |
|
157 | 157 | modules = [] No newline at end of file |
|
158 | 158 | No newline at end of file |
|
159 | 159 | for argument in iD: No newline at end of file |
|
160 | 160 | t = Thread(target=self.checkModule, args=(argument, q)) No newline at end of file |
|
161 | 161 | t.start() No newline at end of file |
|
162 | 162 | threads.append(t) No newline at end of file |
|
163 | 163 | No newline at end of file |
|
164 | 164 | for t in threads: No newline at end of file |
|
165 | 165 | t.join() No newline at end of file |
|
166 | 166 | No newline at end of file |
|
167 | 167 | for _ in range(len(iD)): No newline at end of file |
|
168 | 168 | tOut.append(q.get()) No newline at end of file |
|
169 | 169 | No newline at end of file |
|
170 | 170 | for i in tOut: No newline at end of file |
|
171 | 171 | if i.values()[0] == 'ok': No newline at end of file |
|
172 | 172 | modules.append(i.keys()[0]) No newline at end of file |
|
173 | 173 | No newline at end of file |
|
174 | 174 | return modules No newline at end of file |
|
175 | 175 | No newline at end of file |
|
176 | 176 | def __ConnectionWithControlModules(self,data,cmd,id): No newline at end of file |
|
177 | 177 | No newline at end of file |
|
178 | 178 | self.commClientObj.open_socket() No newline at end of file |
|
179 | 179 | ip = "192.168.1." + str(id) No newline at end of file |
|
180 | 180 | self.commClientObj.sendData(cmd, data, ip) No newline at end of file |
|
181 | 181 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() No newline at end of file |
|
182 | 182 | self.commClientObj.close_socket() No newline at end of file |
|
183 | 183 | No newline at end of file |
|
184 | 184 | return tmp No newline at end of file |
|
185 | 185 | No newline at end of file |
|
186 | 186 | def abs2ControlModuleFormatFile(self, filename): No newline at end of file |
|
187 | 187 | No newline at end of file |
|
188 | 188 | #From matriz to control module format No newline at end of file |
|
189 | 189 | self.wFiles.toCentralControlFormat(filename) No newline at end of file |
|
190 | 190 | FileName = "CentralControlFormat.txt" No newline at end of file |
|
191 | 191 | F_Obj = open(FileName,"r") No newline at end of file |
|
192 | 192 | FileList = F_Obj.readlines() No newline at end of file |
|
193 | 193 | F_Obj.close() No newline at end of file |
|
194 | 194 | FileStr = "".join(FileList) No newline at end of file |
|
195 | 195 | No newline at end of file |
|
196 | 196 | return FileStr No newline at end of file |
|
197 | 197 | No newline at end of file |
|
198 | 198 | def __All2Blocks(self,input): No newline at end of file |
|
199 | 199 | No newline at end of file |
|
200 | 200 | rx_frame_lst = input.split('\n',2) No newline at end of file |
|
201 | 201 | No newline at end of file |
|
202 | 202 | header = rx_frame_lst[0] + "\n" No newline at end of file |
|
203 | 203 | control_modules_str = rx_frame_lst[2] No newline at end of file |
|
204 | 204 | control_modules_lst = control_modules_str.split("------\n") No newline at end of file |
|
205 | 205 | No newline at end of file |
|
206 | 206 | return header, control_modules_lst No newline at end of file |
|
207 | 207 | No newline at end of file |
|
208 | 208 | No newline at end of file |
|
209 | 209 | def __sendFile2Modules(self,cmd, rx_buffer): No newline at end of file |
|
210 | 210 | No newline at end of file |
|
211 | 211 | # rx_buffer_lst = self.rx_buffer.split('\n',1) No newline at end of file |
|
212 | 212 | rx_buffer_lst = rx_buffer.split('\n',1) No newline at end of file |
|
213 | 213 | #Getting the filename from the begining of data No newline at end of file |
|
214 | 214 | filename = rx_buffer_lst[0] No newline at end of file |
|
215 | 215 | tmp = rx_buffer_lst[1] No newline at end of file |
|
216 | 216 | self.__writeNewFile(filename,tmp) No newline at end of file |
|
217 | 217 | data = self.abs2ControlModuleFormatFile(filename) No newline at end of file |
|
218 | 218 | No newline at end of file |
|
219 | 219 | print data No newline at end of file |
|
220 | 220 | #Needed for the loop No newline at end of file |
|
221 | 221 | header, control_modules_lst = self.__All2Blocks(data) No newline at end of file |
|
222 | 222 | correct = 0 No newline at end of file |
|
223 | 223 | No newline at end of file |
|
224 | 224 | for id in range(1,65): No newline at end of file |
|
225 | 225 | No newline at end of file |
|
226 | 226 | if id not in self.enaModules: No newline at end of file |
|
227 | 227 | continue No newline at end of file |
|
228 | 228 | No newline at end of file |
|
229 | 229 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": No newline at end of file |
|
230 | 230 | correct = correct + 1 No newline at end of file |
|
231 | 231 | No newline at end of file |
|
232 | 232 | if correct == len(self.enaModules): No newline at end of file |
|
233 | 233 | rpta = "OK" No newline at end of file |
|
234 | 234 | else: No newline at end of file |
|
235 | 235 | rpta = "Failure" No newline at end of file |
|
236 | 236 | No newline at end of file |
|
237 | 237 | return rpta No newline at end of file |
|
238 | 238 | No newline at end of file |
|
239 | 239 | def __getFileFromModules(self, cmd, rx_buffer): No newline at end of file |
|
240 | 240 | No newline at end of file |
|
241 | 241 | for id in range(1,65): No newline at end of file |
|
242 | 242 | if id not in self.enaModules: No newline at end of file |
|
243 | 243 | continue No newline at end of file |
|
244 | 244 | No newline at end of file |
|
245 | 245 | file = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
246 | 246 | del self.rxFile[id-1] No newline at end of file |
|
247 | 247 | self.rxFile.insert(id-1, file) No newline at end of file |
|
248 | 248 | No newline at end of file |
|
249 | 249 | return self.rxFile No newline at end of file |
|
250 | 250 | No newline at end of file |
|
251 | 251 | def __changeBeam(self, cmd, rx_buffer): No newline at end of file |
|
252 | 252 | No newline at end of file |
|
253 | 253 | correct = 0 No newline at end of file |
|
254 | 254 | # enaModules = self.checkAntenna() No newline at end of file |
|
255 | 255 | # enaModules = [11,12,13,14] No newline at end of file |
|
256 | 256 | No newline at end of file |
|
257 | 257 | for id in range(1,65): No newline at end of file |
|
258 | 258 | if id not in self.enaModules: No newline at end of file |
|
259 | 259 | continue No newline at end of file |
|
260 | 260 | No newline at end of file |
|
261 | 261 | if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK": No newline at end of file |
|
262 | 262 | correct = correct + 1 No newline at end of file |
|
263 | 263 | No newline at end of file |
|
264 | 264 | if correct == len(self.enaModules): No newline at end of file |
|
265 | 265 | rpta = "OK" No newline at end of file |
|
266 | 266 | else: No newline at end of file |
|
267 | 267 | rpta = "Failure" No newline at end of file |
|
268 | 268 | No newline at end of file |
|
269 | 269 | return rpta No newline at end of file |
|
270 | 270 | No newline at end of file |
|
271 | 271 | def __getControlModuleStatus(self, cmd, rx_buffer): No newline at end of file |
|
272 | 272 | No newline at end of file |
|
273 | 273 | # all_blocks = "" No newline at end of file |
|
274 | 274 | # all_blocks = [] No newline at end of file |
|
275 | 275 | # enaModules = self.checkAntenna() No newline at end of file |
|
276 | 276 | # enaModules = [11,12,13,14] No newline at end of file |
|
277 | 277 | No newline at end of file |
|
278 | 278 | for id in range(1,65): No newline at end of file |
|
279 | 279 | if id not in self.enaModules: No newline at end of file |
|
280 | 280 | continue No newline at end of file |
|
281 | 281 | No newline at end of file |
|
282 | 282 | bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
283 | 283 | del self.bits[id-1] No newline at end of file |
|
284 | 284 | self.bits.insert(id-1, bits) No newline at end of file |
|
285 | 285 | No newline at end of file |
|
286 | 286 | # all_blocks.append(one_block) No newline at end of file |
|
287 | 287 | #Using tx buffer No newline at end of file |
|
288 | 288 | No newline at end of file |
|
289 | 289 | return self.bits No newline at end of file |
|
290 | 290 | No newline at end of file |
|
291 | 291 | def __getControlModuleStatus_new(self, cmd, type): No newline at end of file |
|
292 | 292 | No newline at end of file |
|
293 | 293 | cm_lst = self.__gettingDataFromControlModules(cmd = cmd, rx_buffer = type) No newline at end of file |
|
294 | 294 | out_str = self.__processingCMdata(in_data = cm_lst, type = type) No newline at end of file |
|
295 | 295 | No newline at end of file |
|
296 | 296 | return out_str No newline at end of file |
|
297 | 297 | No newline at end of file |
|
298 | 298 | def __gettingDataFromControlModules(self, cmd, rx_buffer): No newline at end of file |
|
299 | 299 | No newline at end of file |
|
300 | 300 | for id in range(1,65): No newline at end of file |
|
301 | 301 | if id not in self.enaModules: No newline at end of file |
|
302 | 302 | continue No newline at end of file |
|
303 | 303 | No newline at end of file |
|
304 | 304 | cm = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
305 | 305 | del self.test[id-1] No newline at end of file |
|
306 | 306 | self.test.insert(id-1, cm) No newline at end of file |
|
307 | 307 | No newline at end of file |
|
308 | 308 | return self.test No newline at end of file |
|
309 | 309 | No newline at end of file |
|
310 | 310 | def __processingCMdata(self,in_data, type): No newline at end of file |
|
311 | 311 | No newline at end of file |
|
312 | 312 | if (type == "0") or (type == "1") or (type == "2"): No newline at end of file |
|
313 | 313 | out_str = "".join(in_data) No newline at end of file |
|
314 | 314 | elif type == "3": No newline at end of file |
|
315 | 315 | out_str = self.__TwoComparation(in_lst = in_data) No newline at end of file |
|
316 | 316 | else: No newline at end of file |
|
317 | 317 | out_str = self.__ThreeComparation(in_lst = in_data) No newline at end of file |
|
318 | 318 | No newline at end of file |
|
319 | 319 | return out_str No newline at end of file |
|
320 | 320 | No newline at end of file |
|
321 | 321 | def __TwoComparation(self, in_lst): No newline at end of file |
|
322 | 322 | No newline at end of file |
|
323 | 323 | No newline at end of file |
|
324 | 324 | file = [] No newline at end of file |
|
325 | 325 | relay = [] No newline at end of file |
|
326 | 326 | status = [] No newline at end of file |
|
327 | 327 | mode = '0' No newline at end of file |
|
328 | 328 | No newline at end of file |
|
329 | 329 | if mode == '0': No newline at end of file |
|
330 | 330 | No newline at end of file |
|
331 | 331 | for i in in_lst: No newline at end of file |
|
332 | 332 | if len(i) == 7: No newline at end of file |
|
333 | 333 | file.append("xxxxxx") No newline at end of file |
|
334 | 334 | relay.append("xxxxxx") No newline at end of file |
|
335 | 335 | else: No newline at end of file |
|
336 | 336 | file.append(i[16:22]) No newline at end of file |
|
337 | 337 | relay.append(i[23:29]) No newline at end of file |
|
338 | 338 | #Loop to generate a status No newline at end of file |
|
339 | 339 | for i in range(64): No newline at end of file |
|
340 | 340 | cnt = 0 No newline at end of file |
|
341 | 341 | if file[i] == "xxxxxx": No newline at end of file |
|
342 | 342 | status.append("xx") No newline at end of file |
|
343 | 343 | continue No newline at end of file |
|
344 | 344 | No newline at end of file |
|
345 | 345 | if cmp(file[i],relay[i]) == 0: No newline at end of file |
|
346 | 346 | cnt = cnt + 1 No newline at end of file |
|
347 | 347 | No newline at end of file |
|
348 | 348 | if cmp(file[i][0:3],relay[i][0:3]) == 0: No newline at end of file |
|
349 | 349 | cnt = cnt + 1 No newline at end of file |
|
350 | 350 | No newline at end of file |
|
351 | 351 | if cmp(file[i][3:6],relay[i][3:6]) == 0: No newline at end of file |
|
352 | 352 | cnt = cnt + 2 No newline at end of file |
|
353 | 353 | No newline at end of file |
|
354 | 354 | No newline at end of file |
|
355 | 355 | No newline at end of file |
|
356 | 356 | if cnt == 4: No newline at end of file |
|
357 | 357 | status.append("00") No newline at end of file |
|
358 | 358 | elif cnt == 0: No newline at end of file |
|
359 | 359 | status.append("11") No newline at end of file |
|
360 | 360 | elif cnt == 1: No newline at end of file |
|
361 | status.append("01") | |
|
No newline at end of file | ||
|
362 | else: No newline at end of file | |
|
361 | 363 | status.append("10") |
|
No newline at end of file | ||
|
362 | else: | |
|
No newline at end of file | ||
|
363 | status.append("01") No newline at end of file | |
|
364 | 364 | No newline at end of file |
|
365 | 365 | else: No newline at end of file |
|
366 | 366 | No newline at end of file |
|
367 | 367 | cm_up =[] No newline at end of file |
|
368 | 368 | cm_dw =[] No newline at end of file |
|
369 | 369 | relay_up =[] No newline at end of file |
|
370 | 370 | relay_dw =[] No newline at end of file |
|
371 | 371 | No newline at end of file |
|
372 | 372 | for i in in_lst: No newline at end of file |
|
373 | 373 | if len(i) == 8: No newline at end of file |
|
374 | 374 | relay_up.append("-") No newline at end of file |
|
375 | 375 | relay_dw.append("-") No newline at end of file |
|
376 | 376 | cm_up.append("-") No newline at end of file |
|
377 | 377 | cm_dw.append("-") No newline at end of file |
|
378 | 378 | continue No newline at end of file |
|
379 | 379 | relay_up.append(i[14:17]) No newline at end of file |
|
380 | 380 | relay_dw.append(i[17:20]) No newline at end of file |
|
381 | 381 | cm_up.append(i[21:24]) No newline at end of file |
|
382 | 382 | cm_dw.append(i[24:27]) No newline at end of file |
|
383 | 383 | No newline at end of file |
|
384 | 384 | comp_up = [] No newline at end of file |
|
385 | 385 | comp_dw = [] No newline at end of file |
|
386 | 386 | No newline at end of file |
|
387 | 387 | for i in range(64): No newline at end of file |
|
388 | 388 | if len(relay_up == 1): No newline at end of file |
|
389 | 389 | comp_up.append('x') No newline at end of file |
|
390 | 390 | else: No newline at end of file |
|
391 | 391 | if cmp(relay_up[i], cm_up[i]) == 0: No newline at end of file |
|
392 | 392 | comp_up.append('0') No newline at end of file |
|
393 | 393 | else: No newline at end of file |
|
394 | 394 | comp_up.append('1') No newline at end of file |
|
395 | 395 | No newline at end of file |
|
396 | 396 | for i in range(64): No newline at end of file |
|
397 | 397 | if len(relay_dw == 1): No newline at end of file |
|
398 | 398 | comp_dw.append('x') No newline at end of file |
|
399 | 399 | else: No newline at end of file |
|
400 | 400 | if cmp(relay_dw[i], cm_dw[i]) == 0: No newline at end of file |
|
401 | 401 | comp_dw.append('0') No newline at end of file |
|
402 | 402 | else: No newline at end of file |
|
403 | 403 | comp_dw.append('1') No newline at end of file |
|
404 | 404 | No newline at end of file |
|
405 | 405 | # Example: No newline at end of file |
|
406 | 406 | # comp_up = [1,0,x,1,1,1 ..,1,0,1,x] No newline at end of file |
|
407 | 407 | # No newline at end of file |
|
408 | 408 | print comp_up No newline at end of file |
|
409 | 409 | print comp_dw No newline at end of file |
|
410 | 410 | No newline at end of file |
|
411 | 411 | #Doing final format No newline at end of file |
|
412 | 412 | return self.__FinalFormat(data1 = file, data2 = relay, data3 = status) No newline at end of file |
|
413 | 413 | No newline at end of file |
|
414 | 414 | def __FinalFormat(self,data1,data2,data3): No newline at end of file |
|
415 | 415 | No newline at end of file |
|
416 | 416 | header = "Device\tFile\tRelay\tStatus\n" No newline at end of file |
|
417 | 417 | body = "" No newline at end of file |
|
418 | 418 | for i in range(64): No newline at end of file |
|
419 | 419 | if i<9: No newline at end of file |
|
420 | 420 | device = "CM0" + str(i+1) No newline at end of file |
|
421 | 421 | else: No newline at end of file |
|
422 | 422 | device = "CM" + str(i+1) No newline at end of file |
|
423 | 423 | No newline at end of file |
|
424 | 424 | line = device + '\t' + data1[i] + '\t' + data2[i] + '\t' + data3[i] + '\n' No newline at end of file |
|
425 | 425 | body = body + line No newline at end of file |
|
426 | 426 | No newline at end of file |
|
427 | 427 | report = header + body No newline at end of file |
|
428 | 428 | No newline at end of file |
|
429 | 429 | return report No newline at end of file |
|
430 | 430 | No newline at end of file |
|
431 | 431 | def __ThreeComparation(self, in_lst): No newline at end of file |
|
432 | 432 | pass No newline at end of file |
|
433 | 433 | No newline at end of file |
|
434 | 434 | def __getControlModuleBigPhase(self, cmd, rx_buffer): No newline at end of file |
|
435 | 435 | No newline at end of file |
|
436 | 436 | # all_blocks = "" No newline at end of file |
|
437 | 437 | all_blocks = [] No newline at end of file |
|
438 | 438 | # enaModules = self.checkAntenna() No newline at end of file |
|
439 | 439 | # enaModules = [11,12,13,14] No newline at end of file |
|
440 | 440 | No newline at end of file |
|
441 | 441 | for id in range(1,65): No newline at end of file |
|
442 | 442 | if id not in self.enaModules: No newline at end of file |
|
443 | 443 | continue No newline at end of file |
|
444 | 444 | No newline at end of file |
|
445 | 445 | one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
446 | 446 | No newline at end of file |
|
447 | 447 | # all_blocks = all_blocks + one_block No newline at end of file |
|
448 | 448 | all_blocks.append(one_block) No newline at end of file |
|
449 | 449 | #Using tx buffer No newline at end of file |
|
450 | 450 | return all_blocks No newline at end of file |
|
451 | 451 | No newline at end of file |
|
452 | 452 | def __getControlModuleLowPhase(self, cmd, rx_buffer): No newline at end of file |
|
453 | 453 | No newline at end of file |
|
454 | 454 | # all_blocks = "" No newline at end of file |
|
455 | 455 | # all_blocks = [] No newline at end of file |
|
456 | 456 | # enaModules = self.checkAntenna() No newline at end of file |
|
457 | 457 | # enaModules = [11,12,13,14] No newline at end of file |
|
458 | 458 | No newline at end of file |
|
459 | 459 | for id in range(1,65): No newline at end of file |
|
460 | 460 | if id not in self.enaModules: No newline at end of file |
|
461 | 461 | continue No newline at end of file |
|
462 | 462 | No newline at end of file |
|
463 | 463 | phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
464 | 464 | del self.phase[id-1] No newline at end of file |
|
465 | 465 | self.phase.insert(id-1, phase) No newline at end of file |
|
466 | 466 | # all_blocks = all_blocks + one_block No newline at end of file |
|
467 | 467 | # all_blocks.append(one_block) No newline at end of file |
|
468 | 468 | #Using tx buffer No newline at end of file |
|
469 | 469 | # return all_blocks No newline at end of file |
|
470 | 470 | No newline at end of file |
|
471 | 471 | def __getConnectionStatus(self, cmd, rx_buffer): No newline at end of file |
|
472 | 472 | No newline at end of file |
|
473 | 473 | ena = self.checkAntenna() No newline at end of file |
|
474 | 474 | print ena No newline at end of file |
|
475 | 475 | self.enaModules = ena No newline at end of file |
|
476 | 476 | No newline at end of file |
|
477 | 477 | blockLst = [] No newline at end of file |
|
478 | 478 | No newline at end of file |
|
479 | 479 | for id in range(1,65): No newline at end of file |
|
480 | 480 | if id not in self.enaModules: No newline at end of file |
|
481 | 481 | continue No newline at end of file |
|
482 | 482 | No newline at end of file |
|
483 | 483 | blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
484 | 484 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") No newline at end of file |
|
485 | 485 | #Using tx buffer No newline at end of file |
|
486 | 486 | all_blocks = "".join(blockLst) No newline at end of file |
|
487 | 487 | No newline at end of file |
|
488 | 488 | return all_blocks No newline at end of file |
|
489 | 489 | No newline at end of file |
|
490 | 490 | def getConnectionStatus(self, cmd): No newline at end of file |
|
491 | 491 | No newline at end of file |
|
492 | 492 | ena = self.checkAntenna() No newline at end of file |
|
493 | 493 | self.enaModules = ena No newline at end of file |
|
494 | 494 | No newline at end of file |
|
495 | 495 | blockLst = [] No newline at end of file |
|
496 | 496 | No newline at end of file |
|
497 | 497 | for id in range(1,65): No newline at end of file |
|
498 | 498 | if id not in self.enaModules: No newline at end of file |
|
499 | 499 | continue No newline at end of file |
|
500 | 500 | No newline at end of file |
|
501 | 501 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) No newline at end of file |
|
502 | 502 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") No newline at end of file |
|
503 | 503 | #Using tx buffer No newline at end of file |
|
504 | 504 | self.tx_buffer = "".join(blockLst) No newline at end of file |
|
505 | 505 | print self.tx_buffer No newline at end of file |
|
506 | 506 | No newline at end of file |
|
507 | 507 | return self.tx_buffer No newline at end of file |
|
508 | 508 | No newline at end of file |
|
509 | 509 | def __getControlModuleStatus_old(self, cmd, rx_buffer): No newline at end of file |
|
510 | 510 | No newline at end of file |
|
511 | 511 | all_blocks = "" No newline at end of file |
|
512 | 512 | # enaModules = self.checkAntenna() No newline at end of file |
|
513 | 513 | # enaModules = [11,12,13,14] No newline at end of file |
|
514 | 514 | No newline at end of file |
|
515 | 515 | for id in range(1,65): No newline at end of file |
|
516 | 516 | if id not in self.enaModules: No newline at end of file |
|
517 | 517 | continue No newline at end of file |
|
518 | 518 | No newline at end of file |
|
519 | 519 | one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) No newline at end of file |
|
520 | 520 | No newline at end of file |
|
521 | 521 | all_blocks = all_blocks + one_block No newline at end of file |
|
522 | 522 | #Using tx buffer No newline at end of file |
|
523 | 523 | print all_blocks No newline at end of file |
|
524 | 524 | self.tx_buffer = all_blocks No newline at end of file |
|
525 | 525 | No newline at end of file |
|
526 | 526 | return all_blocks No newline at end of file |
|
527 | 527 | No newline at end of file |
|
528 | 528 | def __StartingAutomaticControlModules(self): No newline at end of file |
|
529 | 529 | No newline at end of file |
|
530 | 530 | #Starting file No newline at end of file |
|
531 | 531 | self.__CreateFile("Monitoring.txt") No newline at end of file |
|
532 | 532 | # data = "MOD.\t BITS\t\t PHASE\n" No newline at end of file |
|
533 | 533 | # self.__writeFile("Monitoring.txt", data) No newline at end of file |
|
534 | 534 | #Starting lists No newline at end of file |
|
535 | 535 | self.txFile = list("------\n------\n------\n" for i in range(64)) No newline at end of file |
|
536 | 536 | self.rxFile = list("------\n------\n------\n" for i in range(64)) No newline at end of file |
|
537 | 537 | self.bits = list("------\n------\n------\n" for i in range(64)) No newline at end of file |
|
538 | 538 | self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64)) No newline at end of file |
|
539 | 539 | self.test = list("------\n" for i in range(64)) No newline at end of file |
|
540 | 540 | No newline at end of file |
|
541 | 541 | def __AutomaticControlModules(self): No newline at end of file |
|
542 | 542 | No newline at end of file |
|
543 | 543 | # cmd = "GETF" No newline at end of file |
|
544 | 544 | # rx_buffer = "experimento1.ab1" + "\n" No newline at end of file |
|
545 | 545 | # self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
546 | 546 | # No newline at end of file |
|
547 | 547 | # print self.rxFile No newline at end of file |
|
548 | 548 | No newline at end of file |
|
549 | 549 | cmd = "ANST" No newline at end of file |
|
550 | 550 | rx_buffer = "1" No newline at end of file |
|
551 | 551 | self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
552 | 552 | No newline at end of file |
|
553 | 553 | cmd = "LWPH" No newline at end of file |
|
554 | 554 | rx_buffer = "0" No newline at end of file |
|
555 | 555 | self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) No newline at end of file |
|
556 | 556 | print "Saving file..." No newline at end of file |
|
557 | 557 | No newline at end of file |
|
558 | 558 | No newline at end of file |
|
559 | 559 | print self.bits No newline at end of file |
|
560 | 560 | print self.phase No newline at end of file |
|
561 | 561 | No newline at end of file |
|
562 | 562 | self.__WritingMonitoringFile() No newline at end of file |
|
563 | 563 | No newline at end of file |
|
564 | 564 | threading.Timer(60, self.__AutomaticControlModules).start() No newline at end of file |
|
565 | 565 | No newline at end of file |
|
566 | 566 | def __WritingMonitoringFile(self): No newline at end of file |
|
567 | 567 | filename = "Monitoring.txt" No newline at end of file |
|
568 | 568 | data = '===============================' + '\n' No newline at end of file |
|
569 | 569 | self.__writeFile(filename, data) No newline at end of file |
|
570 | 570 | data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime()) No newline at end of file |
|
571 | 571 | self.__writeFile(filename, data) No newline at end of file |
|
572 | 572 | data = "MOD.\t BITS\t\t PHASE\n" No newline at end of file |
|
573 | 573 | self.__writeFile(filename, data) No newline at end of file |
|
574 | 574 | data = '===============================' + '\n' No newline at end of file |
|
575 | 575 | self.__writeFile(filename, data) No newline at end of file |
|
576 | 576 | for i in range(64): No newline at end of file |
|
577 | 577 | tmp = self.bits[i].split('\n',3) No newline at end of file |
|
578 | 578 | self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2]) No newline at end of file |
|
579 | 579 | tmp = self.phase[i].split('\n',3) No newline at end of file |
|
580 | 580 | self.__writeFile(filename, '\t\t' + tmp[2] + '\n') No newline at end of file |
|
581 | 581 | No newline at end of file |
|
582 | 582 | No newline at end of file |
|
583 | 583 | if __name__ == '__main__': No newline at end of file |
|
584 | 584 | No newline at end of file |
|
585 | 585 | absObj = ABSServer() No newline at end of file |
|
586 | 586 | No newline at end of file |
|
587 | 587 | while 1: No newline at end of file |
|
588 | 588 | absObj.waitRequest() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now