@@ -1,6 +1,7 | |||
|
1 | 1 | import os |
|
2 | 2 | import library3 |
|
3 | 3 | import time |
|
4 | import threading | |
|
4 | 5 | |
|
5 | 6 | class ABSServer: |
|
6 | 7 | |
@@ -20,7 +21,10 | |||
|
20 | 21 | |
|
21 | 22 | self.createObjects() |
|
22 | 23 | |
|
24 | print "Checking control modules, please wait ..." | |
|
23 | 25 | self.enaModules = self.checkAntenna() |
|
26 | print "Starting automatic control module status." | |
|
27 | self.__AutomaticControlModules() | |
|
24 | 28 | |
|
25 | 29 | def createObjects(self): |
|
26 | 30 | |
@@ -32,32 +36,26 | |||
|
32 | 36 | def waitRequest(self): |
|
33 | 37 | |
|
34 | 38 | #Using rx buffer |
|
35 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() | |
|
39 | # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() | |
|
40 | ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData() | |
|
36 | 41 | |
|
37 | 42 | if cmd == "SNDF": |
|
38 | datarpta = self.__sendFile2Modules(cmd = cmd) | |
|
43 | datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer) | |
|
39 | 44 | |
|
40 | 45 | if cmd == "CHGB": |
|
41 | datarpta = self.__changeBeam(cmd = cmd) | |
|
46 | datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer) | |
|
42 | 47 | |
|
43 | 48 | if cmd == "ANST": |
|
44 | self.__getControlModuleStatus(cmd = cmd) | |
|
45 | #Using tx buffer | |
|
46 | datarpta = self.tx_buffer | |
|
49 | datarpta = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) | |
|
47 | 50 | |
|
48 | 51 | if cmd == "BGPH": |
|
49 | self.__getControlModuleBigPhase(cmd = cmd) | |
|
50 | #Using tx buffer | |
|
51 | datarpta = self.tx_buffer | |
|
52 | datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer) | |
|
52 | 53 | |
|
53 | 54 | if cmd == "LWPH": |
|
54 | self.__getControlModuleLowPhase(cmd = cmd) | |
|
55 | #Using tx buffer | |
|
56 | datarpta = self.tx_buffer | |
|
55 | datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) | |
|
57 | 56 | |
|
58 | 57 | if cmd == "NTST": |
|
59 | #Using tx buffer | |
|
60 | datarpta = self.__getConnectionStatus(cmd = cmd) | |
|
58 | datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer) | |
|
61 | 59 | |
|
62 | 60 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) |
|
63 | 61 | |
@@ -149,9 +147,10 | |||
|
149 | 147 | return header, control_modules_lst |
|
150 | 148 | |
|
151 | 149 | |
|
152 | def __sendFile2Modules(self,cmd): | |
|
153 | ||
|
154 | rx_buffer_lst = self.rx_buffer.split('\n',1) | |
|
150 | def __sendFile2Modules(self,cmd, rx_buffer): | |
|
151 | ||
|
152 | # rx_buffer_lst = self.rx_buffer.split('\n',1) | |
|
153 | rx_buffer_lst = rx_buffer.split('\n',1) | |
|
155 | 154 | #Getting the filename from the begining of data |
|
156 | 155 | filename = rx_buffer_lst[0] |
|
157 | 156 | tmp = rx_buffer_lst[1] |
@@ -176,7 +175,7 | |||
|
176 | 175 | |
|
177 | 176 | return rpta |
|
178 | 177 | |
|
179 | def __changeBeam(self, cmd): | |
|
178 | def __changeBeam(self, cmd, rx_buffer): | |
|
180 | 179 | |
|
181 | 180 | correct = 0 |
|
182 | 181 | # enaModules = self.checkAntenna() |
@@ -186,7 +185,7 | |||
|
186 | 185 | if id not in self.enaModules: |
|
187 | 186 | continue |
|
188 | 187 | |
|
189 |
if self.__ConnectionWithControlModules( |
|
|
188 | if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK": | |
|
190 | 189 | correct = correct + 1 |
|
191 | 190 | |
|
192 | 191 | if correct == len(self.enaModules): |
@@ -196,7 +195,7 | |||
|
196 | 195 | |
|
197 | 196 | return rpta |
|
198 | 197 | |
|
199 | def __getControlModuleStatus(self, cmd): | |
|
198 | def __getControlModuleStatus(self, cmd, rx_buffer): | |
|
200 | 199 | |
|
201 | 200 | all_blocks = "" |
|
202 | 201 | # enaModules = self.checkAntenna() |
@@ -206,14 +205,14 | |||
|
206 | 205 | if id not in self.enaModules: |
|
207 | 206 | continue |
|
208 | 207 | |
|
209 |
one_block = self.__ConnectionWithControlModules( |
|
|
208 | one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
210 | 209 | |
|
211 | 210 | all_blocks = all_blocks + one_block |
|
212 | 211 | #Using tx buffer |
|
213 | print all_blocks | |
|
214 |
|
|
|
215 | ||
|
216 | def __getControlModuleBigPhase(self, cmd): | |
|
212 | ||
|
213 | return all_blocks | |
|
214 | ||
|
215 | def __getControlModuleBigPhase(self, cmd, rx_buffer): | |
|
217 | 216 | |
|
218 | 217 | all_blocks = "" |
|
219 | 218 | # enaModules = self.checkAntenna() |
@@ -223,14 +222,13 | |||
|
223 | 222 | if id not in self.enaModules: |
|
224 | 223 | continue |
|
225 | 224 | |
|
226 |
one_block = self.__ConnectionWithControlModules( |
|
|
225 | one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
227 | 226 | |
|
228 | 227 | all_blocks = all_blocks + one_block |
|
229 | 228 | #Using tx buffer |
|
230 |
|
|
|
231 | self.tx_buffer = all_blocks | |
|
232 | ||
|
233 | def __getControlModuleLowPhase(self, cmd): | |
|
229 | return all_blocks | |
|
230 | ||
|
231 | def __getControlModuleLowPhase(self, cmd, rx_buffer): | |
|
234 | 232 | |
|
235 | 233 | all_blocks = "" |
|
236 | 234 | # enaModules = self.checkAntenna() |
@@ -240,14 +238,13 | |||
|
240 | 238 | if id not in self.enaModules: |
|
241 | 239 | continue |
|
242 | 240 | |
|
243 |
one_block = self.__ConnectionWithControlModules( |
|
|
241 | one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
244 | 242 | |
|
245 | 243 | all_blocks = all_blocks + one_block |
|
246 | 244 | #Using tx buffer |
|
247 |
|
|
|
248 | self.tx_buffer = all_blocks | |
|
249 | ||
|
250 | def __getConnectionStatus(self, cmd): | |
|
245 | return all_blocks | |
|
246 | ||
|
247 | def __getConnectionStatus(self, cmd, rx_buffer): | |
|
251 | 248 | |
|
252 | 249 | ena = self.checkAntenna() |
|
253 | 250 | print ena |
@@ -259,6 +256,24 | |||
|
259 | 256 | if id not in self.enaModules: |
|
260 | 257 | continue |
|
261 | 258 | |
|
259 | blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id) | |
|
260 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |
|
261 | #Using tx buffer | |
|
262 | all_blocks = "".join(blockLst) | |
|
263 | ||
|
264 | return all_blocks | |
|
265 | ||
|
266 | def getConnectionStatus(self, cmd): | |
|
267 | ||
|
268 | ena = self.checkAntenna() | |
|
269 | self.enaModules = ena | |
|
270 | ||
|
271 | blockLst = [] | |
|
272 | ||
|
273 | for id in range(1,65): | |
|
274 | if id not in self.enaModules: | |
|
275 | continue | |
|
276 | ||
|
262 | 277 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
263 | 278 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") |
|
264 | 279 | #Using tx buffer |
@@ -266,25 +281,6 | |||
|
266 | 281 | print self.tx_buffer |
|
267 | 282 | |
|
268 | 283 | return self.tx_buffer |
|
269 | ||
|
270 | def getConnectionStatus(self, cmd): | |
|
271 | ||
|
272 | ena = self.checkAntenna() | |
|
273 | self.enaModules = ena | |
|
274 | ||
|
275 | blockLst = [] | |
|
276 | ||
|
277 | for id in range(1,65): | |
|
278 | if id not in self.enaModules: | |
|
279 | continue | |
|
280 | ||
|
281 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |
|
282 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |
|
283 | #Using tx buffer | |
|
284 | self.tx_buffer = "".join(blockLst) | |
|
285 | print self.tx_buffer | |
|
286 | ||
|
287 | return self.tx_buffer | |
|
288 | 284 | |
|
289 | 285 | def getControlModuleStatus(self, cmd): |
|
290 | 286 | |
@@ -304,6 +300,21 | |||
|
304 | 300 | self.tx_buffer = all_blocks |
|
305 | 301 | |
|
306 | 302 | return all_blocks |
|
303 | ||
|
304 | def __AutomaticControlModules(self): | |
|
305 | ||
|
306 | cmd = "ANST" | |
|
307 | rx_buffer = "1" | |
|
308 | tmp1 = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) | |
|
309 | ||
|
310 | cmd = "LWPH" | |
|
311 | rx_buffer = "0" | |
|
312 | tmp2 = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) | |
|
313 | print "getting this: " | |
|
314 | print tmp1 | |
|
315 | print tmp2 | |
|
316 | ||
|
317 | threading.Timer(30, self.__AutomaticControlModules).start() | |
|
307 | 318 | |
|
308 | 319 | |
|
309 | 320 | if __name__ == '__main__': |
@@ -1,8 +1,12 | |||
|
1 | 1 | import file |
|
2 | 2 | from client3 import * |
|
3 | import sys | |
|
3 | 4 | |
|
4 | ns = "4" | |
|
5 | ||
|
6 | 5 | absObj = ABSClient(ipDestino="10.10.10.97") |
|
7 | 6 | #absObj = ABSClient() |
|
8 | absObj.getControlModuleStatus(ns) No newline at end of file | |
|
7 | if len(sys.argv) == 2: | |
|
8 | # ns = "4" | |
|
9 | ns = sys.argv[1] | |
|
10 | absObj.getControlModuleStatus(ns) | |
|
11 | else: | |
|
12 | print "Only one argument needed." No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now