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