##// END OF EJS Templates
imanay -
r54:55
parent child
Show More
@@ -39,10 +39,17
39 39 self.commObj.sendData(cmd="CHGB", data=newBeam)
40 40 self.commObj.waitData()
41 41
42 def __writeFile(self, filename, data):
43
44 fobj = open(filename,"w")
45 fobj.writelines(data)
46 fobj.close()
47
42 48 def getStatus(self, data):
43 49
44 50 self.commObj.sendData(cmd="ANST", data = data)
45 self.commObj.waitData2()
51 ipSource, ipDestino, cmd, data = self.commObj.waitData()
52 self.__writeFile("report.txt", data)
46 53
47 54 ##########
48 55
@@ -12,6 +12,7
12 12 self.portDestino = portDestino
13 13 self.addr = (ipDestino,portDestino)
14 14 self.answer = ipDestino #test
15 self.mode = "none"
15 16
16 17 self.openSocket(asServer)
17 18
@@ -23,8 +24,10
23 24
24 25 if asServer:
25 26 self.configAsServer()
27 self.mode = "server"
26 28 else:
27 29 self.configAsClient()
30 self.mode = "client"
28 31
29 32 def configAsClient(self):
30 33 #Configurar broadcast
@@ -40,42 +43,25
40 43 print "\nWaiting some data"
41 44 trama_rx, self.answer = self.socket_c.recvfrom(nbytes)
42 45 print "\nThis socket has received some data"
46 print self.answer
43 47 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
44
45 return ipSource, ipDestino, cmd, data
46
47 def waitData2(self, nbytes = 16384):
48
49 print "\nWaiting some data"
50 trama_rx, self.answer = self.socket_c.recvfrom(nbytes)
51 print "\nThis socket has received some data"
52 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
53 filename = "report.txt"
54 fobj = open(filename,"w")
55 fobj.writelines(data)
56 fobj.close()
57 48
58 49 return ipSource, ipDestino, cmd, data
59 50
60 51 def sendData(self, cmd, data):
61 52
62 trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":"
53 if self.portDestino == 7000:
54 trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":"
55 else:
56 trama_tx = data
57
58 if self.mode == "client":
59 destiny = self.addr
60 else:
61 destiny = self.answer
63 62 # Send messages
64 if(self.socket_c.sendto(trama_tx, self.addr)):
63 if(self.socket_c.sendto(trama_tx, destiny)):
65 64 print "Sending message:[" + trama_tx + "]"
66
67 def sendData2(self, cmd, data):
68
69 trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":"
70 # Send messages
71 if(self.socket_c.sendto(trama_tx, self.answer)):
72 print "Sending message:[" + trama_tx + "]"
73
74 def sendData2ControlModules(self, trama_tx):
75
76 # Send messages
77 if(self.socket_c.sendto(trama_tx, self.addr)):
78 print "Sending message:[" + trama_tx + "]"
79 65
80 66 def __getTrama(self, trama):
81 67
@@ -25,52 +25,6
25 25 self.commServerObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino, asServer)
26 26 self.commClientObj = library.UDPComm(self.ipSource, self.ipDestino2, self.portDestino2)
27 27 #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino)
28
29 def sendFile(self, base):
30
31 #Needed for the loop
32 rx_frame_list = self.datarx.split('\n',2)
33
34 experiment_name = rx_frame_list[0]
35 experiment_number = rx_frame_list[1]
36 str_control_modules = rx_frame_list[2]
37
38 lst_control_modules = str_control_modules.split("------\n")
39 #Setting variables of the loop
40 i =3
41 module = 1
42 number_of_modules = 16
43 number_of_beams = int (experiment_number)
44 module_list = self.connection_status(10)
45 #Loop for creating and sending the control module files
46 while module <= number_of_modules:
47 #Generating the control modules files
48 fobj = open(experiment_name,"w")
49 fobj.write(experiment_name + "\n")
50 fobj.write("------\n")
51 # tmp_list = rx_frame_list[i:i + number_of_beams + 1]
52 fobj.write(lst_control_modules[module-1])
53 fobj.write("------\n")
54 fobj.close()
55 if module_list[module -1] == "1":
56 #Preparing and doing the tftp command
57 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c put " + experiment_name
58 print cmd
59 os.system(cmd)
60 #Updating variables of the loop
61 i = i + number_of_beams + 2
62 module += 1
63 #Working with the UDP socket
64 # self.commClientObj.sendData2ControlModules("CARGA:" + experiment_name + ":")
65 # self.commClientObj.sendData2ControlModules("CAMBIA:0:")
66 #Another tftp way
67 # self.ftpCommObj.sendFile(filename)
68 # rpta = self.commClientObj.sendTxRxCommand(cmd# filename2 = "report.txt"
69 #fobj2 = open(filename2,"w")
70 #fobj2.write("Verification_file\n")
71 #fobj2.write("-----------------\n")
72 #fobj2.close()='CARGA', data=filename)
73 self.experiment_name = experiment_name
74 28
75 29
76 30 def waitRequest(self):
@@ -86,11 +40,20
86 40 self.changeBeam()
87 41
88 42 if cmd == "ANST":
89 self.getStatus(10, mode=2)
43 self.getStatus(mode=3)
90 44 datarpta = self.tx_buffer
91 45
92 self.commServerObj.sendData2(cmd=cmd, data=datarpta)
93
46 self.commServerObj.sendData(cmd=cmd, data=datarpta)
47
48 def checkModule(self, address):
49
50 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
51 status = os.system(cmd)
52
53 if status == 256:
54 return False
55
56 return True
94 57
95 58 def __writeReport(self, enaModules):
96 59
@@ -107,16 +70,6
107 70 f = open("module_status.txt","w")
108 71 f.writelines(status_array)
109 72 f.close()
110
111 def checkModule(self, address):
112
113 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
114 status = os.system(cmd)
115
116 if status == 256:
117 return False
118
119 return True
120 73
121 74 def checkAntenna(self):
122 75
@@ -138,12 +91,34
138 91
139 92 self.__writeReport(enaModules)
140 93 return enaModules
141
142 def __loadFile(self):
143
144 #Working with the UDP socket
145 self.commClientObj.sendData2ControlModules("CARGA:" + self.experiment_name + ":")
146 self.commClientObj.sendData2ControlModules("CAMBIA:0:")
94
95 def sendFile2Modules(self):
96
97 #Needed for the loop
98 rx_frame_list = self.datarx.split('\n',2)
99
100 experiment_name = rx_frame_list[0]
101 experiment_number = rx_frame_list[1]
102 str_control_modules = rx_frame_list[2]
103
104 lst_control_modules = str_control_modules.split("------\n")
105
106 enaModules = self.checkAntenna()
107
108 for address in range(1,65):
109
110 if address not in enaModules:
111 continue
112
113 self.__writeModuleFile(experiment_name, lst_control_modules[address-1])
114
115 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + experiment_name
116 print cmd
117 os.system(cmd)
118
119 self.experiment_name = experiment_name
120
121 self.__loadFile()
147 122
148 123 def __writeModuleFile(self, filename, str):
149 124
@@ -153,43 +128,40
153 128 fobj.write(str)
154 129 fobj.write("------\n")
155 130 fobj.close()
156
157 def sendFile2Modules(self):
158
159 #Needed for the loop
160 rx_frame_list = self.datarx.split('\n',2)
161
162 experiment_name = rx_frame_list[0]
163 experiment_number = rx_frame_list[1]
164 str_control_modules = rx_frame_list[2]
165
166 lst_control_modules = str_control_modules.split("------\n")
167
168 enaModules = self.checkAntenna()
169
170 for address in range(1,65):
171
172 if address not in enaModules:
173 continue
174
175 self.__writeModuleFile(experiment_name, lst_control_modules[address-1])
176
177 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + experiment_name
178 print cmd
179 os.system(cmd)
180
181 self.experiment_name = experiment_name
182
183 self.__loadFile()
131
132 def __readModuleFile(self, filename):
133
134 fobj1 = open(filename,"r")
135 file_list_1 = fobj1.readlines()
136 fobj1.close()
137 content_str = ''.join(file_list_1[2:-1])
138
139 return content_str
140
141 def __loadFile(self):
142
143 #Working with the UDP socket
144 self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":")
145 self.commClientObj.sendData("none", "CAMBIA:0:")
184 146
185 147 def changeBeam(self):
186 148
187 149 #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0")
188 self.commClientObj.sendData2ControlModules("CAMBIA:" + self.datarx + ":")
150 self.commClientObj.sendData("CAMBIA:" + self.datarx + ":")
151
152 def getStatus(self,mode):
153
154 if mode == 1:
155 self.__getStsMode1()
156 elif mode == 2:
157 self.__getStsMode2()
158 else:
159 self.__getStsMode3()
160
189 161
190 162 def __getStsMode1(self):
191 163 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
192 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
164 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
193 165 seconds = int (self.datarx)
194 166 # Give 5 seconds to the control modules
195 167 time.sleep(seconds)
@@ -229,15 +201,13
229 201 def __getStsMode2(self):
230 202
231 203 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
232 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
204 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
233 205 seconds = int (self.datarx)
234 206 # Give 5 seconds to the control modules
235 207 time.sleep(seconds)
236 208 # Checking the module connection
237 209 enaModules = self.checkAntenna()
238 210 #Generating the complete report
239 module = 1
240 number_of_modules = 16
241 211 filename1 = "Verificacion"
242 212 line1 = "Verification_file\n"
243 213 line2 = "-----------------\n"
@@ -262,54 +232,46
262 232 #Ending
263 233 report_list.append("------\n")
264 234 #print "\nFinalizado"
265 self.tx_buffer = ''.join(report_list)
266
235 self.tx_buffer = ''.join(report_list)
236
237 def __AddingHeader(self,content_list, title):
238
239 line1 = title + "\n"
240 line2 = "-----------------\n"
241 header_list = [line1, line2]
242 verification_list = header_list + content_list
243 # Arming the frame
244 self.tx_buffer = ''.join(verification_list)
245
246 def __getModuleFile(self, filename):
247
248 enaModules = self.checkAntenna()
249 content_list = []
250 for address in range(1,65):
251
252 if address not in enaModules:
253 continue
254 #Preparing and doing the tftp command
255 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename
256 print cmd
257 os.system(cmd)
258 #Sub_header
259 content_list.append("ABS_" + str(address) + "\n")
260 # From module file to list
261 content_str = self.__readModuleFile(filename)
262 content_list.append(content_str)
263 content_list.append("------\n")
264
265 self.__AddingHeader(content_list, title = "Verification_file")
266
267 267 def __getStsMode3(self):
268 268
269 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
270 self.commClientObj.sendData2ControlModules("CHEQUEO:" + self.datarx + ":")
269 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
271 270 seconds = int (self.datarx)
272 271 # Give 5 seconds to the control modules
273 272 time.sleep(seconds)
274 # Checking the module connection
275 module_list = self.connection_status(10)
276 #Generating the complete report
277 module = 1
278 number_of_modules = 16
279 filename1 = "Verificacion"
280 line1 = "Verification_file\n"
281 line2 = "-----------------\n"
282 report_list = [line1, line2]
283 while module <= number_of_modules:
284 if module_list[module -1] == "1":
285 #Preparing and doing the tftp command
286 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
287 print cmd
288 os.system(cmd)
289 #Sub_header
290 if base == 10:
291 report_list.append("S" + str(module) + "\n")
292 else:
293 report_list.append("N" + str(module) + "\n")
294 # Content
295 fobj1 = open(filename1,"r")
296 file_list_1 = fobj1.readlines()
297 fobj1.close()
298 content = ''.join(file_list_1[2:-1])
299 # content = "010101\n"
300 report_list.append(content)
301 #Ending
302 report_list.append("------\n")
303 module = module + 1
304 #print "\nFinalizado"
305 self.tx_buffer = ''.join(report_list)
306
307 def getStatus(self, base, mode):
308
309 if mode == 1:
310 self.__getStsMode1()
311 else:
312 self.__getStsMode2()
273
274 self.__getModuleFile(filename = "Verificacion")
313 275
314 276
315 277 if __name__ == '__main__':
General Comments 0
You need to be logged in to leave comments. Login now