##// END OF EJS Templates
imanay -
r64:65
parent child
Show More
@@ -1,280 +1,281
1 import os
1 import os
2 import library
2 import library
3 import time
3 import time
4
4
5 class ABSServer:
5 class ABSServer:
6
6
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.100", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None):
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.225", portDestino2=5500, ftpPortDestino=None):
8
8
9 self.ipSource = ipSource
9 self.ipSource = ipSource
10 self.ipDestino = ipDestino
10 self.ipDestino = ipDestino
11 self.portDestino = portDestino
11 self.portDestino = portDestino
12
12
13 self.ipDestino2 = ipDestino2
13 self.ipDestino2 = ipDestino2
14 self.portDestino2 = portDestino2
14 self.portDestino2 = portDestino2
15
15
16 self.ftpPortDestino = ftpPortDestino
16 self.ftpPortDestino = ftpPortDestino
17 self.experiment_name = "default"
17 self.experiment_name = "default"
18 self.tx_buffer = "default"
18 self.tx_buffer = "default"
19
19
20 self.createObjects()
20 self.createObjects()
21
21
22 def createObjects(self):
22 def createObjects(self):
23
23
24 asServer = True
24 asServer = True
25 self.commServerObj = library.TCPComm(self.ipSource, self.ipDestino, self.portDestino, asServer)
25 self.commServerObj = library.TCPComm(self.ipSource, self.ipDestino, self.portDestino, asServer)
26 self.commClientObj = library.TCPComm(self.ipSource, self.ipDestino2, self.portDestino2)
26 # self.commClientObj = library.TCPComm(self.ipSource, self.ipDestino2, self.portDestino2)
27 #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino)
27 #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino)
28
28
29
29
30 def waitRequest(self):
30 def waitRequest(self):
31
31
32 ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData()
32 ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData()
33
33
34 datarpta = "OK"
34 datarpta = "OK"
35
35
36 if cmd == "SNDF":
36 if cmd == "SNDF":
37 self.sendFile2Modules()
37 # self.sendFile2Modules()
38 pass
38
39
39 if cmd == "CHGB":
40 if cmd == "CHGB":
40 self.changeBeam()
41 self.changeBeam()
41
42
42 if cmd == "ANST":
43 if cmd == "ANST":
43 self.getStatus(mode=3)
44 self.getStatus(mode=3)
44 datarpta = self.tx_buffer
45 datarpta = self.tx_buffer
45
46
46 self.commServerObj.sendData(cmd=cmd, data=datarpta)
47 self.commServerObj.sendData(cmd=cmd, data=datarpta)
47
48
48 def checkModule(self, address):
49 def checkModule(self, address):
49
50
50 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
51 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
51 status = os.system(cmd)
52 status = os.system(cmd)
52
53
53 if status == 256:
54 if status == 256:
54 return False
55 return False
55
56
56 return True
57 return True
57
58
58 def __writeReport(self, enaModules):
59 def __writeReport(self, enaModules):
59
60
60 status_array = ["Status of modules\n"]
61 status_array = ["Status of modules\n"]
61 status_array.append("----------------\n")
62 status_array.append("----------------\n")
62
63
63 for address in range(1,65):
64 for address in range(1,65):
64 if address in enaModules:
65 if address in enaModules:
65 # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n")
66 # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n")
66 status_array.append("192.168.1." + str(address) + " [1 1]\n")
67 status_array.append("192.168.1." + str(address) + " [1 1]\n")
67 else:
68 else:
68 status_array.append("192.168.1." + str(address) + " [0 0]\n")
69 status_array.append("192.168.1." + str(address) + " [0 0]\n")
69
70
70 f = open("module_status.txt","w")
71 f = open("module_status.txt","w")
71 f.writelines(status_array)
72 f.writelines(status_array)
72 f.close()
73 f.close()
73
74
74 def checkAntenna(self):
75 def checkAntenna(self):
75
76
76 """
77 """
77 Direccion de los modulos de las antenas:
78 Direccion de los modulos de las antenas:
78
79
79 Norte : 01-16
80 Norte : 01-16
80 Este : 17-32
81 Este : 17-32
81 Oeste: : 33-48
82 Oeste: : 33-48
82 Sur : 49-64
83 Sur : 49-64
83
84
84 """
85 """
85
86
86 enaModules = []
87 enaModules = []
87
88
88 for address in range(1,65):
89 for address in range(1,65):
89 if self.checkModule(address):
90 if self.checkModule(address):
90 enaModules.append(address)
91 enaModules.append(address)
91
92
92 self.__writeReport(enaModules)
93 self.__writeReport(enaModules)
93 return enaModules
94 return enaModules
94
95
95 def sendFile2Modules(self):
96 def sendFile2Modules(self):
96
97
97 #Needed for the loop
98 #Needed for the loop
98 rx_frame_list = self.datarx.split('\n',2)
99 rx_frame_list = self.datarx.split('\n',2)
99
100
100 self.experiment_name = rx_frame_list[0]
101 self.experiment_name = rx_frame_list[0]
101 experiment_number = rx_frame_list[1]
102 experiment_number = rx_frame_list[1]
102 str_control_modules = rx_frame_list[2]
103 str_control_modules = rx_frame_list[2]
103
104
104 lst_control_modules = str_control_modules.split("------\n")
105 lst_control_modules = str_control_modules.split("------\n")
105
106
106 enaModules = self.checkAntenna()
107 enaModules = self.checkAntenna()
107
108
108 for address in range(1,65):
109 for address in range(1,65):
109
110
110 if address not in enaModules:
111 if address not in enaModules:
111 continue
112 continue
112
113
113 self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1])
114 self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1])
114
115
115 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name
116 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name
116 print cmd
117 print cmd
117 os.system(cmd)
118 os.system(cmd)
118
119
119 self.__loadFile()
120 self.__loadFile()
120
121
121 def __writeModuleFile(self, filename, str):
122 def __writeModuleFile(self, filename, str):
122
123
123 fobj = open(filename,"w")
124 fobj = open(filename,"w")
124 fobj.write(filename + "\n")
125 fobj.write(filename + "\n")
125 fobj.write("------\n")
126 fobj.write("------\n")
126 fobj.write(str)
127 fobj.write(str)
127 fobj.write("------\n")
128 fobj.write("------\n")
128 fobj.close()
129 fobj.close()
129
130
130 def __readModuleFile(self, filename):
131 def __readModuleFile(self, filename):
131
132
132 fobj1 = open(filename,"r")
133 fobj1 = open(filename,"r")
133 file_list_1 = fobj1.readlines()
134 file_list_1 = fobj1.readlines()
134 fobj1.close()
135 fobj1.close()
135 content_str = ''.join(file_list_1[2:-1])
136 content_str = ''.join(file_list_1[2:-1])
136
137
137 return content_str
138 return content_str
138
139
139 def __loadFile(self):
140 def __loadFile(self):
140
141
141 #Working with the UDP socket
142 #Working with the UDP socket
142 self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":")
143 self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":")
143 self.commClientObj.sendData("none", "CAMBIA:0:")
144 self.commClientObj.sendData("none", "CAMBIA:0:")
144
145
145 def changeBeam(self):
146 def changeBeam(self):
146
147
147 #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0")
148 #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0")
148 self.commClientObj.sendData("none", "CAMBIA:" + self.datarx + ":")
149 self.commClientObj.sendData("none", "CAMBIA:" + self.datarx + ":")
149
150
150 def getStatus(self,mode):
151 def getStatus(self,mode):
151
152
152 if mode == 1:
153 if mode == 1:
153 self.__getStsMode1()
154 self.__getStsMode1()
154 elif mode == 2:
155 elif mode == 2:
155 self.__getStsMode2()
156 self.__getStsMode2()
156 else:
157 else:
157 self.__getStsMode3()
158 self.__getStsMode3()
158
159
159
160
160 def __getStsMode1(self):
161 def __getStsMode1(self):
161 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
162 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
162 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
163 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
163 seconds = int (self.datarx)
164 seconds = int (self.datarx)
164 # Give 5 seconds to the control modules
165 # Give 5 seconds to the control modules
165 time.sleep(seconds)
166 time.sleep(seconds)
166 # Checking the module connection
167 # Checking the module connection
167 module_list = self.connection_status(10)
168 module_list = self.connection_status(10)
168 #Generating the complete report
169 #Generating the complete report
169 module = 1
170 module = 1
170 number_of_modules = 16
171 number_of_modules = 16
171 filename1 = "Verificacion"
172 filename1 = "Verificacion"
172 filename2 = "report.txt"
173 filename2 = "report.txt"
173 fobj2 = open(filename2,"w")
174 fobj2 = open(filename2,"w")
174 fobj2.write("Verification_file\n")
175 fobj2.write("Verification_file\n")
175 fobj2.write("-----------------\n")
176 fobj2.write("-----------------\n")
176 fobj2.close()
177 fobj2.close()
177 while module <= number_of_modules:
178 while module <= number_of_modules:
178 if module_list[module -1] == "1":
179 if module_list[module -1] == "1":
179 #Preparing and doing the tftp command
180 #Preparing and doing the tftp command
180 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
181 cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
181 print cmd
182 print cmd
182 os.system(cmd)
183 os.system(cmd)
183 # Getting data from the control module file
184 # Getting data from the control module file
184 fobj1 = open(filename1,"r")
185 fobj1 = open(filename1,"r")
185 file_list_1 = fobj1.readlines()
186 file_list_1 = fobj1.readlines()
186 fobj1.close()
187 fobj1.close()
187 content = file_list_1[2:-1]
188 content = file_list_1[2:-1]
188 #
189 #
189 fobj2 = open(filename2,"a")
190 fobj2 = open(filename2,"a")
190 if base == 10:
191 if base == 10:
191 fobj2.write("S" + str(module) + "\n")
192 fobj2.write("S" + str(module) + "\n")
192 else:
193 else:
193 fobj2.write("N" + str(module) + "\n")
194 fobj2.write("N" + str(module) + "\n")
194 fobj2.writelines(content)
195 fobj2.writelines(content)
195 fobj2.write("------\n")
196 fobj2.write("------\n")
196 fobj2.close()
197 fobj2.close()
197 module = module + 1
198 module = module + 1
198
199
199 def __getStsMode2(self):
200 def __getStsMode2(self):
200
201
201 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
202 #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
202 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
203 self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":")
203 seconds = int (self.datarx)
204 seconds = int (self.datarx)
204 # Give 5 seconds to the control modules
205 # Give 5 seconds to the control modules
205 time.sleep(seconds)
206 time.sleep(seconds)
206 # Checking the module connection
207 # Checking the module connection
207 enaModules = self.checkAntenna()
208 enaModules = self.checkAntenna()
208 #Generating the complete report
209 #Generating the complete report
209 filename1 = "Verificacion"
210 filename1 = "Verificacion"
210 line1 = "Verification_file\n"
211 line1 = "Verification_file\n"
211 line2 = "-----------------\n"
212 line2 = "-----------------\n"
212 report_list = [line1, line2]
213 report_list = [line1, line2]
213
214
214 for address in range(1,65):
215 for address in range(1,65):
215
216
216 if address not in enaModules:
217 if address not in enaModules:
217 continue
218 continue
218 #Preparing and doing the tftp command
219 #Preparing and doing the tftp command
219 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1
220 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1
220 print cmd
221 print cmd
221 os.system(cmd)
222 os.system(cmd)
222 #Sub_header
223 #Sub_header
223 report_list.append("ABS_" + str(address) + "\n")
224 report_list.append("ABS_" + str(address) + "\n")
224 # Content
225 # Content
225 fobj1 = open(filename1,"r")
226 fobj1 = open(filename1,"r")
226 file_list_1 = fobj1.readlines()
227 file_list_1 = fobj1.readlines()
227 fobj1.close()
228 fobj1.close()
228 content = ''.join(file_list_1[2:-1])
229 content = ''.join(file_list_1[2:-1])
229 report_list.append(content)
230 report_list.append(content)
230 #Ending
231 #Ending
231 report_list.append("------\n")
232 report_list.append("------\n")
232 #print "\nFinalizado"
233 #print "\nFinalizado"
233 self.tx_buffer = ''.join(report_list)
234 self.tx_buffer = ''.join(report_list)
234
235
235 def __AddingHeader(self,content_list, title):
236 def __AddingHeader(self,content_list, title):
236
237
237 line1 = title + "\n"
238 line1 = title + "\n"
238 line2 = "-----------------\n"
239 line2 = "-----------------\n"
239 header_list = [line1, line2]
240 header_list = [line1, line2]
240 verification_list = header_list + content_list
241 verification_list = header_list + content_list
241 # Arming the frame
242 # Arming the frame
242 self.tx_buffer = ''.join(verification_list)
243 self.tx_buffer = ''.join(verification_list)
243
244
244 def __getModuleFile(self, filename):
245 def __getModuleFile(self, filename):
245
246
246 enaModules = self.checkAntenna()
247 enaModules = self.checkAntenna()
247 content_list = []
248 content_list = []
248 for address in range(1,65):
249 for address in range(1,65):
249
250
250 if address not in enaModules:
251 if address not in enaModules:
251 continue
252 continue
252 #Preparing and doing the tftp command
253 #Preparing and doing the tftp command
253 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename
254 cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename
254 print cmd
255 print cmd
255 os.system(cmd)
256 os.system(cmd)
256 #Sub_header
257 #Sub_header
257 content_list.append("ABS_" + str(address) + "\n")
258 content_list.append("ABS_" + str(address) + "\n")
258 # From module file to list
259 # From module file to list
259 content_str = self.__readModuleFile(filename)
260 content_str = self.__readModuleFile(filename)
260 content_list.append(content_str)
261 content_list.append(content_str)
261 content_list.append("------\n")
262 content_list.append("------\n")
262
263
263 self.__AddingHeader(content_list, title = "Verification_file")
264 self.__AddingHeader(content_list, title = "Verification_file")
264
265
265 def __getStsMode3(self):
266 def __getStsMode3(self):
266
267
267 self.commClientObj.sendData("none", "CHEQUEO:" + self.datarx + ":")
268 self.commClientObj.sendData("none", "CHEQUEO:" + self.datarx + ":")
268 seconds = int (self.datarx)
269 seconds = int (self.datarx)
269 # Give 5 seconds to the control modules
270 # Give 5 seconds to the control modules
270 time.sleep(seconds)
271 time.sleep(seconds)
271
272
272 self.__getModuleFile(filename = "Verificacion")
273 self.__getModuleFile(filename = "Verificacion")
273
274
274
275
275 if __name__ == '__main__':
276 if __name__ == '__main__':
276
277
277 absObj = ABSServer()
278 absObj = ABSServer()
278
279
279 while 1:
280 while 1:
280 absObj.waitRequest() No newline at end of file
281 absObj.waitRequest()
General Comments 0
You need to be logged in to leave comments. Login now