@@ -15,6 +15,7 | |||||
15 |
|
15 | |||
16 | self.tx_buffer = "default" |
|
16 | self.tx_buffer = "default" | |
17 | self.rx_buffer = "default" |
|
17 | self.rx_buffer = "default" | |
|
18 | self.enaModules = [] | |||
18 |
|
19 | |||
19 | self.createObjects() |
|
20 | self.createObjects() | |
20 |
|
21 | |||
@@ -26,20 +27,24 | |||||
26 |
|
27 | |||
27 | def waitRequest(self): |
|
28 | def waitRequest(self): | |
28 |
|
29 | |||
29 |
|
|
30 | #Using rx buffer | |
30 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer() |
|
31 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer() | |
31 |
|
32 | |||
32 | if cmd == "SNDF": |
|
33 | if cmd == "SNDF": | |
33 | # datarpta = self.sendFile2Modules(mode=2, cmd = cmd) |
|
|||
34 | datarpta = self.__sendFile2Modules(cmd = cmd) |
|
34 | datarpta = self.__sendFile2Modules(cmd = cmd) | |
35 |
|
35 | |||
36 | if cmd == "CHGB": |
|
36 | if cmd == "CHGB": | |
37 | datarpta = self.__changeBeam(cmd = cmd) |
|
37 | datarpta = self.__changeBeam(cmd = cmd) | |
38 |
|
38 | |||
39 | if cmd == "ANST": |
|
39 | if cmd == "ANST": | |
40 | self.__getStatus(cmd = cmd) |
|
40 | self.__getControlModuleStatus(cmd = cmd) | |
41 |
|
|
41 | #Using tx buffer | |
42 | datarpta = self.tx_buffer |
|
42 | datarpta = self.tx_buffer | |
|
43 | ||||
|
44 | if cmd == "NTST": | |||
|
45 | self.enaModules = self.__getConnectionStatus() | |||
|
46 | #Using tx buffer | |||
|
47 | datarpta = self.enaModules | |||
43 |
|
48 | |||
44 | self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource) |
|
49 | self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource) | |
45 |
|
50 | |||
@@ -80,48 +85,14 | |||||
80 |
|
85 | |||
81 | """ |
|
86 | """ | |
82 |
|
87 | |||
83 | enaModules = [] |
|
88 | enaModules2 = [] | |
84 |
|
89 | |||
85 | for address in range(1,65): |
|
90 | for address in range(1,65): | |
86 | if self.checkModule(address): |
|
91 | if self.checkModule(address): | |
87 | enaModules.append(address) |
|
92 | enaModules2.append(address) | |
88 |
|
93 | |||
89 | self.__writeReport(enaModules) |
|
94 | self.__writeReport(enaModules2) | |
90 | return enaModules |
|
95 | return enaModules2 | |
91 |
|
||||
92 | # def sendFile2Modules(self, mode, cmd): |
|
|||
93 | # |
|
|||
94 | # if mode == 1: |
|
|||
95 | # self.__sendFile2Modules1() |
|
|||
96 | # else: |
|
|||
97 | # self.__sendFile2Modules2(cmd) |
|
|||
98 | # |
|
|||
99 | # def __sendFile2Modules1(self): |
|
|||
100 | # |
|
|||
101 | # #Needed for the loop |
|
|||
102 | # rx_frame_list = self.rx_buffer.split('\n',2) |
|
|||
103 | # |
|
|||
104 | # self.experiment_name = rx_frame_list[0] |
|
|||
105 | # experiment_number = rx_frame_list[1] |
|
|||
106 | # str_control_modules = rx_frame_list[2] |
|
|||
107 | # |
|
|||
108 | # lst_control_modules = str_control_modules.split("------\n") |
|
|||
109 | # |
|
|||
110 | ## enaModules = self.checkAntenna() |
|
|||
111 | # enaModules = [11,12,13,14] |
|
|||
112 | # |
|
|||
113 | # for address in range(1,65): |
|
|||
114 | # |
|
|||
115 | # if address not in enaModules: |
|
|||
116 | # continue |
|
|||
117 | # |
|
|||
118 | # self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1]) |
|
|||
119 | # |
|
|||
120 | # cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name |
|
|||
121 | # print cmd |
|
|||
122 | # os.system(cmd) |
|
|||
123 | # |
|
|||
124 | # self.__loadFile() |
|
|||
125 |
|
96 | |||
126 | def __sendFile2Modules(self,cmd): |
|
97 | def __sendFile2Modules(self,cmd): | |
127 |
|
98 | |||
@@ -135,11 +106,11 | |||||
135 | lst_control_modules = str_control_modules.split("------\n") |
|
106 | lst_control_modules = str_control_modules.split("------\n") | |
136 |
|
107 | |||
137 | # enaModules = self.checkAntenna() |
|
108 | # enaModules = self.checkAntenna() | |
138 | enaModules = [11,12,13,14] |
|
109 | # enaModules = [11,12,13,14] | |
139 |
|
110 | |||
140 | for id in range(1,65): |
|
111 | for id in range(1,65): | |
141 |
|
112 | |||
142 | if id not in enaModules: |
|
113 | if id not in self.enaModules: | |
143 | continue |
|
114 | continue | |
144 | #tcp client needed |
|
115 | #tcp client needed | |
145 | self.commClientObj.open_socket() |
|
116 | self.commClientObj.open_socket() | |
@@ -153,53 +124,27 | |||||
153 | else: |
|
124 | else: | |
154 | failure = failure + 1 |
|
125 | failure = failure + 1 | |
155 |
|
126 | |||
156 | if correct == len(enaModules): |
|
127 | if correct == len(self.enaModules): | |
157 | rpta = "OK" |
|
128 | rpta = "OK" | |
158 | else: |
|
129 | else: | |
159 | rpta = "Failure" |
|
130 | rpta = "Failure" | |
160 |
|
131 | |||
161 | return rpta |
|
132 | return rpta | |
162 |
|
||||
163 |
|
||||
164 | def __writeModuleFile(self, filename, str): |
|
|||
165 |
|
||||
166 | fobj = open(filename,"w") |
|
|||
167 | fobj.write(filename + "\n") |
|
|||
168 | fobj.write("------\n") |
|
|||
169 | fobj.write(str) |
|
|||
170 | fobj.write("------\n") |
|
|||
171 | fobj.close() |
|
|||
172 |
|
||||
173 | def __readModuleFile(self, filename): |
|
|||
174 |
|
||||
175 | fobj1 = open(filename,"r") |
|
|||
176 | file_list_1 = fobj1.readlines() |
|
|||
177 | fobj1.close() |
|
|||
178 | content_str = ''.join(file_list_1[2:-1]) |
|
|||
179 |
|
||||
180 | return content_str |
|
|||
181 |
|
||||
182 | def __loadFile(self): |
|
|||
183 |
|
||||
184 | #Working with the UDP socket |
|
|||
185 | self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") |
|
|||
186 | self.commClientObj.sendData("none", "CAMBIA:0:") |
|
|||
187 |
|
133 | |||
188 | def __changeBeam(self, cmd): |
|
134 | def __changeBeam(self, cmd): | |
189 |
|
135 | |||
190 | correct = 0 |
|
136 | correct = 0 | |
191 | failure = 0 |
|
137 | failure = 0 | |
192 | # enaModules = self.checkAntenna() |
|
138 | # enaModules = self.checkAntenna() | |
193 | enaModules = [11,12,13,14] |
|
139 | # enaModules = [11,12,13,14] | |
194 |
|
140 | |||
195 | for id in range(1,65): |
|
141 | for id in range(1,65): | |
196 | if id not in enaModules: |
|
142 | if id not in self.enaModules: | |
197 | continue |
|
143 | continue | |
198 |
|
144 | |||
199 | self.commClientObj.open_socket() |
|
145 | self.commClientObj.open_socket() | |
200 | ip = "192.168.1." + str(id) |
|
146 | ip = "192.168.1." + str(id) | |
201 | self.commClientObj.sendData2(cmd, self.rx_buffer, ip) |
|
147 | self.commClientObj.sendData2(cmd, self.rx_buffer, ip) | |
202 | # ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() |
|
|||
203 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() |
|
148 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |
204 | self.commClientObj.close_socket() |
|
149 | self.commClientObj.close_socket() | |
205 |
|
150 | |||
@@ -208,147 +153,21 | |||||
208 | else: |
|
153 | else: | |
209 | failure = failure + 1 |
|
154 | failure = failure + 1 | |
210 |
|
155 | |||
211 | if correct == len(enaModules): |
|
156 | if correct == len(self.enaModules): | |
212 | rpta = "OK" |
|
157 | rpta = "OK" | |
213 | else: |
|
158 | else: | |
214 | rpta = "Failure" |
|
159 | rpta = "Failure" | |
215 |
|
160 | |||
216 | return rpta |
|
161 | return rpta | |
217 |
|
||||
218 | # def __getStatus(self, mode, cmd): |
|
|||
219 | # |
|
|||
220 | # if mode == 1: |
|
|||
221 | # self.__getStsMode1() |
|
|||
222 | # elif mode == 2: |
|
|||
223 | # self.__getStsMode2() |
|
|||
224 | # elif mode == 3: |
|
|||
225 | # self.__getStsMode3() |
|
|||
226 | # else: |
|
|||
227 | # self.__getStsMode4(cmd) |
|
|||
228 |
|
||||
229 |
|
162 | |||
230 |
|
|
163 | def __getControlModuleStatus(self, cmd): | |
231 | # #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") |
|
|||
232 | # self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") |
|
|||
233 | # seconds = int (self.rx_buffer) |
|
|||
234 | # # Give 5 seconds to the control modules |
|
|||
235 | # time.sleep(seconds) |
|
|||
236 | # # Checking the module connection |
|
|||
237 | # module_list = self.connection_status(10) |
|
|||
238 | # #Generating the complete report |
|
|||
239 | # module = 1 |
|
|||
240 | # number_of_modules = 16 |
|
|||
241 | # filename1 = "Verificacion" |
|
|||
242 | # filename2 = "report.txt" |
|
|||
243 | # fobj2 = open(filename2,"w") |
|
|||
244 | # fobj2.write("Verification_file\n") |
|
|||
245 | # fobj2.write("-----------------\n") |
|
|||
246 | # fobj2.close() |
|
|||
247 | # while module <= number_of_modules: |
|
|||
248 | # if module_list[module -1] == "1": |
|
|||
249 | # #Preparing and doing the tftp command |
|
|||
250 | # cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1 |
|
|||
251 | # print cmd |
|
|||
252 | # os.system(cmd) |
|
|||
253 | # # Getting data from the control module file |
|
|||
254 | # fobj1 = open(filename1,"r") |
|
|||
255 | # file_list_1 = fobj1.readlines() |
|
|||
256 | # fobj1.close() |
|
|||
257 | # content = file_list_1[2:-1] |
|
|||
258 | # # |
|
|||
259 | # fobj2 = open(filename2,"a") |
|
|||
260 | # if base == 10: |
|
|||
261 | # fobj2.write("S" + str(module) + "\n") |
|
|||
262 | # else: |
|
|||
263 | # fobj2.write("N" + str(module) + "\n") |
|
|||
264 | # fobj2.writelines(content) |
|
|||
265 | # fobj2.write("------\n") |
|
|||
266 | # fobj2.close() |
|
|||
267 | # module = module + 1 |
|
|||
268 |
|
||||
269 | # def __getStsMode2(self): |
|
|||
270 | # |
|
|||
271 | # #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") |
|
|||
272 | # self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") |
|
|||
273 | # seconds = int (self.rx_buffer) |
|
|||
274 | # # Give 5 seconds to the control modules |
|
|||
275 | # time.sleep(seconds) |
|
|||
276 | # # Checking the module connection |
|
|||
277 | # enaModules = self.checkAntenna() |
|
|||
278 | # #Generating the complete report |
|
|||
279 | # filename1 = "Verificacion" |
|
|||
280 | # line1 = "Verification_file\n" |
|
|||
281 | # line2 = "-----------------\n" |
|
|||
282 | # report_list = [line1, line2] |
|
|||
283 | # |
|
|||
284 | # for address in range(1,65): |
|
|||
285 | # |
|
|||
286 | # if address not in enaModules: |
|
|||
287 | # continue |
|
|||
288 | # #Preparing and doing the tftp command |
|
|||
289 | # cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1 |
|
|||
290 | # print cmd |
|
|||
291 | # os.system(cmd) |
|
|||
292 | # #Sub_header |
|
|||
293 | # report_list.append("ABS_" + str(address) + "\n") |
|
|||
294 | # # Content |
|
|||
295 | # fobj1 = open(filename1,"r") |
|
|||
296 | # file_list_1 = fobj1.readlines() |
|
|||
297 | # fobj1.close() |
|
|||
298 | # content = ''.join(file_list_1[2:-1]) |
|
|||
299 | # report_list.append(content) |
|
|||
300 | # #Ending |
|
|||
301 | # report_list.append("------\n") |
|
|||
302 | # #print "\nFinalizado" |
|
|||
303 | # self.tx_buffer = ''.join(report_list) |
|
|||
304 |
|
||||
305 | def __AddingHeader(self,content_list, title): |
|
|||
306 |
|
||||
307 | line1 = title + "\n" |
|
|||
308 | line2 = "-----------------\n" |
|
|||
309 | header_list = [line1, line2] |
|
|||
310 | verification_list = header_list + content_list |
|
|||
311 | # Arming the frame |
|
|||
312 | self.tx_buffer = ''.join(verification_list) |
|
|||
313 |
|
||||
314 | # def __getModuleFile(self, filename): |
|
|||
315 | # |
|
|||
316 | # enaModules = self.checkAntenna() |
|
|||
317 | # content_list = [] |
|
|||
318 | # for address in range(1,65): |
|
|||
319 | # |
|
|||
320 | # if address not in enaModules: |
|
|||
321 | # continue |
|
|||
322 | # #Preparing and doing the tftp command |
|
|||
323 | # cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename |
|
|||
324 | # print cmd |
|
|||
325 | # os.system(cmd) |
|
|||
326 | # #Sub_header |
|
|||
327 | # content_list.append("ABS_" + str(address) + "\n") |
|
|||
328 | # # From module file to list |
|
|||
329 | # content_str = self.__readModuleFile(filename) |
|
|||
330 | # content_list.append(content_str) |
|
|||
331 | # content_list.append("------\n") |
|
|||
332 | # |
|
|||
333 | # self.__AddingHeader(content_list, title = "Verification_file") |
|
|||
334 |
|
||||
335 | # def __getStsMode3(self): |
|
|||
336 | # |
|
|||
337 | # self.commClientObj.sendData("none", "CHEQUEO:" + self.rx_buffer + ":") |
|
|||
338 | # seconds = int (self.rx_buffer) |
|
|||
339 | # # Give 5 seconds to the control modules |
|
|||
340 | # time.sleep(seconds) |
|
|||
341 | # |
|
|||
342 | # self.__getModuleFile(filename = "Verificacion") |
|
|||
343 |
|
||||
344 | def __getStatus(self, cmd): |
|
|||
345 |
|
164 | |||
346 | content_str = "" |
|
165 | content_str = "" | |
347 | # enaModules = self.checkAntenna() |
|
166 | # enaModules = self.checkAntenna() | |
348 | enaModules = [11,12,13,14] |
|
167 | # enaModules = [11,12,13,14] | |
349 |
|
168 | |||
350 | for id in range(1,65): |
|
169 | for id in range(1,65): | |
351 | if id not in enaModules: |
|
170 | if id not in self.enaModules: | |
352 | continue |
|
171 | continue | |
353 |
|
172 | |||
354 | self.commClientObj.open_socket() |
|
173 | self.commClientObj.open_socket() | |
@@ -358,9 +177,14 | |||||
358 | self.commClientObj.close_socket() |
|
177 | self.commClientObj.close_socket() | |
359 |
|
178 | |||
360 | content_str = content_str + tmp |
|
179 | content_str = content_str + tmp | |
361 | # self.__AddingHeader(content_list, title = "Verification_file") |
|
|||
362 | #Using tx buffer |
|
180 | #Using tx buffer | |
363 |
self.tx_buffer = content_str |
|
181 | self.tx_buffer = content_str | |
|
182 | ||||
|
183 | def __getConnectionStatus(self): | |||
|
184 | ||||
|
185 | enaModules = self.checkAntenna() | |||
|
186 | ||||
|
187 | return enaModules | |||
364 |
|
188 | |||
365 | if __name__ == '__main__': |
|
189 | if __name__ == '__main__': | |
366 |
|
190 |
General Comments 0
You need to be logged in to leave comments.
Login now