##// END OF EJS Templates
changes to integrate to the web interface
imanay -
r141:142
parent child
Show More
@@ -1,88 +1,87
1 import library3
1 import library3
2
2
3 class ABSClient:
3 class ABSClient:
4
4
5 def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000):
5 def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000):
6
6
7 self.ipSource = ipSource
7 self.ipSource = ipSource
8 self.iDSource = iDSource
8 self.iDSource = iDSource
9 self.ipDestino = ipDestino
9 self.ipDestino = ipDestino
10 self.iDDestino = iDDestino
10 self.iDDestino = iDDestino
11 self.portDestino = portDestino
11 self.portDestino = portDestino
12
12
13 self.createObjects()
13 self.createObjects()
14
14
15 def createObjects(self):
15 def createObjects(self):
16
16
17 self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino)
17 self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino)
18 # self.wFiles = library3.FilesStuff()
18 # self.wFiles = library3.FilesStuff()
19
19
20 def __ConnectionWithCentralControl(self, cmd, data):
20 def __ConnectionWithCentralControl(self, cmd, data):
21
21
22 self.commObj.open_socket()
22 self.commObj.open_socket()
23 self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino)
23 self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino)
24 ipSource, ipDestino, cmd, output = self.commObj.waitData()
24 ipSource, ipDestino, cmd, output = self.commObj.waitData()
25 self.commObj.close_socket()
25 self.commObj.close_socket()
26
26
27 return output
27 return output
28
28
29 # def abs2ControlModuleFormatFile(self, filename):
29 # def abs2ControlModuleFormatFile(self, filename):
30 #
30 #
31 # #From matriz to control module format
31 # #From matriz to control module format
32 # self.wFiles.toCentralControlFormat(filename)
32 # self.wFiles.toCentralControlFormat(filename)
33 # FileName = "CentralControlFormat.txt"
33 # FileName = "CentralControlFormat.txt"
34 # F_Obj = open(FileName,"r")
34 # F_Obj = open(FileName,"r")
35 # FileList = F_Obj.readlines()
35 # FileList = F_Obj.readlines()
36 # F_Obj.close()
36 # F_Obj.close()
37 # FileStr = "".join(FileList)
37 # FileStr = "".join(FileList)
38 #
38 #
39 # return FileStr
39 # return FileStr
40
40
41 def sendFile(self, filename):
41 def sendFile(self, filename):
42
42
43 # data = self.abs2ControlModuleFormatFile(filename)
43 data = self.__readFile(filename)
44 tmp = self.__readFile(filename)
45 #Sending content of file and the file name
46 data = filename + '\n' + tmp
47 self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
44 self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
48
45
49 def changeBeam(self, newBeam):
46 def changeBeam(self, newBeam):
50
47
51 self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
48 self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
52
49
53 def __writeFile(self, filename, data):
50 def __writeFile(self, filename, data):
54
51
55 fobj = open(filename,"w")
52 fobj = open(filename,"w")
56 fobj.writelines(data)
53 fobj.writelines(data)
57 fobj.close()
54 fobj.close()
58
55
59 def __readFile(self, filename):
56 def __readFile(self, filename):
60
57
61 fobj = open(filename,"r")
58 fobj = open(filename,"r")
62 listData = fobj.readlines()
59 listData = fobj.readlines()
63 fobj.close()
60 fobj.close()
64 data = "".join(listData)
61 tmp = "".join(listData)
62 #Adding filename to the begining of the data
63 data = filename + '\n' + tmp
65 return data
64 return data
66
65
67
66
68 def getControlModuleStatus(self, data):
67 def getControlModuleStatus(self, data):
69
68
70 data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
69 data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
71 self.__writeFile("report.txt", data)
70 self.__writeFile("report.txt", data)
72
71
73 def getControlModulePhase(self, data):
72 def getControlModulePhase(self, data):
74
73
75 data = self.__ConnectionWithCentralControl(cmd = "ANPH", data = data)
74 data = self.__ConnectionWithCentralControl(cmd = "ANPH", data = data)
76 # self.__writeFile("report.txt", data)
75 # self.__writeFile("report.txt", data)
77
76
78 def getConnectionStatus(self):
77 def getConnectionStatus(self):
79
78
80 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
79 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
81 self.__writeFile("connection_status.txt", data)
80 self.__writeFile("connection_status.txt", data)
82
81
83 if __name__ == '__main__':
82 if __name__ == '__main__':
84
83
85 filename = "experimento1.abs"
84 filename = "experimento1.abs"
86
85
87 absObj = ABSClient()
86 absObj = ABSClient()
88 absObj.sendFile(filename)
87 absObj.sendFile(filename)
@@ -1,289 +1,290
1 import os
1 import os
2 import library3
2 import library3
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.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
7 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
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.tx_buffer = "default"
16 self.tx_buffer = "default"
17 # self.rx_buffer = "default"
17 # self.rx_buffer = "default"
18 self.rx_buffer = rx_buffer
18 self.rx_buffer = rx_buffer
19 self.enaModules = []
19 self.enaModules = []
20
20
21 self.createObjects()
21 self.createObjects()
22
22
23 def createObjects(self):
23 def createObjects(self):
24
24
25 asServer = True
25 asServer = True
26 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
26 self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
27 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
27 self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
28 self.wFiles = library3.FilesStuff()
28 self.wFiles = library3.FilesStuff()
29
29
30 def waitRequest(self):
30 def waitRequest(self):
31
31
32 #Using rx buffer
32 #Using rx buffer
33 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
33 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
34
34
35 if cmd == "SNDF":
35 if cmd == "SNDF":
36 datarpta = self.__sendFile2Modules(cmd = cmd)
36 datarpta = self.__sendFile2Modules(cmd = cmd)
37
37
38 if cmd == "CHGB":
38 if cmd == "CHGB":
39 datarpta = self.__changeBeam(cmd = cmd)
39 datarpta = self.__changeBeam(cmd = cmd)
40
40
41 if cmd == "ANST":
41 if cmd == "ANST":
42 self.__getControlModuleStatus(cmd = cmd)
42 self.__getControlModuleStatus(cmd = cmd)
43 #Using tx buffer
43 #Using tx buffer
44 datarpta = self.tx_buffer
44 datarpta = self.tx_buffer
45
45
46 if cmd == "ANPH":
46 if cmd == "ANPH":
47 self.__getControlModulePhase(cmd = cmd)
47 self.__getControlModulePhase(cmd = cmd)
48 #Using tx buffer
48 #Using tx buffer
49 datarpta = self.tx_buffer
49 datarpta = self.tx_buffer
50
50
51 if cmd == "NTST":
51 if cmd == "NTST":
52 #Using tx buffer
52 #Using tx buffer
53 datarpta = self.__getConnectionStatus(cmd = cmd)
53 datarpta = self.__getConnectionStatus(cmd = cmd)
54
54
55 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
55 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
56
56
57 def checkModule(self, address):
57 def checkModule(self, address):
58
58
59 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
59 cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
60 status = os.system(cmd)
60 status = os.system(cmd)
61
61
62 if status == 256:
62 if status == 256:
63 return False
63 return False
64
64
65 return True
65 return True
66
66
67 def __writeReport(self, enaModules):
67 def __writeReport(self, enaModules):
68
68
69 status_array = ["Status of modules\n"]
69 status_array = ["Status of modules\n"]
70 status_array.append("----------------\n")
70 status_array.append("----------------\n")
71
71
72 for address in range(1,65):
72 for address in range(1,65):
73 if address in enaModules:
73 if address in enaModules:
74 status_array.append("192.168.1." + str(address) + " [1 1]\n")
74 status_array.append("192.168.1." + str(address) + " [1 1]\n")
75 else:
75 else:
76 status_array.append("192.168.1." + str(address) + " [0 0]\n")
76 status_array.append("192.168.1." + str(address) + " [0 0]\n")
77
77
78 filename = "module_status.txt"
78 filename = "module_status.txt"
79 self.__writeFile(filename,status_array)
79 self.__writeFile(filename,status_array)
80 # f = open("module_status.txt","w")
80 # f = open("module_status.txt","w")
81 # f.writelines(status_array)
81 # f.writelines(status_array)
82 # f.close()
82 # f.close()
83
83
84
84
85 def __writeFile(self, filename, data):
85 def __writeFile(self, filename, data):
86
86
87 fobj = open(filename,"w")
87 fobj = open(filename,"w")
88 fobj.writelines(data)
88 fobj.writelines(data)
89 fobj.close()
89 fobj.close()
90
90
91 def checkAntenna(self):
91 def checkAntenna(self):
92
92
93 """
93 """
94 Direccion de los modulos de las antenas:
94 Direccion de los modulos de las antenas:
95
95
96 Norte : 01-16
96 Norte : 01-16
97 Este : 17-32
97 Este : 17-32
98 Oeste: : 33-48
98 Oeste: : 33-48
99 Sur : 49-64
99 Sur : 49-64
100
100
101 """
101 """
102
102
103 enaModules2 = []
103 enaModules2 = []
104
104
105 for address in range(1,65):
105 for address in range(1,65):
106 if self.checkModule(address):
106 if self.checkModule(address):
107 enaModules2.append(address)
107 enaModules2.append(address)
108
108
109 self.__writeReport(enaModules2)
109 self.__writeReport(enaModules2)
110 return enaModules2
110 return enaModules2
111
111
112 def __ConnectionWithControlModules(self,data,cmd,id):
112 def __ConnectionWithControlModules(self,data,cmd,id):
113
113
114 self.commClientObj.open_socket()
114 self.commClientObj.open_socket()
115 ip = "192.168.1." + str(id)
115 ip = "192.168.1." + str(id)
116 self.commClientObj.sendData(cmd, data, ip)
116 self.commClientObj.sendData(cmd, data, ip)
117 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
117 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
118 self.commClientObj.close_socket()
118 self.commClientObj.close_socket()
119
119
120 return tmp
120 return tmp
121
121
122 def abs2ControlModuleFormatFile(self, filename):
122 def abs2ControlModuleFormatFile(self, filename):
123
123
124 #From matriz to control module format
124 #From matriz to control module format
125 self.wFiles.toCentralControlFormat(filename)
125 self.wFiles.toCentralControlFormat(filename)
126 FileName = "CentralControlFormat.txt"
126 FileName = "CentralControlFormat.txt"
127 F_Obj = open(FileName,"r")
127 F_Obj = open(FileName,"r")
128 FileList = F_Obj.readlines()
128 FileList = F_Obj.readlines()
129 F_Obj.close()
129 F_Obj.close()
130 FileStr = "".join(FileList)
130 FileStr = "".join(FileList)
131
131
132 return FileStr
132 return FileStr
133
133
134 def __All2Blocks(self,input):
134 def __All2Blocks(self,input):
135
135
136 rx_frame_lst = input.split('\n',2)
136 rx_frame_lst = input.split('\n',2)
137
137
138 header = rx_frame_lst[0] + "\n"
138 header = rx_frame_lst[0] + "\n"
139 control_modules_str = rx_frame_lst[2]
139 control_modules_str = rx_frame_lst[2]
140 control_modules_lst = control_modules_str.split("------\n")
140 control_modules_lst = control_modules_str.split("------\n")
141
141
142 return header, control_modules_lst
142 return header, control_modules_lst
143
143
144
144
145 def __sendFile2Modules(self,cmd):
145 def __sendFile2Modules(self,cmd):
146
146
147 rx_buffer_lst = self.rx_buffer.split('\n',1)
147 rx_buffer_lst = self.rx_buffer.split('\n',1)
148 #Getting the filename from the begining of data
148 filename = rx_buffer_lst[0]
149 filename = rx_buffer_lst[0]
149 tmp = rx_buffer_lst[1]
150 tmp = rx_buffer_lst[1]
150 self.__writeFile(filename,tmp)
151 self.__writeFile(filename,tmp)
151 data = self.abs2ControlModuleFormatFile(filename)
152 data = self.abs2ControlModuleFormatFile(filename)
152 #Needed for the loop
153 #Needed for the loop
153 header, control_modules_lst = self.__All2Blocks(data)
154 header, control_modules_lst = self.__All2Blocks(data)
154 correct = 0
155 correct = 0
155
156
156 for id in range(1,65):
157 for id in range(1,65):
157
158
158 if id not in self.enaModules:
159 if id not in self.enaModules:
159 continue
160 continue
160
161
161 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
162 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
162 correct = correct + 1
163 correct = correct + 1
163
164
164 if correct == len(self.enaModules):
165 if correct == len(self.enaModules):
165 rpta = "OK"
166 rpta = "OK"
166 else:
167 else:
167 rpta = "Failure"
168 rpta = "Failure"
168
169
169 return rpta
170 return rpta
170
171
171 def __changeBeam(self, cmd):
172 def __changeBeam(self, cmd):
172
173
173 correct = 0
174 correct = 0
174 # enaModules = self.checkAntenna()
175 # enaModules = self.checkAntenna()
175 # enaModules = [11,12,13,14]
176 # enaModules = [11,12,13,14]
176
177
177 for id in range(1,65):
178 for id in range(1,65):
178 if id not in self.enaModules:
179 if id not in self.enaModules:
179 continue
180 continue
180
181
181 if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK":
182 if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK":
182 correct = correct + 1
183 correct = correct + 1
183
184
184 if correct == len(self.enaModules):
185 if correct == len(self.enaModules):
185 rpta = "OK"
186 rpta = "OK"
186 else:
187 else:
187 rpta = "Failure"
188 rpta = "Failure"
188
189
189 return rpta
190 return rpta
190
191
191 def __getControlModuleStatus(self, cmd):
192 def __getControlModuleStatus(self, cmd):
192
193
193 all_blocks = ""
194 all_blocks = ""
194 # enaModules = self.checkAntenna()
195 # enaModules = self.checkAntenna()
195 # enaModules = [11,12,13,14]
196 # enaModules = [11,12,13,14]
196
197
197 for id in range(1,65):
198 for id in range(1,65):
198 if id not in self.enaModules:
199 if id not in self.enaModules:
199 continue
200 continue
200
201
201 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
202 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
202
203
203 all_blocks = all_blocks + one_block
204 all_blocks = all_blocks + one_block
204 #Using tx buffer
205 #Using tx buffer
205 print all_blocks
206 print all_blocks
206 self.tx_buffer = all_blocks
207 self.tx_buffer = all_blocks
207
208
208 def __getControlModulePhase(self, cmd):
209 def __getControlModulePhase(self, cmd):
209
210
210 all_blocks = ""
211 all_blocks = ""
211 # enaModules = self.checkAntenna()
212 # enaModules = self.checkAntenna()
212 # enaModules = [11,12,13,14]
213 # enaModules = [11,12,13,14]
213
214
214 for id in range(1,65):
215 for id in range(1,65):
215 if id not in self.enaModules:
216 if id not in self.enaModules:
216 continue
217 continue
217
218
218 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
219 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
219
220
220 all_blocks = all_blocks + one_block
221 all_blocks = all_blocks + one_block
221 #Using tx buffer
222 #Using tx buffer
222 print all_blocks
223 print all_blocks
223 self.tx_buffer = all_blocks
224 self.tx_buffer = all_blocks
224
225
225 def __getConnectionStatus(self, cmd):
226 def __getConnectionStatus(self, cmd):
226
227
227 ena = self.checkAntenna()
228 ena = self.checkAntenna()
228 print ena
229 print ena
229 self.enaModules = ena
230 self.enaModules = ena
230
231
231 blockLst = []
232 blockLst = []
232
233
233 for id in range(1,65):
234 for id in range(1,65):
234 if id not in self.enaModules:
235 if id not in self.enaModules:
235 continue
236 continue
236
237
237 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
238 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
238 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
239 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
239 #Using tx buffer
240 #Using tx buffer
240 self.tx_buffer = "".join(blockLst)
241 self.tx_buffer = "".join(blockLst)
241 print self.tx_buffer
242 print self.tx_buffer
242
243
243 return self.tx_buffer
244 return self.tx_buffer
244
245
245 def getConnectionStatus(self, cmd):
246 def getConnectionStatus(self, cmd):
246
247
247 ena = self.checkAntenna()
248 ena = self.checkAntenna()
248 self.enaModules = ena
249 self.enaModules = ena
249
250
250 blockLst = []
251 blockLst = []
251
252
252 for id in range(1,65):
253 for id in range(1,65):
253 if id not in self.enaModules:
254 if id not in self.enaModules:
254 continue
255 continue
255
256
256 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
257 blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
257 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
258 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
258 #Using tx buffer
259 #Using tx buffer
259 self.tx_buffer = "".join(blockLst)
260 self.tx_buffer = "".join(blockLst)
260 print self.tx_buffer
261 print self.tx_buffer
261
262
262 return self.tx_buffer
263 return self.tx_buffer
263
264
264 def getControlModuleStatus(self, cmd):
265 def getControlModuleStatus(self, cmd):
265
266
266 all_blocks = ""
267 all_blocks = ""
267 # enaModules = self.checkAntenna()
268 # enaModules = self.checkAntenna()
268 # enaModules = [11,12,13,14]
269 # enaModules = [11,12,13,14]
269
270
270 for id in range(1,65):
271 for id in range(1,65):
271 if id not in self.enaModules:
272 if id not in self.enaModules:
272 continue
273 continue
273
274
274 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
275 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
275
276
276 all_blocks = all_blocks + one_block
277 all_blocks = all_blocks + one_block
277 #Using tx buffer
278 #Using tx buffer
278 print all_blocks
279 print all_blocks
279 self.tx_buffer = all_blocks
280 self.tx_buffer = all_blocks
280
281
281 return all_blocks
282 return all_blocks
282
283
283
284
284 if __name__ == '__main__':
285 if __name__ == '__main__':
285
286
286 absObj = ABSServer()
287 absObj = ABSServer()
287
288
288 while 1:
289 while 1:
289 absObj.waitRequest() No newline at end of file
290 absObj.waitRequest()
General Comments 0
You need to be logged in to leave comments. Login now