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