|
1 | NO CONTENT: new file 10644 |
@@ -0,0 +1,488 | |||
|
1 | # imports needed for the file convertion | |
|
2 | import os | |
|
3 | import sys | |
|
4 | import time | |
|
5 | import numpy as np | |
|
6 | ||
|
7 | import library | |
|
8 | ||
|
9 | class ABSClient: | |
|
10 | ||
|
11 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000): | |
|
12 | ||
|
13 | self.ipSource = ipSource | |
|
14 | self.ipDestino = ipDestino | |
|
15 | self.portDestino = portDestino | |
|
16 | ||
|
17 | self.createObjects() | |
|
18 | ||
|
19 | def createObjects(self): | |
|
20 | ||
|
21 | self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino) | |
|
22 | ||
|
23 | def sendFile(self, filename): | |
|
24 | ||
|
25 | #From matriz to control module format | |
|
26 | self.FuncionMaestra_GeneraFormatoControlCentral(filename) | |
|
27 | FileName = "FormatoControlCentral.txt" | |
|
28 | F_Obj = open(FileName,"r") | |
|
29 | FileList = F_Obj.readlines() | |
|
30 | F_Obj.close() | |
|
31 | FileStr = "".join(FileList) | |
|
32 | data = FileStr | |
|
33 | ||
|
34 | self.commObj.sendData(cmd="SNDF", data=data) | |
|
35 | self.commObj.waitData() | |
|
36 | ||
|
37 | def changeBeam(self, newBeam): | |
|
38 | ||
|
39 | self.commObj.sendData(cmd="CHGB", data=newBeam) | |
|
40 | self.commObj.waitData() | |
|
41 | ||
|
42 | def __writeFile(self, filename, data): | |
|
43 | ||
|
44 | fobj = open(filename,"w") | |
|
45 | fobj.writelines(data) | |
|
46 | fobj.close() | |
|
47 | ||
|
48 | def getStatus(self, data): | |
|
49 | ||
|
50 | self.commObj.sendData(cmd="ANST", data = data) | |
|
51 | ipSource, ipDestino, cmd, data = self.commObj.waitData() | |
|
52 | self.__writeFile("report.txt", data) | |
|
53 | ||
|
54 | ########## | |
|
55 | ||
|
56 | def FuncionMaestra_GeneraFormatoControlCentral(self,archivo): | |
|
57 | """ Funcion que genera un archivo para el control central""" | |
|
58 | ||
|
59 | # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/' | |
|
60 | CarpetaDeTrabajo = os.getcwd() + '/' | |
|
61 | #print CarpetaDeTrabajo | |
|
62 | #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/' | |
|
63 | ||
|
64 | def lst2string(lst): | |
|
65 | string='' | |
|
66 | for i in lst: | |
|
67 | string=string+i | |
|
68 | return string | |
|
69 | ||
|
70 | def string2lst(string): | |
|
71 | lst = [] | |
|
72 | for i in string: | |
|
73 | lst.append(i) | |
|
74 | return lst | |
|
75 | ||
|
76 | ||
|
77 | def file1(string, type): | |
|
78 | lst = string2lst(archivo) | |
|
79 | fin = -1 | |
|
80 | t = len(lst) | |
|
81 | for i in np.arange(-1,-t,-1): | |
|
82 | if lst[i]=='/': | |
|
83 | fin=i | |
|
84 | break | |
|
85 | if type == '1': | |
|
86 | nombre2 = lst[fin+1:] | |
|
87 | nombre2[-1]='s' | |
|
88 | nombre2 = lst2string(nombre2) | |
|
89 | return nombre2 | |
|
90 | if type == '2': | |
|
91 | nombre2 = lst[fin+1:] | |
|
92 | nombre2[-1]='1' | |
|
93 | nombre2 = lst2string(nombre2) | |
|
94 | return nombre2 | |
|
95 | ||
|
96 | ||
|
97 | def EliminaSaltoDeLinea(cadena): | |
|
98 | i = 0 | |
|
99 | for elemento in cadena: | |
|
100 | if elemento =='\n' or elemento =='\r': | |
|
101 | pass | |
|
102 | else: | |
|
103 | i=i+1 | |
|
104 | return cadena [:i] | |
|
105 | ||
|
106 | def NumeroDeExperimentos(path): | |
|
107 | fichero1=open(path,'r') | |
|
108 | cont=0 | |
|
109 | for cadena in fichero1: | |
|
110 | cont=cont+1 | |
|
111 | if cont==3: | |
|
112 | nexp='' | |
|
113 | pos=0 | |
|
114 | for elemento in cadena: | |
|
115 | pos=pos+1 | |
|
116 | if elemento=='=': | |
|
117 | nexp=int(cadena[pos:]) | |
|
118 | return nexp | |
|
119 | fichero1.close() | |
|
120 | ||
|
121 | def Paridad(numero): | |
|
122 | if numero%2==0: return 'par' | |
|
123 | elif numero%2==1: return 'impar' | |
|
124 | ||
|
125 | def EvaluaCadena(cadena): | |
|
126 | if len(cadena)>35: | |
|
127 | if cadena[-1]=='$': | |
|
128 | return cadena[-35:-2] | |
|
129 | elif cadena[-1]==']': | |
|
130 | return cadena[-34:-1] | |
|
131 | else: | |
|
132 | return None | |
|
133 | ||
|
134 | def GuardaEnLista(path): | |
|
135 | fichero=open(path,'r') | |
|
136 | lista=[] | |
|
137 | for cadena in fichero: | |
|
138 | cadena = EliminaSaltoDeLinea(cadena) | |
|
139 | cadena = EvaluaCadena(cadena) | |
|
140 | if cadena != None: | |
|
141 | lista.append(cadena) | |
|
142 | fichero.close() | |
|
143 | return lista | |
|
144 | ||
|
145 | def CreaFicherosPrevios(): | |
|
146 | vector = GuardaEnLista(archivo) | |
|
147 | for i in range(1,NumeroDeExperimentos(archivo)+1): | |
|
148 | fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w') | |
|
149 | for j in range(0,16): | |
|
150 | fichero.write(vector[j+16*(i-1)]+'\n') | |
|
151 | fichero.close() | |
|
152 | ||
|
153 | def CapturaValoresEnArchivo(path,polarizacion='up'): | |
|
154 | fichero =open(path,'r') | |
|
155 | cnt=0 | |
|
156 | lstup=[] | |
|
157 | lstdw=[] | |
|
158 | for cadena in fichero: | |
|
159 | cnt=cnt+1 | |
|
160 | if cnt==5: | |
|
161 | su01=cadena[17:20] | |
|
162 | su02=cadena[21:24] | |
|
163 | su03=cadena[25:28] | |
|
164 | su04=cadena[29:32] | |
|
165 | if cnt==6: | |
|
166 | su05=cadena[17:20] | |
|
167 | su06=cadena[21:24] | |
|
168 | su07=cadena[25:28] | |
|
169 | su08=cadena[29:32] | |
|
170 | if cnt==7: | |
|
171 | su09=cadena[17:20] | |
|
172 | su10=cadena[21:24] | |
|
173 | su11=cadena[25:28] | |
|
174 | su12=cadena[29:32] | |
|
175 | if cnt==8: | |
|
176 | su13=cadena[17:20] | |
|
177 | su14=cadena[21:24] | |
|
178 | su15=cadena[25:28] | |
|
179 | su16=cadena[29:32] | |
|
180 | if cnt==13: | |
|
181 | sd01=cadena[17:20] | |
|
182 | sd02=cadena[21:24] | |
|
183 | sd03=cadena[25:28] | |
|
184 | sd04=cadena[29:32] | |
|
185 | if cnt==14: | |
|
186 | sd05=cadena[17:20] | |
|
187 | sd06=cadena[21:24] | |
|
188 | sd07=cadena[25:28] | |
|
189 | sd08=cadena[29:32] | |
|
190 | if cnt==15: | |
|
191 | sd09=cadena[17:20] | |
|
192 | sd10=cadena[21:24] | |
|
193 | sd11=cadena[25:28] | |
|
194 | sd12=cadena[29:32] | |
|
195 | if cnt==16: | |
|
196 | sd13=cadena[17:20] | |
|
197 | sd14=cadena[21:24] | |
|
198 | sd15=cadena[25:28] | |
|
199 | sd16=cadena[29:32] | |
|
200 | lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] | |
|
201 | lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] | |
|
202 | if polarizacion=='up': | |
|
203 | return lstup | |
|
204 | elif polarizacion=='dw': | |
|
205 | return lstdw | |
|
206 | fichero.close() | |
|
207 | ||
|
208 | def CapturaValoresEnArchivo2(path,polarizacion='up'): | |
|
209 | fichero =open(path,'r') | |
|
210 | cnt=0 | |
|
211 | lstup=[] | |
|
212 | lstdw=[] | |
|
213 | for cadena in fichero: | |
|
214 | cnt=cnt+1 | |
|
215 | if cnt==1: | |
|
216 | nu01=cadena[1:4] | |
|
217 | nu02=cadena[5:8] | |
|
218 | nu03=cadena[9:12] | |
|
219 | nu04=cadena[13:16] | |
|
220 | eu01=cadena[17:20] | |
|
221 | eu02=cadena[21:24] | |
|
222 | eu03=cadena[25:28] | |
|
223 | eu04=cadena[29:32] | |
|
224 | if cnt==2: | |
|
225 | nu05=cadena[1:4] | |
|
226 | nu06=cadena[5:8] | |
|
227 | nu07=cadena[9:12] | |
|
228 | nu08=cadena[13:16] | |
|
229 | eu05=cadena[17:20] | |
|
230 | eu06=cadena[21:24] | |
|
231 | eu07=cadena[25:28] | |
|
232 | eu08=cadena[29:32] | |
|
233 | if cnt==3: | |
|
234 | nu09=cadena[1:4] | |
|
235 | nu10=cadena[5:8] | |
|
236 | nu11=cadena[9:12] | |
|
237 | nu12=cadena[13:16] | |
|
238 | eu09=cadena[17:20] | |
|
239 | eu10=cadena[21:24] | |
|
240 | eu11=cadena[25:28] | |
|
241 | eu12=cadena[29:32] | |
|
242 | if cnt==4: | |
|
243 | nu13=cadena[1:4] | |
|
244 | nu14=cadena[5:8] | |
|
245 | nu15=cadena[9:12] | |
|
246 | nu16=cadena[13:16] | |
|
247 | eu13=cadena[17:20] | |
|
248 | eu14=cadena[21:24] | |
|
249 | eu15=cadena[25:28] | |
|
250 | eu16=cadena[29:32] | |
|
251 | if cnt==5: | |
|
252 | wu01=cadena[1:4] | |
|
253 | wu02=cadena[5:8] | |
|
254 | wu03=cadena[9:12] | |
|
255 | wu04=cadena[13:16] | |
|
256 | su01=cadena[17:20] | |
|
257 | su02=cadena[21:24] | |
|
258 | su03=cadena[25:28] | |
|
259 | su04=cadena[29:32] | |
|
260 | if cnt==6: | |
|
261 | wu05=cadena[1:4] | |
|
262 | wu06=cadena[5:8] | |
|
263 | wu07=cadena[9:12] | |
|
264 | wu08=cadena[13:16] | |
|
265 | su05=cadena[17:20] | |
|
266 | su06=cadena[21:24] | |
|
267 | su07=cadena[25:28] | |
|
268 | su08=cadena[29:32] | |
|
269 | if cnt==7: | |
|
270 | wu09=cadena[1:4] | |
|
271 | wu10=cadena[5:8] | |
|
272 | wu11=cadena[9:12] | |
|
273 | wu12=cadena[13:16] | |
|
274 | su09=cadena[17:20] | |
|
275 | su10=cadena[21:24] | |
|
276 | su11=cadena[25:28] | |
|
277 | su12=cadena[29:32] | |
|
278 | if cnt==8: | |
|
279 | wu13=cadena[1:4] | |
|
280 | wu14=cadena[5:8] | |
|
281 | wu15=cadena[9:12] | |
|
282 | wu16=cadena[13:16] | |
|
283 | su13=cadena[17:20] | |
|
284 | su14=cadena[21:24] | |
|
285 | su15=cadena[25:28] | |
|
286 | su16=cadena[29:32] | |
|
287 | if cnt==9: | |
|
288 | nd01=cadena[1:4] | |
|
289 | nd02=cadena[5:8] | |
|
290 | nd03=cadena[9:12] | |
|
291 | nd04=cadena[13:16] | |
|
292 | ed01=cadena[17:20] | |
|
293 | ed02=cadena[21:24] | |
|
294 | ed03=cadena[25:28] | |
|
295 | ed04=cadena[29:32] | |
|
296 | if cnt==10: | |
|
297 | nd05=cadena[1:4] | |
|
298 | nd06=cadena[5:8] | |
|
299 | nd07=cadena[9:12] | |
|
300 | nd08=cadena[13:16] | |
|
301 | ed05=cadena[17:20] | |
|
302 | ed06=cadena[21:24] | |
|
303 | ed07=cadena[25:28] | |
|
304 | ed08=cadena[29:32] | |
|
305 | if cnt==11: | |
|
306 | nd09=cadena[1:4] | |
|
307 | nd10=cadena[5:8] | |
|
308 | nd11=cadena[9:12] | |
|
309 | nd12=cadena[13:16] | |
|
310 | ed09=cadena[17:20] | |
|
311 | ed10=cadena[21:24] | |
|
312 | ed11=cadena[25:28] | |
|
313 | ed12=cadena[29:32] | |
|
314 | if cnt==12: | |
|
315 | nd13=cadena[1:4] | |
|
316 | nd14=cadena[5:8] | |
|
317 | nd15=cadena[9:12] | |
|
318 | nd16=cadena[13:16] | |
|
319 | ed13=cadena[17:20] | |
|
320 | ed14=cadena[21:24] | |
|
321 | ed15=cadena[25:28] | |
|
322 | ed16=cadena[29:32] | |
|
323 | if cnt==13: | |
|
324 | wd01=cadena[1:4] | |
|
325 | wd02=cadena[5:8] | |
|
326 | wd03=cadena[9:12] | |
|
327 | wd04=cadena[13:16] | |
|
328 | sd01=cadena[17:20] | |
|
329 | sd02=cadena[21:24] | |
|
330 | sd03=cadena[25:28] | |
|
331 | sd04=cadena[29:32] | |
|
332 | if cnt==14: | |
|
333 | wd05=cadena[1:4] | |
|
334 | wd06=cadena[5:8] | |
|
335 | wd07=cadena[9:12] | |
|
336 | wd08=cadena[13:16] | |
|
337 | sd05=cadena[17:20] | |
|
338 | sd06=cadena[21:24] | |
|
339 | sd07=cadena[25:28] | |
|
340 | sd08=cadena[29:32] | |
|
341 | if cnt==15: | |
|
342 | wd09=cadena[1:4] | |
|
343 | wd10=cadena[5:8] | |
|
344 | wd11=cadena[9:12] | |
|
345 | wd12=cadena[13:16] | |
|
346 | sd09=cadena[17:20] | |
|
347 | sd10=cadena[21:24] | |
|
348 | sd11=cadena[25:28] | |
|
349 | sd12=cadena[29:32] | |
|
350 | if cnt==16: | |
|
351 | wd13=cadena[1:4] | |
|
352 | wd14=cadena[5:8] | |
|
353 | wd15=cadena[9:12] | |
|
354 | wd16=cadena[13:16] | |
|
355 | sd13=cadena[17:20] | |
|
356 | sd14=cadena[21:24] | |
|
357 | sd15=cadena[25:28] | |
|
358 | sd16=cadena[29:32] | |
|
359 | lst_n_up=[nu01,nu02,nu03,nu04,nu05,nu06,nu07,nu08,nu09,nu10,nu11,nu12,nu13,nu14,nu15,nu16] | |
|
360 | lst_n_dw=[nd01,nd02,nd03,nd04,nd05,nd06,nd07,nd08,nd09,nd10,nd11,nd12,nd13,nd14,nd15,nd16] | |
|
361 | lst_s_up=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] | |
|
362 | lst_s_dw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] | |
|
363 | lst_w_up=[wu01,wu02,wu03,wu04,wu05,wu06,wu07,wu08,wu09,wu10,wu11,wu12,wu13,wu14,wu15,wu16] | |
|
364 | lst_w_dw=[wd01,wd02,wd03,wd04,wd05,wd06,wd07,wd08,wd09,wd10,wd11,wd12,wd13,wd14,wd15,wd16] | |
|
365 | lst_e_up=[eu01,eu02,eu03,eu04,eu05,eu06,eu07,eu08,eu09,eu10,eu11,eu12,eu13,eu14,eu15,eu16] | |
|
366 | lst_e_dw=[ed01,ed02,ed03,ed04,ed05,ed06,ed07,ed08,ed09,ed10,ed11,ed12,ed13,ed14,ed15,ed16] | |
|
367 | ||
|
368 | lstup = lst_s_up + lst_w_up + lst_n_up + lst_e_up | |
|
369 | lstdw = lst_s_dw + lst_w_dw + lst_n_up + lst_e_up | |
|
370 | ||
|
371 | if polarizacion=='up': | |
|
372 | return lstup | |
|
373 | elif polarizacion=='dw': | |
|
374 | return lstdw | |
|
375 | fichero.close() | |
|
376 | ||
|
377 | ||
|
378 | def CreaFormatoFinal(): | |
|
379 | ne=NumeroDeExperimentos(archivo) | |
|
380 | ||
|
381 | #nombre01 = file1(archivo,'1') | |
|
382 | nombre02 = file1(archivo,'2') | |
|
383 | fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') | |
|
384 | fichero.write(nombre02+'\n') | |
|
385 | fichero.write(str(ne)+'\n') | |
|
386 | for i in range(1,17): | |
|
387 | ||
|
388 | if i<10: | |
|
389 | nmod = '0'+str(i) | |
|
390 | else: nmod = str(i) | |
|
391 | ||
|
392 | ||
|
393 | fichero.write('S'+nmod+'\n') | |
|
394 | for j in range(1,ne+1): | |
|
395 | ruta=CarpetaDeTrabajo+str(j)+'.txt' | |
|
396 | lu=CapturaValoresEnArchivo(ruta,polarizacion='up') | |
|
397 | ld=CapturaValoresEnArchivo(ruta,polarizacion='dw') | |
|
398 | part1='' | |
|
399 | part2='' | |
|
400 | if lu[i-1]=='1.0': part1='000' | |
|
401 | if lu[i-1]=='2.0': part1='001' | |
|
402 | if lu[i-1]=='3.0': part1='010' | |
|
403 | if lu[i-1]=='0.0': part1='011' | |
|
404 | if lu[i-1]=='0.5': part1='100' | |
|
405 | if lu[i-1]=='1.5': part1='101' | |
|
406 | if lu[i-1]=='2.5': part1='110' | |
|
407 | if lu[i-1]=='3.5': part1='111' | |
|
408 | if ld[i-1]=='1.0': part2='000' | |
|
409 | if ld[i-1]=='2.0': part2='001' | |
|
410 | if ld[i-1]=='3.0': part2='010' | |
|
411 | if ld[i-1]=='0.0': part2='011' | |
|
412 | if ld[i-1]=='0.5': part2='100' | |
|
413 | if ld[i-1]=='1.5': part2='101' | |
|
414 | if ld[i-1]=='2.5': part2='110' | |
|
415 | if ld[i-1]=='3.5': part2='111' | |
|
416 | fichero.write(part1+part2+'\n') | |
|
417 | fichero.write('------'+'\n') | |
|
418 | fichero.close() | |
|
419 | ||
|
420 | def CreaFormatoFinal2(): | |
|
421 | ne=NumeroDeExperimentos(archivo) | |
|
422 | ||
|
423 | #nombre01 = file1(archivo,'1') | |
|
424 | nombre02 = file1(archivo,'2') | |
|
425 | fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') | |
|
426 | fichero.write(nombre02+'\n') | |
|
427 | fichero.write(str(ne)+'\n') | |
|
428 | ||
|
429 | for i in range(1,65): | |
|
430 | ||
|
431 | if i<10: | |
|
432 | nmod = '0'+str(i) | |
|
433 | else: nmod = str(i) | |
|
434 | ||
|
435 | fichero.write("ABS_" + nmod+'\n') | |
|
436 | ||
|
437 | for j in range(1,ne+1): | |
|
438 | ruta=CarpetaDeTrabajo+str(j)+'.txt' | |
|
439 | lu=CapturaValoresEnArchivo2(ruta,polarizacion='up') | |
|
440 | ld=CapturaValoresEnArchivo2(ruta,polarizacion='dw') | |
|
441 | part1='' | |
|
442 | part2='' | |
|
443 | if lu[i-1]=='1.0': part1='000' | |
|
444 | if lu[i-1]=='2.0': part1='001' | |
|
445 | if lu[i-1]=='3.0': part1='010' | |
|
446 | if lu[i-1]=='0.0': part1='011' | |
|
447 | if lu[i-1]=='0.5': part1='100' | |
|
448 | if lu[i-1]=='1.5': part1='101' | |
|
449 | if lu[i-1]=='2.5': part1='110' | |
|
450 | if lu[i-1]=='3.5': part1='111' | |
|
451 | if ld[i-1]=='1.0': part2='000' | |
|
452 | if ld[i-1]=='2.0': part2='001' | |
|
453 | if ld[i-1]=='3.0': part2='010' | |
|
454 | if ld[i-1]=='0.0': part2='011' | |
|
455 | if ld[i-1]=='0.5': part2='100' | |
|
456 | if ld[i-1]=='1.5': part2='101' | |
|
457 | if ld[i-1]=='2.5': part2='110' | |
|
458 | if ld[i-1]=='3.5': part2='111' | |
|
459 | fichero.write(part1+part2+'\n') | |
|
460 | fichero.write('------'+'\n') | |
|
461 | fichero.close() | |
|
462 | ||
|
463 | def EliminaArchivosEnLaCarpeta(): | |
|
464 | ne=NumeroDeExperimentos(archivo) | |
|
465 | for i in range(1,ne+1): | |
|
466 | os.remove(CarpetaDeTrabajo+str(i)+'.txt') | |
|
467 | ||
|
468 | CreaFicherosPrevios() | |
|
469 | CreaFormatoFinal2() | |
|
470 | EliminaArchivosEnLaCarpeta() | |
|
471 | ||
|
472 | ########## | |
|
473 | ||
|
474 | if __name__ == '__main__': | |
|
475 | ||
|
476 | filename = "experimento1.abs" | |
|
477 | ||
|
478 | absObj = ABSClient() | |
|
479 | absObj.sendFile(filename) | |
|
480 | # absObj.changeBeam("0") | |
|
481 | # absObj.changeBeam("1") | |
|
482 | # absObj.changeBeam("2") | |
|
483 | # absObj.changeBeam("3") | |
|
484 | # absObj.changeBeam("4") | |
|
485 | # absObj.changeBeam("5") | |
|
486 | # absObj.changeBeam("6") | |
|
487 | # absObj.changeBeam("7") | |
|
488 | # absObj.getStatus(5) No newline at end of file |
@@ -0,0 +1,500 | |||
|
1 | # imports needed for the file convertion | |
|
2 | import os | |
|
3 | import sys | |
|
4 | import time | |
|
5 | import numpy as np | |
|
6 | ||
|
7 | import library2 | |
|
8 | ||
|
9 | class ABSClient: | |
|
10 | ||
|
11 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000): | |
|
12 | ||
|
13 | self.ipSource = ipSource | |
|
14 | self.ipDestino = ipDestino | |
|
15 | self.portDestino = portDestino | |
|
16 | ||
|
17 | self.createObjects() | |
|
18 | ||
|
19 | def createObjects(self): | |
|
20 | ||
|
21 | self.commObj = library2.TCPComm(self.ipSource, self.ipDestino, self.portDestino) | |
|
22 | ||
|
23 | def sendFile(self, filename): | |
|
24 | ||
|
25 | #From matriz to control module format | |
|
26 | self.FuncionMaestra_GeneraFormatoControlCentral(filename) | |
|
27 | FileName = "FormatoControlCentral.txt" | |
|
28 | F_Obj = open(FileName,"r") | |
|
29 | FileList = F_Obj.readlines() | |
|
30 | F_Obj.close() | |
|
31 | FileStr = "".join(FileList) | |
|
32 | data = FileStr | |
|
33 | ||
|
34 | self.commObj.open_socket() | |
|
35 | # self.commObj.sendData(cmd="SNDF", data=data, id = 117) | |
|
36 | self.commObj.sendData2(cmd="SNDF", data=data, ipDestino = self.ipDestino) | |
|
37 | # self.commObj.waitData() | |
|
38 | self.commObj.waitClient() | |
|
39 | self.commObj.close_socket() | |
|
40 | ||
|
41 | def changeBeam(self, newBeam): | |
|
42 | ||
|
43 | self.commObj.open_socket() | |
|
44 | # self.commObj.sendData(cmd="CHGB", data=newBeam, id = 117) | |
|
45 | self.commObj.sendData2(cmd="CHGB", data=newBeam, ipDestino = self.ipDestino) | |
|
46 | # self.commObj.waitData() | |
|
47 | self.commObj.waitClient() | |
|
48 | self.commObj.close_socket() | |
|
49 | ||
|
50 | def __writeFile(self, filename, data): | |
|
51 | ||
|
52 | fobj = open(filename,"w") | |
|
53 | fobj.writelines(data) | |
|
54 | fobj.close() | |
|
55 | ||
|
56 | def getStatus(self, data): | |
|
57 | ||
|
58 | self.commObj.open_socket() | |
|
59 | # self.commObj.sendData(cmd="ANST", data = data, id = 117) | |
|
60 | self.commObj.sendData2(cmd="ANST", data = data, ipDestino = self.ipDestino) | |
|
61 | # ipSource, ipDestino, cmd, data = self.commObj.waitData() | |
|
62 | ipSource, ipDestino, cmd, data = self.commObj.waitClient() | |
|
63 | self.commObj.close_socket() | |
|
64 | self.__writeFile("report.txt", data) | |
|
65 | ||
|
66 | ########## | |
|
67 | ||
|
68 | def FuncionMaestra_GeneraFormatoControlCentral(self,archivo): | |
|
69 | """ Funcion que genera un archivo para el control central""" | |
|
70 | ||
|
71 | # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/' | |
|
72 | CarpetaDeTrabajo = os.getcwd() + '/' | |
|
73 | #print CarpetaDeTrabajo | |
|
74 | #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/' | |
|
75 | ||
|
76 | def lst2string(lst): | |
|
77 | string='' | |
|
78 | for i in lst: | |
|
79 | string=string+i | |
|
80 | return string | |
|
81 | ||
|
82 | def string2lst(string): | |
|
83 | lst = [] | |
|
84 | for i in string: | |
|
85 | lst.append(i) | |
|
86 | return lst | |
|
87 | ||
|
88 | ||
|
89 | def file1(string, type): | |
|
90 | lst = string2lst(archivo) | |
|
91 | fin = -1 | |
|
92 | t = len(lst) | |
|
93 | for i in np.arange(-1,-t,-1): | |
|
94 | if lst[i]=='/': | |
|
95 | fin=i | |
|
96 | break | |
|
97 | if type == '1': | |
|
98 | nombre2 = lst[fin+1:] | |
|
99 | nombre2[-1]='s' | |
|
100 | nombre2 = lst2string(nombre2) | |
|
101 | return nombre2 | |
|
102 | if type == '2': | |
|
103 | nombre2 = lst[fin+1:] | |
|
104 | nombre2[-1]='1' | |
|
105 | nombre2 = lst2string(nombre2) | |
|
106 | return nombre2 | |
|
107 | ||
|
108 | ||
|
109 | def EliminaSaltoDeLinea(cadena): | |
|
110 | i = 0 | |
|
111 | for elemento in cadena: | |
|
112 | if elemento =='\n' or elemento =='\r': | |
|
113 | pass | |
|
114 | else: | |
|
115 | i=i+1 | |
|
116 | return cadena [:i] | |
|
117 | ||
|
118 | def NumeroDeExperimentos(path): | |
|
119 | fichero1=open(path,'r') | |
|
120 | cont=0 | |
|
121 | for cadena in fichero1: | |
|
122 | cont=cont+1 | |
|
123 | if cont==3: | |
|
124 | nexp='' | |
|
125 | pos=0 | |
|
126 | for elemento in cadena: | |
|
127 | pos=pos+1 | |
|
128 | if elemento=='=': | |
|
129 | nexp=int(cadena[pos:]) | |
|
130 | return nexp | |
|
131 | fichero1.close() | |
|
132 | ||
|
133 | def Paridad(numero): | |
|
134 | if numero%2==0: return 'par' | |
|
135 | elif numero%2==1: return 'impar' | |
|
136 | ||
|
137 | def EvaluaCadena(cadena): | |
|
138 | if len(cadena)>35: | |
|
139 | if cadena[-1]=='$': | |
|
140 | return cadena[-35:-2] | |
|
141 | elif cadena[-1]==']': | |
|
142 | return cadena[-34:-1] | |
|
143 | else: | |
|
144 | return None | |
|
145 | ||
|
146 | def GuardaEnLista(path): | |
|
147 | fichero=open(path,'r') | |
|
148 | lista=[] | |
|
149 | for cadena in fichero: | |
|
150 | cadena = EliminaSaltoDeLinea(cadena) | |
|
151 | cadena = EvaluaCadena(cadena) | |
|
152 | if cadena != None: | |
|
153 | lista.append(cadena) | |
|
154 | fichero.close() | |
|
155 | return lista | |
|
156 | ||
|
157 | def CreaFicherosPrevios(): | |
|
158 | vector = GuardaEnLista(archivo) | |
|
159 | for i in range(1,NumeroDeExperimentos(archivo)+1): | |
|
160 | fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w') | |
|
161 | for j in range(0,16): | |
|
162 | fichero.write(vector[j+16*(i-1)]+'\n') | |
|
163 | fichero.close() | |
|
164 | ||
|
165 | def CapturaValoresEnArchivo(path,polarizacion='up'): | |
|
166 | fichero =open(path,'r') | |
|
167 | cnt=0 | |
|
168 | lstup=[] | |
|
169 | lstdw=[] | |
|
170 | for cadena in fichero: | |
|
171 | cnt=cnt+1 | |
|
172 | if cnt==5: | |
|
173 | su01=cadena[17:20] | |
|
174 | su02=cadena[21:24] | |
|
175 | su03=cadena[25:28] | |
|
176 | su04=cadena[29:32] | |
|
177 | if cnt==6: | |
|
178 | su05=cadena[17:20] | |
|
179 | su06=cadena[21:24] | |
|
180 | su07=cadena[25:28] | |
|
181 | su08=cadena[29:32] | |
|
182 | if cnt==7: | |
|
183 | su09=cadena[17:20] | |
|
184 | su10=cadena[21:24] | |
|
185 | su11=cadena[25:28] | |
|
186 | su12=cadena[29:32] | |
|
187 | if cnt==8: | |
|
188 | su13=cadena[17:20] | |
|
189 | su14=cadena[21:24] | |
|
190 | su15=cadena[25:28] | |
|
191 | su16=cadena[29:32] | |
|
192 | if cnt==13: | |
|
193 | sd01=cadena[17:20] | |
|
194 | sd02=cadena[21:24] | |
|
195 | sd03=cadena[25:28] | |
|
196 | sd04=cadena[29:32] | |
|
197 | if cnt==14: | |
|
198 | sd05=cadena[17:20] | |
|
199 | sd06=cadena[21:24] | |
|
200 | sd07=cadena[25:28] | |
|
201 | sd08=cadena[29:32] | |
|
202 | if cnt==15: | |
|
203 | sd09=cadena[17:20] | |
|
204 | sd10=cadena[21:24] | |
|
205 | sd11=cadena[25:28] | |
|
206 | sd12=cadena[29:32] | |
|
207 | if cnt==16: | |
|
208 | sd13=cadena[17:20] | |
|
209 | sd14=cadena[21:24] | |
|
210 | sd15=cadena[25:28] | |
|
211 | sd16=cadena[29:32] | |
|
212 | lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] | |
|
213 | lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] | |
|
214 | if polarizacion=='up': | |
|
215 | return lstup | |
|
216 | elif polarizacion=='dw': | |
|
217 | return lstdw | |
|
218 | fichero.close() | |
|
219 | ||
|
220 | def CapturaValoresEnArchivo2(path,polarizacion='up'): | |
|
221 | fichero =open(path,'r') | |
|
222 | cnt=0 | |
|
223 | lstup=[] | |
|
224 | lstdw=[] | |
|
225 | for cadena in fichero: | |
|
226 | cnt=cnt+1 | |
|
227 | if cnt==1: | |
|
228 | nu01=cadena[1:4] | |
|
229 | nu02=cadena[5:8] | |
|
230 | nu03=cadena[9:12] | |
|
231 | nu04=cadena[13:16] | |
|
232 | eu01=cadena[17:20] | |
|
233 | eu02=cadena[21:24] | |
|
234 | eu03=cadena[25:28] | |
|
235 | eu04=cadena[29:32] | |
|
236 | if cnt==2: | |
|
237 | nu05=cadena[1:4] | |
|
238 | nu06=cadena[5:8] | |
|
239 | nu07=cadena[9:12] | |
|
240 | nu08=cadena[13:16] | |
|
241 | eu05=cadena[17:20] | |
|
242 | eu06=cadena[21:24] | |
|
243 | eu07=cadena[25:28] | |
|
244 | eu08=cadena[29:32] | |
|
245 | if cnt==3: | |
|
246 | nu09=cadena[1:4] | |
|
247 | nu10=cadena[5:8] | |
|
248 | nu11=cadena[9:12] | |
|
249 | nu12=cadena[13:16] | |
|
250 | eu09=cadena[17:20] | |
|
251 | eu10=cadena[21:24] | |
|
252 | eu11=cadena[25:28] | |
|
253 | eu12=cadena[29:32] | |
|
254 | if cnt==4: | |
|
255 | nu13=cadena[1:4] | |
|
256 | nu14=cadena[5:8] | |
|
257 | nu15=cadena[9:12] | |
|
258 | nu16=cadena[13:16] | |
|
259 | eu13=cadena[17:20] | |
|
260 | eu14=cadena[21:24] | |
|
261 | eu15=cadena[25:28] | |
|
262 | eu16=cadena[29:32] | |
|
263 | if cnt==5: | |
|
264 | wu01=cadena[1:4] | |
|
265 | wu02=cadena[5:8] | |
|
266 | wu03=cadena[9:12] | |
|
267 | wu04=cadena[13:16] | |
|
268 | su01=cadena[17:20] | |
|
269 | su02=cadena[21:24] | |
|
270 | su03=cadena[25:28] | |
|
271 | su04=cadena[29:32] | |
|
272 | if cnt==6: | |
|
273 | wu05=cadena[1:4] | |
|
274 | wu06=cadena[5:8] | |
|
275 | wu07=cadena[9:12] | |
|
276 | wu08=cadena[13:16] | |
|
277 | su05=cadena[17:20] | |
|
278 | su06=cadena[21:24] | |
|
279 | su07=cadena[25:28] | |
|
280 | su08=cadena[29:32] | |
|
281 | if cnt==7: | |
|
282 | wu09=cadena[1:4] | |
|
283 | wu10=cadena[5:8] | |
|
284 | wu11=cadena[9:12] | |
|
285 | wu12=cadena[13:16] | |
|
286 | su09=cadena[17:20] | |
|
287 | su10=cadena[21:24] | |
|
288 | su11=cadena[25:28] | |
|
289 | su12=cadena[29:32] | |
|
290 | if cnt==8: | |
|
291 | wu13=cadena[1:4] | |
|
292 | wu14=cadena[5:8] | |
|
293 | wu15=cadena[9:12] | |
|
294 | wu16=cadena[13:16] | |
|
295 | su13=cadena[17:20] | |
|
296 | su14=cadena[21:24] | |
|
297 | su15=cadena[25:28] | |
|
298 | su16=cadena[29:32] | |
|
299 | if cnt==9: | |
|
300 | nd01=cadena[1:4] | |
|
301 | nd02=cadena[5:8] | |
|
302 | nd03=cadena[9:12] | |
|
303 | nd04=cadena[13:16] | |
|
304 | ed01=cadena[17:20] | |
|
305 | ed02=cadena[21:24] | |
|
306 | ed03=cadena[25:28] | |
|
307 | ed04=cadena[29:32] | |
|
308 | if cnt==10: | |
|
309 | nd05=cadena[1:4] | |
|
310 | nd06=cadena[5:8] | |
|
311 | nd07=cadena[9:12] | |
|
312 | nd08=cadena[13:16] | |
|
313 | ed05=cadena[17:20] | |
|
314 | ed06=cadena[21:24] | |
|
315 | ed07=cadena[25:28] | |
|
316 | ed08=cadena[29:32] | |
|
317 | if cnt==11: | |
|
318 | nd09=cadena[1:4] | |
|
319 | nd10=cadena[5:8] | |
|
320 | nd11=cadena[9:12] | |
|
321 | nd12=cadena[13:16] | |
|
322 | ed09=cadena[17:20] | |
|
323 | ed10=cadena[21:24] | |
|
324 | ed11=cadena[25:28] | |
|
325 | ed12=cadena[29:32] | |
|
326 | if cnt==12: | |
|
327 | nd13=cadena[1:4] | |
|
328 | nd14=cadena[5:8] | |
|
329 | nd15=cadena[9:12] | |
|
330 | nd16=cadena[13:16] | |
|
331 | ed13=cadena[17:20] | |
|
332 | ed14=cadena[21:24] | |
|
333 | ed15=cadena[25:28] | |
|
334 | ed16=cadena[29:32] | |
|
335 | if cnt==13: | |
|
336 | wd01=cadena[1:4] | |
|
337 | wd02=cadena[5:8] | |
|
338 | wd03=cadena[9:12] | |
|
339 | wd04=cadena[13:16] | |
|
340 | sd01=cadena[17:20] | |
|
341 | sd02=cadena[21:24] | |
|
342 | sd03=cadena[25:28] | |
|
343 | sd04=cadena[29:32] | |
|
344 | if cnt==14: | |
|
345 | wd05=cadena[1:4] | |
|
346 | wd06=cadena[5:8] | |
|
347 | wd07=cadena[9:12] | |
|
348 | wd08=cadena[13:16] | |
|
349 | sd05=cadena[17:20] | |
|
350 | sd06=cadena[21:24] | |
|
351 | sd07=cadena[25:28] | |
|
352 | sd08=cadena[29:32] | |
|
353 | if cnt==15: | |
|
354 | wd09=cadena[1:4] | |
|
355 | wd10=cadena[5:8] | |
|
356 | wd11=cadena[9:12] | |
|
357 | wd12=cadena[13:16] | |
|
358 | sd09=cadena[17:20] | |
|
359 | sd10=cadena[21:24] | |
|
360 | sd11=cadena[25:28] | |
|
361 | sd12=cadena[29:32] | |
|
362 | if cnt==16: | |
|
363 | wd13=cadena[1:4] | |
|
364 | wd14=cadena[5:8] | |
|
365 | wd15=cadena[9:12] | |
|
366 | wd16=cadena[13:16] | |
|
367 | sd13=cadena[17:20] | |
|
368 | sd14=cadena[21:24] | |
|
369 | sd15=cadena[25:28] | |
|
370 | sd16=cadena[29:32] | |
|
371 | lst_n_up=[nu01,nu02,nu03,nu04,nu05,nu06,nu07,nu08,nu09,nu10,nu11,nu12,nu13,nu14,nu15,nu16] | |
|
372 | lst_n_dw=[nd01,nd02,nd03,nd04,nd05,nd06,nd07,nd08,nd09,nd10,nd11,nd12,nd13,nd14,nd15,nd16] | |
|
373 | lst_s_up=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] | |
|
374 | lst_s_dw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] | |
|
375 | lst_w_up=[wu01,wu02,wu03,wu04,wu05,wu06,wu07,wu08,wu09,wu10,wu11,wu12,wu13,wu14,wu15,wu16] | |
|
376 | lst_w_dw=[wd01,wd02,wd03,wd04,wd05,wd06,wd07,wd08,wd09,wd10,wd11,wd12,wd13,wd14,wd15,wd16] | |
|
377 | lst_e_up=[eu01,eu02,eu03,eu04,eu05,eu06,eu07,eu08,eu09,eu10,eu11,eu12,eu13,eu14,eu15,eu16] | |
|
378 | lst_e_dw=[ed01,ed02,ed03,ed04,ed05,ed06,ed07,ed08,ed09,ed10,ed11,ed12,ed13,ed14,ed15,ed16] | |
|
379 | ||
|
380 | lstup = lst_s_up + lst_w_up + lst_n_up + lst_e_up | |
|
381 | lstdw = lst_s_dw + lst_w_dw + lst_n_up + lst_e_up | |
|
382 | ||
|
383 | if polarizacion=='up': | |
|
384 | return lstup | |
|
385 | elif polarizacion=='dw': | |
|
386 | return lstdw | |
|
387 | fichero.close() | |
|
388 | ||
|
389 | ||
|
390 | def CreaFormatoFinal(): | |
|
391 | ne=NumeroDeExperimentos(archivo) | |
|
392 | ||
|
393 | #nombre01 = file1(archivo,'1') | |
|
394 | nombre02 = file1(archivo,'2') | |
|
395 | fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') | |
|
396 | fichero.write(nombre02+'\n') | |
|
397 | fichero.write(str(ne)+'\n') | |
|
398 | for i in range(1,17): | |
|
399 | ||
|
400 | if i<10: | |
|
401 | nmod = '0'+str(i) | |
|
402 | else: nmod = str(i) | |
|
403 | ||
|
404 | ||
|
405 | fichero.write('S'+nmod+'\n') | |
|
406 | for j in range(1,ne+1): | |
|
407 | ruta=CarpetaDeTrabajo+str(j)+'.txt' | |
|
408 | lu=CapturaValoresEnArchivo(ruta,polarizacion='up') | |
|
409 | ld=CapturaValoresEnArchivo(ruta,polarizacion='dw') | |
|
410 | part1='' | |
|
411 | part2='' | |
|
412 | if lu[i-1]=='1.0': part1='000' | |
|
413 | if lu[i-1]=='2.0': part1='001' | |
|
414 | if lu[i-1]=='3.0': part1='010' | |
|
415 | if lu[i-1]=='0.0': part1='011' | |
|
416 | if lu[i-1]=='0.5': part1='100' | |
|
417 | if lu[i-1]=='1.5': part1='101' | |
|
418 | if lu[i-1]=='2.5': part1='110' | |
|
419 | if lu[i-1]=='3.5': part1='111' | |
|
420 | if ld[i-1]=='1.0': part2='000' | |
|
421 | if ld[i-1]=='2.0': part2='001' | |
|
422 | if ld[i-1]=='3.0': part2='010' | |
|
423 | if ld[i-1]=='0.0': part2='011' | |
|
424 | if ld[i-1]=='0.5': part2='100' | |
|
425 | if ld[i-1]=='1.5': part2='101' | |
|
426 | if ld[i-1]=='2.5': part2='110' | |
|
427 | if ld[i-1]=='3.5': part2='111' | |
|
428 | fichero.write(part1+part2+'\n') | |
|
429 | fichero.write('------'+'\n') | |
|
430 | fichero.close() | |
|
431 | ||
|
432 | def CreaFormatoFinal2(): | |
|
433 | ne=NumeroDeExperimentos(archivo) | |
|
434 | ||
|
435 | #nombre01 = file1(archivo,'1') | |
|
436 | nombre02 = file1(archivo,'2') | |
|
437 | fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') | |
|
438 | fichero.write(nombre02+'\n') | |
|
439 | fichero.write(str(ne)+'\n') | |
|
440 | ||
|
441 | for i in range(1,65): | |
|
442 | ||
|
443 | if i<10: | |
|
444 | nmod = '0'+str(i) | |
|
445 | else: nmod = str(i) | |
|
446 | ||
|
447 | fichero.write("ABS_" + nmod+'\n') | |
|
448 | ||
|
449 | for j in range(1,ne+1): | |
|
450 | ruta=CarpetaDeTrabajo+str(j)+'.txt' | |
|
451 | lu=CapturaValoresEnArchivo2(ruta,polarizacion='up') | |
|
452 | ld=CapturaValoresEnArchivo2(ruta,polarizacion='dw') | |
|
453 | part1='' | |
|
454 | part2='' | |
|
455 | if lu[i-1]=='1.0': part1='000' | |
|
456 | if lu[i-1]=='2.0': part1='001' | |
|
457 | if lu[i-1]=='3.0': part1='010' | |
|
458 | if lu[i-1]=='0.0': part1='011' | |
|
459 | if lu[i-1]=='0.5': part1='100' | |
|
460 | if lu[i-1]=='1.5': part1='101' | |
|
461 | if lu[i-1]=='2.5': part1='110' | |
|
462 | if lu[i-1]=='3.5': part1='111' | |
|
463 | if ld[i-1]=='1.0': part2='000' | |
|
464 | if ld[i-1]=='2.0': part2='001' | |
|
465 | if ld[i-1]=='3.0': part2='010' | |
|
466 | if ld[i-1]=='0.0': part2='011' | |
|
467 | if ld[i-1]=='0.5': part2='100' | |
|
468 | if ld[i-1]=='1.5': part2='101' | |
|
469 | if ld[i-1]=='2.5': part2='110' | |
|
470 | if ld[i-1]=='3.5': part2='111' | |
|
471 | fichero.write(part1+part2+'\n') | |
|
472 | fichero.write('------'+'\n') | |
|
473 | fichero.close() | |
|
474 | ||
|
475 | def EliminaArchivosEnLaCarpeta(): | |
|
476 | ne=NumeroDeExperimentos(archivo) | |
|
477 | for i in range(1,ne+1): | |
|
478 | os.remove(CarpetaDeTrabajo+str(i)+'.txt') | |
|
479 | ||
|
480 | CreaFicherosPrevios() | |
|
481 | CreaFormatoFinal2() | |
|
482 | EliminaArchivosEnLaCarpeta() | |
|
483 | ||
|
484 | ########## | |
|
485 | ||
|
486 | if __name__ == '__main__': | |
|
487 | ||
|
488 | filename = "experimento1.abs" | |
|
489 | ||
|
490 | absObj = ABSClient() | |
|
491 | # absObj.sendFile(filename) | |
|
492 | # absObj.changeBeam("0") | |
|
493 | absObj.changeBeam("1") | |
|
494 | # absObj.changeBeam("2") | |
|
495 | # absObj.changeBeam("3") | |
|
496 | # absObj.changeBeam("4") | |
|
497 | # absObj.changeBeam("5") | |
|
498 | # absObj.changeBeam("6") | |
|
499 | # absObj.changeBeam("7") | |
|
500 | # absObj.getStatus(5) No newline at end of file |
@@ -0,0 +1,97 | |||
|
1 | import library3 | |
|
2 | import os.path | |
|
3 | ||
|
4 | class ABSClient(object): | |
|
5 | ||
|
6 | def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000): | |
|
7 | ||
|
8 | self.ipSource = ipSource | |
|
9 | self.iDSource = iDSource | |
|
10 | self.ipDestino = ipDestino | |
|
11 | self.iDDestino = iDDestino | |
|
12 | self.portDestino = portDestino | |
|
13 | ||
|
14 | self.createObjects() | |
|
15 | ||
|
16 | def createObjects(self): | |
|
17 | ||
|
18 | self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino) | |
|
19 | #self.wFiles = library3.FilesStuff() | |
|
20 | ||
|
21 | def __ConnectionWithCentralControl(self, cmd, data): | |
|
22 | ||
|
23 | self.commObj.open_socket() | |
|
24 | self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino) | |
|
25 | ipSource, ipDestino, cmd, output = self.commObj.waitData() | |
|
26 | self.commObj.close_socket() | |
|
27 | ||
|
28 | return output | |
|
29 | ||
|
30 | # def abs2ControlModuleFormatFile(self, filename): | |
|
31 | # | |
|
32 | # #From matriz to control module format | |
|
33 | # self.wFiles.toCentralControlFormat(filename) | |
|
34 | # FileName = "CentralControlFormat.txt" | |
|
35 | # F_Obj = open(FileName,"r") | |
|
36 | # FileList = F_Obj.readlines() | |
|
37 | # F_Obj.close() | |
|
38 | # FileStr = "".join(FileList) | |
|
39 | # | |
|
40 | # return FileStr | |
|
41 | ||
|
42 | def sendFile(self, filename): | |
|
43 | ||
|
44 | data = self.__readFile(filename) | |
|
45 | self.__ConnectionWithCentralControl(cmd = "SNDF", data = data) | |
|
46 | ||
|
47 | def changeBeam(self, newBeam): | |
|
48 | ||
|
49 | self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam) | |
|
50 | ||
|
51 | def __writeFile(self, filename, data): | |
|
52 | ||
|
53 | fobj = open(filename,"w") | |
|
54 | fobj.writelines(data) | |
|
55 | fobj.close() | |
|
56 | ||
|
57 | def __readFile(self, filename): | |
|
58 | ||
|
59 | fobj = open(filename,"r") | |
|
60 | listData = fobj.readlines() | |
|
61 | fobj.close() | |
|
62 | tmp = "".join(listData) | |
|
63 | #Adding filename to the begining of the data | |
|
64 | newfilename = os.path.split(filename)[1] | |
|
65 | #data = filename + '\n' + tmp | |
|
66 | data = newfilename + '\n' + tmp | |
|
67 | return data | |
|
68 | ||
|
69 | ||
|
70 | def getControlModuleStatus(self, data): | |
|
71 | ||
|
72 | data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data) | |
|
73 | self.__writeFile("report.txt", data) | |
|
74 | ||
|
75 | def getControlModulePhase(self, opt, u = "50", pw = "10"): | |
|
76 | ||
|
77 | if opt == '0': | |
|
78 | data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/') | |
|
79 | elif opt == '1': | |
|
80 | data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/') | |
|
81 | elif opt == '2': | |
|
82 | data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/') | |
|
83 | else: | |
|
84 | data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/') | |
|
85 | # self.__writeFile("report.txt", data) | |
|
86 | ||
|
87 | def getConnectionStatus(self): | |
|
88 | ||
|
89 | data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none") | |
|
90 | self.__writeFile("connection_status.txt", data) | |
|
91 | ||
|
92 | if __name__ == '__main__': | |
|
93 | ||
|
94 | filename = "experimento1.abs" | |
|
95 | ||
|
96 | absObj = ABSClient() | |
|
97 | absObj.sendFile(filename) |
@@ -0,0 +1,231 | |||
|
1 | title ='MST-ISR 2009 (NS-Up)' | |
|
2 | ||
|
3 | #Experiments = 12 | |
|
4 | ||
|
5 | 1 = | |
|
6 | [[0.5,0.5,0.5,0.5,1.5,0.5,0.5,0.5],$ | |
|
7 | [2.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0],$ | |
|
8 | [0.0,0.5,0.5,0.5,0.0,0.5,0.5,0.5],$ | |
|
9 | [3.5,0.5,0.5,0.5,2.5,0.5,0.5,0.5],$ | |
|
10 | [1.0,1.0,1.0,1.0,1.0,2.0,3.0,0.0],$ | |
|
11 | [0.5,0.5,0.5,1.0,2.0,3.0,0.0,1.0],$ | |
|
12 | [1.0,1.0,1.0,1.0,3.0,0.0,1.0,2.0],$ | |
|
13 | [0.5,0.5,0.5,0.5,0.0,1.0,2.0,3.0]] | |
|
14 | ||
|
15 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
16 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
17 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
18 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
19 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
20 | [0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0],$ | |
|
21 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
22 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]] | |
|
23 | ||
|
24 | 2 = | |
|
25 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
26 | [1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0],$ | |
|
27 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
28 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
29 | [1.0,1.0,1.0,1.0,2.0,3.0,0.0,1.0],$ | |
|
30 | [0.5,0.5,0.5,1.0,3.0,0.0,1.0,2.0],$ | |
|
31 | [1.0,1.0,1.0,1.0,0.0,1.0,2.0,3.0],$ | |
|
32 | [0.5,0.5,0.5,0.5,1.0,2.0,3.0,0.0]] | |
|
33 | ||
|
34 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
35 | [1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0],$ | |
|
36 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
37 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
38 | [1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0],$ | |
|
39 | [0.5,0.5,0.5,1.0,2.0,2.0,2.0,2.0],$ | |
|
40 | [1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0],$ | |
|
41 | [0.5,0.5,0.5,0.5,2.0,2.0,2.0,2.0]] | |
|
42 | ||
|
43 | 3 = | |
|
44 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
45 | [1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
46 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
47 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
48 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
49 | [0.5,0.5,0.5,1.0,3.0,3.0,3.0,3.0],$ | |
|
50 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
51 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]] | |
|
52 | ||
|
53 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
54 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
55 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
56 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
57 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
58 | [0.5,0.5,0.5,1.0,3.0,3.0,3.0,3.0],$ | |
|
59 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
60 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]] | |
|
61 | ||
|
62 | 4 = | |
|
63 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
64 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
65 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
66 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
67 | [1.0,1.0,1.0,1.0,0.0,1.0,2.0,3.0],$ | |
|
68 | [0.5,0.5,0.5,1.0,1.0,2.0,3.0,0.0],$ | |
|
69 | [1.0,1.0,1.0,1.0,2.0,3.0,0.0,1.0],$ | |
|
70 | [0.5,0.5,0.5,0.5,3.0,0.0,1.0,2.0]] | |
|
71 | ||
|
72 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
73 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
74 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
75 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
76 | [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ | |
|
77 | [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0],$ | |
|
78 | [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ | |
|
79 | [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]] | |
|
80 | ||
|
81 | 5 = | |
|
82 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
83 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
84 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
85 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
86 | [1.0,1.0,1.0,1.0,0.5,1.5,2.5,3.5],$ | |
|
87 | [0.5,0.5,0.5,1.0,1.5,2.5,3.5,0.5],$ | |
|
88 | [1.0,1.0,1.0,1.0,2.5,3.5,0.5,1.5],$ | |
|
89 | [0.5,0.5,0.5,0.5,3.5,0.5,1.5,2.5]] | |
|
90 | ||
|
91 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
92 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
93 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
94 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
95 | [1.0,1.0,1.0,1.0,0.5,0.5,0.5,0.5],$ | |
|
96 | [0.5,0.5,0.5,1.0,0.5,0.5,0.5,0.5],$ | |
|
97 | [1.0,1.0,1.0,1.0,0.5,0.5,0.5,0.5],$ | |
|
98 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]] | |
|
99 | ||
|
100 | 6= | |
|
101 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
102 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
103 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
104 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
105 | [1.0,1.0,1.0,1.0,1.5,1.5,1.5,1.5],$ | |
|
106 | [0.5,0.5,0.5,1.0,1.5,1.5,1.5,1.5],$ | |
|
107 | [1.0,1.0,1.0,1.0,1.5,1.5,1.5,1.5],$ | |
|
108 | [0.5,0.5,0.5,0.5,1.5,1.5,1.5,1.5]] | |
|
109 | ||
|
110 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
111 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
112 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
113 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
114 | [1.0,1.0,1.0,1.0,1.5,1.5,1.5,1.5],$ | |
|
115 | [0.5,0.5,0.5,1.0,1.5,1.5,1.5,1.5],$ | |
|
116 | [1.0,1.0,1.0,1.0,1.5,1.5,1.5,1.5],$ | |
|
117 | [0.5,0.5,0.5,0.5,1.5,1.5,1.5,1.5]] | |
|
118 | ||
|
119 | 7 = | |
|
120 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
121 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
122 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
123 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
124 | [1.0,1.0,1.0,1.0,2.5,2.5,2.5,2.5],$ | |
|
125 | [0.5,0.5,0.5,1.0,2.5,2.5,2.5,2.5],$ | |
|
126 | [1.0,1.0,1.0,1.0,2.5,2.5,2.5,2.5],$ | |
|
127 | [0.5,0.5,0.5,0.5,2.5,2.5,2.5,2.5]] | |
|
128 | ||
|
129 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
130 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
131 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
132 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
133 | [1.0,1.0,1.0,1.0,2.5,2.5,2.5,2.5],$ | |
|
134 | [0.5,0.5,0.5,1.0,2.5,2.5,2.5,2.5],$ | |
|
135 | [1.0,1.0,1.0,1.0,2.5,2.5,2.5,2.5],$ | |
|
136 | [0.5,0.5,0.5,0.5,2.5,2.5,2.5,2.5]] | |
|
137 | 8 = | |
|
No newline at end of file | ||
|
138 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
139 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
140 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
141 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
142 | [1.0,1.0,1.0,1.0,3.5,3.5,3.5,3.5],$ | |
|
143 | [0.5,0.5,0.5,1.0,3.5,3.5,3.5,3.5],$ | |
|
144 | [1.0,1.0,1.0,1.0,3.5,3.5,3.5,3.5],$ | |
|
145 | [0.5,0.5,0.5,0.5,3.5,3.5,3.5,3.5]] | |
|
146 | ||
|
147 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
148 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
149 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
150 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
151 | [1.0,1.0,1.0,1.0,3.5,3.5,3.5,3.5],$ | |
|
152 | [0.5,0.5,0.5,1.0,3.5,3.5,3.5,3.5],$ | |
|
153 | [1.0,1.0,1.0,1.0,3.5,3.5,3.5,3.5],$ | |
|
154 | [0.5,0.5,0.5,0.5,3.5,3.5,3.5,3.5]] | |
|
155 | ||
|
156 | 9 = | |
|
157 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
158 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
159 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
160 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
161 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
162 | [0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0],$ | |
|
163 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
164 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]] | |
|
165 | ||
|
166 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
167 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
168 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
169 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
170 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
171 | [0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0],$ | |
|
172 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
173 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]] | |
|
174 | ||
|
175 | 10 = | |
|
176 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
177 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
178 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
179 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
180 | [1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0],$ | |
|
181 | [0.5,0.5,0.5,1.0,2.0,2.0,2.0,2.0],$ | |
|
182 | [1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0],$ | |
|
183 | [0.5,0.5,0.5,0.5,2.0,2.0,2.0,2.0]] | |
|
184 | ||
|
185 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
186 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
187 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
188 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
189 | [1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0],$ | |
|
190 | [0.5,0.5,0.5,1.0,2.0,2.0,2.0,2.0],$ | |
|
191 | [1.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0],$ | |
|
192 | [0.5,0.5,0.5,0.5,2.0,2.0,2.0,2.0]] | |
|
193 | ||
|
194 | 11 = | |
|
195 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
196 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
197 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
198 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
199 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
200 | [0.5,0.5,0.5,1.0,3.0,3.0,3.0,3.0],$ | |
|
201 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
202 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]] | |
|
203 | ||
|
204 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
205 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
206 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
207 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
208 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
209 | [0.5,0.5,0.5,1.0,3.0,3.0,3.0,3.0],$ | |
|
210 | [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ | |
|
211 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]] | |
|
212 | ||
|
213 | 12 = | |
|
214 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
215 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
216 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
217 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
218 | [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ | |
|
219 | [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0],$ | |
|
220 | [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ | |
|
221 | [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]] | |
|
222 | ||
|
223 | [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
224 | [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ | |
|
225 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
226 | [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ | |
|
227 | [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ | |
|
228 | [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0],$ | |
|
229 | [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ | |
|
230 | [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]] | |
|
231 |
@@ -0,0 +1,209 | |||
|
1 | #import tftpy | |
|
2 | import socket | |
|
3 | ||
|
4 | class UDPComm: | |
|
5 | ||
|
6 | __HEADER = "ABS" | |
|
7 | ||
|
8 | def __init__(self, ipSource, ipDestino, portDestino, asServer=False): | |
|
9 | ||
|
10 | self.ipSource = ipSource | |
|
11 | self.ipDestino = ipDestino | |
|
12 | self.portDestino = portDestino | |
|
13 | self.addr = (ipDestino,portDestino) | |
|
14 | self.answer = "none" #test | |
|
15 | self.mode = "none" | |
|
16 | ||
|
17 | ||
|
18 | self.openSocket(asServer) | |
|
19 | ||
|
20 | def openSocket(self, asServer): | |
|
21 | ||
|
22 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |
|
23 | self.socket_c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0) | |
|
24 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |
|
25 | ||
|
26 | if asServer: | |
|
27 | self.configAsServer() | |
|
28 | self.mode = "server" | |
|
29 | else: | |
|
30 | self.configAsClient() | |
|
31 | self.mode = "client" | |
|
32 | ||
|
33 | def configAsClient(self): | |
|
34 | #Configurar broadcast | |
|
35 | self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
|
36 | ||
|
37 | def configAsServer(self): | |
|
38 | ||
|
39 | self.socket_c.bind(self.addr) | |
|
40 | print "\nServer initialized" | |
|
41 | ||
|
42 | def waitData(self, nbytes = 16384): | |
|
43 | ||
|
44 | print "\nWaiting some data" | |
|
45 | trama_rx, self.answer = self.socket_c.recvfrom(nbytes) | |
|
46 | print "\nThis socket has received some data from:" | |
|
47 | print self.answer | |
|
48 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |
|
49 | ||
|
50 | return ipSource, ipDestino, cmd, data | |
|
51 | ||
|
52 | def sendData(self, cmd, data): | |
|
53 | ||
|
54 | if self.portDestino == 7000: | |
|
55 | trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":" | |
|
56 | else: | |
|
57 | trama_tx = data | |
|
58 | ||
|
59 | if self.mode == "client": | |
|
60 | destiny = self.addr | |
|
61 | else: | |
|
62 | destiny = self.answer | |
|
63 | # Send messages | |
|
64 | if(self.socket_c.sendto(trama_tx, destiny)): | |
|
65 | print "Sending message:[" + trama_tx + "] to " + str(destiny) | |
|
66 | ||
|
67 | def __getTrama(self, trama): | |
|
68 | ||
|
69 | FrameList = trama.split(':') | |
|
70 | ||
|
71 | header = FrameList[0] | |
|
72 | ipSource = FrameList[1] | |
|
73 | ipDestino = FrameList[2] | |
|
74 | cmd = FrameList[3] | |
|
75 | data = FrameList[4] | |
|
76 | trash = FrameList[5] | |
|
77 | ||
|
78 | return ipSource, ipDestino, cmd, data | |
|
79 | ||
|
80 | class TCPComm: | |
|
81 | ||
|
82 | __HEADER = "JRO" | |
|
83 | __TYPE = "ABS" | |
|
84 | ||
|
85 | def __init__(self, ipSource, ipDestino, portDestino, asServer=False): | |
|
86 | ||
|
87 | self.ipSource = ipSource | |
|
88 | self.ipDestino = ipDestino | |
|
89 | self.portDestino = portDestino | |
|
90 | self.addr = (ipDestino,portDestino) | |
|
91 | ||
|
92 | self.sc = "none" | |
|
93 | self.answer = "none" #test | |
|
94 | self.mode = "none" | |
|
95 | self.len = 0 | |
|
96 | self.crc = 0 | |
|
97 | ||
|
98 | self.openSocket(asServer) | |
|
99 | ||
|
100 | def openSocket(self, asServer): | |
|
101 | ||
|
102 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |
|
103 | # self.socket_c = socket.socket() | |
|
104 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |
|
105 | ||
|
106 | if asServer: | |
|
107 | self.socket_c = socket.socket() | |
|
108 | # self.configAsServer() | |
|
109 | self.socket_c.bind(self.addr) | |
|
110 | self.mode = "server" | |
|
111 | else: | |
|
112 | # self.configAsClient() | |
|
113 | self.mode = "client" #Socket is opened at the sendData function | |
|
114 | ||
|
115 | # def configAsClient(self): | |
|
116 | #Buscar broadcast TCP | |
|
117 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
|
118 | # self.socket_c.connect(self.addr) | |
|
119 | # pass | |
|
120 | ||
|
121 | # def configAsServer(self): | |
|
122 | # | |
|
123 | # self.socket_c.bind(self.addr) | |
|
124 | ||
|
125 | def waitData(self, nbytes = 1024): | |
|
126 | ||
|
127 | print "\nWaiting some client." | |
|
128 | ||
|
129 | if self.mode == "client": | |
|
130 | # Short data through ethernet | |
|
131 | trama_rx = self.socket_c.recv(nbytes) | |
|
132 | else: | |
|
133 | self.socket_c.listen(1) | |
|
134 | sc, addr = self.socket_c.accept() | |
|
135 | self.sc = sc | |
|
136 | self.answer = addr | |
|
137 | # Big data through ethernet | |
|
138 | trama_rx = "" | |
|
139 | while True: | |
|
140 | tmp = self.sc.recv(nbytes) | |
|
141 | trama_rx = trama_rx + tmp | |
|
142 | if trama_rx[-4:] == "quit": | |
|
143 | break | |
|
144 | ||
|
145 | print "\nThis socket has received some data." | |
|
146 | ||
|
147 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |
|
148 | ||
|
149 | return ipSource, ipDestino, cmd, data | |
|
150 | ||
|
151 | def sendData(self, cmd, data, id): | |
|
152 | ||
|
153 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) | |
|
154 | ||
|
155 | if self.portDestino == 7000: | |
|
156 | trama_tx = trama_tx + ":" + "quit" | |
|
157 | # Send messages | |
|
158 | if self.mode == "client": | |
|
159 | host = "192.168.1." + str(id) | |
|
160 | self.socket_c.connect((host, self.portDestino)) | |
|
161 | self.socket_c.send(trama_tx) | |
|
162 | else: | |
|
163 | self.sc.send(trama_tx) | |
|
164 | print "Sending message:[" + trama_tx + "]" | |
|
165 | ||
|
166 | def __getTrama(self, trama): | |
|
167 | ||
|
168 | FrameList = trama.split(':') | |
|
169 | ||
|
170 | header = FrameList[0] | |
|
171 | TypeOfInstrument = FrameList[1] | |
|
172 | ipSource = FrameList[2] | |
|
173 | ipDestino = FrameList[3] | |
|
174 | len = FrameList[4] | |
|
175 | cmd = FrameList[5] | |
|
176 | data = FrameList[6] | |
|
177 | crc = FrameList[7] | |
|
178 | trash = FrameList[8] | |
|
179 | ||
|
180 | return ipSource, ipDestino, cmd, data | |
|
181 | ||
|
182 | def close_socket(self): | |
|
183 | self.socket_c.close() | |
|
184 | ||
|
185 | def open_socket(self): | |
|
186 | self.socket_c = socket.socket() | |
|
187 | ||
|
188 | #class FTPComm: | |
|
189 | # | |
|
190 | # ftp_servidor = 'ftp.servidor.com' | |
|
191 | # ftp_usuario = 'miusuario' | |
|
192 | # ftp_clave = 'miclave' | |
|
193 | # ftp_raiz = '/public_html' | |
|
194 | # | |
|
195 | # def __init__(self): | |
|
196 | # | |
|
197 | # self.client = tftpy.TftpClient(self.ftp_servidor, '69') | |
|
198 | # | |
|
199 | # | |
|
200 | # def sendFile(self, filename): | |
|
201 | # | |
|
202 | # self.client.upload(filename) | |
|
203 | # | |
|
204 | #if __name__ == '__main__': | |
|
205 | # | |
|
206 | # obj = FTPComm() | |
|
207 | ||
|
208 | ||
|
209 | No newline at end of file |
@@ -0,0 +1,165 | |||
|
1 | import socket | |
|
2 | ||
|
3 | class TCPComm: | |
|
4 | ||
|
5 | __HEADER = "JRO" | |
|
6 | __TYPE = "ABS" | |
|
7 | ||
|
8 | def __init__(self, ipSource, ipDestino, portDestino, asServer=False): | |
|
9 | ||
|
10 | self.ipSource = ipSource | |
|
11 | self.ipDestino = ipDestino | |
|
12 | self.portDestino = portDestino | |
|
13 | self.addr = (ipDestino,portDestino) | |
|
14 | ||
|
15 | self.sc = "none" | |
|
16 | self.answer = "none" #test | |
|
17 | self.asServer = False | |
|
18 | self.len = 0 | |
|
19 | self.crc = 0 | |
|
20 | ||
|
21 | self.openSocket(asServer) | |
|
22 | ||
|
23 | def openSocket(self, asServer): | |
|
24 | ||
|
25 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |
|
26 | # self.socket_c = socket.socket() | |
|
27 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |
|
28 | ||
|
29 | if asServer: | |
|
30 | self.socket_c = socket.socket() | |
|
31 | # self.configAsServer() | |
|
32 | self.socket_c.bind(self.addr) | |
|
33 | self.asServer = True | |
|
34 | else: | |
|
35 | # self.configAsClient() | |
|
36 | self.asServer = False #Socket is opened at the sendData function | |
|
37 | ||
|
38 | # def configAsClient(self): | |
|
39 | #Buscar broadcast TCP | |
|
40 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
|
41 | # self.socket_c.connect(self.addr) | |
|
42 | # pass | |
|
43 | ||
|
44 | # def configAsServer(self): | |
|
45 | # | |
|
46 | # self.socket_c.bind(self.addr) | |
|
47 | ||
|
48 | def waitData(self, nbytes = 1024): | |
|
49 | ||
|
50 | print "\nWaiting some client." | |
|
51 | ||
|
52 | if self.asServer == False: | |
|
53 | # Short data through ethernet | |
|
54 | trama_rx = self.socket_c.recv(nbytes) | |
|
55 | else: | |
|
56 | self.socket_c.listen(1) | |
|
57 | sc, addr = self.socket_c.accept() | |
|
58 | self.sc = sc | |
|
59 | self.answer = addr | |
|
60 | # Big data through ethernet | |
|
61 | trama_rx = "" | |
|
62 | while True: | |
|
63 | tmp = self.sc.recv(nbytes) | |
|
64 | trama_rx = trama_rx + tmp | |
|
65 | if trama_rx[-4:] == "quit": | |
|
66 | break | |
|
67 | ||
|
68 | print "\nThis socket has received some data." | |
|
69 | ||
|
70 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |
|
71 | ||
|
72 | return ipSource, ipDestino, cmd, data | |
|
73 | ||
|
74 | def waitServer(self, nbytes = 1024): | |
|
75 | ||
|
76 | print "\nWaiting some client." | |
|
77 | self.socket_c.listen(1) | |
|
78 | sc, addr = self.socket_c.accept() | |
|
79 | self.sc = sc | |
|
80 | self.answer = addr | |
|
81 | # Big data through ethernet | |
|
82 | trama_rx = "" | |
|
83 | while True: | |
|
84 | tmp = self.sc.recv(nbytes) | |
|
85 | trama_rx = trama_rx + tmp | |
|
86 | if trama_rx[-4:] == "quit": | |
|
87 | break | |
|
88 | ||
|
89 | print "\nThis socket has received some data from: " + str(self.answer) | |
|
90 | ||
|
91 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |
|
92 | ||
|
93 | return ipSource, ipDestino, cmd, data | |
|
94 | ||
|
95 | def waitClient(self, nbytes = 1024): | |
|
96 | ||
|
97 | print "\nWaiting the server." | |
|
98 | # Short data through ethernet | |
|
99 | trama_rx = self.socket_c.recv(nbytes) | |
|
100 | ||
|
101 | print "\nThis socket has received this data: " + str(trama_rx) | |
|
102 | ||
|
103 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |
|
104 | ||
|
105 | return ipSource, ipDestino, cmd, data | |
|
106 | ||
|
107 | def sendData(self, cmd, data, id): | |
|
108 | ||
|
109 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + \ | |
|
110 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) | |
|
111 | ||
|
112 | if self.portDestino == 7000: | |
|
113 | trama_tx = trama_tx + ":" + "quit" | |
|
114 | # Send messages | |
|
115 | if self.asServer == False: | |
|
116 | host = "192.168.1." + str(id) | |
|
117 | self.socket_c.connect((host, self.portDestino)) | |
|
118 | self.socket_c.send(trama_tx) | |
|
119 | else: | |
|
120 | self.sc.send(trama_tx) | |
|
121 | print "Sending message:[" + trama_tx + "]" | |
|
122 | ||
|
123 | def sendData2(self, cmd, data, ipDestino): | |
|
124 | ||
|
125 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ | |
|
126 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" | |
|
127 | ||
|
128 | if self.asServer == True: | |
|
129 | self.SendAsServer(trama_tx) | |
|
130 | else: | |
|
131 | self.SendAsClient(ipDestino, trama_tx) | |
|
132 | ||
|
133 | def SendAsServer(self, trama_tx): | |
|
134 | ||
|
135 | self.sc.send(trama_tx) | |
|
136 | print "Sending message:[" + trama_tx + "] to: " + str(self.answer) | |
|
137 | ||
|
138 | ||
|
139 | def SendAsClient(self, ipDestino, trama_tx): | |
|
140 | ||
|
141 | self.socket_c.connect((ipDestino, self.portDestino)) | |
|
142 | self.socket_c.send(trama_tx) | |
|
143 | print "Sending message:[" + trama_tx + "] to: " + ipDestino | |
|
144 | ||
|
145 | def __getTrama(self, trama): | |
|
146 | ||
|
147 | FrameList = trama.split(':') | |
|
148 | ||
|
149 | header = FrameList[0] | |
|
150 | TypeOfInstrument = FrameList[1] | |
|
151 | ipSource = FrameList[2] | |
|
152 | ipDestino = FrameList[3] | |
|
153 | len = FrameList[4] | |
|
154 | cmd = FrameList[5] | |
|
155 | data = FrameList[6] | |
|
156 | crc = FrameList[7] | |
|
157 | trash = FrameList[8] | |
|
158 | ||
|
159 | return ipSource, ipDestino, cmd, data | |
|
160 | ||
|
161 | def close_socket(self): | |
|
162 | self.socket_c.close() | |
|
163 | ||
|
164 | def open_socket(self): | |
|
165 | self.socket_c = socket.socket() No newline at end of file |
This diff has been collapsed as it changes many lines, (537 lines changed) Show them Hide them | |||
@@ -0,0 +1,537 | |||
|
1 | # Needed for the FilesStuff class | |
|
2 | import os | |
|
3 | import numpy as np | |
|
4 | # Needed for the TCPComm class | |
|
5 | import socket | |
|
6 | ||
|
7 | class TCPComm: | |
|
8 | ||
|
9 | __HEADER = "JRO" | |
|
10 | __TYPE = "ABS" | |
|
11 | ||
|
12 | def __init__(self, ipSource, iDSource, ipDestino, iDDestino, portDestino, asServer=False): | |
|
13 | ||
|
14 | self.ipSource = ipSource | |
|
15 | self.iDSource = iDSource | |
|
16 | self.ipDestino = ipDestino | |
|
17 | self.iDDestino = iDDestino | |
|
18 | self.portDestino = portDestino | |
|
19 | self.addr = (ipDestino,portDestino) | |
|
20 | ||
|
21 | self.sc = "none" | |
|
22 | self.answer = "none" #test | |
|
23 | self.asServer = False | |
|
24 | self.len = "000000" | |
|
25 | self.crc = "0" | |
|
26 | ||
|
27 | self.openSocket(asServer) | |
|
28 | ||
|
29 | def openSocket(self, asServer): | |
|
30 | ||
|
31 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |
|
32 | # self.socket_c = socket.socket() | |
|
33 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |
|
34 | ||
|
35 | if asServer: | |
|
36 | self.socket_c = socket.socket() | |
|
37 | # self.configAsServer() | |
|
38 | self.socket_c.bind(self.addr) | |
|
39 | self.asServer = True | |
|
40 | else: | |
|
41 | # self.configAsClient() | |
|
42 | self.asServer = False #Socket is opened at the sendData function | |
|
43 | ||
|
44 | # def configAsClient(self): | |
|
45 | #Buscar broadcast TCP | |
|
46 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
|
47 | # self.socket_c.connect(self.addr) | |
|
48 | # pass | |
|
49 | ||
|
50 | # def configAsServer(self): | |
|
51 | # | |
|
52 | # self.socket_c.bind(self.addr) | |
|
53 | ||
|
54 | def waitData(self): | |
|
55 | if self.asServer == True: | |
|
56 | trama_rx, l = self.waitAsServer() | |
|
57 | else: | |
|
58 | trama_rx, l = self.waitAsClient() | |
|
59 | ||
|
60 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx, l) | |
|
61 | ||
|
62 | return ipSource, ipDestino, cmd, data | |
|
63 | ||
|
64 | def waitAsClient2(self, nbytes = 1024): | |
|
65 | print "\nWaiting the server." | |
|
66 | # Short data through ethernet | |
|
67 | trama_rx = self.socket_c.recv(nbytes) | |
|
68 | print "\nThis socket has received this data: " + str(trama_rx) | |
|
69 | ||
|
70 | return trama_rx | |
|
71 | ||
|
72 | def waitAsServer2(self, nbytes = 1024): | |
|
73 | print "\nWaiting some client." | |
|
74 | self.socket_c.listen(1) | |
|
75 | sc, addr = self.socket_c.accept() | |
|
76 | self.sc = sc | |
|
77 | self.answer = addr | |
|
78 | # Big data through ethernet | |
|
79 | trama_rx = "" | |
|
80 | while True: | |
|
81 | tmp = self.sc.recv(nbytes) | |
|
82 | trama_rx = trama_rx + tmp | |
|
83 | if trama_rx[-4:] == "quit": | |
|
84 | break | |
|
85 | ||
|
86 | print "\nThis socket has received some data from: " + str(self.answer) | |
|
87 | ||
|
88 | return trama_rx | |
|
89 | ||
|
90 | def waitAsServer(self, nbytes = 1024): | |
|
91 | print "\nWaiting some client." | |
|
92 | self.socket_c.listen(1) | |
|
93 | sc, addr = self.socket_c.accept() | |
|
94 | self.sc = sc | |
|
95 | self.answer = addr | |
|
96 | # Big data through ethernet | |
|
97 | cnt = 0; | |
|
98 | first = 0; | |
|
99 | trama_rx = "" | |
|
100 | while True: | |
|
101 | tmp = self.sc.recv(nbytes) | |
|
102 | trama_rx = trama_rx + tmp | |
|
103 | cnt = len(trama_rx) | |
|
104 | if first == 0: | |
|
105 | first = 1 | |
|
106 | lng = int(trama_rx[20:26]) | |
|
107 | frm_lng= lng + 31 # 31 bytes are fixed and added to the data size to get the frame size | |
|
108 | if cnt == frm_lng: | |
|
109 | break | |
|
110 | ||
|
111 | print "\nThis socket has received some data from: " + str(self.answer) | |
|
112 | ||
|
113 | return trama_rx, lng | |
|
114 | ||
|
115 | def waitAsClient(self, nbytes = 1024): | |
|
116 | print "\nWaiting the server." | |
|
117 | # Short data through ethernet | |
|
118 | try: | |
|
119 | trama_rx = self.socket_c.recv(nbytes) | |
|
120 | lng = int(trama_rx[20:26]) | |
|
121 | except: | |
|
122 | print "Waiting error" | |
|
123 | trama_rx = "Error" | |
|
124 | lng = 0 | |
|
125 | else: | |
|
126 | print "\nThis socket has received this data: " + str(trama_rx) | |
|
127 | ||
|
128 | return trama_rx, lng | |
|
129 | ||
|
130 | def sendData2(self, cmd, data, ipDestino): | |
|
131 | ||
|
132 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ | |
|
133 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" | |
|
134 | ||
|
135 | if self.asServer == True: | |
|
136 | self.SendAsServer(trama_tx) | |
|
137 | else: | |
|
138 | self.SendAsClient(ipDestino, trama_tx) | |
|
139 | ||
|
140 | def sendData(self, cmd, data, ipDestino): | |
|
141 | ||
|
142 | trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ | |
|
143 | self.iDDestino + self.len + str(cmd) + str(data) + self.crc | |
|
144 | ||
|
145 | self.len = self.int2str(len(data)) | |
|
146 | ||
|
147 | trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ | |
|
148 | self.iDDestino + self.len + str(cmd) + str(data) + self.crc | |
|
149 | ||
|
150 | if self.asServer == True: | |
|
151 | self.SendAsServer(trama_tx) | |
|
152 | else: | |
|
153 | self.SendAsClient(ipDestino, trama_tx) | |
|
154 | ||
|
155 | def SendAsServer(self, trama_tx): | |
|
156 | ||
|
157 | self.sc.send(trama_tx) | |
|
158 | print "Sending message:[" + trama_tx + "] to: " + str(self.answer) | |
|
159 | ||
|
160 | ||
|
161 | def SendAsClient(self, ipDestino, trama_tx): | |
|
162 | ||
|
163 | try: | |
|
164 | self.socket_c.connect((ipDestino, self.portDestino)) | |
|
165 | except: | |
|
166 | print "Connection error with:" + ipDestino | |
|
167 | else: | |
|
168 | self.socket_c.send(trama_tx) | |
|
169 | print "Sending message:[" + trama_tx + "] to: " + ipDestino | |
|
170 | ||
|
171 | def __getTrama2(self, trama): | |
|
172 | ||
|
173 | FrameList = trama.split(':') | |
|
174 | ||
|
175 | header = FrameList[0] | |
|
176 | TypeOfInstrument = FrameList[1] | |
|
177 | ipSource = FrameList[2] | |
|
178 | ipDestino = FrameList[3] | |
|
179 | len = FrameList[4] | |
|
180 | cmd = FrameList[5] | |
|
181 | data = FrameList[6] | |
|
182 | crc = FrameList[7] | |
|
183 | trash = FrameList[8] | |
|
184 | ||
|
185 | return ipSource, ipDestino, cmd, data | |
|
186 | ||
|
187 | def __getTrama(self, trama, l): | |
|
188 | ||
|
189 | header = trama[0:3] | |
|
190 | TypeOfInstrument = trama[3:6] | |
|
191 | ipSource = trama[6:13] | |
|
192 | ipDestino = trama[13:20] | |
|
193 | len = trama[20:26] | |
|
194 | cmd = trama[26:30] | |
|
195 | data = trama[30:30+int(l)] | |
|
196 | crc = trama[30+ int(l):] | |
|
197 | ||
|
198 | return ipSource, ipDestino, cmd, data | |
|
199 | ||
|
200 | def close_socket(self): | |
|
201 | self.socket_c.close() | |
|
202 | ||
|
203 | def open_socket(self): | |
|
204 | self.socket_c = socket.socket() | |
|
205 | ||
|
206 | def int2str(self, n): | |
|
207 | ||
|
208 | str_n = str(n) | |
|
209 | l_n = len(str_n) | |
|
210 | if l_n == 1: | |
|
211 | str_n = "00000" + str_n | |
|
212 | elif l_n == 2: | |
|
213 | str_n = "0000" + str_n | |
|
214 | elif l_n == 3: | |
|
215 | str_n = "000" + str_n | |
|
216 | elif l_n == 4: | |
|
217 | str_n = "00" + str_n | |
|
218 | elif l_n == 5: | |
|
219 | str_n = "0" + str_n | |
|
220 | return str_n | |
|
221 | ||
|
222 | class FilesStuff(): | |
|
223 | ||
|
224 | def lst2string(self, lst): | |
|
225 | string='' | |
|
226 | for i in lst: | |
|
227 | string=string+i | |
|
228 | return string | |
|
229 | ||
|
230 | def string2lst(self, string): | |
|
231 | lst = [] | |
|
232 | for i in string: | |
|
233 | lst.append(i) | |
|
234 | return lst | |
|
235 | ||
|
236 | ||
|
237 | def file1(self, filename, type): | |
|
238 | lst = self.string2lst(filename) | |
|
239 | fin = -1 | |
|
240 | t = len(lst) | |
|
241 | for i in np.arange(-1,-t,-1): | |
|
242 | if lst[i]=='/': | |
|
243 | fin=i | |
|
244 | break | |
|
245 | if type == '1': | |
|
246 | nombre2 = lst[fin+1:] | |
|
247 | nombre2[-1]='s' | |
|
248 | nombre2 = self.lst2string(nombre2) | |
|
249 | return nombre2 | |
|
250 | if type == '2': | |
|
251 | nombre2 = lst[fin+1:] | |
|
252 | nombre2[-1]='1' | |
|
253 | nombre2 = self.lst2string(nombre2) | |
|
254 | return nombre2 | |
|
255 | ||
|
256 | ||
|
257 | def EliminaSaltoDeLinea(self,cadena): | |
|
258 | i = 0 | |
|
259 | for elemento in cadena: | |
|
260 | if elemento =='\n' or elemento =='\r': | |
|
261 | pass | |
|
262 | else: | |
|
263 | i=i+1 | |
|
264 | return cadena [:i] | |
|
265 | ||
|
266 | def NumeroDeExperimentos(self, path): | |
|
267 | fichero1=open(path,'r') | |
|
268 | cont=0 | |
|
269 | for cadena in fichero1: | |
|
270 | cont=cont+1 | |
|
271 | if cont==3: | |
|
272 | nexp='' | |
|
273 | pos=0 | |
|
274 | for elemento in cadena: | |
|
275 | pos=pos+1 | |
|
276 | if elemento=='=': | |
|
277 | nexp=int(cadena[pos:]) | |
|
278 | return nexp | |
|
279 | fichero1.close() | |
|
280 | ||
|
281 | def Paridad(self, numero): | |
|
282 | if numero%2==0: return 'par' | |
|
283 | elif numero%2==1: return 'impar' | |
|
284 | ||
|
285 | def EvaluaCadena(self,cadena): | |
|
286 | if len(cadena)>35: | |
|
287 | if cadena[-1]=='$': | |
|
288 | return cadena[-35:-2] | |
|
289 | elif cadena[-1]==']': | |
|
290 | return cadena[-34:-1] | |
|
291 | else: | |
|
292 | return None | |
|
293 | ||
|
294 | def GuardaEnLista(self,path): | |
|
295 | fichero=open(path,'r') | |
|
296 | lista=[] | |
|
297 | for cadena in fichero: | |
|
298 | cadena = self.EliminaSaltoDeLinea(cadena) | |
|
299 | cadena = self.EvaluaCadena(cadena) | |
|
300 | if cadena != None: | |
|
301 | lista.append(cadena) | |
|
302 | fichero.close() | |
|
303 | return lista | |
|
304 | ||
|
305 | def CreaFicherosPrevios(self, path, archivo): | |
|
306 | vector = self.GuardaEnLista(archivo) | |
|
307 | for i in range(1,self.NumeroDeExperimentos(archivo)+1): | |
|
308 | fichero =open(path + str(i)+ '.txt','w') | |
|
309 | for j in range(0,16): | |
|
310 | fichero.write(vector[j+16*(i-1)]+'\n') | |
|
311 | fichero.close() | |
|
312 | ||
|
313 | def CapturaValoresEnArchivo(self, path, polarizacion='up'): | |
|
314 | fichero =open(path,'r') | |
|
315 | cnt=0 | |
|
316 | lstup=[] | |
|
317 | lstdw=[] | |
|
318 | for cadena in fichero: | |
|
319 | cnt=cnt+1 | |
|
320 | if cnt==1: | |
|
321 | nu01=cadena[1:4] | |
|
322 | nu02=cadena[5:8] | |
|
323 | nu03=cadena[9:12] | |
|
324 | nu04=cadena[13:16] | |
|
325 | eu01=cadena[17:20] | |
|
326 | eu02=cadena[21:24] | |
|
327 | eu03=cadena[25:28] | |
|
328 | eu04=cadena[29:32] | |
|
329 | if cnt==2: | |
|
330 | nu05=cadena[1:4] | |
|
331 | nu06=cadena[5:8] | |
|
332 | nu07=cadena[9:12] | |
|
333 | nu08=cadena[13:16] | |
|
334 | eu05=cadena[17:20] | |
|
335 | eu06=cadena[21:24] | |
|
336 | eu07=cadena[25:28] | |
|
337 | eu08=cadena[29:32] | |
|
338 | if cnt==3: | |
|
339 | nu09=cadena[1:4] | |
|
340 | nu10=cadena[5:8] | |
|
341 | nu11=cadena[9:12] | |
|
342 | nu12=cadena[13:16] | |
|
343 | eu09=cadena[17:20] | |
|
344 | eu10=cadena[21:24] | |
|
345 | eu11=cadena[25:28] | |
|
346 | eu12=cadena[29:32] | |
|
347 | if cnt==4: | |
|
348 | nu13=cadena[1:4] | |
|
349 | nu14=cadena[5:8] | |
|
350 | nu15=cadena[9:12] | |
|
351 | nu16=cadena[13:16] | |
|
352 | eu13=cadena[17:20] | |
|
353 | eu14=cadena[21:24] | |
|
354 | eu15=cadena[25:28] | |
|
355 | eu16=cadena[29:32] | |
|
356 | if cnt==5: | |
|
357 | wu01=cadena[1:4] | |
|
358 | wu02=cadena[5:8] | |
|
359 | wu03=cadena[9:12] | |
|
360 | wu04=cadena[13:16] | |
|
361 | su01=cadena[17:20] | |
|
362 | su02=cadena[21:24] | |
|
363 | su03=cadena[25:28] | |
|
364 | su04=cadena[29:32] | |
|
365 | if cnt==6: | |
|
366 | wu05=cadena[1:4] | |
|
367 | wu06=cadena[5:8] | |
|
368 | wu07=cadena[9:12] | |
|
369 | wu08=cadena[13:16] | |
|
370 | su05=cadena[17:20] | |
|
371 | su06=cadena[21:24] | |
|
372 | su07=cadena[25:28] | |
|
373 | su08=cadena[29:32] | |
|
374 | if cnt==7: | |
|
375 | wu09=cadena[1:4] | |
|
376 | wu10=cadena[5:8] | |
|
377 | wu11=cadena[9:12] | |
|
378 | wu12=cadena[13:16] | |
|
379 | su09=cadena[17:20] | |
|
380 | su10=cadena[21:24] | |
|
381 | su11=cadena[25:28] | |
|
382 | su12=cadena[29:32] | |
|
383 | if cnt==8: | |
|
384 | wu13=cadena[1:4] | |
|
385 | wu14=cadena[5:8] | |
|
386 | wu15=cadena[9:12] | |
|
387 | wu16=cadena[13:16] | |
|
388 | su13=cadena[17:20] | |
|
389 | su14=cadena[21:24] | |
|
390 | su15=cadena[25:28] | |
|
391 | su16=cadena[29:32] | |
|
392 | if cnt==9: | |
|
393 | nd01=cadena[1:4] | |
|
394 | nd02=cadena[5:8] | |
|
395 | nd03=cadena[9:12] | |
|
396 | nd04=cadena[13:16] | |
|
397 | ed01=cadena[17:20] | |
|
398 | ed02=cadena[21:24] | |
|
399 | ed03=cadena[25:28] | |
|
400 | ed04=cadena[29:32] | |
|
401 | if cnt==10: | |
|
402 | nd05=cadena[1:4] | |
|
403 | nd06=cadena[5:8] | |
|
404 | nd07=cadena[9:12] | |
|
405 | nd08=cadena[13:16] | |
|
406 | ed05=cadena[17:20] | |
|
407 | ed06=cadena[21:24] | |
|
408 | ed07=cadena[25:28] | |
|
409 | ed08=cadena[29:32] | |
|
410 | if cnt==11: | |
|
411 | nd09=cadena[1:4] | |
|
412 | nd10=cadena[5:8] | |
|
413 | nd11=cadena[9:12] | |
|
414 | nd12=cadena[13:16] | |
|
415 | ed09=cadena[17:20] | |
|
416 | ed10=cadena[21:24] | |
|
417 | ed11=cadena[25:28] | |
|
418 | ed12=cadena[29:32] | |
|
419 | if cnt==12: | |
|
420 | nd13=cadena[1:4] | |
|
421 | nd14=cadena[5:8] | |
|
422 | nd15=cadena[9:12] | |
|
423 | nd16=cadena[13:16] | |
|
424 | ed13=cadena[17:20] | |
|
425 | ed14=cadena[21:24] | |
|
426 | ed15=cadena[25:28] | |
|
427 | ed16=cadena[29:32] | |
|
428 | if cnt==13: | |
|
429 | wd01=cadena[1:4] | |
|
430 | wd02=cadena[5:8] | |
|
431 | wd03=cadena[9:12] | |
|
432 | wd04=cadena[13:16] | |
|
433 | sd01=cadena[17:20] | |
|
434 | sd02=cadena[21:24] | |
|
435 | sd03=cadena[25:28] | |
|
436 | sd04=cadena[29:32] | |
|
437 | if cnt==14: | |
|
438 | wd05=cadena[1:4] | |
|
439 | wd06=cadena[5:8] | |
|
440 | wd07=cadena[9:12] | |
|
441 | wd08=cadena[13:16] | |
|
442 | sd05=cadena[17:20] | |
|
443 | sd06=cadena[21:24] | |
|
444 | sd07=cadena[25:28] | |
|
445 | sd08=cadena[29:32] | |
|
446 | if cnt==15: | |
|
447 | wd09=cadena[1:4] | |
|
448 | wd10=cadena[5:8] | |
|
449 | wd11=cadena[9:12] | |
|
450 | wd12=cadena[13:16] | |
|
451 | sd09=cadena[17:20] | |
|
452 | sd10=cadena[21:24] | |
|
453 | sd11=cadena[25:28] | |
|
454 | sd12=cadena[29:32] | |
|
455 | if cnt==16: | |
|
456 | wd13=cadena[1:4] | |
|
457 | wd14=cadena[5:8] | |
|
458 | wd15=cadena[9:12] | |
|
459 | wd16=cadena[13:16] | |
|
460 | sd13=cadena[17:20] | |
|
461 | sd14=cadena[21:24] | |
|
462 | sd15=cadena[25:28] | |
|
463 | sd16=cadena[29:32] | |
|
464 | blck_1_up = [nu01,nu02,nu03,nu04,eu01,eu02,eu03,eu04,nu05,nu06,nu07,nu08,eu05,eu06,eu07,eu08] | |
|
465 | blck_1_dw = [nd01,nd02,nd03,nd04,ed01,ed02,ed03,ed04,nd05,nd06,nd07,nd08,ed05,ed06,ed07,ed08] | |
|
466 | blck_2_up = [nu09,nu10,nu11,nu12,eu09,eu10,eu11,eu12,nu13,nu14,nu15,nu16,eu13,eu14,eu15,eu16] | |
|
467 | blck_2_dw = [nd09,nd10,nd11,nd12,ed09,ed10,ed11,ed12,nd13,nd14,nd15,nd16,ed13,ed14,ed15,ed16] | |
|
468 | blck_3_up = [wu01,wu02,wu03,wu04,su01,su02,su03,su04,wu05,wu06,wu07,wu08,su05,su06,su07,su08] | |
|
469 | blck_3_dw = [wd01,wd02,wd03,wd04,sd01,sd02,sd03,sd04,wd05,wd06,wd07,wd08,sd05,sd06,sd07,sd08] | |
|
470 | blck_4_up = [wu09,wu10,wu11,wu12,su09,su10,su11,su12,wu13,wu14,wu15,wu16,su13,su14,su15,su16] | |
|
471 | blck_4_dw = [wd09,wd10,wd11,wd12,sd09,sd10,sd11,sd12,wd13,wd14,wd15,wd16,sd13,sd14,sd15,sd16] | |
|
472 | ||
|
473 | lstup = blck_1_up + blck_2_up + blck_3_up + blck_4_up | |
|
474 | lstdw = blck_1_dw + blck_2_dw + blck_3_dw + blck_4_dw | |
|
475 | ||
|
476 | if polarizacion=='up': | |
|
477 | return lstup | |
|
478 | elif polarizacion=='dw': | |
|
479 | return lstdw | |
|
480 | fichero.close() | |
|
481 | ||
|
482 | def CreaFormatoFinal(self, path, filename): | |
|
483 | ne=self.NumeroDeExperimentos(filename) | |
|
484 | ||
|
485 | #nombre01 = file1(archivo,'1') | |
|
486 | nombre02 = self.file1(filename,'2') | |
|
487 | fichero=open(path + 'CentralControlFormat.txt','w') | |
|
488 | fichero.write(nombre02+'\n') | |
|
489 | fichero.write(str(ne)+'\n') | |
|
490 | ||
|
491 | for i in range(1,65): | |
|
492 | ||
|
493 | if i<10: | |
|
494 | nmod = '0'+str(i) | |
|
495 | else: nmod = str(i) | |
|
496 | ||
|
497 | fichero.write("ABS_" + nmod+'\n') | |
|
498 | ||
|
499 | for j in range(1,ne+1): | |
|
500 | ruta=path+str(j)+'.txt' | |
|
501 | lu=self.CapturaValoresEnArchivo(ruta,polarizacion='up') | |
|
502 | ld=self.CapturaValoresEnArchivo(ruta,polarizacion='dw') | |
|
503 | part1='' | |
|
504 | part2='' | |
|
505 | if lu[i-1]=='1.0': part1='000' | |
|
506 | if lu[i-1]=='2.0': part1='001' | |
|
507 | if lu[i-1]=='3.0': part1='010' | |
|
508 | if lu[i-1]=='0.0': part1='011' | |
|
509 | if lu[i-1]=='0.5': part1='100' | |
|
510 | if lu[i-1]=='1.5': part1='101' | |
|
511 | if lu[i-1]=='2.5': part1='110' | |
|
512 | if lu[i-1]=='3.5': part1='111' | |
|
513 | if ld[i-1]=='1.0': part2='000' | |
|
514 | if ld[i-1]=='2.0': part2='001' | |
|
515 | if ld[i-1]=='3.0': part2='010' | |
|
516 | if ld[i-1]=='0.0': part2='011' | |
|
517 | if ld[i-1]=='0.5': part2='100' | |
|
518 | if ld[i-1]=='1.5': part2='101' | |
|
519 | if ld[i-1]=='2.5': part2='110' | |
|
520 | if ld[i-1]=='3.5': part2='111' | |
|
521 | fichero.write(part1+part2+'\n') | |
|
522 | fichero.write('------'+'\n') | |
|
523 | fichero.close() | |
|
524 | ||
|
525 | def EliminaArchivosEnLaCarpeta(self, path, filename): | |
|
526 | ne=self.NumeroDeExperimentos(filename) | |
|
527 | for i in range(1,ne+1): | |
|
528 | os.remove(path + str(i)+'.txt') | |
|
529 | ||
|
530 | ||
|
531 | def toCentralControlFormat(self, filename): | |
|
532 | """ Funcion que genera un archivo para el control central""" | |
|
533 | ||
|
534 | path = os.getcwd() + '/' | |
|
535 | self.CreaFicherosPrevios(path, filename) | |
|
536 | self.CreaFormatoFinal(path, filename) | |
|
537 | self.EliminaArchivosEnLaCarpeta(path, filename) |
@@ -0,0 +1,66 | |||
|
1 | Status of modules | |
|
2 | ---------------- | |
|
3 | 192.168.1.1 [1 1] | |
|
4 | 192.168.1.2 [0 0] | |
|
5 | 192.168.1.3 [0 0] | |
|
6 | 192.168.1.4 [0 0] | |
|
7 | 192.168.1.5 [0 0] | |
|
8 | 192.168.1.6 [0 0] | |
|
9 | 192.168.1.7 [0 0] | |
|
10 | 192.168.1.8 [0 0] | |
|
11 | 192.168.1.9 [0 0] | |
|
12 | 192.168.1.10 [0 0] | |
|
13 | 192.168.1.11 [0 0] | |
|
14 | 192.168.1.12 [0 0] | |
|
15 | 192.168.1.13 [0 0] | |
|
16 | 192.168.1.14 [0 0] | |
|
17 | 192.168.1.15 [0 0] | |
|
18 | 192.168.1.16 [0 0] | |
|
19 | 192.168.1.17 [0 0] | |
|
20 | 192.168.1.18 [0 0] | |
|
21 | 192.168.1.19 [0 0] | |
|
22 | 192.168.1.20 [0 0] | |
|
23 | 192.168.1.21 [0 0] | |
|
24 | 192.168.1.22 [0 0] | |
|
25 | 192.168.1.23 [0 0] | |
|
26 | 192.168.1.24 [0 0] | |
|
27 | 192.168.1.25 [0 0] | |
|
28 | 192.168.1.26 [0 0] | |
|
29 | 192.168.1.27 [0 0] | |
|
30 | 192.168.1.28 [0 0] | |
|
31 | 192.168.1.29 [0 0] | |
|
32 | 192.168.1.30 [0 0] | |
|
33 | 192.168.1.31 [0 0] | |
|
34 | 192.168.1.32 [0 0] | |
|
35 | 192.168.1.33 [0 0] | |
|
36 | 192.168.1.34 [0 0] | |
|
37 | 192.168.1.35 [0 0] | |
|
38 | 192.168.1.36 [0 0] | |
|
39 | 192.168.1.37 [0 0] | |
|
40 | 192.168.1.38 [0 0] | |
|
41 | 192.168.1.39 [0 0] | |
|
42 | 192.168.1.40 [0 0] | |
|
43 | 192.168.1.41 [0 0] | |
|
44 | 192.168.1.42 [0 0] | |
|
45 | 192.168.1.43 [0 0] | |
|
46 | 192.168.1.44 [0 0] | |
|
47 | 192.168.1.45 [0 0] | |
|
48 | 192.168.1.46 [0 0] | |
|
49 | 192.168.1.47 [0 0] | |
|
50 | 192.168.1.48 [0 0] | |
|
51 | 192.168.1.49 [0 0] | |
|
52 | 192.168.1.50 [0 0] | |
|
53 | 192.168.1.51 [0 0] | |
|
54 | 192.168.1.52 [0 0] | |
|
55 | 192.168.1.53 [0 0] | |
|
56 | 192.168.1.54 [0 0] | |
|
57 | 192.168.1.55 [0 0] | |
|
58 | 192.168.1.56 [0 0] | |
|
59 | 192.168.1.57 [0 0] | |
|
60 | 192.168.1.58 [0 0] | |
|
61 | 192.168.1.59 [0 0] | |
|
62 | 192.168.1.60 [0 0] | |
|
63 | 192.168.1.61 [0 0] | |
|
64 | 192.168.1.62 [0 0] | |
|
65 | 192.168.1.63 [0 0] | |
|
66 | 192.168.1.64 [0 0] |
@@ -0,0 +1,281 | |||
|
1 | import os | |
|
2 | import library | |
|
3 | import time | |
|
4 | ||
|
5 | class ABSServer: | |
|
6 | ||
|
7 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None): | |
|
8 | ||
|
9 | self.ipSource = ipSource | |
|
10 | self.ipDestino = ipDestino | |
|
11 | self.portDestino = portDestino | |
|
12 | ||
|
13 | self.ipDestino2 = ipDestino2 | |
|
14 | self.portDestino2 = portDestino2 | |
|
15 | ||
|
16 | self.ftpPortDestino = ftpPortDestino | |
|
17 | self.experiment_name = "default" | |
|
18 | self.tx_buffer = "default" | |
|
19 | ||
|
20 | self.createObjects() | |
|
21 | ||
|
22 | def createObjects(self): | |
|
23 | ||
|
24 | asServer = True | |
|
25 | self.commServerObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino, asServer) | |
|
26 | self.commClientObj = library.UDPComm(self.ipSource, self.ipDestino2, self.portDestino2) | |
|
27 | #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino) | |
|
28 | ||
|
29 | ||
|
30 | def waitRequest(self): | |
|
31 | ||
|
32 | ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData() | |
|
33 | ||
|
34 | datarpta = "OK" | |
|
35 | ||
|
36 | if cmd == "SNDF": | |
|
37 | self.sendFile2Modules() | |
|
38 | pass | |
|
39 | ||
|
40 | if cmd == "CHGB": | |
|
41 | self.changeBeam() | |
|
42 | ||
|
43 | if cmd == "ANST": | |
|
44 | self.getStatus(mode=3) | |
|
45 | datarpta = self.tx_buffer | |
|
46 | ||
|
47 | self.commServerObj.sendData(cmd=cmd, data=datarpta) | |
|
48 | ||
|
49 | def checkModule(self, address): | |
|
50 | ||
|
51 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" | |
|
52 | status = os.system(cmd) | |
|
53 | ||
|
54 | if status == 256: | |
|
55 | return False | |
|
56 | ||
|
57 | return True | |
|
58 | ||
|
59 | def __writeReport(self, enaModules): | |
|
60 | ||
|
61 | status_array = ["Status of modules\n"] | |
|
62 | status_array.append("----------------\n") | |
|
63 | ||
|
64 | for address in range(1,65): | |
|
65 | if address in enaModules: | |
|
66 | # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n") | |
|
67 | status_array.append("192.168.1." + str(address) + " [1 1]\n") | |
|
68 | else: | |
|
69 | status_array.append("192.168.1." + str(address) + " [0 0]\n") | |
|
70 | ||
|
71 | f = open("module_status.txt","w") | |
|
72 | f.writelines(status_array) | |
|
73 | f.close() | |
|
74 | ||
|
75 | def checkAntenna(self): | |
|
76 | ||
|
77 | """ | |
|
78 | Direccion de los modulos de las antenas: | |
|
79 | ||
|
80 | Norte : 01-16 | |
|
81 | Este : 17-32 | |
|
82 | Oeste: : 33-48 | |
|
83 | Sur : 49-64 | |
|
84 | ||
|
85 | """ | |
|
86 | ||
|
87 | enaModules = [] | |
|
88 | ||
|
89 | for address in range(1,65): | |
|
90 | if self.checkModule(address): | |
|
91 | enaModules.append(address) | |
|
92 | ||
|
93 | self.__writeReport(enaModules) | |
|
94 | return enaModules | |
|
95 | ||
|
96 | def sendFile2Modules(self): | |
|
97 | ||
|
98 | #Needed for the loop | |
|
99 | rx_frame_list = self.datarx.split('\n',2) | |
|
100 | ||
|
101 | self.experiment_name = rx_frame_list[0] | |
|
102 | experiment_number = rx_frame_list[1] | |
|
103 | str_control_modules = rx_frame_list[2] | |
|
104 | ||
|
105 | lst_control_modules = str_control_modules.split("------\n") | |
|
106 | ||
|
107 | enaModules = self.checkAntenna() | |
|
108 | ||
|
109 | for address in range(1,65): | |
|
110 | ||
|
111 | if address not in enaModules: | |
|
112 | continue | |
|
113 | ||
|
114 | self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1]) | |
|
115 | ||
|
116 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name | |
|
117 | print cmd | |
|
118 | os.system(cmd) | |
|
119 | ||
|
120 | self.__loadFile() | |
|
121 | ||
|
122 | def __writeModuleFile(self, filename, str): | |
|
123 | ||
|
124 | fobj = open(filename,"w") | |
|
125 | fobj.write(filename + "\n") | |
|
126 | fobj.write("------\n") | |
|
127 | fobj.write(str) | |
|
128 | fobj.write("------\n") | |
|
129 | fobj.close() | |
|
130 | ||
|
131 | def __readModuleFile(self, filename): | |
|
132 | ||
|
133 | fobj1 = open(filename,"r") | |
|
134 | file_list_1 = fobj1.readlines() | |
|
135 | fobj1.close() | |
|
136 | content_str = ''.join(file_list_1[2:-1]) | |
|
137 | ||
|
138 | return content_str | |
|
139 | ||
|
140 | def __loadFile(self): | |
|
141 | ||
|
142 | #Working with the UDP socket | |
|
143 | self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") | |
|
144 | self.commClientObj.sendData("none", "CAMBIA:0:") | |
|
145 | ||
|
146 | def changeBeam(self): | |
|
147 | ||
|
148 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0") | |
|
149 | self.commClientObj.sendData("none", "CAMBIA:" + self.datarx + ":") | |
|
150 | ||
|
151 | def getStatus(self,mode): | |
|
152 | ||
|
153 | if mode == 1: | |
|
154 | self.__getStsMode1() | |
|
155 | elif mode == 2: | |
|
156 | self.__getStsMode2() | |
|
157 | else: | |
|
158 | self.__getStsMode3() | |
|
159 | ||
|
160 | ||
|
161 | def __getStsMode1(self): | |
|
162 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") | |
|
163 | self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") | |
|
164 | seconds = int (self.datarx) | |
|
165 | # Give 5 seconds to the control modules | |
|
166 | time.sleep(seconds) | |
|
167 | # Checking the module connection | |
|
168 | module_list = self.connection_status(10) | |
|
169 | #Generating the complete report | |
|
170 | module = 1 | |
|
171 | number_of_modules = 16 | |
|
172 | filename1 = "Verificacion" | |
|
173 | filename2 = "report.txt" | |
|
174 | fobj2 = open(filename2,"w") | |
|
175 | fobj2.write("Verification_file\n") | |
|
176 | fobj2.write("-----------------\n") | |
|
177 | fobj2.close() | |
|
178 | while module <= number_of_modules: | |
|
179 | if module_list[module -1] == "1": | |
|
180 | #Preparing and doing the tftp command | |
|
181 | cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1 | |
|
182 | print cmd | |
|
183 | os.system(cmd) | |
|
184 | # Getting data from the control module file | |
|
185 | fobj1 = open(filename1,"r") | |
|
186 | file_list_1 = fobj1.readlines() | |
|
187 | fobj1.close() | |
|
188 | content = file_list_1[2:-1] | |
|
189 | # | |
|
190 | fobj2 = open(filename2,"a") | |
|
191 | if base == 10: | |
|
192 | fobj2.write("S" + str(module) + "\n") | |
|
193 | else: | |
|
194 | fobj2.write("N" + str(module) + "\n") | |
|
195 | fobj2.writelines(content) | |
|
196 | fobj2.write("------\n") | |
|
197 | fobj2.close() | |
|
198 | module = module + 1 | |
|
199 | ||
|
200 | def __getStsMode2(self): | |
|
201 | ||
|
202 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") | |
|
203 | self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") | |
|
204 | seconds = int (self.datarx) | |
|
205 | # Give 5 seconds to the control modules | |
|
206 | time.sleep(seconds) | |
|
207 | # Checking the module connection | |
|
208 | enaModules = self.checkAntenna() | |
|
209 | #Generating the complete report | |
|
210 | filename1 = "Verificacion" | |
|
211 | line1 = "Verification_file\n" | |
|
212 | line2 = "-----------------\n" | |
|
213 | report_list = [line1, line2] | |
|
214 | ||
|
215 | for address in range(1,65): | |
|
216 | ||
|
217 | if address not in enaModules: | |
|
218 | continue | |
|
219 | #Preparing and doing the tftp command | |
|
220 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1 | |
|
221 | print cmd | |
|
222 | os.system(cmd) | |
|
223 | #Sub_header | |
|
224 | report_list.append("ABS_" + str(address) + "\n") | |
|
225 | # Content | |
|
226 | fobj1 = open(filename1,"r") | |
|
227 | file_list_1 = fobj1.readlines() | |
|
228 | fobj1.close() | |
|
229 | content = ''.join(file_list_1[2:-1]) | |
|
230 | report_list.append(content) | |
|
231 | #Ending | |
|
232 | report_list.append("------\n") | |
|
233 | #print "\nFinalizado" | |
|
234 | self.tx_buffer = ''.join(report_list) | |
|
235 | ||
|
236 | def __AddingHeader(self,content_list, title): | |
|
237 | ||
|
238 | line1 = title + "\n" | |
|
239 | line2 = "-----------------\n" | |
|
240 | header_list = [line1, line2] | |
|
241 | verification_list = header_list + content_list | |
|
242 | # Arming the frame | |
|
243 | self.tx_buffer = ''.join(verification_list) | |
|
244 | ||
|
245 | def __getModuleFile(self, filename): | |
|
246 | ||
|
247 | enaModules = self.checkAntenna() | |
|
248 | content_list = [] | |
|
249 | for address in range(1,65): | |
|
250 | ||
|
251 | if address not in enaModules: | |
|
252 | continue | |
|
253 | #Preparing and doing the tftp command | |
|
254 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename | |
|
255 | print cmd | |
|
256 | os.system(cmd) | |
|
257 | #Sub_header | |
|
258 | content_list.append("ABS_" + str(address) + "\n") | |
|
259 | # From module file to list | |
|
260 | content_str = self.__readModuleFile(filename) | |
|
261 | content_list.append(content_str) | |
|
262 | content_list.append("------\n") | |
|
263 | ||
|
264 | self.__AddingHeader(content_list, title = "Verification_file") | |
|
265 | ||
|
266 | def __getStsMode3(self): | |
|
267 | ||
|
268 | self.commClientObj.sendData("none", "CHEQUEO:" + self.datarx + ":") | |
|
269 | seconds = int (self.datarx) | |
|
270 | # Give 5 seconds to the control modules | |
|
271 | time.sleep(seconds) | |
|
272 | ||
|
273 | self.__getModuleFile(filename = "Verificacion") | |
|
274 | ||
|
275 | ||
|
276 | if __name__ == '__main__': | |
|
277 | ||
|
278 | absObj = ABSServer() | |
|
279 | ||
|
280 | while 1: | |
|
281 | absObj.waitRequest() No newline at end of file |
@@ -0,0 +1,369 | |||
|
1 | import os | |
|
2 | import library2 | |
|
3 | import time | |
|
4 | ||
|
5 | class ABSServer: | |
|
6 | ||
|
7 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): | |
|
8 | ||
|
9 | self.ipSource = ipSource | |
|
10 | self.ipDestino = ipDestino | |
|
11 | self.portDestino = portDestino | |
|
12 | ||
|
13 | self.ipDestino2 = ipDestino2 | |
|
14 | self.portDestino2 = portDestino2 | |
|
15 | ||
|
16 | self.tx_buffer = "default" | |
|
17 | self.rx_buffer = "default" | |
|
18 | ||
|
19 | self.createObjects() | |
|
20 | ||
|
21 | def createObjects(self): | |
|
22 | ||
|
23 | asServer = True | |
|
24 | self.commServerObj = library2.TCPComm("Central_Control", self.ipDestino, self.portDestino, asServer) | |
|
25 | self.commClientObj = library2.TCPComm("Central_Control", self.ipDestino2, self.portDestino2) | |
|
26 | ||
|
27 | def waitRequest(self): | |
|
28 | ||
|
29 | # Using rx buffer | |
|
30 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer() | |
|
31 | ||
|
32 | if cmd == "SNDF": | |
|
33 | datarpta = self.sendFile2Modules(mode=2, cmd = cmd) | |
|
34 | ||
|
35 | if cmd == "CHGB": | |
|
36 | datarpta = self.changeBeam(cmd = cmd) | |
|
37 | ||
|
38 | if cmd == "ANST": | |
|
39 | self.getStatus(mode=4, cmd = cmd) | |
|
40 | # Using tx buffer | |
|
41 | datarpta = self.tx_buffer | |
|
42 | ||
|
43 | self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource) | |
|
44 | ||
|
45 | def checkModule(self, address): | |
|
46 | ||
|
47 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" | |
|
48 | status = os.system(cmd) | |
|
49 | ||
|
50 | if status == 256: | |
|
51 | return False | |
|
52 | ||
|
53 | return True | |
|
54 | ||
|
55 | def __writeReport(self, enaModules): | |
|
56 | ||
|
57 | status_array = ["Status of modules\n"] | |
|
58 | status_array.append("----------------\n") | |
|
59 | ||
|
60 | for address in range(1,65): | |
|
61 | if address in enaModules: | |
|
62 | status_array.append("192.168.1." + str(address) + " [1 1]\n") | |
|
63 | else: | |
|
64 | status_array.append("192.168.1." + str(address) + " [0 0]\n") | |
|
65 | ||
|
66 | f = open("module_status.txt","w") | |
|
67 | f.writelines(status_array) | |
|
68 | f.close() | |
|
69 | ||
|
70 | def checkAntenna(self): | |
|
71 | ||
|
72 | """ | |
|
73 | Direccion de los modulos de las antenas: | |
|
74 | ||
|
75 | Norte : 01-16 | |
|
76 | Este : 17-32 | |
|
77 | Oeste: : 33-48 | |
|
78 | Sur : 49-64 | |
|
79 | ||
|
80 | """ | |
|
81 | ||
|
82 | enaModules = [] | |
|
83 | ||
|
84 | for address in range(1,65): | |
|
85 | if self.checkModule(address): | |
|
86 | enaModules.append(address) | |
|
87 | ||
|
88 | self.__writeReport(enaModules) | |
|
89 | return enaModules | |
|
90 | ||
|
91 | def sendFile2Modules(self, mode, cmd): | |
|
92 | ||
|
93 | if mode == 1: | |
|
94 | self.__sendFile2Modules1() | |
|
95 | else: | |
|
96 | self.__sendFile2Modules2(cmd) | |
|
97 | ||
|
98 | def __sendFile2Modules1(self): | |
|
99 | ||
|
100 | #Needed for the loop | |
|
101 | rx_frame_list = self.rx_buffer.split('\n',2) | |
|
102 | ||
|
103 | self.experiment_name = rx_frame_list[0] | |
|
104 | experiment_number = rx_frame_list[1] | |
|
105 | str_control_modules = rx_frame_list[2] | |
|
106 | ||
|
107 | lst_control_modules = str_control_modules.split("------\n") | |
|
108 | ||
|
109 | # enaModules = self.checkAntenna() | |
|
110 | enaModules = [11,12,13,14] | |
|
111 | ||
|
112 | for address in range(1,65): | |
|
113 | ||
|
114 | if address not in enaModules: | |
|
115 | continue | |
|
116 | ||
|
117 | self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1]) | |
|
118 | ||
|
119 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name | |
|
120 | print cmd | |
|
121 | os.system(cmd) | |
|
122 | ||
|
123 | self.__loadFile() | |
|
124 | ||
|
125 | def __sendFile2Modules2(self,cmd): | |
|
126 | ||
|
127 | #Needed for the loop | |
|
128 | rx_frame_list = self.rx_buffer.split('\n',2) | |
|
129 | correct = 0 | |
|
130 | failure = 0 | |
|
131 | header = rx_frame_list[0] + "\n" | |
|
132 | str_control_modules = rx_frame_list[2] | |
|
133 | ||
|
134 | lst_control_modules = str_control_modules.split("------\n") | |
|
135 | ||
|
136 | # enaModules = self.checkAntenna() | |
|
137 | enaModules = [11,12,13,14] | |
|
138 | ||
|
139 | for id in range(1,65): | |
|
140 | ||
|
141 | if id not in enaModules: | |
|
142 | continue | |
|
143 | #tcp client needed | |
|
144 | self.commClientObj.open_socket() | |
|
145 | ip = "192.168.1." + str(id) | |
|
146 | self.commClientObj.sendData2(cmd, header + lst_control_modules[id-1], ip) | |
|
147 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |
|
148 | self.commClientObj.close_socket() | |
|
149 | ||
|
150 | if tmp == "OK": | |
|
151 | correct = correct + 1 | |
|
152 | else: | |
|
153 | failure = failure + 1 | |
|
154 | ||
|
155 | if correct == len(enaModules): | |
|
156 | rpta = "OK" | |
|
157 | else: | |
|
158 | rpta = "Failure" | |
|
159 | ||
|
160 | return rpta | |
|
161 | ||
|
162 | ||
|
163 | def __writeModuleFile(self, filename, str): | |
|
164 | ||
|
165 | fobj = open(filename,"w") | |
|
166 | fobj.write(filename + "\n") | |
|
167 | fobj.write("------\n") | |
|
168 | fobj.write(str) | |
|
169 | fobj.write("------\n") | |
|
170 | fobj.close() | |
|
171 | ||
|
172 | def __readModuleFile(self, filename): | |
|
173 | ||
|
174 | fobj1 = open(filename,"r") | |
|
175 | file_list_1 = fobj1.readlines() | |
|
176 | fobj1.close() | |
|
177 | content_str = ''.join(file_list_1[2:-1]) | |
|
178 | ||
|
179 | return content_str | |
|
180 | ||
|
181 | def __loadFile(self): | |
|
182 | ||
|
183 | #Working with the UDP socket | |
|
184 | self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") | |
|
185 | self.commClientObj.sendData("none", "CAMBIA:0:") | |
|
186 | ||
|
187 | def changeBeam(self, cmd): | |
|
188 | ||
|
189 | correct = 0 | |
|
190 | failure = 0 | |
|
191 | # enaModules = self.checkAntenna() | |
|
192 | enaModules = [11,12,13,14] | |
|
193 | ||
|
194 | for id in range(1,65): | |
|
195 | if id not in enaModules: | |
|
196 | continue | |
|
197 | ||
|
198 | self.commClientObj.open_socket() | |
|
199 | ip = "192.168.1." + str(id) | |
|
200 | self.commClientObj.sendData2(cmd, self.rx_buffer, ip) | |
|
201 | # ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() | |
|
202 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |
|
203 | self.commClientObj.close_socket() | |
|
204 | ||
|
205 | if tmp == "OK": | |
|
206 | correct = correct + 1 | |
|
207 | else: | |
|
208 | failure = failure + 1 | |
|
209 | ||
|
210 | if correct == len(enaModules): | |
|
211 | rpta = "OK" | |
|
212 | else: | |
|
213 | rpta = "Failure" | |
|
214 | ||
|
215 | return rpta | |
|
216 | ||
|
217 | def getStatus(self, mode, cmd): | |
|
218 | ||
|
219 | if mode == 1: | |
|
220 | self.__getStsMode1() | |
|
221 | elif mode == 2: | |
|
222 | self.__getStsMode2() | |
|
223 | elif mode == 3: | |
|
224 | self.__getStsMode3() | |
|
225 | else: | |
|
226 | self.__getStsMode4(cmd) | |
|
227 | ||
|
228 | ||
|
229 | def __getStsMode1(self): | |
|
230 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") | |
|
231 | self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") | |
|
232 | seconds = int (self.rx_buffer) | |
|
233 | # Give 5 seconds to the control modules | |
|
234 | time.sleep(seconds) | |
|
235 | # Checking the module connection | |
|
236 | module_list = self.connection_status(10) | |
|
237 | #Generating the complete report | |
|
238 | module = 1 | |
|
239 | number_of_modules = 16 | |
|
240 | filename1 = "Verificacion" | |
|
241 | filename2 = "report.txt" | |
|
242 | fobj2 = open(filename2,"w") | |
|
243 | fobj2.write("Verification_file\n") | |
|
244 | fobj2.write("-----------------\n") | |
|
245 | fobj2.close() | |
|
246 | while module <= number_of_modules: | |
|
247 | if module_list[module -1] == "1": | |
|
248 | #Preparing and doing the tftp command | |
|
249 | cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1 | |
|
250 | print cmd | |
|
251 | os.system(cmd) | |
|
252 | # Getting data from the control module file | |
|
253 | fobj1 = open(filename1,"r") | |
|
254 | file_list_1 = fobj1.readlines() | |
|
255 | fobj1.close() | |
|
256 | content = file_list_1[2:-1] | |
|
257 | # | |
|
258 | fobj2 = open(filename2,"a") | |
|
259 | if base == 10: | |
|
260 | fobj2.write("S" + str(module) + "\n") | |
|
261 | else: | |
|
262 | fobj2.write("N" + str(module) + "\n") | |
|
263 | fobj2.writelines(content) | |
|
264 | fobj2.write("------\n") | |
|
265 | fobj2.close() | |
|
266 | module = module + 1 | |
|
267 | ||
|
268 | def __getStsMode2(self): | |
|
269 | ||
|
270 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") | |
|
271 | self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") | |
|
272 | seconds = int (self.rx_buffer) | |
|
273 | # Give 5 seconds to the control modules | |
|
274 | time.sleep(seconds) | |
|
275 | # Checking the module connection | |
|
276 | enaModules = self.checkAntenna() | |
|
277 | #Generating the complete report | |
|
278 | filename1 = "Verificacion" | |
|
279 | line1 = "Verification_file\n" | |
|
280 | line2 = "-----------------\n" | |
|
281 | report_list = [line1, line2] | |
|
282 | ||
|
283 | for address in range(1,65): | |
|
284 | ||
|
285 | if address not in enaModules: | |
|
286 | continue | |
|
287 | #Preparing and doing the tftp command | |
|
288 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1 | |
|
289 | print cmd | |
|
290 | os.system(cmd) | |
|
291 | #Sub_header | |
|
292 | report_list.append("ABS_" + str(address) + "\n") | |
|
293 | # Content | |
|
294 | fobj1 = open(filename1,"r") | |
|
295 | file_list_1 = fobj1.readlines() | |
|
296 | fobj1.close() | |
|
297 | content = ''.join(file_list_1[2:-1]) | |
|
298 | report_list.append(content) | |
|
299 | #Ending | |
|
300 | report_list.append("------\n") | |
|
301 | #print "\nFinalizado" | |
|
302 | self.tx_buffer = ''.join(report_list) | |
|
303 | ||
|
304 | def __AddingHeader(self,content_list, title): | |
|
305 | ||
|
306 | line1 = title + "\n" | |
|
307 | line2 = "-----------------\n" | |
|
308 | header_list = [line1, line2] | |
|
309 | verification_list = header_list + content_list | |
|
310 | # Arming the frame | |
|
311 | self.tx_buffer = ''.join(verification_list) | |
|
312 | ||
|
313 | def __getModuleFile(self, filename): | |
|
314 | ||
|
315 | enaModules = self.checkAntenna() | |
|
316 | content_list = [] | |
|
317 | for address in range(1,65): | |
|
318 | ||
|
319 | if address not in enaModules: | |
|
320 | continue | |
|
321 | #Preparing and doing the tftp command | |
|
322 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename | |
|
323 | print cmd | |
|
324 | os.system(cmd) | |
|
325 | #Sub_header | |
|
326 | content_list.append("ABS_" + str(address) + "\n") | |
|
327 | # From module file to list | |
|
328 | content_str = self.__readModuleFile(filename) | |
|
329 | content_list.append(content_str) | |
|
330 | content_list.append("------\n") | |
|
331 | ||
|
332 | self.__AddingHeader(content_list, title = "Verification_file") | |
|
333 | ||
|
334 | def __getStsMode3(self): | |
|
335 | ||
|
336 | self.commClientObj.sendData("none", "CHEQUEO:" + self.rx_buffer + ":") | |
|
337 | seconds = int (self.rx_buffer) | |
|
338 | # Give 5 seconds to the control modules | |
|
339 | time.sleep(seconds) | |
|
340 | ||
|
341 | self.__getModuleFile(filename = "Verificacion") | |
|
342 | ||
|
343 | def __getStsMode4(self, cmd): | |
|
344 | ||
|
345 | content_str = "" | |
|
346 | # enaModules = self.checkAntenna() | |
|
347 | enaModules = [11,12,13,14] | |
|
348 | ||
|
349 | for id in range(1,65): | |
|
350 | if id not in enaModules: | |
|
351 | continue | |
|
352 | ||
|
353 | self.commClientObj.open_socket() | |
|
354 | ip = "192.168.1." + str(id) | |
|
355 | self.commClientObj.sendData2(cmd, self.rx_buffer, ip) | |
|
356 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |
|
357 | self.commClientObj.close_socket() | |
|
358 | ||
|
359 | content_str = content_str + tmp | |
|
360 | # self.__AddingHeader(content_list, title = "Verification_file") | |
|
361 | #Using tx buffer | |
|
362 | self.tx_buffer = content_str | |
|
363 | ||
|
364 | if __name__ == '__main__': | |
|
365 | ||
|
366 | absObj = ABSServer() | |
|
367 | ||
|
368 | while 1: | |
|
369 | absObj.waitRequest() No newline at end of file |
@@ -0,0 +1,399 | |||
|
1 | import os | |
|
2 | import library3 | |
|
3 | import time | |
|
4 | import threading | |
|
5 | ||
|
6 | class ABSServer: | |
|
7 | ||
|
8 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"): | |
|
9 | ||
|
10 | self.ipSource = ipSource | |
|
11 | self.ipDestino = ipDestino | |
|
12 | self.portDestino = portDestino | |
|
13 | ||
|
14 | self.ipDestino2 = ipDestino2 | |
|
15 | self.portDestino2 = portDestino2 | |
|
16 | ||
|
17 | self.tx_buffer = "default" | |
|
18 | # self.rx_buffer = "default" | |
|
19 | self.rx_buffer = rx_buffer | |
|
20 | self.enaModules = [] | |
|
21 | self.bits = [] | |
|
22 | self.phase = [] | |
|
23 | self.txFile = [] | |
|
24 | self.rxFile = [] | |
|
25 | ||
|
26 | self.createObjects() | |
|
27 | ||
|
28 | print "Checking control modules, please wait ..." | |
|
29 | self.enaModules = self.checkAntenna() | |
|
30 | print "Starting automatic control module status." | |
|
31 | self.__StartingAutomaticControlModules() | |
|
32 | self.__AutomaticControlModules() | |
|
33 | ||
|
34 | def createObjects(self): | |
|
35 | ||
|
36 | asServer = True | |
|
37 | self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) | |
|
38 | self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) | |
|
39 | self.wFiles = library3.FilesStuff() | |
|
40 | ||
|
41 | def waitRequest(self): | |
|
42 | ||
|
43 | #Using rx buffer | |
|
44 | # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() | |
|
45 | ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData() | |
|
46 | ||
|
47 | if cmd == "SNDF": | |
|
48 | datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer) | |
|
49 | ||
|
50 | if cmd == "GETF": | |
|
51 | datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) | |
|
52 | ||
|
53 | if cmd == "CHGB": | |
|
54 | datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer) | |
|
55 | ||
|
56 | if cmd == "ANST": | |
|
57 | datarpta = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) | |
|
58 | ||
|
59 | if cmd == "BGPH": | |
|
60 | datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer) | |
|
61 | ||
|
62 | if cmd == "LWPH": | |
|
63 | datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) | |
|
64 | ||
|
65 | if cmd == "NTST": | |
|
66 | datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer) | |
|
67 | ||
|
68 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) | |
|
69 | ||
|
70 | def checkModule(self, address): | |
|
71 | ||
|
72 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" | |
|
73 | status = os.system(cmd) | |
|
74 | ||
|
75 | if status == 256: | |
|
76 | return False | |
|
77 | ||
|
78 | return True | |
|
79 | ||
|
80 | def __writeReport(self, enaModules): | |
|
81 | ||
|
82 | status_array = ["Status of modules\n"] | |
|
83 | status_array.append("----------------\n") | |
|
84 | ||
|
85 | for address in range(1,65): | |
|
86 | if address in enaModules: | |
|
87 | status_array.append("192.168.1." + str(address) + " [1 1]\n") | |
|
88 | else: | |
|
89 | status_array.append("192.168.1." + str(address) + " [0 0]\n") | |
|
90 | ||
|
91 | filename = "module_status.txt" | |
|
92 | self.__writeFile(filename,status_array) | |
|
93 | # f = open("module_status.txt","w") | |
|
94 | # f.writelines(status_array) | |
|
95 | # f.close() | |
|
96 | ||
|
97 | ||
|
98 | def __CreateFile(self, filename): | |
|
99 | ||
|
100 | fobj = open(filename,"w") | |
|
101 | fobj.close() | |
|
102 | ||
|
103 | def __writeNewFile(self, filename, data): | |
|
104 | ||
|
105 | fobj = open(filename,"w") | |
|
106 | fobj.writelines(data) | |
|
107 | fobj.close() | |
|
108 | ||
|
109 | def __writeFile(self, filename, data): | |
|
110 | ||
|
111 | fobj = open(filename,"a") | |
|
112 | fobj.writelines(data) | |
|
113 | fobj.close() | |
|
114 | ||
|
115 | def checkAntenna(self): | |
|
116 | ||
|
117 | """ | |
|
118 | Direccion de los modulos de las antenas: | |
|
119 | ||
|
120 | Norte : 01-16 | |
|
121 | Este : 17-32 | |
|
122 | Oeste: : 33-48 | |
|
123 | Sur : 49-64 | |
|
124 | ||
|
125 | """ | |
|
126 | ||
|
127 | enaModules2 = [] | |
|
128 | ||
|
129 | for address in range(1,65): | |
|
130 | if self.checkModule(address): | |
|
131 | enaModules2.append(address) | |
|
132 | ||
|
133 | self.__writeReport(enaModules2) | |
|
134 | return enaModules2 | |
|
135 | ||
|
136 | def __ConnectionWithControlModules(self,data,cmd,id): | |
|
137 | ||
|
138 | self.commClientObj.open_socket() | |
|
139 | ip = "192.168.1." + str(id) | |
|
140 | self.commClientObj.sendData(cmd, data, ip) | |
|
141 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() | |
|
142 | self.commClientObj.close_socket() | |
|
143 | ||
|
144 | return tmp | |
|
145 | ||
|
146 | def abs2ControlModuleFormatFile(self, filename): | |
|
147 | ||
|
148 | #From matriz to control module format | |
|
149 | self.wFiles.toCentralControlFormat(filename) | |
|
150 | FileName = "CentralControlFormat.txt" | |
|
151 | F_Obj = open(FileName,"r") | |
|
152 | FileList = F_Obj.readlines() | |
|
153 | F_Obj.close() | |
|
154 | FileStr = "".join(FileList) | |
|
155 | ||
|
156 | return FileStr | |
|
157 | ||
|
158 | def __All2Blocks(self,input): | |
|
159 | ||
|
160 | rx_frame_lst = input.split('\n',2) | |
|
161 | ||
|
162 | header = rx_frame_lst[0] + "\n" | |
|
163 | control_modules_str = rx_frame_lst[2] | |
|
164 | control_modules_lst = control_modules_str.split("------\n") | |
|
165 | ||
|
166 | return header, control_modules_lst | |
|
167 | ||
|
168 | ||
|
169 | def __sendFile2Modules(self,cmd, rx_buffer): | |
|
170 | ||
|
171 | # rx_buffer_lst = self.rx_buffer.split('\n',1) | |
|
172 | rx_buffer_lst = rx_buffer.split('\n',1) | |
|
173 | #Getting the filename from the begining of data | |
|
174 | filename = rx_buffer_lst[0] | |
|
175 | tmp = rx_buffer_lst[1] | |
|
176 | self.__writeFile(filename,tmp) | |
|
177 | data = self.abs2ControlModuleFormatFile(filename) | |
|
178 | #Needed for the loop | |
|
179 | header, control_modules_lst = self.__All2Blocks(data) | |
|
180 | correct = 0 | |
|
181 | ||
|
182 | for id in range(1,65): | |
|
183 | ||
|
184 | if id not in self.enaModules: | |
|
185 | continue | |
|
186 | ||
|
187 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": | |
|
188 | correct = correct + 1 | |
|
189 | ||
|
190 | if correct == len(self.enaModules): | |
|
191 | rpta = "OK" | |
|
192 | else: | |
|
193 | rpta = "Failure" | |
|
194 | ||
|
195 | return rpta | |
|
196 | ||
|
197 | def __getFileFromModules(self, cmd, rx_buffer): | |
|
198 | ||
|
199 | for id in range(1,65): | |
|
200 | if id not in self.enaModules: | |
|
201 | continue | |
|
202 | ||
|
203 | file = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
204 | del self.rxFile[id-1] | |
|
205 | self.rxFile.insert(id-1, file) | |
|
206 | ||
|
207 | def __changeBeam(self, cmd, rx_buffer): | |
|
208 | ||
|
209 | correct = 0 | |
|
210 | # enaModules = self.checkAntenna() | |
|
211 | # enaModules = [11,12,13,14] | |
|
212 | ||
|
213 | for id in range(1,65): | |
|
214 | if id not in self.enaModules: | |
|
215 | continue | |
|
216 | ||
|
217 | if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK": | |
|
218 | correct = correct + 1 | |
|
219 | ||
|
220 | if correct == len(self.enaModules): | |
|
221 | rpta = "OK" | |
|
222 | else: | |
|
223 | rpta = "Failure" | |
|
224 | ||
|
225 | return rpta | |
|
226 | ||
|
227 | def __getControlModuleStatus(self, cmd, rx_buffer): | |
|
228 | ||
|
229 | # all_blocks = "" | |
|
230 | # all_blocks = [] | |
|
231 | # enaModules = self.checkAntenna() | |
|
232 | # enaModules = [11,12,13,14] | |
|
233 | ||
|
234 | for id in range(1,65): | |
|
235 | if id not in self.enaModules: | |
|
236 | continue | |
|
237 | ||
|
238 | bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
239 | del self.bits[id-1] | |
|
240 | self.bits.insert(id-1, bits) | |
|
241 | ||
|
242 | # all_blocks.append(one_block) | |
|
243 | #Using tx buffer | |
|
244 | ||
|
245 | # return all_blocks | |
|
246 | ||
|
247 | def __getControlModuleBigPhase(self, cmd, rx_buffer): | |
|
248 | ||
|
249 | # all_blocks = "" | |
|
250 | all_blocks = [] | |
|
251 | # enaModules = self.checkAntenna() | |
|
252 | # enaModules = [11,12,13,14] | |
|
253 | ||
|
254 | for id in range(1,65): | |
|
255 | if id not in self.enaModules: | |
|
256 | continue | |
|
257 | ||
|
258 | one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
259 | ||
|
260 | # all_blocks = all_blocks + one_block | |
|
261 | all_blocks.append(one_block) | |
|
262 | #Using tx buffer | |
|
263 | return all_blocks | |
|
264 | ||
|
265 | def __getControlModuleLowPhase(self, cmd, rx_buffer): | |
|
266 | ||
|
267 | # all_blocks = "" | |
|
268 | # all_blocks = [] | |
|
269 | # enaModules = self.checkAntenna() | |
|
270 | # enaModules = [11,12,13,14] | |
|
271 | ||
|
272 | for id in range(1,65): | |
|
273 | if id not in self.enaModules: | |
|
274 | continue | |
|
275 | ||
|
276 | phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
277 | del self.phase[id-1] | |
|
278 | self.phase.insert(id-1, phase) | |
|
279 | # all_blocks = all_blocks + one_block | |
|
280 | # all_blocks.append(one_block) | |
|
281 | #Using tx buffer | |
|
282 | # return all_blocks | |
|
283 | ||
|
284 | def __getConnectionStatus(self, cmd, rx_buffer): | |
|
285 | ||
|
286 | ena = self.checkAntenna() | |
|
287 | print ena | |
|
288 | self.enaModules = ena | |
|
289 | ||
|
290 | blockLst = [] | |
|
291 | ||
|
292 | for id in range(1,65): | |
|
293 | if id not in self.enaModules: | |
|
294 | continue | |
|
295 | ||
|
296 | blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
297 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |
|
298 | #Using tx buffer | |
|
299 | all_blocks = "".join(blockLst) | |
|
300 | ||
|
301 | return all_blocks | |
|
302 | ||
|
303 | def getConnectionStatus(self, cmd): | |
|
304 | ||
|
305 | ena = self.checkAntenna() | |
|
306 | self.enaModules = ena | |
|
307 | ||
|
308 | blockLst = [] | |
|
309 | ||
|
310 | for id in range(1,65): | |
|
311 | if id not in self.enaModules: | |
|
312 | continue | |
|
313 | ||
|
314 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |
|
315 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |
|
316 | #Using tx buffer | |
|
317 | self.tx_buffer = "".join(blockLst) | |
|
318 | print self.tx_buffer | |
|
319 | ||
|
320 | return self.tx_buffer | |
|
321 | ||
|
322 | def getControlModuleStatus(self, cmd): | |
|
323 | ||
|
324 | all_blocks = "" | |
|
325 | # enaModules = self.checkAntenna() | |
|
326 | # enaModules = [11,12,13,14] | |
|
327 | ||
|
328 | for id in range(1,65): | |
|
329 | if id not in self.enaModules: | |
|
330 | continue | |
|
331 | ||
|
332 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |
|
333 | ||
|
334 | all_blocks = all_blocks + one_block | |
|
335 | #Using tx buffer | |
|
336 | print all_blocks | |
|
337 | self.tx_buffer = all_blocks | |
|
338 | ||
|
339 | return all_blocks | |
|
340 | ||
|
341 | def __StartingAutomaticControlModules(self): | |
|
342 | ||
|
343 | #Starting file | |
|
344 | self.__CreateFile("Monitoring.txt") | |
|
345 | # data = "MOD.\t BITS\t\t PHASE\n" | |
|
346 | # self.__writeFile("Monitoring.txt", data) | |
|
347 | #Starting lists | |
|
348 | self.txFile = list("------\n------\n------\n" for i in range(64)) | |
|
349 | self.rxFile = list("------\n------\n------\n" for i in range(64)) | |
|
350 | self.bits = list("------\n------\n------\n" for i in range(64)) | |
|
351 | self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64)) | |
|
352 | ||
|
353 | def __AutomaticControlModules(self): | |
|
354 | ||
|
355 | cmd = "GETF" | |
|
356 | rx_buffer = "experimento1.ab1" + "\n" | |
|
357 | self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) | |
|
358 | ||
|
359 | print self.rxFile | |
|
360 | ||
|
361 | cmd = "ANST" | |
|
362 | rx_buffer = "1" | |
|
363 | self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) | |
|
364 | ||
|
365 | cmd = "LWPH" | |
|
366 | rx_buffer = "0" | |
|
367 | self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) | |
|
368 | print "Saving file..." | |
|
369 | ||
|
370 | ||
|
371 | print self.bits | |
|
372 | print self.phase | |
|
373 | ||
|
374 | self.__WritingMonitoringFile() | |
|
375 | ||
|
376 | threading.Timer(60, self.__AutomaticControlModules).start() | |
|
377 | ||
|
378 | def __WritingMonitoringFile(self): | |
|
379 | filename = "Monitoring.txt" | |
|
380 | data = '===============================' + '\n' | |
|
381 | self.__writeFile(filename, data) | |
|
382 | data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime()) | |
|
383 | self.__writeFile(filename, data) | |
|
384 | data = "MOD.\t BITS\t\t PHASE\n" | |
|
385 | self.__writeFile(filename, data) | |
|
386 | data = '===============================' + '\n' | |
|
387 | self.__writeFile(filename, data) | |
|
388 | for i in range(64): | |
|
389 | tmp = self.bits[i].split('\n',3) | |
|
390 | self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2]) | |
|
391 | tmp = self.phase[i].split('\n',3) | |
|
392 | self.__writeFile(filename, '\t\t' + tmp[2] + '\n') | |
|
393 | ||
|
394 | if __name__ == '__main__': | |
|
395 | ||
|
396 | absObj = ABSServer() | |
|
397 | ||
|
398 | while 1: | |
|
399 | absObj.waitRequest() No newline at end of file |
@@ -1,9 +1,9 | |||
|
1 | 1 | import optparse, os, sys |
|
2 | 2 | |
|
3 | pathFile = os.getcwd() | |
|
3 | pathFile = os.path.dirname(os.path.abspath(__file__)) | |
|
4 | 4 | sys.path.append(os.path.split(pathFile)[0]) |
|
5 | 5 | |
|
6 |
from |
|
|
6 | from bin.client3 import ABSClient | |
|
7 | 7 | |
|
8 | 8 | class changeBeam(object): |
|
9 | 9 | |
@@ -16,7 +16,6 | |||
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | usage = "::::::::::::\n" |
|
19 | ||
|
20 | 19 | |
|
21 | 20 | if __name__ == '__main__': |
|
22 | 21 |
@@ -1,10 +1,10 | |||
|
1 | 1 | |
|
2 | 2 | import optparse, os, sys |
|
3 | 3 | |
|
4 | pathFile = os.getcwd() | |
|
4 | pathFile = os.path.dirname(os.path.abspath(__file__)) | |
|
5 | 5 | sys.path.append(os.path.split(pathFile)[0]) |
|
6 | 6 | |
|
7 |
from |
|
|
7 | from bin.client3 import ABSClient | |
|
8 | 8 | |
|
9 | 9 | class sendFile(object): |
|
10 | 10 | |
@@ -15,12 +15,11 | |||
|
15 | 15 | if os.path.exists(filename): |
|
16 | 16 | absObj = ABSClient(ipDestino="10.10.10.97") |
|
17 | 17 | absObj.sendFile(filename) |
|
18 | pass | |
|
18 | #pass | |
|
19 | 19 | else: |
|
20 | 20 | print "No file" |
|
21 | 21 | |
|
22 | 22 | usage = "::::::::::::\n" |
|
23 | ||
|
24 | 23 | |
|
25 | 24 | if __name__ == '__main__': |
|
26 | 25 |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now