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