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