##// END OF EJS Templates
imanay -
r49:50
parent child
Show More
@@ -1,268 +1,481
1 # imports needed for the file convertion
1 # imports needed for the file convertion
2 import os
2 import os
3 import sys
3 import sys
4 import time
4 import time
5 import numpy as np
5 import numpy as np
6
6
7 import library
7 import library
8
8
9 class ABSClient:
9 class ABSClient:
10
10
11 def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000):
11 def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000):
12
12
13 self.ipSource = ipSource
13 self.ipSource = ipSource
14 self.ipDestino = ipDestino
14 self.ipDestino = ipDestino
15 self.portDestino = portDestino
15 self.portDestino = portDestino
16
16
17 self.createObjects()
17 self.createObjects()
18
18
19 def createObjects(self):
19 def createObjects(self):
20
20
21 self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino)
21 self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino)
22
22
23 def sendFile(self, filename):
23 def sendFile(self, filename):
24
24
25 #From matriz to control module format
25 #From matriz to control module format
26 self.FuncionMaestra_GeneraFormatoControlCentral(filename)
26 self.FuncionMaestra_GeneraFormatoControlCentral(filename)
27 FileName = "FormatoControlCentral.txt"
27 FileName = "FormatoControlCentral.txt"
28 F_Obj = open(FileName,"r")
28 F_Obj = open(FileName,"r")
29 FileList = F_Obj.readlines()
29 FileList = F_Obj.readlines()
30 F_Obj.close()
30 F_Obj.close()
31 FileStr = "".join(FileList)
31 FileStr = "".join(FileList)
32 data = FileStr
32 data = FileStr
33
33
34 self.commObj.sendData(cmd="SNDF", data=data)
34 self.commObj.sendData(cmd="SNDF", data=data)
35 self.commObj.waitData()
35 self.commObj.waitData()
36
36
37 def changeBeam(self, newBeam):
37 def changeBeam(self, newBeam):
38
38
39 self.commObj.sendData(cmd="CHGB", data=newBeam)
39 self.commObj.sendData(cmd="CHGB", data=newBeam)
40 self.commObj.waitData()
40 self.commObj.waitData()
41
41
42 def getStatus(self, data):
42 def getStatus(self, data):
43
43
44 self.commObj.sendData(cmd="ANST", data = data)
44 self.commObj.sendData(cmd="ANST", data = data)
45 self.commObj.waitData2()
45 self.commObj.waitData2()
46
46
47 ##########
47 ##########
48
48
49 def FuncionMaestra_GeneraFormatoControlCentral(self,archivo):
49 def FuncionMaestra_GeneraFormatoControlCentral(self,archivo):
50 """ Funcion que genera un archivo para el control central"""
50 """ Funcion que genera un archivo para el control central"""
51
51
52 # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/'
52 # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/'
53 CarpetaDeTrabajo = os.getcwd() + '/'
53 CarpetaDeTrabajo = os.getcwd() + '/'
54 #print CarpetaDeTrabajo
54 #print CarpetaDeTrabajo
55 #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/'
55 #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/'
56
56
57 def lst2string(lst):
57 def lst2string(lst):
58 string=''
58 string=''
59 for i in lst:
59 for i in lst:
60 string=string+i
60 string=string+i
61 return string
61 return string
62
62
63 def string2lst(string):
63 def string2lst(string):
64 lst = []
64 lst = []
65 for i in string:
65 for i in string:
66 lst.append(i)
66 lst.append(i)
67 return lst
67 return lst
68
68
69
69
70 def file1(string, type):
70 def file1(string, type):
71 lst = string2lst(archivo)
71 lst = string2lst(archivo)
72 fin = -1
72 fin = -1
73 t = len(lst)
73 t = len(lst)
74 for i in np.arange(-1,-t,-1):
74 for i in np.arange(-1,-t,-1):
75 if lst[i]=='/':
75 if lst[i]=='/':
76 fin=i
76 fin=i
77 break
77 break
78 if type == '1':
78 if type == '1':
79 nombre2 = lst[fin+1:]
79 nombre2 = lst[fin+1:]
80 nombre2[-1]='s'
80 nombre2[-1]='s'
81 nombre2 = lst2string(nombre2)
81 nombre2 = lst2string(nombre2)
82 return nombre2
82 return nombre2
83 if type == '2':
83 if type == '2':
84 nombre2 = lst[fin+1:]
84 nombre2 = lst[fin+1:]
85 nombre2[-1]='1'
85 nombre2[-1]='1'
86 nombre2 = lst2string(nombre2)
86 nombre2 = lst2string(nombre2)
87 return nombre2
87 return nombre2
88
88
89
89
90 def EliminaSaltoDeLinea(cadena):
90 def EliminaSaltoDeLinea(cadena):
91 i = 0
91 i = 0
92 for elemento in cadena:
92 for elemento in cadena:
93 if elemento =='\n' or elemento =='\r':
93 if elemento =='\n' or elemento =='\r':
94 pass
94 pass
95 else:
95 else:
96 i=i+1
96 i=i+1
97 return cadena [:i]
97 return cadena [:i]
98
98
99 def NumeroDeExperimentos(path):
99 def NumeroDeExperimentos(path):
100 fichero1=open(path,'r')
100 fichero1=open(path,'r')
101 cont=0
101 cont=0
102 for cadena in fichero1:
102 for cadena in fichero1:
103 cont=cont+1
103 cont=cont+1
104 if cont==3:
104 if cont==3:
105 nexp=''
105 nexp=''
106 pos=0
106 pos=0
107 for elemento in cadena:
107 for elemento in cadena:
108 pos=pos+1
108 pos=pos+1
109 if elemento=='=':
109 if elemento=='=':
110 nexp=int(cadena[pos:])
110 nexp=int(cadena[pos:])
111 return nexp
111 return nexp
112 fichero1.close()
112 fichero1.close()
113
113
114 def Paridad(numero):
114 def Paridad(numero):
115 if numero%2==0: return 'par'
115 if numero%2==0: return 'par'
116 elif numero%2==1: return 'impar'
116 elif numero%2==1: return 'impar'
117
117
118 def EvaluaCadena(cadena):
118 def EvaluaCadena(cadena):
119 if len(cadena)>35:
119 if len(cadena)>35:
120 if cadena[-1]=='$':
120 if cadena[-1]=='$':
121 return cadena[-35:-2]
121 return cadena[-35:-2]
122 elif cadena[-1]==']':
122 elif cadena[-1]==']':
123 return cadena[-34:-1]
123 return cadena[-34:-1]
124 else:
124 else:
125 return None
125 return None
126
126
127 def GuardaEnLista(path):
127 def GuardaEnLista(path):
128 fichero=open(path,'r')
128 fichero=open(path,'r')
129 lista=[]
129 lista=[]
130 for cadena in fichero:
130 for cadena in fichero:
131 cadena = EliminaSaltoDeLinea(cadena)
131 cadena = EliminaSaltoDeLinea(cadena)
132 cadena = EvaluaCadena(cadena)
132 cadena = EvaluaCadena(cadena)
133 if cadena != None:
133 if cadena != None:
134 lista.append(cadena)
134 lista.append(cadena)
135 fichero.close()
135 fichero.close()
136 return lista
136 return lista
137
137
138 def CreaFicherosPrevios():
138 def CreaFicherosPrevios():
139 vector = GuardaEnLista(archivo)
139 vector = GuardaEnLista(archivo)
140 for i in range(1,NumeroDeExperimentos(archivo)+1):
140 for i in range(1,NumeroDeExperimentos(archivo)+1):
141 fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w')
141 fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w')
142 for j in range(0,16):
142 for j in range(0,16):
143 fichero.write(vector[j+16*(i-1)]+'\n')
143 fichero.write(vector[j+16*(i-1)]+'\n')
144 fichero.close()
144 fichero.close()
145
145
146 def CapturaValoresEnArchivo(path,polarizacion='up'):
146 def CapturaValoresEnArchivo(path,polarizacion='up'):
147 fichero =open(path,'r')
147 fichero =open(path,'r')
148 cnt=0
148 cnt=0
149 lstup=[]
149 lstup=[]
150 lstdw=[]
150 lstdw=[]
151 for cadena in fichero:
151 for cadena in fichero:
152 cnt=cnt+1
152 cnt=cnt+1
153 if cnt==5:
153 if cnt==5:
154 su01=cadena[17:20]
154 su01=cadena[17:20]
155 su02=cadena[21:24]
155 su02=cadena[21:24]
156 su03=cadena[25:28]
156 su03=cadena[25:28]
157 su04=cadena[29:32]
157 su04=cadena[29:32]
158 if cnt==6:
158 if cnt==6:
159 su05=cadena[17:20]
159 su05=cadena[17:20]
160 su06=cadena[21:24]
160 su06=cadena[21:24]
161 su07=cadena[25:28]
161 su07=cadena[25:28]
162 su08=cadena[29:32]
162 su08=cadena[29:32]
163 if cnt==7:
163 if cnt==7:
164 su09=cadena[17:20]
164 su09=cadena[17:20]
165 su10=cadena[21:24]
165 su10=cadena[21:24]
166 su11=cadena[25:28]
166 su11=cadena[25:28]
167 su12=cadena[29:32]
167 su12=cadena[29:32]
168 if cnt==8:
168 if cnt==8:
169 su13=cadena[17:20]
169 su13=cadena[17:20]
170 su14=cadena[21:24]
170 su14=cadena[21:24]
171 su15=cadena[25:28]
171 su15=cadena[25:28]
172 su16=cadena[29:32]
172 su16=cadena[29:32]
173 if cnt==13:
173 if cnt==13:
174 sd01=cadena[17:20]
174 sd01=cadena[17:20]
175 sd02=cadena[21:24]
175 sd02=cadena[21:24]
176 sd03=cadena[25:28]
176 sd03=cadena[25:28]
177 sd04=cadena[29:32]
177 sd04=cadena[29:32]
178 if cnt==14:
178 if cnt==14:
179 sd05=cadena[17:20]
179 sd05=cadena[17:20]
180 sd06=cadena[21:24]
180 sd06=cadena[21:24]
181 sd07=cadena[25:28]
181 sd07=cadena[25:28]
182 sd08=cadena[29:32]
182 sd08=cadena[29:32]
183 if cnt==15:
183 if cnt==15:
184 sd09=cadena[17:20]
184 sd09=cadena[17:20]
185 sd10=cadena[21:24]
185 sd10=cadena[21:24]
186 sd11=cadena[25:28]
186 sd11=cadena[25:28]
187 sd12=cadena[29:32]
187 sd12=cadena[29:32]
188 if cnt==16:
188 if cnt==16:
189 sd13=cadena[17:20]
189 sd13=cadena[17:20]
190 sd14=cadena[21:24]
190 sd14=cadena[21:24]
191 sd15=cadena[25:28]
191 sd15=cadena[25:28]
192 sd16=cadena[29:32]
192 sd16=cadena[29:32]
193 lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16]
193 lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16]
194 lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16]
194 lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16]
195 if polarizacion=='up':
195 if polarizacion=='up':
196 return lstup
196 return lstup
197 elif polarizacion=='dw':
197 elif polarizacion=='dw':
198 return lstdw
198 return lstdw
199 fichero.close()
199 fichero.close()
200
200
201 def CapturaValoresEnArchivo2(path,polarizacion='up'):
202 fichero =open(path,'r')
203 cnt=0
204 lstup=[]
205 lstdw=[]
206 for cadena in fichero:
207 cnt=cnt+1
208 if cnt==1:
209 nu01=cadena[1:4]
210 nu02=cadena[5:8]
211 nu03=cadena[9:12]
212 nu04=cadena[13:16]
213 eu01=cadena[17:20]
214 eu02=cadena[21:24]
215 eu03=cadena[25:28]
216 eu04=cadena[29:32]
217 if cnt==2:
218 nu05=cadena[1:4]
219 nu06=cadena[5:8]
220 nu07=cadena[9:12]
221 nu08=cadena[13:16]
222 eu05=cadena[17:20]
223 eu06=cadena[21:24]
224 eu07=cadena[25:28]
225 eu08=cadena[29:32]
226 if cnt==3:
227 nu09=cadena[1:4]
228 nu10=cadena[5:8]
229 nu11=cadena[9:12]
230 nu12=cadena[13:16]
231 eu09=cadena[17:20]
232 eu10=cadena[21:24]
233 eu11=cadena[25:28]
234 eu12=cadena[29:32]
235 if cnt==4:
236 nu13=cadena[1:4]
237 nu14=cadena[5:8]
238 nu15=cadena[9:12]
239 nu16=cadena[13:16]
240 eu13=cadena[17:20]
241 eu14=cadena[21:24]
242 eu15=cadena[25:28]
243 eu16=cadena[29:32]
244 if cnt==5:
245 wu01=cadena[1:4]
246 wu02=cadena[5:8]
247 wu03=cadena[9:12]
248 wu04=cadena[13:16]
249 su01=cadena[17:20]
250 su02=cadena[21:24]
251 su03=cadena[25:28]
252 su04=cadena[29:32]
253 if cnt==6:
254 wu05=cadena[1:4]
255 wu06=cadena[5:8]
256 wu07=cadena[9:12]
257 wu08=cadena[13:16]
258 su05=cadena[17:20]
259 su06=cadena[21:24]
260 su07=cadena[25:28]
261 su08=cadena[29:32]
262 if cnt==7:
263 wu09=cadena[1:4]
264 wu10=cadena[5:8]
265 wu11=cadena[9:12]
266 wu12=cadena[13:16]
267 su09=cadena[17:20]
268 su10=cadena[21:24]
269 su11=cadena[25:28]
270 su12=cadena[29:32]
271 if cnt==8:
272 wu13=cadena[1:4]
273 wu14=cadena[5:8]
274 wu15=cadena[9:12]
275 wu16=cadena[13:16]
276 su13=cadena[17:20]
277 su14=cadena[21:24]
278 su15=cadena[25:28]
279 su16=cadena[29:32]
280 if cnt==9:
281 nd01=cadena[1:4]
282 nd02=cadena[5:8]
283 nd03=cadena[9:12]
284 nd04=cadena[13:16]
285 ed01=cadena[17:20]
286 ed02=cadena[21:24]
287 ed03=cadena[25:28]
288 ed04=cadena[29:32]
289 if cnt==10:
290 nd05=cadena[1:4]
291 nd06=cadena[5:8]
292 nd07=cadena[9:12]
293 nd08=cadena[13:16]
294 ed05=cadena[17:20]
295 ed06=cadena[21:24]
296 ed07=cadena[25:28]
297 ed08=cadena[29:32]
298 if cnt==11:
299 nd09=cadena[1:4]
300 nd10=cadena[5:8]
301 nd11=cadena[9:12]
302 nd12=cadena[13:16]
303 ed09=cadena[17:20]
304 ed10=cadena[21:24]
305 ed11=cadena[25:28]
306 ed12=cadena[29:32]
307 if cnt==12:
308 nd13=cadena[1:4]
309 nd14=cadena[5:8]
310 nd15=cadena[9:12]
311 nd16=cadena[13:16]
312 ed13=cadena[17:20]
313 ed14=cadena[21:24]
314 ed15=cadena[25:28]
315 ed16=cadena[29:32]
316 if cnt==13:
317 wd01=cadena[1:4]
318 wd02=cadena[5:8]
319 wd03=cadena[9:12]
320 wd04=cadena[13:16]
321 sd01=cadena[17:20]
322 sd02=cadena[21:24]
323 sd03=cadena[25:28]
324 sd04=cadena[29:32]
325 if cnt==14:
326 wd05=cadena[1:4]
327 wd06=cadena[5:8]
328 wd07=cadena[9:12]
329 wd08=cadena[13:16]
330 sd05=cadena[17:20]
331 sd06=cadena[21:24]
332 sd07=cadena[25:28]
333 sd08=cadena[29:32]
334 if cnt==15:
335 wd09=cadena[1:4]
336 wd10=cadena[5:8]
337 wd11=cadena[9:12]
338 wd12=cadena[13:16]
339 sd09=cadena[17:20]
340 sd10=cadena[21:24]
341 sd11=cadena[25:28]
342 sd12=cadena[29:32]
343 if cnt==16:
344 wd13=cadena[1:4]
345 wd14=cadena[5:8]
346 wd15=cadena[9:12]
347 wd16=cadena[13:16]
348 sd13=cadena[17:20]
349 sd14=cadena[21:24]
350 sd15=cadena[25:28]
351 sd16=cadena[29:32]
352 lst_n_up=[nu01,nu02,nu03,nu04,nu05,nu06,nu07,nu08,nu09,nu10,nu11,nu12,nu13,nu14,nu15,nu16]
353 lst_n_dw=[nd01,nd02,nd03,nd04,nd05,nd06,nd07,nd08,nd09,nd10,nd11,nd12,nd13,nd14,nd15,nd16]
354 lst_s_up=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16]
355 lst_s_dw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16]
356 lst_w_up=[wu01,wu02,wu03,wu04,wu05,wu06,wu07,wu08,wu09,wu10,wu11,wu12,wu13,wu14,wu15,wu16]
357 lst_w_dw=[wd01,wd02,wd03,wd04,wd05,wd06,wd07,wd08,wd09,wd10,wd11,wd12,wd13,wd14,wd15,wd16]
358 lst_e_up=[eu01,eu02,eu03,eu04,eu05,eu06,eu07,eu08,eu09,eu10,eu11,eu12,eu13,eu14,eu15,eu16]
359 lst_e_dw=[ed01,ed02,ed03,ed04,ed05,ed06,ed07,ed08,ed09,ed10,ed11,ed12,ed13,ed14,ed15,ed16]
360
361 lstup = lst_s_up + lst_w_up + lst_n_up + lst_e_up
362 lstdw = lst_s_dw + lst_w_dw + lst_n_up + lst_e_up
363
364 if polarizacion=='up':
365 return lstup
366 elif polarizacion=='dw':
367 return lstdw
368 fichero.close()
369
370
201 def CreaFormatoFinal():
371 def CreaFormatoFinal():
202 ne=NumeroDeExperimentos(archivo)
372 ne=NumeroDeExperimentos(archivo)
203
373
204 #nombre01 = file1(archivo,'1')
374 #nombre01 = file1(archivo,'1')
205 nombre02 = file1(archivo,'2')
375 nombre02 = file1(archivo,'2')
206 fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w')
376 fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w')
207 fichero.write(nombre02+'\n')
377 fichero.write(nombre02+'\n')
208 fichero.write(str(ne)+'\n')
378 fichero.write(str(ne)+'\n')
209 for i in range(1,17):
379 for i in range(1,17):
210
380
211 if i<10:
381 if i<10:
212 nmod = '0'+str(i)
382 nmod = '0'+str(i)
213 else: nmod = str(i)
383 else: nmod = str(i)
214
384
215
385
216 fichero.write('S'+nmod+'\n')
386 fichero.write('S'+nmod+'\n')
217 for j in range(1,ne+1):
387 for j in range(1,ne+1):
218 ruta=CarpetaDeTrabajo+str(j)+'.txt'
388 ruta=CarpetaDeTrabajo+str(j)+'.txt'
219 lu=CapturaValoresEnArchivo(ruta,polarizacion='up')
389 lu=CapturaValoresEnArchivo(ruta,polarizacion='up')
220 ld=CapturaValoresEnArchivo(ruta,polarizacion='dw')
390 ld=CapturaValoresEnArchivo(ruta,polarizacion='dw')
221 part1=''
391 part1=''
222 part2=''
392 part2=''
223 if lu[i-1]=='1.0': part1='000'
393 if lu[i-1]=='1.0': part1='000'
224 if lu[i-1]=='2.0': part1='001'
394 if lu[i-1]=='2.0': part1='001'
225 if lu[i-1]=='3.0': part1='010'
395 if lu[i-1]=='3.0': part1='010'
226 if lu[i-1]=='0.0': part1='011'
396 if lu[i-1]=='0.0': part1='011'
227 if lu[i-1]=='0.5': part1='100'
397 if lu[i-1]=='0.5': part1='100'
228 if lu[i-1]=='1.5': part1='101'
398 if lu[i-1]=='1.5': part1='101'
229 if lu[i-1]=='2.5': part1='110'
399 if lu[i-1]=='2.5': part1='110'
230 if lu[i-1]=='3.5': part1='111'
400 if lu[i-1]=='3.5': part1='111'
231 if ld[i-1]=='1.0': part2='000'
401 if ld[i-1]=='1.0': part2='000'
232 if ld[i-1]=='2.0': part2='001'
402 if ld[i-1]=='2.0': part2='001'
233 if ld[i-1]=='3.0': part2='010'
403 if ld[i-1]=='3.0': part2='010'
234 if ld[i-1]=='0.0': part2='011'
404 if ld[i-1]=='0.0': part2='011'
235 if ld[i-1]=='0.5': part2='100'
405 if ld[i-1]=='0.5': part2='100'
236 if ld[i-1]=='1.5': part2='101'
406 if ld[i-1]=='1.5': part2='101'
237 if ld[i-1]=='2.5': part2='110'
407 if ld[i-1]=='2.5': part2='110'
238 if ld[i-1]=='3.5': part2='111'
408 if ld[i-1]=='3.5': part2='111'
239 fichero.write(part1+part2+'\n')
409 fichero.write(part1+part2+'\n')
240 fichero.write('------'+'\n')
410 fichero.write('------'+'\n')
241 fichero.close()
411 fichero.close()
242
412
413 def CreaFormatoFinal2():
414 ne=NumeroDeExperimentos(archivo)
415
416 #nombre01 = file1(archivo,'1')
417 nombre02 = file1(archivo,'2')
418 fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w')
419 fichero.write(nombre02+'\n')
420 fichero.write(str(ne)+'\n')
421
422 for i in range(1,65):
423
424 if i<10:
425 nmod = '0'+str(i)
426 else: nmod = str(i)
427
428 fichero.write("ABS_" + nmod+'\n')
429
430 for j in range(1,ne+1):
431 ruta=CarpetaDeTrabajo+str(j)+'.txt'
432 lu=CapturaValoresEnArchivo2(ruta,polarizacion='up')
433 ld=CapturaValoresEnArchivo2(ruta,polarizacion='dw')
434 part1=''
435 part2=''
436 if lu[i-1]=='1.0': part1='000'
437 if lu[i-1]=='2.0': part1='001'
438 if lu[i-1]=='3.0': part1='010'
439 if lu[i-1]=='0.0': part1='011'
440 if lu[i-1]=='0.5': part1='100'
441 if lu[i-1]=='1.5': part1='101'
442 if lu[i-1]=='2.5': part1='110'
443 if lu[i-1]=='3.5': part1='111'
444 if ld[i-1]=='1.0': part2='000'
445 if ld[i-1]=='2.0': part2='001'
446 if ld[i-1]=='3.0': part2='010'
447 if ld[i-1]=='0.0': part2='011'
448 if ld[i-1]=='0.5': part2='100'
449 if ld[i-1]=='1.5': part2='101'
450 if ld[i-1]=='2.5': part2='110'
451 if ld[i-1]=='3.5': part2='111'
452 fichero.write(part1+part2+'\n')
453 fichero.write('------'+'\n')
454 fichero.close()
455
243 def EliminaArchivosEnLaCarpeta():
456 def EliminaArchivosEnLaCarpeta():
244 ne=NumeroDeExperimentos(archivo)
457 ne=NumeroDeExperimentos(archivo)
245 for i in range(1,ne+1):
458 for i in range(1,ne+1):
246 os.remove(CarpetaDeTrabajo+str(i)+'.txt')
459 os.remove(CarpetaDeTrabajo+str(i)+'.txt')
247
460
248 CreaFicherosPrevios()
461 CreaFicherosPrevios()
249 CreaFormatoFinal()
462 CreaFormatoFinal2()
250 EliminaArchivosEnLaCarpeta()
463 EliminaArchivosEnLaCarpeta()
251
464
252 ##########
465 ##########
253
466
254 if __name__ == '__main__':
467 if __name__ == '__main__':
255
468
256 filename = "experimento1.abs"
469 filename = "experimento1.abs"
257
470
258 absObj = ABSClient()
471 absObj = ABSClient()
259 absObj.sendFile(filename)
472 # absObj.sendFile(filename)
260 # absObj.changeBeam("0")
473 # absObj.changeBeam("0")
261 # absObj.changeBeam("1")
474 # absObj.changeBeam("1")
262 # absObj.changeBeam("2")
475 # absObj.changeBeam("2")
263 # absObj.changeBeam("3")
476 # absObj.changeBeam("3")
264 # absObj.changeBeam("4")
477 # absObj.changeBeam("4")
265 # absObj.changeBeam("5")
478 # absObj.changeBeam("5")
266 # absObj.changeBeam("6")
479 # absObj.changeBeam("6")
267 # absObj.changeBeam("7")
480 # absObj.changeBeam("7")
268 # absObj.getStatus(5) No newline at end of file
481 absObj.getStatus(5) No newline at end of file
@@ -1,336 +1,336
1 import os
1 import os
2 import library
2 import library
3 import time
3 import time
4
4
5 class ABSServer:
5 class ABSServer:
6
6
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None):
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None):
8
8
9 self.ipSource = ipSource
9 self.ipSource = ipSource
10 self.ipDestino = ipDestino
10 self.ipDestino = ipDestino
11 self.portDestino = portDestino
11 self.portDestino = portDestino
12
12
13 self.ipDestino2 = ipDestino2
13 self.ipDestino2 = ipDestino2
14 self.portDestino2 = portDestino2
14 self.portDestino2 = portDestino2
15
15
16 self.ftpPortDestino = ftpPortDestino
16 self.ftpPortDestino = ftpPortDestino
17 self.experiment_name = "default"
17 self.experiment_name = "default"
18 self.tx_buffer = "default"
18 self.tx_buffer = "default"
19
19
20 self.createObjects()
20 self.createObjects()
21
21
22 def createObjects(self):
22 def createObjects(self):
23
23
24 asServer = True
24 asServer = True
25 self.commServerObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino, asServer)
25 self.commServerObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino, asServer)
26 self.commClientObj = library.UDPComm(self.ipSource, self.ipDestino2, self.portDestino2)
26 self.commClientObj = library.UDPComm(self.ipSource, self.ipDestino2, self.portDestino2)
27 #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino)
27 #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino)
28
28
29 def sendFile(self, base):
29 def sendFile(self, base):
30
30
31 #Needed for the loop
31 #Needed for the loop
32 rx_frame_list = self.datarx.split('\n',2)
32 rx_frame_list = self.datarx.split('\n',2)
33
33
34 experiment_name = rx_frame_list[0]
34 experiment_name = rx_frame_list[0]
35 experiment_number = rx_frame_list[1]
35 experiment_number = rx_frame_list[1]
36 str_control_modules = rx_frame_list[2]
36 str_control_modules = rx_frame_list[2]
37
37
38 lst_control_modules = str_control_modules.split("------\n")
38 lst_control_modules = str_control_modules.split("------\n")
39 #Setting variables of the loop
39 #Setting variables of the loop
40 i =3
40 i =3
41 module = 1
41 module = 1
42 number_of_modules = 16
42 number_of_modules = 16
43 number_of_beams = int (experiment_number)
43 number_of_beams = int (experiment_number)
44 module_list = self.connection_status(10)
44 module_list = self.connection_status(10)
45 #Loop for creating and sending the control module files
45 #Loop for creating and sending the control module files
46 while module <= number_of_modules:
46 while module <= number_of_modules:
47 #Generating the control modules files
47 #Generating the control modules files
48 fobj = open(experiment_name,"w")
48 fobj = open(experiment_name,"w")
49 fobj.write(experiment_name + "\n")
49 fobj.write(experiment_name + "\n")
50 fobj.write("------\n")
50 fobj.write("------\n")
51 # tmp_list = rx_frame_list[i:i + number_of_beams + 1]
51 # tmp_list = rx_frame_list[i:i + number_of_beams + 1]
52 fobj.write(lst_control_modules[module-1])
52 fobj.write(lst_control_modules[module-1])
53 fobj.write("------\n")
53 fobj.write("------\n")
54 fobj.close()
54 fobj.close()
55 if module_list[module -1] == "1":
55 if module_list[module -1] == "1":
56 #Preparing and doing the tftp command
56 #Preparing and doing the tftp command
57 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c put " + experiment_name
57 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c put " + experiment_name
58 print cmd
58 print cmd
59 os.system(cmd)
59 os.system(cmd)
60 #Updating variables of the loop
60 #Updating variables of the loop
61 i = i + number_of_beams + 2
61 i = i + number_of_beams + 2
62 module += 1
62 module += 1
63 #Working with the UDP socket
63 #Working with the UDP socket
64 # self.commClientObj.sendData2ControlModules("CARGA:" + experiment_name + ":")
64 # self.commClientObj.sendData2ControlModules("CARGA:" + experiment_name + ":")
65 # self.commClientObj.sendData2ControlModules("CAMBIA:0:")
65 # self.commClientObj.sendData2ControlModules("CAMBIA:0:")
66 #Another tftp way
66 #Another tftp way
67 # self.ftpCommObj.sendFile(filename)
67 # self.ftpCommObj.sendFile(filename)
68 # rpta = self.commClientObj.sendTxRxCommand(cmd# filename2 = "report.txt"
68 # rpta = self.commClientObj.sendTxRxCommand(cmd# filename2 = "report.txt"
69 #fobj2 = open(filename2,"w")
69 #fobj2 = open(filename2,"w")
70 #fobj2.write("Verification_file\n")
70 #fobj2.write("Verification_file\n")
71 #fobj2.write("-----------------\n")
71 #fobj2.write("-----------------\n")
72 #fobj2.close()='CARGA', data=filename)
72 #fobj2.close()='CARGA', data=filename)
73 self.experiment_name = experiment_name
73 self.experiment_name = experiment_name
74
74
75
75
76 def __sendAnswer(self, cmd):
76 def sendAnswer(self, cmd):
77
77
78 data = "OK"
78 data = "OK"
79
79
80 if cmd == "SNDF":
80 if cmd == "SNDF":
81 self.commServerObj.sendData2(cmd="SNDF", data=data)
81 self.commServerObj.sendData2(cmd="SNDF", data=data)
82 if cmd == "CHGB":
82 if cmd == "CHGB":
83 self.commServerObj.sendData2(cmd="CHGB", data=data)
83 self.commServerObj.sendData2(cmd="CHGB", data=data)
84 if cmd == "ANST":
84 if cmd == "ANST":
85 data = self.tx_buffer
85 data = self.tx_buffer
86 self.commServerObj.sendData2(cmd="ANST", data=data)
86 self.commServerObj.sendData2(cmd="ANST", data=data)
87
87
88 def waitRequest(self):
88 def waitRequest(self):
89
89
90 ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData()
90 ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData()
91
91
92 datarpta = "OK"
92 datarpta = "OK"
93
93
94 if cmd == "SNDF":
94 if cmd == "SNDF":
95 self.sendFile2Modules()
95 self.sendFile2Modules()
96
96
97 if cmd == "CHGB":
97 if cmd == "CHGB":
98 self.changeBeam()
98 self.changeBeam()
99
99
100 if cmd == "ANST":
100 if cmd == "ANST":
101 self.getStatus(10, mode=2)
101 self.getStatus(10, mode=2)
102 datarpta = self.tx_buffer
102 datarpta = self.tx_buffer
103
103
104 self.commServerObj.sendData2(cmd=cmd, data=datarpta)
104 self.commServerObj.sendData2(cmd=cmd, data=datarpta)
105
105
106 return cmd
106 return cmd
107
107
108 def __writeReport(self, enaModules):
108 def __writeReport(self, enaModules):
109
109
110 status_array = ["Status of modules\n"]
110 status_array = ["Status of modules\n"]
111 status_array.append("----------------\n")
111 status_array.append("----------------\n")
112
112
113 for address in range(1,65):
113 for address in range(1,65):
114 if address in enaModules:
114 if address in enaModules:
115 # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n")
115 # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n")
116 status_array.append("192.168.1." + str(address) + " [1 1]\n")
116 status_array.append("192.168.1." + str(address) + " [1 1]\n")
117 else:
117 else:
118 status_array.append("192.168.1." + str(address) + " [0 0]\n")
118 status_array.append("192.168.1." + str(address) + " [0 0]\n")
119
119
120 f = open("module_status.txt","w")
120 f = open("module_status.txt","w")
121 f.writelines(status_array)
121 f.writelines(status_array)
122 f.close()
122 f.close()
123
123
124 def checkModule(self, address):
124 def checkModule(self, address):
125
125
126 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
126 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
127 status = os.system(cmd)
127 status = os.system(cmd)
128
128
129 if status == 256:
129 if status == 256:
130 return False
130 return False
131
131
132 return True
132 return True
133
133
134 def checkAntenna(self):
134 def checkAntenna(self):
135
135
136 """
136 """
137 Direccion de los modulos de las antenas:
137 Direccion de los modulos de las antenas:
138
138
139 Norte : 01-16
139 Norte : 01-16
140 Este : 17-32
140 Este : 17-32
141 Oeste: : 33-48
141 Oeste: : 33-48
142 Sur : 49-64
142 Sur : 49-64
143
143
144 """
144 """
145
145
146 enaModules = []
146 enaModules = []
147
147
148 for address in range(1,65):
148 for address in range(1,65):
149 if self.checkModule(address):
149 if self.checkModule(address):
150 enaModules.append(address)
150 enaModules.append(address)
151
151
152 self.__writeReport(enaModules)
152 self.__writeReport(enaModules)
153 return enaModules
153 return enaModules
154
154
155 def __loadFile(self):
155 def __loadFile(self):
156
156
157 #Working with the UDP socket
157 #Working with the UDP socket
158 self.commClientObj.sendData2ControlModules("CARGA:" + self.experiment_name + ":")
158 self.commClientObj.sendData2ControlModules("CARGA:" + self.experiment_name + ":")
159 self.commClientObj.sendData2ControlModules("CAMBIA:0:")
159 self.commClientObj.sendData2ControlModules("CAMBIA:0:")
160
160
161 def __writeModuleFile(self, filename, str):
161 def __writeModuleFile(self, filename, str):
162
162
163 fobj = open(filename,"w")
163 fobj = open(filename,"w")
164 fobj.write(filename + "\n")
164 fobj.write(filename + "\n")
165 fobj.write("------\n")
165 fobj.write("------\n")
166 fobj.write(str)
166 fobj.write(str)
167 fobj.write("------\n")
167 fobj.write("------\n")
168 fobj.close()
168 fobj.close()
169
169
170 def sendFile2Modules(self):
170 def sendFile2Modules(self):
171
171
172 #Needed for the loop
172 #Needed for the loop
173 rx_frame_list = self.datarx.split('\n',2)
173 rx_frame_list = self.datarx.split('\n',2)
174
174
175 experiment_name = rx_frame_list[0]
175 experiment_name = rx_frame_list[0]
176 experiment_number = rx_frame_list[1]
176 experiment_number = rx_frame_list[1]
177 str_control_modules = rx_frame_list[2]
177 str_control_modules = rx_frame_list[2]
178
178
179 lst_control_modules = str_control_modules.split("------\n")
179 lst_control_modules = str_control_modules.split("------\n")
180
180
181 enaModules = self.checkAntenna()
181 enaModules = self.checkAntenna()
182
182
183 for address in range(1,65):
183 for address in range(1,65):
184
184
185 if address not in enaModules:
185 if address not in enaModules:
186 continue
186 continue
187
187
188 self.__writeModuleFile(experiment_name, lst_control_modules[address-1])
188 self.__writeModuleFile(experiment_name, lst_control_modules[address-1])
189
189
190 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + experiment_name
190 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + experiment_name
191 print cmd
191 print cmd
192 os.system(cmd)
192 os.system(cmd)
193
193
194 self.experiment_name = experiment_name
194 self.experiment_name = experiment_name
195
195
196 self.__loadFile()
196 self.__loadFile()
197
197
198 def changeBeam(self):
198 def changeBeam(self):
199
199
200 #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0")
200 #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0")
201 self.commClientObj.sendData2ControlModules("CAMBIA:" + self.datarx + ":")
201 self.commClientObj.sendData2ControlModules("CAMBIA:" + self.datarx + ":")
202
202
203 def __getStsMode1(self):
203 def __getStsMode1(self):
204 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
204 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
205 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
205 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
206 seconds = int (self.datarx)
206 seconds = int (self.datarx)
207 # Give 5 seconds to the control modules
207 # Give 5 seconds to the control modules
208 time.sleep(seconds)
208 time.sleep(seconds)
209 # Checking the module connection
209 # Checking the module connection
210 module_list = self.connection_status(10)
210 module_list = self.connection_status(10)
211 #Generating the complete report
211 #Generating the complete report
212 module = 1
212 module = 1
213 number_of_modules = 16
213 number_of_modules = 16
214 filename1 = "Verificacion"
214 filename1 = "Verificacion"
215 filename2 = "report.txt"
215 filename2 = "report.txt"
216 fobj2 = open(filename2,"w")
216 fobj2 = open(filename2,"w")
217 fobj2.write("Verification_file\n")
217 fobj2.write("Verification_file\n")
218 fobj2.write("-----------------\n")
218 fobj2.write("-----------------\n")
219 fobj2.close()
219 fobj2.close()
220 while module <= number_of_modules:
220 while module <= number_of_modules:
221 if module_list[module -1] == "1":
221 if module_list[module -1] == "1":
222 #Preparing and doing the tftp command
222 #Preparing and doing the tftp command
223 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
223 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
224 print cmd
224 print cmd
225 os.system(cmd)
225 os.system(cmd)
226 # Getting data from the control module file
226 # Getting data from the control module file
227 fobj1 = open(filename1,"r")
227 fobj1 = open(filename1,"r")
228 file_list_1 = fobj1.readlines()
228 file_list_1 = fobj1.readlines()
229 fobj1.close()
229 fobj1.close()
230 content = file_list_1[2:-1]
230 content = file_list_1[2:-1]
231 #
231 #
232 fobj2 = open(filename2,"a")
232 fobj2 = open(filename2,"a")
233 if base == 10:
233 if base == 10:
234 fobj2.write("S" + str(module) + "\n")
234 fobj2.write("S" + str(module) + "\n")
235 else:
235 else:
236 fobj2.write("N" + str(module) + "\n")
236 fobj2.write("N" + str(module) + "\n")
237 fobj2.writelines(content)
237 fobj2.writelines(content)
238 fobj2.write("------\n")
238 fobj2.write("------\n")
239 fobj2.close()
239 fobj2.close()
240 module = module + 1
240 module = module + 1
241
241
242 def __getStsMode2(self):
242 def __getStsMode2(self):
243
243
244 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
244 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
245 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
245 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
246 seconds = int (self.datarx)
246 seconds = int (self.datarx)
247 # Give 5 seconds to the control modules
247 # Give 5 seconds to the control modules
248 time.sleep(seconds)
248 time.sleep(seconds)
249 # Checking the module connection
249 # Checking the module connection
250 module_list = self.connection_status(10)
250 module_list = self.connection_status(10)
251 #Generating the complete report
251 #Generating the complete report
252 module = 1
252 module = 1
253 number_of_modules = 16
253 number_of_modules = 16
254 filename1 = "Verificacion"
254 filename1 = "Verificacion"
255 line1 = "Verification_file\n"
255 line1 = "Verification_file\n"
256 line2 = "-----------------\n"
256 line2 = "-----------------\n"
257 report_list = [line1, line2]
257 report_list = [line1, line2]
258 while module <= number_of_modules:
258 while module <= number_of_modules:
259 if module_list[module -1] == "1":
259 if module_list[module -1] == "1":
260 #Preparing and doing the tftp command
260 #Preparing and doing the tftp command
261 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
261 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
262 print cmd
262 print cmd
263 os.system(cmd)
263 os.system(cmd)
264 #Sub_header
264 #Sub_header
265 if base == 10:
265 if base == 10:
266 report_list.append("S" + str(module) + "\n")
266 report_list.append("S" + str(module) + "\n")
267 else:
267 else:
268 report_list.append("N" + str(module) + "\n")
268 report_list.append("N" + str(module) + "\n")
269 # Content
269 # Content
270 fobj1 = open(filename1,"r")
270 fobj1 = open(filename1,"r")
271 file_list_1 = fobj1.readlines()
271 file_list_1 = fobj1.readlines()
272 fobj1.close()
272 fobj1.close()
273 content = ''.join(file_list_1[2:-1])
273 content = ''.join(file_list_1[2:-1])
274 # content = "010101\n"
274 # content = "010101\n"
275 report_list.append(content)
275 report_list.append(content)
276 #Ending
276 #Ending
277 report_list.append("------\n")
277 report_list.append("------\n")
278 module = module + 1
278 module = module + 1
279 #print "\nFinalizado"
279 #print "\nFinalizado"
280 self.tx_buffer = ''.join(report_list)
280 self.tx_buffer = ''.join(report_list)
281
281
282 def __getStsMode3(self):
282 def __getStsMode3(self):
283
283
284 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
284 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
285 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
285 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
286 seconds = int (self.datarx)
286 seconds = int (self.datarx)
287 # Give 5 seconds to the control modules
287 # Give 5 seconds to the control modules
288 time.sleep(seconds)
288 time.sleep(seconds)
289 # Checking the module connection
289 # Checking the module connection
290 module_list = self.connection_status(10)
290 module_list = self.connection_status(10)
291 #Generating the complete report
291 #Generating the complete report
292 module = 1
292 module = 1
293 number_of_modules = 16
293 number_of_modules = 16
294 filename1 = "Verificacion"
294 filename1 = "Verificacion"
295 line1 = "Verification_file\n"
295 line1 = "Verification_file\n"
296 line2 = "-----------------\n"
296 line2 = "-----------------\n"
297 report_list = [line1, line2]
297 report_list = [line1, line2]
298 while module <= number_of_modules:
298 while module <= number_of_modules:
299 if module_list[module -1] == "1":
299 if module_list[module -1] == "1":
300 #Preparing and doing the tftp command
300 #Preparing and doing the tftp command
301 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
301 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
302 print cmd
302 print cmd
303 os.system(cmd)
303 os.system(cmd)
304 #Sub_header
304 #Sub_header
305 if base == 10:
305 if base == 10:
306 report_list.append("S" + str(module) + "\n")
306 report_list.append("S" + str(module) + "\n")
307 else:
307 else:
308 report_list.append("N" + str(module) + "\n")
308 report_list.append("N" + str(module) + "\n")
309 # Content
309 # Content
310 fobj1 = open(filename1,"r")
310 fobj1 = open(filename1,"r")
311 file_list_1 = fobj1.readlines()
311 file_list_1 = fobj1.readlines()
312 fobj1.close()
312 fobj1.close()
313 content = ''.join(file_list_1[2:-1])
313 content = ''.join(file_list_1[2:-1])
314 # content = "010101\n"
314 # content = "010101\n"
315 report_list.append(content)
315 report_list.append(content)
316 #Ending
316 #Ending
317 report_list.append("------\n")
317 report_list.append("------\n")
318 module = module + 1
318 module = module + 1
319 #print "\nFinalizado"
319 #print "\nFinalizado"
320 self.tx_buffer = ''.join(report_list)
320 self.tx_buffer = ''.join(report_list)
321
321
322 def getStatus(self, base, mode):
322 def getStatus(self, base, mode):
323
323
324 if mode == 1:
324 if mode == 1:
325 self.__getStsMode1()
325 self.__getStsMode1()
326 else:
326 else:
327 self.__getStsMode2()
327 self.__getStsMode2()
328
328
329
329
330 if __name__ == '__main__':
330 if __name__ == '__main__':
331
331
332 absObj = ABSServer()
332 absObj = ABSServer()
333
333
334 while 1:
334 while 1:
335 cmd = absObj.waitRequest()
335 cmd = absObj.waitRequest()
336 absObj.__sendAnswer(cmd) No newline at end of file
336 absObj.sendAnswer(cmd) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now