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