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