@@ -1,259 +1,259 | |||||
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.sendTxRxCommand(cmd="SNDF", data=data) |
|
34 | self.commObj.sendTxRxCommand(cmd="SNDF", data=data) | |
35 |
|
35 | |||
36 | def changeBeam(self, newBeam): |
|
36 | def changeBeam(self, newBeam): | |
37 |
|
37 | |||
38 | self.commObj.sendTxRxCommand(cmd="CHGB", data=newBeam) |
|
38 | self.commObj.sendTxRxCommand(cmd="CHGB", data=newBeam) | |
39 |
|
39 | |||
40 | def getStatus(self): |
|
40 | def getStatus(self): | |
41 |
|
41 | |||
42 | self.commObj.sendTxRxCommand(cmd="ANST", data="ABS") |
|
42 | self.commObj.sendTxRxCommand(cmd="ANST", data="ABS") | |
43 |
|
43 | |||
44 | ########## |
|
44 | ########## | |
45 |
|
45 | |||
46 | def FuncionMaestra_GeneraFormatoControlCentral(self,archivo): |
|
46 | def FuncionMaestra_GeneraFormatoControlCentral(self,archivo): | |
47 | """ Funcion que genera un archivo para el control central""" |
|
47 | """ Funcion que genera un archivo para el control central""" | |
48 |
|
48 | |||
49 | # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/' |
|
49 | # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/' | |
50 | CarpetaDeTrabajo = os.getcwd() + '/' |
|
50 | CarpetaDeTrabajo = os.getcwd() + '/' | |
51 | #print CarpetaDeTrabajo |
|
51 | #print CarpetaDeTrabajo | |
52 | #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/' |
|
52 | #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/' | |
53 |
|
53 | |||
54 | def lst2string(lst): |
|
54 | def lst2string(lst): | |
55 | string='' |
|
55 | string='' | |
56 | for i in lst: |
|
56 | for i in lst: | |
57 | string=string+i |
|
57 | string=string+i | |
58 | return string |
|
58 | return string | |
59 |
|
59 | |||
60 | def string2lst(string): |
|
60 | def string2lst(string): | |
61 | lst = [] |
|
61 | lst = [] | |
62 | for i in string: |
|
62 | for i in string: | |
63 | lst.append(i) |
|
63 | lst.append(i) | |
64 | return lst |
|
64 | return lst | |
65 |
|
65 | |||
66 |
|
66 | |||
67 | def file1(string, type): |
|
67 | def file1(string, type): | |
68 | lst = string2lst(archivo) |
|
68 | lst = string2lst(archivo) | |
69 | fin = -1 |
|
69 | fin = -1 | |
70 | t = len(lst) |
|
70 | t = len(lst) | |
71 | for i in np.arange(-1,-t,-1): |
|
71 | for i in np.arange(-1,-t,-1): | |
72 | if lst[i]=='/': |
|
72 | if lst[i]=='/': | |
73 | fin=i |
|
73 | fin=i | |
74 | break |
|
74 | break | |
75 | if type == '1': |
|
75 | if type == '1': | |
76 | nombre2 = lst[fin+1:] |
|
76 | nombre2 = lst[fin+1:] | |
77 | nombre2[-1]='s' |
|
77 | nombre2[-1]='s' | |
78 | nombre2 = lst2string(nombre2) |
|
78 | nombre2 = lst2string(nombre2) | |
79 | return nombre2 |
|
79 | return nombre2 | |
80 | if type == '2': |
|
80 | if type == '2': | |
81 | nombre2 = lst[fin+1:] |
|
81 | nombre2 = lst[fin+1:] | |
82 | nombre2[-1]='1' |
|
82 | nombre2[-1]='1' | |
83 | nombre2 = lst2string(nombre2) |
|
83 | nombre2 = lst2string(nombre2) | |
84 | return nombre2 |
|
84 | return nombre2 | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | def EliminaSaltoDeLinea(cadena): |
|
87 | def EliminaSaltoDeLinea(cadena): | |
88 | i = 0 |
|
88 | i = 0 | |
89 | for elemento in cadena: |
|
89 | for elemento in cadena: | |
90 | if elemento =='\n' or elemento =='\r': |
|
90 | if elemento =='\n' or elemento =='\r': | |
91 | pass |
|
91 | pass | |
92 | else: |
|
92 | else: | |
93 | i=i+1 |
|
93 | i=i+1 | |
94 | return cadena [:i] |
|
94 | return cadena [:i] | |
95 |
|
95 | |||
96 | def NumeroDeExperimentos(path): |
|
96 | def NumeroDeExperimentos(path): | |
97 | fichero1=open(path,'r') |
|
97 | fichero1=open(path,'r') | |
98 | cont=0 |
|
98 | cont=0 | |
99 | for cadena in fichero1: |
|
99 | for cadena in fichero1: | |
100 | cont=cont+1 |
|
100 | cont=cont+1 | |
101 | if cont==3: |
|
101 | if cont==3: | |
102 | nexp='' |
|
102 | nexp='' | |
103 | pos=0 |
|
103 | pos=0 | |
104 | for elemento in cadena: |
|
104 | for elemento in cadena: | |
105 | pos=pos+1 |
|
105 | pos=pos+1 | |
106 | if elemento=='=': |
|
106 | if elemento=='=': | |
107 | nexp=int(cadena[pos:]) |
|
107 | nexp=int(cadena[pos:]) | |
108 | return nexp |
|
108 | return nexp | |
109 | fichero1.close() |
|
109 | fichero1.close() | |
110 |
|
110 | |||
111 | def Paridad(numero): |
|
111 | def Paridad(numero): | |
112 | if numero%2==0: return 'par' |
|
112 | if numero%2==0: return 'par' | |
113 | elif numero%2==1: return 'impar' |
|
113 | elif numero%2==1: return 'impar' | |
114 |
|
114 | |||
115 | def EvaluaCadena(cadena): |
|
115 | def EvaluaCadena(cadena): | |
116 | if len(cadena)>35: |
|
116 | if len(cadena)>35: | |
117 | if cadena[-1]=='$': |
|
117 | if cadena[-1]=='$': | |
118 | return cadena[-35:-2] |
|
118 | return cadena[-35:-2] | |
119 | elif cadena[-1]==']': |
|
119 | elif cadena[-1]==']': | |
120 | return cadena[-34:-1] |
|
120 | return cadena[-34:-1] | |
121 | else: |
|
121 | else: | |
122 | return None |
|
122 | return None | |
123 |
|
123 | |||
124 | def GuardaEnLista(path): |
|
124 | def GuardaEnLista(path): | |
125 | fichero=open(path,'r') |
|
125 | fichero=open(path,'r') | |
126 | lista=[] |
|
126 | lista=[] | |
127 | for cadena in fichero: |
|
127 | for cadena in fichero: | |
128 | cadena = EliminaSaltoDeLinea(cadena) |
|
128 | cadena = EliminaSaltoDeLinea(cadena) | |
129 | cadena = EvaluaCadena(cadena) |
|
129 | cadena = EvaluaCadena(cadena) | |
130 | if cadena != None: |
|
130 | if cadena != None: | |
131 | lista.append(cadena) |
|
131 | lista.append(cadena) | |
132 | fichero.close() |
|
132 | fichero.close() | |
133 | return lista |
|
133 | return lista | |
134 |
|
134 | |||
135 | def CreaFicherosPrevios(): |
|
135 | def CreaFicherosPrevios(): | |
136 | vector = GuardaEnLista(archivo) |
|
136 | vector = GuardaEnLista(archivo) | |
137 | for i in range(1,NumeroDeExperimentos(archivo)+1): |
|
137 | for i in range(1,NumeroDeExperimentos(archivo)+1): | |
138 | fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w') |
|
138 | fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w') | |
139 | for j in range(0,16): |
|
139 | for j in range(0,16): | |
140 | fichero.write(vector[j+16*(i-1)]+'\n') |
|
140 | fichero.write(vector[j+16*(i-1)]+'\n') | |
141 | fichero.close() |
|
141 | fichero.close() | |
142 |
|
142 | |||
143 | def CapturaValoresEnArchivo(path,polarizacion='up'): |
|
143 | def CapturaValoresEnArchivo(path,polarizacion='up'): | |
144 | fichero =open(path,'r') |
|
144 | fichero =open(path,'r') | |
145 | cnt=0 |
|
145 | cnt=0 | |
146 | lstup=[] |
|
146 | lstup=[] | |
147 | lstdw=[] |
|
147 | lstdw=[] | |
148 | for cadena in fichero: |
|
148 | for cadena in fichero: | |
149 | cnt=cnt+1 |
|
149 | cnt=cnt+1 | |
150 | if cnt==5: |
|
150 | if cnt==5: | |
151 | su01=cadena[17:20] |
|
151 | su01=cadena[17:20] | |
152 | su02=cadena[21:24] |
|
152 | su02=cadena[21:24] | |
153 | su03=cadena[25:28] |
|
153 | su03=cadena[25:28] | |
154 | su04=cadena[29:32] |
|
154 | su04=cadena[29:32] | |
155 | if cnt==6: |
|
155 | if cnt==6: | |
156 | su05=cadena[17:20] |
|
156 | su05=cadena[17:20] | |
157 | su06=cadena[21:24] |
|
157 | su06=cadena[21:24] | |
158 | su07=cadena[25:28] |
|
158 | su07=cadena[25:28] | |
159 | su08=cadena[29:32] |
|
159 | su08=cadena[29:32] | |
160 | if cnt==7: |
|
160 | if cnt==7: | |
161 | su09=cadena[17:20] |
|
161 | su09=cadena[17:20] | |
162 | su10=cadena[21:24] |
|
162 | su10=cadena[21:24] | |
163 | su11=cadena[25:28] |
|
163 | su11=cadena[25:28] | |
164 | su12=cadena[29:32] |
|
164 | su12=cadena[29:32] | |
165 | if cnt==8: |
|
165 | if cnt==8: | |
166 | su13=cadena[17:20] |
|
166 | su13=cadena[17:20] | |
167 | su14=cadena[21:24] |
|
167 | su14=cadena[21:24] | |
168 | su15=cadena[25:28] |
|
168 | su15=cadena[25:28] | |
169 | su16=cadena[29:32] |
|
169 | su16=cadena[29:32] | |
170 | if cnt==13: |
|
170 | if cnt==13: | |
171 | sd01=cadena[17:20] |
|
171 | sd01=cadena[17:20] | |
172 | sd02=cadena[21:24] |
|
172 | sd02=cadena[21:24] | |
173 | sd03=cadena[25:28] |
|
173 | sd03=cadena[25:28] | |
174 | sd04=cadena[29:32] |
|
174 | sd04=cadena[29:32] | |
175 | if cnt==14: |
|
175 | if cnt==14: | |
176 | sd05=cadena[17:20] |
|
176 | sd05=cadena[17:20] | |
177 | sd06=cadena[21:24] |
|
177 | sd06=cadena[21:24] | |
178 | sd07=cadena[25:28] |
|
178 | sd07=cadena[25:28] | |
179 | sd08=cadena[29:32] |
|
179 | sd08=cadena[29:32] | |
180 | if cnt==15: |
|
180 | if cnt==15: | |
181 | sd09=cadena[17:20] |
|
181 | sd09=cadena[17:20] | |
182 | sd10=cadena[21:24] |
|
182 | sd10=cadena[21:24] | |
183 | sd11=cadena[25:28] |
|
183 | sd11=cadena[25:28] | |
184 | sd12=cadena[29:32] |
|
184 | sd12=cadena[29:32] | |
185 | if cnt==16: |
|
185 | if cnt==16: | |
186 | sd13=cadena[17:20] |
|
186 | sd13=cadena[17:20] | |
187 | sd14=cadena[21:24] |
|
187 | sd14=cadena[21:24] | |
188 | sd15=cadena[25:28] |
|
188 | sd15=cadena[25:28] | |
189 | sd16=cadena[29:32] |
|
189 | sd16=cadena[29:32] | |
190 | lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] |
|
190 | lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] | |
191 | lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] |
|
191 | lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] | |
192 | if polarizacion=='up': |
|
192 | if polarizacion=='up': | |
193 | return lstup |
|
193 | return lstup | |
194 | elif polarizacion=='dw': |
|
194 | elif polarizacion=='dw': | |
195 | return lstdw |
|
195 | return lstdw | |
196 | fichero.close() |
|
196 | fichero.close() | |
197 |
|
197 | |||
198 | def CreaFormatoFinal(): |
|
198 | def CreaFormatoFinal(): | |
199 | ne=NumeroDeExperimentos(archivo) |
|
199 | ne=NumeroDeExperimentos(archivo) | |
200 |
|
200 | |||
201 | #nombre01 = file1(archivo,'1') |
|
201 | #nombre01 = file1(archivo,'1') | |
202 | nombre02 = file1(archivo,'1') |
|
202 | nombre02 = file1(archivo,'1') | |
203 | fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') |
|
203 | fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') | |
204 | fichero.write(nombre02+'\n') |
|
204 | fichero.write(nombre02+'\n') | |
205 | fichero.write(str(ne)+'\n') |
|
205 | fichero.write(str(ne)+'\n') | |
206 | for i in range(1,17): |
|
206 | for i in range(1,17): | |
207 |
|
207 | |||
208 | if i<10: |
|
208 | if i<10: | |
209 | nmod = '0'+str(i) |
|
209 | nmod = '0'+str(i) | |
210 | else: nmod = str(i) |
|
210 | else: nmod = str(i) | |
211 |
|
211 | |||
212 |
|
212 | |||
213 | fichero.write('S'+nmod+'\n') |
|
213 | fichero.write('S'+nmod+'\n') | |
214 | for j in range(1,ne+1): |
|
214 | for j in range(1,ne+1): | |
215 | ruta=CarpetaDeTrabajo+str(j)+'.txt' |
|
215 | ruta=CarpetaDeTrabajo+str(j)+'.txt' | |
216 | lu=CapturaValoresEnArchivo(ruta,polarizacion='up') |
|
216 | lu=CapturaValoresEnArchivo(ruta,polarizacion='up') | |
217 | ld=CapturaValoresEnArchivo(ruta,polarizacion='dw') |
|
217 | ld=CapturaValoresEnArchivo(ruta,polarizacion='dw') | |
218 | part1='' |
|
218 | part1='' | |
219 | part2='' |
|
219 | part2='' | |
220 | if lu[i-1]=='1.0': part1='000' |
|
220 | if lu[i-1]=='1.0': part1='000' | |
221 | if lu[i-1]=='2.0': part1='001' |
|
221 | if lu[i-1]=='2.0': part1='001' | |
222 | if lu[i-1]=='3.0': part1='010' |
|
222 | if lu[i-1]=='3.0': part1='010' | |
223 | if lu[i-1]=='0.0': part1='011' |
|
223 | if lu[i-1]=='0.0': part1='011' | |
224 | if lu[i-1]=='0.5': part1='100' |
|
224 | if lu[i-1]=='0.5': part1='100' | |
225 | if lu[i-1]=='1.5': part1='101' |
|
225 | if lu[i-1]=='1.5': part1='101' | |
226 | if lu[i-1]=='2.5': part1='110' |
|
226 | if lu[i-1]=='2.5': part1='110' | |
227 | if lu[i-1]=='3.5': part1='111' |
|
227 | if lu[i-1]=='3.5': part1='111' | |
228 | if ld[i-1]=='1.0': part2='000' |
|
228 | if ld[i-1]=='1.0': part2='000' | |
229 | if ld[i-1]=='2.0': part2='001' |
|
229 | if ld[i-1]=='2.0': part2='001' | |
230 | if ld[i-1]=='3.0': part2='010' |
|
230 | if ld[i-1]=='3.0': part2='010' | |
231 | if ld[i-1]=='0.0': part2='011' |
|
231 | if ld[i-1]=='0.0': part2='011' | |
232 | if ld[i-1]=='0.5': part2='100' |
|
232 | if ld[i-1]=='0.5': part2='100' | |
233 | if ld[i-1]=='1.5': part2='101' |
|
233 | if ld[i-1]=='1.5': part2='101' | |
234 | if ld[i-1]=='2.5': part2='110' |
|
234 | if ld[i-1]=='2.5': part2='110' | |
235 | if ld[i-1]=='3.5': part2='111' |
|
235 | if ld[i-1]=='3.5': part2='111' | |
236 | fichero.write(part1+part2+'\n') |
|
236 | fichero.write(part1+part2+'\n') | |
237 | fichero.write('------'+'\n') |
|
237 | fichero.write('------'+'\n') | |
238 | fichero.close() |
|
238 | fichero.close() | |
239 |
|
239 | |||
240 | def EliminaArchivosEnLaCarpeta(): |
|
240 | def EliminaArchivosEnLaCarpeta(): | |
241 | ne=NumeroDeExperimentos(archivo) |
|
241 | ne=NumeroDeExperimentos(archivo) | |
242 | for i in range(1,ne+1): |
|
242 | for i in range(1,ne+1): | |
243 | os.remove(CarpetaDeTrabajo+str(i)+'.txt') |
|
243 | os.remove(CarpetaDeTrabajo+str(i)+'.txt') | |
244 |
|
244 | |||
245 | CreaFicherosPrevios() |
|
245 | CreaFicherosPrevios() | |
246 | CreaFormatoFinal() |
|
246 | CreaFormatoFinal() | |
247 | EliminaArchivosEnLaCarpeta() |
|
247 | EliminaArchivosEnLaCarpeta() | |
248 |
|
248 | |||
249 | ########## |
|
249 | ########## | |
250 |
|
250 | |||
251 | if __name__ == '__main__': |
|
251 | if __name__ == '__main__': | |
252 |
|
252 | |||
253 | filename = "experimento1.abs" |
|
253 | filename = "experimento1.abs" | |
254 |
|
254 | |||
255 | absObj = ABSClient() |
|
255 | absObj = ABSClient() | |
256 |
|
|
256 | absObj.sendFile(filename) | |
257 | # absObj.changeBeam("0") |
|
257 | # absObj.changeBeam("0") | |
258 | absObj.changeBeam("2") |
|
258 | # absObj.changeBeam("2") | |
259 | # absObj.changeBeam("7") No newline at end of file |
|
259 | # absObj.changeBeam("7") |
General Comments 0
You need to be logged in to leave comments.
Login now