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