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