##// END OF EJS Templates
Implementation of the central control module using TCP
imanay -
r74:75
parent child
Show More
@@ -0,0 +1,370
1 import os
No newline at end of file
2 import library3
No newline at end of file
3 import time
No newline at end of file
4
No newline at end of file
5 class ABSServer:
No newline at end of file
6
No newline at end of file
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500):
No newline at end of file
8
No newline at end of file
9 self.ipSource = ipSource
No newline at end of file
10 self.ipDestino = ipDestino
No newline at end of file
11 self.portDestino = portDestino
No newline at end of file
12
No newline at end of file
13 self.ipDestino2 = ipDestino2
No newline at end of file
14 self.portDestino2 = portDestino2
No newline at end of file
15
No newline at end of file
16 self.tx_buffer = "default"
No newline at end of file
17 self.rx_buffer = "default"
No newline at end of file
18
No newline at end of file
19 self.createObjects()
No newline at end of file
20
No newline at end of file
21 def createObjects(self):
No newline at end of file
22
No newline at end of file
23 asServer = True
No newline at end of file
24 self.commServerObj = library3.TCPComm("Central_Control", self.ipDestino, self.portDestino, asServer)
No newline at end of file
25 self.commClientObj = library3.TCPComm("Central_Control", self.ipDestino2, self.portDestino2)
No newline at end of file
26
No newline at end of file
27 def waitRequest(self):
No newline at end of file
28
No newline at end of file
29 # Using rx buffer
No newline at end of file
30 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer()
No newline at end of file
31
No newline at end of file
32 if cmd == "SNDF":
No newline at end of file
33 # datarpta = self.sendFile2Modules(mode=2, cmd = cmd)
No newline at end of file
34 datarpta = self.__sendFile2Modules(cmd = cmd)
No newline at end of file
35
No newline at end of file
36 if cmd == "CHGB":
No newline at end of file
37 datarpta = self.__changeBeam(cmd = cmd)
No newline at end of file
38
No newline at end of file
39 if cmd == "ANST":
No newline at end of file
40 self.__getStatus(cmd = cmd)
No newline at end of file
41 # Using tx buffer
No newline at end of file
42 datarpta = self.tx_buffer
No newline at end of file
43
No newline at end of file
44 self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource)
No newline at end of file
45
No newline at end of file
46 def checkModule(self, address):
No newline at end of file
47
No newline at end of file
48 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
No newline at end of file
49 status = os.system(cmd)
No newline at end of file
50
No newline at end of file
51 if status == 256:
No newline at end of file
52 return False
No newline at end of file
53
No newline at end of file
54 return True
No newline at end of file
55
No newline at end of file
56 def __writeReport(self, enaModules):
No newline at end of file
57
No newline at end of file
58 status_array = ["Status of modules\n"]
No newline at end of file
59 status_array.append("----------------\n")
No newline at end of file
60
No newline at end of file
61 for address in range(1,65):
No newline at end of file
62 if address in enaModules:
No newline at end of file
63 status_array.append("192.168.1." + str(address) + " [1 1]\n")
No newline at end of file
64 else:
No newline at end of file
65 status_array.append("192.168.1." + str(address) + " [0 0]\n")
No newline at end of file
66
No newline at end of file
67 f = open("module_status.txt","w")
No newline at end of file
68 f.writelines(status_array)
No newline at end of file
69 f.close()
No newline at end of file
70
No newline at end of file
71 def checkAntenna(self):
No newline at end of file
72
No newline at end of file
73 """
No newline at end of file
74 Direccion de los modulos de las antenas:
No newline at end of file
75
No newline at end of file
76 Norte : 01-16
No newline at end of file
77 Este : 17-32
No newline at end of file
78 Oeste: : 33-48
No newline at end of file
79 Sur : 49-64
No newline at end of file
80
No newline at end of file
81 """
No newline at end of file
82
No newline at end of file
83 enaModules = []
No newline at end of file
84
No newline at end of file
85 for address in range(1,65):
No newline at end of file
86 if self.checkModule(address):
No newline at end of file
87 enaModules.append(address)
No newline at end of file
88
No newline at end of file
89 self.__writeReport(enaModules)
No newline at end of file
90 return enaModules
No newline at end of file
91
No newline at end of file
92 # def sendFile2Modules(self, mode, cmd):
No newline at end of file
93 #
No newline at end of file
94 # if mode == 1:
No newline at end of file
95 # self.__sendFile2Modules1()
No newline at end of file
96 # else:
No newline at end of file
97 # self.__sendFile2Modules2(cmd)
No newline at end of file
98 #
No newline at end of file
99 # def __sendFile2Modules1(self):
No newline at end of file
100 #
No newline at end of file
101 # #Needed for the loop
No newline at end of file
102 # rx_frame_list = self.rx_buffer.split('\n',2)
No newline at end of file
103 #
No newline at end of file
104 # self.experiment_name = rx_frame_list[0]
No newline at end of file
105 # experiment_number = rx_frame_list[1]
No newline at end of file
106 # str_control_modules = rx_frame_list[2]
No newline at end of file
107 #
No newline at end of file
108 # lst_control_modules = str_control_modules.split("------\n")
No newline at end of file
109 #
No newline at end of file
110 ## enaModules = self.checkAntenna()
No newline at end of file
111 # enaModules = [11,12,13,14]
No newline at end of file
112 #
No newline at end of file
113 # for address in range(1,65):
No newline at end of file
114 #
No newline at end of file
115 # if address not in enaModules:
No newline at end of file
116 # continue
No newline at end of file
117 #
No newline at end of file
118 # self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1])
No newline at end of file
119 #
No newline at end of file
120 # cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name
No newline at end of file
121 # print cmd
No newline at end of file
122 # os.system(cmd)
No newline at end of file
123 #
No newline at end of file
124 # self.__loadFile()
No newline at end of file
125
No newline at end of file
126 def __sendFile2Modules(self,cmd):
No newline at end of file
127
No newline at end of file
128 #Needed for the loop
No newline at end of file
129 rx_frame_list = self.rx_buffer.split('\n',2)
No newline at end of file
130 correct = 0
No newline at end of file
131 failure = 0
No newline at end of file
132 header = rx_frame_list[0] + "\n"
No newline at end of file
133 str_control_modules = rx_frame_list[2]
No newline at end of file
134
No newline at end of file
135 lst_control_modules = str_control_modules.split("------\n")
No newline at end of file
136
No newline at end of file
137 # enaModules = self.checkAntenna()
No newline at end of file
138 enaModules = [11,12,13,14]
No newline at end of file
139
No newline at end of file
140 for id in range(1,65):
No newline at end of file
141
No newline at end of file
142 if id not in enaModules:
No newline at end of file
143 continue
No newline at end of file
144 #tcp client needed
No newline at end of file
145 self.commClientObj.open_socket()
No newline at end of file
146 ip = "192.168.1." + str(id)
No newline at end of file
147 self.commClientObj.sendData2(cmd, header + lst_control_modules[id-1], ip)
No newline at end of file
148 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient()
No newline at end of file
149 self.commClientObj.close_socket()
No newline at end of file
150
No newline at end of file
151 if tmp == "OK":
No newline at end of file
152 correct = correct + 1
No newline at end of file
153 else:
No newline at end of file
154 failure = failure + 1
No newline at end of file
155
No newline at end of file
156 if correct == len(enaModules):
No newline at end of file
157 rpta = "OK"
No newline at end of file
158 else:
No newline at end of file
159 rpta = "Failure"
No newline at end of file
160
No newline at end of file
161 return rpta
No newline at end of file
162
No newline at end of file
163
No newline at end of file
164 def __writeModuleFile(self, filename, str):
No newline at end of file
165
No newline at end of file
166 fobj = open(filename,"w")
No newline at end of file
167 fobj.write(filename + "\n")
No newline at end of file
168 fobj.write("------\n")
No newline at end of file
169 fobj.write(str)
No newline at end of file
170 fobj.write("------\n")
No newline at end of file
171 fobj.close()
No newline at end of file
172
No newline at end of file
173 def __readModuleFile(self, filename):
No newline at end of file
174
No newline at end of file
175 fobj1 = open(filename,"r")
No newline at end of file
176 file_list_1 = fobj1.readlines()
No newline at end of file
177 fobj1.close()
No newline at end of file
178 content_str = ''.join(file_list_1[2:-1])
No newline at end of file
179
No newline at end of file
180 return content_str
No newline at end of file
181
No newline at end of file
182 def __loadFile(self):
No newline at end of file
183
No newline at end of file
184 #Working with the UDP socket
No newline at end of file
185 self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":")
No newline at end of file
186 self.commClientObj.sendData("none", "CAMBIA:0:")
No newline at end of file
187
No newline at end of file
188 def __changeBeam(self, cmd):
No newline at end of file
189
No newline at end of file
190 correct = 0
No newline at end of file
191 failure = 0
No newline at end of file
192 # enaModules = self.checkAntenna()
No newline at end of file
193 enaModules = [11,12,13,14]
No newline at end of file
194
No newline at end of file
195 for id in range(1,65):
No newline at end of file
196 if id not in enaModules:
No newline at end of file
197 continue
No newline at end of file
198
No newline at end of file
199 self.commClientObj.open_socket()
No newline at end of file
200 ip = "192.168.1." + str(id)
No newline at end of file
201 self.commClientObj.sendData2(cmd, self.rx_buffer, ip)
No newline at end of file
202 # ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
No newline at end of file
203 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient()
No newline at end of file
204 self.commClientObj.close_socket()
No newline at end of file
205
No newline at end of file
206 if tmp == "OK":
No newline at end of file
207 correct = correct + 1
No newline at end of file
208 else:
No newline at end of file
209 failure = failure + 1
No newline at end of file
210
No newline at end of file
211 if correct == len(enaModules):
No newline at end of file
212 rpta = "OK"
No newline at end of file
213 else:
No newline at end of file
214 rpta = "Failure"
No newline at end of file
215
No newline at end of file
216 return rpta
No newline at end of file
217
No newline at end of file
218 # def __getStatus(self, mode, cmd):
No newline at end of file
219 #
No newline at end of file
220 # if mode == 1:
No newline at end of file
221 # self.__getStsMode1()
No newline at end of file
222 # elif mode == 2:
No newline at end of file
223 # self.__getStsMode2()
No newline at end of file
224 # elif mode == 3:
No newline at end of file
225 # self.__getStsMode3()
No newline at end of file
226 # else:
No newline at end of file
227 # self.__getStsMode4(cmd)
No newline at end of file
228
No newline at end of file
229
No newline at end of file
230 # def __getStsMode1(self):
No newline at end of file
231 # #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
No newline at end of file
232 # self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":")
No newline at end of file
233 # seconds = int (self.rx_buffer)
No newline at end of file
234 # # Give 5 seconds to the control modules
No newline at end of file
235 # time.sleep(seconds)
No newline at end of file
236 # # Checking the module connection
No newline at end of file
237 # module_list = self.connection_status(10)
No newline at end of file
238 # #Generating the complete report
No newline at end of file
239 # module = 1
No newline at end of file
240 # number_of_modules = 16
No newline at end of file
241 # filename1 = "Verificacion"
No newline at end of file
242 # filename2 = "report.txt"
No newline at end of file
243 # fobj2 = open(filename2,"w")
No newline at end of file
244 # fobj2.write("Verification_file\n")
No newline at end of file
245 # fobj2.write("-----------------\n")
No newline at end of file
246 # fobj2.close()
No newline at end of file
247 # while module <= number_of_modules:
No newline at end of file
248 # if module_list[module -1] == "1":
No newline at end of file
249 # #Preparing and doing the tftp command
No newline at end of file
250 # cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1
No newline at end of file
251 # print cmd
No newline at end of file
252 # os.system(cmd)
No newline at end of file
253 # # Getting data from the control module file
No newline at end of file
254 # fobj1 = open(filename1,"r")
No newline at end of file
255 # file_list_1 = fobj1.readlines()
No newline at end of file
256 # fobj1.close()
No newline at end of file
257 # content = file_list_1[2:-1]
No newline at end of file
258 # #
No newline at end of file
259 # fobj2 = open(filename2,"a")
No newline at end of file
260 # if base == 10:
No newline at end of file
261 # fobj2.write("S" + str(module) + "\n")
No newline at end of file
262 # else:
No newline at end of file
263 # fobj2.write("N" + str(module) + "\n")
No newline at end of file
264 # fobj2.writelines(content)
No newline at end of file
265 # fobj2.write("------\n")
No newline at end of file
266 # fobj2.close()
No newline at end of file
267 # module = module + 1
No newline at end of file
268
No newline at end of file
269 # def __getStsMode2(self):
No newline at end of file
270 #
No newline at end of file
271 # #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0")
No newline at end of file
272 # self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":")
No newline at end of file
273 # seconds = int (self.rx_buffer)
No newline at end of file
274 # # Give 5 seconds to the control modules
No newline at end of file
275 # time.sleep(seconds)
No newline at end of file
276 # # Checking the module connection
No newline at end of file
277 # enaModules = self.checkAntenna()
No newline at end of file
278 # #Generating the complete report
No newline at end of file
279 # filename1 = "Verificacion"
No newline at end of file
280 # line1 = "Verification_file\n"
No newline at end of file
281 # line2 = "-----------------\n"
No newline at end of file
282 # report_list = [line1, line2]
No newline at end of file
283 #
No newline at end of file
284 # for address in range(1,65):
No newline at end of file
285 #
No newline at end of file
286 # if address not in enaModules:
No newline at end of file
287 # continue
No newline at end of file
288 # #Preparing and doing the tftp command
No newline at end of file
289 # cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1
No newline at end of file
290 # print cmd
No newline at end of file
291 # os.system(cmd)
No newline at end of file
292 # #Sub_header
No newline at end of file
293 # report_list.append("ABS_" + str(address) + "\n")
No newline at end of file
294 # # Content
No newline at end of file
295 # fobj1 = open(filename1,"r")
No newline at end of file
296 # file_list_1 = fobj1.readlines()
No newline at end of file
297 # fobj1.close()
No newline at end of file
298 # content = ''.join(file_list_1[2:-1])
No newline at end of file
299 # report_list.append(content)
No newline at end of file
300 # #Ending
No newline at end of file
301 # report_list.append("------\n")
No newline at end of file
302 # #print "\nFinalizado"
No newline at end of file
303 # self.tx_buffer = ''.join(report_list)
No newline at end of file
304
No newline at end of file
305 def __AddingHeader(self,content_list, title):
No newline at end of file
306
No newline at end of file
307 line1 = title + "\n"
No newline at end of file
308 line2 = "-----------------\n"
No newline at end of file
309 header_list = [line1, line2]
No newline at end of file
310 verification_list = header_list + content_list
No newline at end of file
311 # Arming the frame
No newline at end of file
312 self.tx_buffer = ''.join(verification_list)
No newline at end of file
313
No newline at end of file
314 # def __getModuleFile(self, filename):
No newline at end of file
315 #
No newline at end of file
316 # enaModules = self.checkAntenna()
No newline at end of file
317 # content_list = []
No newline at end of file
318 # for address in range(1,65):
No newline at end of file
319 #
No newline at end of file
320 # if address not in enaModules:
No newline at end of file
321 # continue
No newline at end of file
322 # #Preparing and doing the tftp command
No newline at end of file
323 # cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename
No newline at end of file
324 # print cmd
No newline at end of file
325 # os.system(cmd)
No newline at end of file
326 # #Sub_header
No newline at end of file
327 # content_list.append("ABS_" + str(address) + "\n")
No newline at end of file
328 # # From module file to list
No newline at end of file
329 # content_str = self.__readModuleFile(filename)
No newline at end of file
330 # content_list.append(content_str)
No newline at end of file
331 # content_list.append("------\n")
No newline at end of file
332 #
No newline at end of file
333 # self.__AddingHeader(content_list, title = "Verification_file")
No newline at end of file
334
No newline at end of file
335 # def __getStsMode3(self):
No newline at end of file
336 #
No newline at end of file
337 # self.commClientObj.sendData("none", "CHEQUEO:" + self.rx_buffer + ":")
No newline at end of file
338 # seconds = int (self.rx_buffer)
No newline at end of file
339 # # Give 5 seconds to the control modules
No newline at end of file
340 # time.sleep(seconds)
No newline at end of file
341 #
No newline at end of file
342 # self.__getModuleFile(filename = "Verificacion")
No newline at end of file
343
No newline at end of file
344 def __getStatus(self, cmd):
No newline at end of file
345
No newline at end of file
346 content_str = ""
No newline at end of file
347 # enaModules = self.checkAntenna()
No newline at end of file
348 enaModules = [11,12,13,14]
No newline at end of file
349
No newline at end of file
350 for id in range(1,65):
No newline at end of file
351 if id not in enaModules:
No newline at end of file
352 continue
No newline at end of file
353
No newline at end of file
354 self.commClientObj.open_socket()
No newline at end of file
355 ip = "192.168.1." + str(id)
No newline at end of file
356 self.commClientObj.sendData2(cmd, self.rx_buffer, ip)
No newline at end of file
357 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient()
No newline at end of file
358 self.commClientObj.close_socket()
No newline at end of file
359
No newline at end of file
360 content_str = content_str + tmp
No newline at end of file
361 # self.__AddingHeader(content_list, title = "Verification_file")
No newline at end of file
362 #Using tx buffer
No newline at end of file
363 self.tx_buffer = content_str
No newline at end of file
364
No newline at end of file
365 if __name__ == '__main__':
No newline at end of file
366
No newline at end of file
367 absObj = ABSServer()
No newline at end of file
368
No newline at end of file
369 while 1:
No newline at end of file
370 absObj.waitRequest() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now