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