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