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