##// END OF EJS Templates
changes with frame corrected
imanay -
r108:109
parent child
Show More
@@ -1,529 +1,531
1 1 # Needed for the FilesStuff class
2 2 import os
3 3 import numpy as np
4 4 # Needed for the TCPComm class
5 5 import socket
6 6
7 7 class TCPComm:
8 8
9 9 __HEADER = "JRO"
10 10 __TYPE = "ABS"
11 11
12 12 def __init__(self, ipSource, iDSource, ipDestino, iDDestino, portDestino, asServer=False):
13 13
14 14 self.ipSource = ipSource
15 15 self.iDSource = iDSource
16 16 self.ipDestino = ipDestino
17 17 self.iDDestino = iDDestino
18 18 self.portDestino = portDestino
19 19 self.addr = (ipDestino,portDestino)
20 20
21 21 self.sc = "none"
22 22 self.answer = "none" #test
23 23 self.asServer = False
24 24 self.len = "000000"
25 25 self.crc = "0"
26 26
27 27 self.openSocket(asServer)
28 28
29 29 def openSocket(self, asServer):
30 30
31 31 #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM)
32 32 # self.socket_c = socket.socket()
33 33 # self.socket_c.connect((self.ipDestino, self.portDestino))
34 34
35 35 if asServer:
36 36 self.socket_c = socket.socket()
37 37 # self.configAsServer()
38 38 self.socket_c.bind(self.addr)
39 39 self.asServer = True
40 40 else:
41 41 # self.configAsClient()
42 42 self.asServer = False #Socket is opened at the sendData function
43 43
44 44 # def configAsClient(self):
45 45 #Buscar broadcast TCP
46 46 # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
47 47 # self.socket_c.connect(self.addr)
48 48 # pass
49 49
50 50 # def configAsServer(self):
51 51 #
52 52 # self.socket_c.bind(self.addr)
53 53
54 54 def waitData(self):
55 55 if self.asServer == True:
56 56 trama_rx, l = self.waitAsServer()
57 57 else:
58 58 trama_rx, l = self.waitAsClient()
59 59
60 60 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx, l)
61 61
62 62 return ipSource, ipDestino, cmd, data
63 63
64 64 def waitAsClient2(self, nbytes = 1024):
65 65 print "\nWaiting the server."
66 66 # Short data through ethernet
67 67 trama_rx = self.socket_c.recv(nbytes)
68 68 print "\nThis socket has received this data: " + str(trama_rx)
69 69
70 70 return trama_rx
71 71
72 72 def waitAsServer2(self, nbytes = 1024):
73 73 print "\nWaiting some client."
74 74 self.socket_c.listen(1)
75 75 sc, addr = self.socket_c.accept()
76 76 self.sc = sc
77 77 self.answer = addr
78 78 # Big data through ethernet
79 79 trama_rx = ""
80 80 while True:
81 81 tmp = self.sc.recv(nbytes)
82 82 trama_rx = trama_rx + tmp
83 83 if trama_rx[-4:] == "quit":
84 84 break
85 85
86 86 print "\nThis socket has received some data from: " + str(self.answer)
87 87
88 88 return trama_rx
89 89
90 90 def waitAsServer(self, nbytes = 1024):
91 91 print "\nWaiting some client."
92 92 self.socket_c.listen(1)
93 93 sc, addr = self.socket_c.accept()
94 94 self.sc = sc
95 95 self.answer = addr
96 96 # Big data through ethernet
97 97 cnt = 0;
98 98 first = 0;
99 99 trama_rx = ""
100 100 while True:
101 101 tmp = self.sc.recv(nbytes)
102 102 trama_rx = trama_rx + tmp
103 103 cnt = len(trama_rx)
104 104 if first == 0:
105 105 first = 1
106 106 lng = int(trama_rx[20:26])
107 print str(lng)
107 108 if cnt == lng:
108 109 break
109 110
110 111 print "\nThis socket has received some data from: " + str(self.answer)
111 112
112 113 return trama_rx, lng
113 114
114 115 def waitAsClient(self, nbytes = 1024):
115 116 print "\nWaiting the server."
116 117 # Short data through ethernet
117 118 trama_rx = self.socket_c.recv(nbytes)
118 119 lng = int(trama_rx[20:26])
120 print str(lng)
119 121 print "\nThis socket has received this data: " + str(trama_rx)
120 122
121 123 return trama_rx, lng
122 124
123 125 def sendData2(self, cmd, data, ipDestino):
124 126
125 127 trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \
126 128 ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit"
127 129
128 130 if self.asServer == True:
129 131 self.SendAsServer(trama_tx)
130 132 else:
131 133 self.SendAsClient(ipDestino, trama_tx)
132 134
133 135 def sendData(self, cmd, data, ipDestino):
134 136
135 137 trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \
136 138 self.iDDestino + self.len + str(cmd) + str(data) + self.crc
137 139
138 140 self.len = self.int2str(len(trama_tx))
139 141
140 142 trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \
141 143 self.iDDestino + self.len + str(cmd) + str(data) + self.crc
142 144
143 145 print trama_tx
144 146
145 147 if self.asServer == True:
146 148 self.SendAsServer(trama_tx)
147 149 else:
148 150 self.SendAsClient(ipDestino, trama_tx)
149 151
150 152 def SendAsServer(self, trama_tx):
151 153
152 154 self.sc.send(trama_tx)
153 155 print "Sending message:[" + trama_tx + "] to: " + str(self.answer)
154 156
155 157
156 158 def SendAsClient(self, ipDestino, trama_tx):
157 159
158 160 self.socket_c.connect((ipDestino, self.portDestino))
159 161 self.socket_c.send(trama_tx)
160 162 print "Sending message:[" + trama_tx + "] to: " + ipDestino
161 163
162 164 def __getTrama2(self, trama):
163 165
164 166 FrameList = trama.split(':')
165 167
166 168 header = FrameList[0]
167 169 TypeOfInstrument = FrameList[1]
168 170 ipSource = FrameList[2]
169 171 ipDestino = FrameList[3]
170 172 len = FrameList[4]
171 173 cmd = FrameList[5]
172 174 data = FrameList[6]
173 175 crc = FrameList[7]
174 176 trash = FrameList[8]
175 177
176 178 return ipSource, ipDestino, cmd, data
177 179
178 180 def __getTrama(self, trama, l):
179 181
180 182 header = trama[0:3]
181 183 TypeOfInstrument = trama[3:6]
182 184 ipSource = trama[6:13]
183 185 ipDestino = trama[13:20]
184 186 len = trama[20:26]
185 187 cmd = trama[26:30]
186 188 ldata = l-31
187 189 data = trama[30:30+ldata]
188 190 crc = trama[30+ldata:]
189 191
190 192 return ipSource, ipDestino, cmd, data
191 193
192 194 def close_socket(self):
193 195 self.socket_c.close()
194 196
195 197 def open_socket(self):
196 198 self.socket_c = socket.socket()
197 199
198 200 def int2str(self, n):
199 201
200 202 str_n = str(n)
201 203 l_n = len(str_n)
202 204 if l_n == 1:
203 205 str_n = "00000" + str_n
204 206 elif l_n == 2:
205 207 str_n = "0000" + str_n
206 208 elif l_n == 3:
207 209 str_n = "000" + str_n
208 210 elif l_n == 4:
209 211 str_n = "00" + str_n
210 212 elif l_n == 5:
211 213 str_n = "0" + str_n
212 214 return str_n
213 215
214 216 class FilesStuff():
215 217
216 218 def lst2string(self, lst):
217 219 string=''
218 220 for i in lst:
219 221 string=string+i
220 222 return string
221 223
222 224 def string2lst(self, string):
223 225 lst = []
224 226 for i in string:
225 227 lst.append(i)
226 228 return lst
227 229
228 230
229 231 def file1(self, filename, type):
230 232 lst = self.string2lst(filename)
231 233 fin = -1
232 234 t = len(lst)
233 235 for i in np.arange(-1,-t,-1):
234 236 if lst[i]=='/':
235 237 fin=i
236 238 break
237 239 if type == '1':
238 240 nombre2 = lst[fin+1:]
239 241 nombre2[-1]='s'
240 242 nombre2 = self.lst2string(nombre2)
241 243 return nombre2
242 244 if type == '2':
243 245 nombre2 = lst[fin+1:]
244 246 nombre2[-1]='1'
245 247 nombre2 = self.lst2string(nombre2)
246 248 return nombre2
247 249
248 250
249 251 def EliminaSaltoDeLinea(self,cadena):
250 252 i = 0
251 253 for elemento in cadena:
252 254 if elemento =='\n' or elemento =='\r':
253 255 pass
254 256 else:
255 257 i=i+1
256 258 return cadena [:i]
257 259
258 260 def NumeroDeExperimentos(self, path):
259 261 fichero1=open(path,'r')
260 262 cont=0
261 263 for cadena in fichero1:
262 264 cont=cont+1
263 265 if cont==3:
264 266 nexp=''
265 267 pos=0
266 268 for elemento in cadena:
267 269 pos=pos+1
268 270 if elemento=='=':
269 271 nexp=int(cadena[pos:])
270 272 return nexp
271 273 fichero1.close()
272 274
273 275 def Paridad(numero):
274 276 if numero%2==0: return 'par'
275 277 elif numero%2==1: return 'impar'
276 278
277 279 def EvaluaCadena(self,cadena):
278 280 if len(cadena)>35:
279 281 if cadena[-1]=='$':
280 282 return cadena[-35:-2]
281 283 elif cadena[-1]==']':
282 284 return cadena[-34:-1]
283 285 else:
284 286 return None
285 287
286 288 def GuardaEnLista(self,path):
287 289 fichero=open(path,'r')
288 290 lista=[]
289 291 for cadena in fichero:
290 292 cadena = self.EliminaSaltoDeLinea(cadena)
291 293 cadena = self.EvaluaCadena(cadena)
292 294 if cadena != None:
293 295 lista.append(cadena)
294 296 fichero.close()
295 297 return lista
296 298
297 299 def CreaFicherosPrevios(self, path, archivo):
298 300 vector = self.GuardaEnLista(archivo)
299 301 for i in range(1,self.NumeroDeExperimentos(archivo)+1):
300 302 fichero =open(path + str(i)+ '.txt','w')
301 303 for j in range(0,16):
302 304 fichero.write(vector[j+16*(i-1)]+'\n')
303 305 fichero.close()
304 306
305 307 def CapturaValoresEnArchivo(self, path, polarizacion='up'):
306 308 fichero =open(path,'r')
307 309 cnt=0
308 310 lstup=[]
309 311 lstdw=[]
310 312 for cadena in fichero:
311 313 cnt=cnt+1
312 314 if cnt==1:
313 315 nu01=cadena[1:4]
314 316 nu02=cadena[5:8]
315 317 nu03=cadena[9:12]
316 318 nu04=cadena[13:16]
317 319 eu01=cadena[17:20]
318 320 eu02=cadena[21:24]
319 321 eu03=cadena[25:28]
320 322 eu04=cadena[29:32]
321 323 if cnt==2:
322 324 nu05=cadena[1:4]
323 325 nu06=cadena[5:8]
324 326 nu07=cadena[9:12]
325 327 nu08=cadena[13:16]
326 328 eu05=cadena[17:20]
327 329 eu06=cadena[21:24]
328 330 eu07=cadena[25:28]
329 331 eu08=cadena[29:32]
330 332 if cnt==3:
331 333 nu09=cadena[1:4]
332 334 nu10=cadena[5:8]
333 335 nu11=cadena[9:12]
334 336 nu12=cadena[13:16]
335 337 eu09=cadena[17:20]
336 338 eu10=cadena[21:24]
337 339 eu11=cadena[25:28]
338 340 eu12=cadena[29:32]
339 341 if cnt==4:
340 342 nu13=cadena[1:4]
341 343 nu14=cadena[5:8]
342 344 nu15=cadena[9:12]
343 345 nu16=cadena[13:16]
344 346 eu13=cadena[17:20]
345 347 eu14=cadena[21:24]
346 348 eu15=cadena[25:28]
347 349 eu16=cadena[29:32]
348 350 if cnt==5:
349 351 wu01=cadena[1:4]
350 352 wu02=cadena[5:8]
351 353 wu03=cadena[9:12]
352 354 wu04=cadena[13:16]
353 355 su01=cadena[17:20]
354 356 su02=cadena[21:24]
355 357 su03=cadena[25:28]
356 358 su04=cadena[29:32]
357 359 if cnt==6:
358 360 wu05=cadena[1:4]
359 361 wu06=cadena[5:8]
360 362 wu07=cadena[9:12]
361 363 wu08=cadena[13:16]
362 364 su05=cadena[17:20]
363 365 su06=cadena[21:24]
364 366 su07=cadena[25:28]
365 367 su08=cadena[29:32]
366 368 if cnt==7:
367 369 wu09=cadena[1:4]
368 370 wu10=cadena[5:8]
369 371 wu11=cadena[9:12]
370 372 wu12=cadena[13:16]
371 373 su09=cadena[17:20]
372 374 su10=cadena[21:24]
373 375 su11=cadena[25:28]
374 376 su12=cadena[29:32]
375 377 if cnt==8:
376 378 wu13=cadena[1:4]
377 379 wu14=cadena[5:8]
378 380 wu15=cadena[9:12]
379 381 wu16=cadena[13:16]
380 382 su13=cadena[17:20]
381 383 su14=cadena[21:24]
382 384 su15=cadena[25:28]
383 385 su16=cadena[29:32]
384 386 if cnt==9:
385 387 nd01=cadena[1:4]
386 388 nd02=cadena[5:8]
387 389 nd03=cadena[9:12]
388 390 nd04=cadena[13:16]
389 391 ed01=cadena[17:20]
390 392 ed02=cadena[21:24]
391 393 ed03=cadena[25:28]
392 394 ed04=cadena[29:32]
393 395 if cnt==10:
394 396 nd05=cadena[1:4]
395 397 nd06=cadena[5:8]
396 398 nd07=cadena[9:12]
397 399 nd08=cadena[13:16]
398 400 ed05=cadena[17:20]
399 401 ed06=cadena[21:24]
400 402 ed07=cadena[25:28]
401 403 ed08=cadena[29:32]
402 404 if cnt==11:
403 405 nd09=cadena[1:4]
404 406 nd10=cadena[5:8]
405 407 nd11=cadena[9:12]
406 408 nd12=cadena[13:16]
407 409 ed09=cadena[17:20]
408 410 ed10=cadena[21:24]
409 411 ed11=cadena[25:28]
410 412 ed12=cadena[29:32]
411 413 if cnt==12:
412 414 nd13=cadena[1:4]
413 415 nd14=cadena[5:8]
414 416 nd15=cadena[9:12]
415 417 nd16=cadena[13:16]
416 418 ed13=cadena[17:20]
417 419 ed14=cadena[21:24]
418 420 ed15=cadena[25:28]
419 421 ed16=cadena[29:32]
420 422 if cnt==13:
421 423 wd01=cadena[1:4]
422 424 wd02=cadena[5:8]
423 425 wd03=cadena[9:12]
424 426 wd04=cadena[13:16]
425 427 sd01=cadena[17:20]
426 428 sd02=cadena[21:24]
427 429 sd03=cadena[25:28]
428 430 sd04=cadena[29:32]
429 431 if cnt==14:
430 432 wd05=cadena[1:4]
431 433 wd06=cadena[5:8]
432 434 wd07=cadena[9:12]
433 435 wd08=cadena[13:16]
434 436 sd05=cadena[17:20]
435 437 sd06=cadena[21:24]
436 438 sd07=cadena[25:28]
437 439 sd08=cadena[29:32]
438 440 if cnt==15:
439 441 wd09=cadena[1:4]
440 442 wd10=cadena[5:8]
441 443 wd11=cadena[9:12]
442 444 wd12=cadena[13:16]
443 445 sd09=cadena[17:20]
444 446 sd10=cadena[21:24]
445 447 sd11=cadena[25:28]
446 448 sd12=cadena[29:32]
447 449 if cnt==16:
448 450 wd13=cadena[1:4]
449 451 wd14=cadena[5:8]
450 452 wd15=cadena[9:12]
451 453 wd16=cadena[13:16]
452 454 sd13=cadena[17:20]
453 455 sd14=cadena[21:24]
454 456 sd15=cadena[25:28]
455 457 sd16=cadena[29:32]
456 458 blck_1_up = [nu01,nu02,nu03,nu04,eu01,eu02,eu03,eu04,nu05,nu06,nu07,nu08,eu05,eu06,eu07,eu08]
457 459 blck_1_dw = [nd01,nd02,nd03,nd04,ed01,ed02,ed03,ed04,nd05,nd06,nd07,nd08,ed05,ed06,ed07,ed08]
458 460 blck_2_up = [nu09,nu10,nu11,nu12,eu09,eu10,eu11,eu12,nu13,nu14,nu15,nu16,eu13,eu14,eu15,eu16]
459 461 blck_2_dw = [nd09,nd10,nd11,nd12,ed09,ed10,ed11,ed12,nd13,nd14,nd15,nd16,ed13,ed14,ed15,ed16]
460 462 blck_3_up = [wu01,wu02,wu03,wu04,su01,su02,su03,su04,wu05,wu06,wu07,wu08,su05,su06,su07,su08]
461 463 blck_3_dw = [wd01,wd02,wd03,wd04,sd01,sd02,sd03,sd04,wd05,wd06,wd07,wd08,sd05,sd06,sd07,sd08]
462 464 blck_4_up = [wu09,wu10,wu11,wu12,su09,su10,su11,su12,wu13,wu14,wu15,wu16,su13,su14,su15,su16]
463 465 blck_4_dw = [wd09,wd10,wd11,wd12,sd09,sd10,sd11,sd12,wd13,wd14,wd15,wd16,sd13,sd14,sd15,sd16]
464 466
465 467 lstup = blck_1_up + blck_2_up + blck_3_up + blck_4_up
466 468 lstdw = blck_1_dw + blck_2_dw + blck_3_dw + blck_4_dw
467 469
468 470 if polarizacion=='up':
469 471 return lstup
470 472 elif polarizacion=='dw':
471 473 return lstdw
472 474 fichero.close()
473 475
474 476 def CreaFormatoFinal(self, path, filename):
475 477 ne=self.NumeroDeExperimentos(filename)
476 478
477 479 #nombre01 = file1(archivo,'1')
478 480 nombre02 = self.file1(filename,'2')
479 481 fichero=open(path + 'CentralControlFormat.txt','w')
480 482 fichero.write(nombre02+'\n')
481 483 fichero.write(str(ne)+'\n')
482 484
483 485 for i in range(1,65):
484 486
485 487 if i<10:
486 488 nmod = '0'+str(i)
487 489 else: nmod = str(i)
488 490
489 491 fichero.write("ABS_" + nmod+'\n')
490 492
491 493 for j in range(1,ne+1):
492 494 ruta=path+str(j)+'.txt'
493 495 lu=self.CapturaValoresEnArchivo(ruta,polarizacion='up')
494 496 ld=self.CapturaValoresEnArchivo(ruta,polarizacion='dw')
495 497 part1=''
496 498 part2=''
497 499 if lu[i-1]=='1.0': part1='000'
498 500 if lu[i-1]=='2.0': part1='001'
499 501 if lu[i-1]=='3.0': part1='010'
500 502 if lu[i-1]=='0.0': part1='011'
501 503 if lu[i-1]=='0.5': part1='100'
502 504 if lu[i-1]=='1.5': part1='101'
503 505 if lu[i-1]=='2.5': part1='110'
504 506 if lu[i-1]=='3.5': part1='111'
505 507 if ld[i-1]=='1.0': part2='000'
506 508 if ld[i-1]=='2.0': part2='001'
507 509 if ld[i-1]=='3.0': part2='010'
508 510 if ld[i-1]=='0.0': part2='011'
509 511 if ld[i-1]=='0.5': part2='100'
510 512 if ld[i-1]=='1.5': part2='101'
511 513 if ld[i-1]=='2.5': part2='110'
512 514 if ld[i-1]=='3.5': part2='111'
513 515 fichero.write(part1+part2+'\n')
514 516 fichero.write('------'+'\n')
515 517 fichero.close()
516 518
517 519 def EliminaArchivosEnLaCarpeta(self, path, filename):
518 520 ne=self.NumeroDeExperimentos(filename)
519 521 for i in range(1,ne+1):
520 522 os.remove(path + str(i)+'.txt')
521 523
522 524
523 525 def toCentralControlFormat(self, filename):
524 526 """ Funcion que genera un archivo para el control central"""
525 527
526 528 path = os.getcwd() + '/'
527 529 self.CreaFicherosPrevios(path, filename)
528 530 self.CreaFormatoFinal(path, filename)
529 531 self.EliminaArchivosEnLaCarpeta(path, filename)
@@ -1,186 +1,187
1 1 import os
2 2 import library3
3 3 import time
4 4
5 5 class ABSServer:
6 6
7 7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500):
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.tx_buffer = "default"
17 17 self.rx_buffer = "default"
18 18 self.enaModules = []
19 19
20 20 self.createObjects()
21 21
22 22 def createObjects(self):
23 23
24 24 asServer = True
25 25 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
26 26 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
27 27
28 28 def waitRequest(self):
29 29
30 30 #Using rx buffer
31 31 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
32 32
33 33 if cmd == "SNDF":
34 34 datarpta = self.__sendFile2Modules(cmd = cmd)
35 35
36 36 if cmd == "CHGB":
37 37 datarpta = self.__changeBeam(cmd = cmd)
38 38
39 39 if cmd == "ANST":
40 40 self.__getControlModuleStatus(cmd = cmd)
41 41 #Using tx buffer
42 42 datarpta = self.tx_buffer
43 43
44 44 if cmd == "NTST":
45 45 self.enaModules = self.__getConnectionStatus()
46 46 #Using tx buffer
47 47 datarpta = self.enaModules
48 48
49 49 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
50 50
51 51 def checkModule(self, address):
52 52
53 53 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
54 54 status = os.system(cmd)
55 55
56 56 if status == 256:
57 57 return False
58 58
59 59 return True
60 60
61 61 def __writeReport(self, enaModules):
62 62
63 63 status_array = ["Status of modules\n"]
64 64 status_array.append("----------------\n")
65 65
66 66 for address in range(1,65):
67 67 if address in enaModules:
68 68 status_array.append("192.168.1." + str(address) + " [1 1]\n")
69 69 else:
70 70 status_array.append("192.168.1." + str(address) + " [0 0]\n")
71 71
72 72 f = open("module_status.txt","w")
73 73 f.writelines(status_array)
74 74 f.close()
75 75
76 76 def checkAntenna(self):
77 77
78 78 """
79 79 Direccion de los modulos de las antenas:
80 80
81 81 Norte : 01-16
82 82 Este : 17-32
83 83 Oeste: : 33-48
84 84 Sur : 49-64
85 85
86 86 """
87 87
88 88 enaModules2 = []
89 89
90 90 for address in range(1,65):
91 91 if self.checkModule(address):
92 92 enaModules2.append(address)
93 93
94 94 self.__writeReport(enaModules2)
95 95 return enaModules2
96 96
97 97 def __ConnectionWithControlModules(self,data,cmd,id):
98 98
99 99 self.commClientObj.open_socket()
100 100 ip = "192.168.1." + str(id)
101 101 self.commClientObj.sendData(cmd, data, ip)
102 102 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
103 103 self.commClientObj.close_socket()
104 104
105 105 return tmp
106 106
107 107 def __All2Blocks(self,input):
108 108
109 109 rx_frame_lst = input.split('\n',2)
110 110
111 111 header = rx_frame_lst[0] + "\n"
112 112 control_modules_str = rx_frame_lst[2]
113 113 control_modules_lst = control_modules_str.split("------\n")
114 114
115 115 return header, control_modules_lst
116 116
117 117
118 118 def __sendFile2Modules(self,cmd):
119 119
120 120 #Needed for the loop
121 121 header, control_modules_lst = self.__All2Blocks(self.rx_buffer)
122 122 correct = 0
123 123
124 124 for id in range(1,65):
125 125
126 126 if id not in self.enaModules:
127 127 continue
128 128
129 129 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
130 130 correct = correct + 1
131 131
132 132 if correct == len(self.enaModules):
133 133 rpta = "OK"
134 134 else:
135 135 rpta = "Failure"
136 136
137 137 return rpta
138 138
139 139 def __changeBeam(self, cmd):
140 140
141 141 correct = 0
142 142 # enaModules = self.checkAntenna()
143 143 # enaModules = [11,12,13,14]
144 144
145 145 for id in range(1,65):
146 146 if id not in self.enaModules:
147 147 continue
148 148
149 149 if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK":
150 150 correct = correct + 1
151 151
152 152 if correct == len(self.enaModules):
153 153 rpta = "OK"
154 154 else:
155 155 rpta = "Failure"
156 156
157 157 return rpta
158 158
159 159 def __getControlModuleStatus(self, cmd):
160 160
161 161 all_blocks = ""
162 162 # enaModules = self.checkAntenna()
163 163 # enaModules = [11,12,13,14]
164 164
165 165 for id in range(1,65):
166 166 if id not in self.enaModules:
167 167 continue
168 168
169 169 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
170 170
171 171 all_blocks = all_blocks + one_block
172 172 #Using tx buffer
173 print all_blocks
173 174 self.tx_buffer = all_blocks
174 175
175 176 def __getConnectionStatus(self):
176 177
177 178 enaModules = self.checkAntenna()
178 179
179 180 return enaModules
180 181
181 182 if __name__ == '__main__':
182 183
183 184 absObj = ABSServer()
184 185
185 186 while 1:
186 187 absObj.waitRequest() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now