@@ -1,187 +1,199 | |||||
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): |
|
7 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): | |
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.enaModules = [] |
|
18 | self.enaModules = [] | |
19 |
|
19 | |||
20 | self.createObjects() |
|
20 | self.createObjects() | |
21 |
|
21 | |||
22 | def createObjects(self): |
|
22 | def createObjects(self): | |
23 |
|
23 | |||
24 | asServer = True |
|
24 | asServer = True | |
25 | self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) |
|
25 | self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) | |
26 | self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) |
|
26 | self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) | |
27 |
|
27 | |||
28 | def waitRequest(self): |
|
28 | def waitRequest(self): | |
29 |
|
29 | |||
30 | #Using rx buffer |
|
30 | #Using rx buffer | |
31 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() |
|
31 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() | |
32 |
|
32 | |||
33 | if cmd == "SNDF": |
|
33 | if cmd == "SNDF": | |
34 | datarpta = self.__sendFile2Modules(cmd = cmd) |
|
34 | datarpta = self.__sendFile2Modules(cmd = cmd) | |
35 |
|
35 | |||
36 | if cmd == "CHGB": |
|
36 | if cmd == "CHGB": | |
37 | datarpta = self.__changeBeam(cmd = cmd) |
|
37 | datarpta = self.__changeBeam(cmd = cmd) | |
38 |
|
38 | |||
39 | if cmd == "ANST": |
|
39 | if cmd == "ANST": | |
40 | self.__getControlModuleStatus(cmd = cmd) |
|
40 | self.__getControlModuleStatus(cmd = cmd) | |
41 | #Using tx buffer |
|
41 | #Using tx buffer | |
42 | datarpta = self.tx_buffer |
|
42 | datarpta = self.tx_buffer | |
43 |
|
43 | |||
44 | if cmd == "NTST": |
|
44 | if cmd == "NTST": | |
45 | self.enaModules = self.__getConnectionStatus() |
|
|||
46 | #Using tx buffer |
|
45 | #Using tx buffer | |
47 |
datarpta = self. |
|
46 | datarpta = self.__getConnectionStatus(cmd = cmd) | |
48 |
|
47 | |||
49 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) |
|
48 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) | |
50 |
|
49 | |||
51 | def checkModule(self, address): |
|
50 | def checkModule(self, address): | |
52 |
|
51 | |||
53 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" |
|
52 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" | |
54 | status = os.system(cmd) |
|
53 | status = os.system(cmd) | |
55 |
|
54 | |||
56 | if status == 256: |
|
55 | if status == 256: | |
57 | return False |
|
56 | return False | |
58 |
|
57 | |||
59 | return True |
|
58 | return True | |
60 |
|
59 | |||
61 | def __writeReport(self, enaModules): |
|
60 | def __writeReport(self, enaModules): | |
62 |
|
61 | |||
63 | status_array = ["Status of modules\n"] |
|
62 | status_array = ["Status of modules\n"] | |
64 | status_array.append("----------------\n") |
|
63 | status_array.append("----------------\n") | |
65 |
|
64 | |||
66 | for address in range(1,65): |
|
65 | for address in range(1,65): | |
67 | if address in enaModules: |
|
66 | if address in enaModules: | |
68 | status_array.append("192.168.1." + str(address) + " [1 1]\n") |
|
67 | status_array.append("192.168.1." + str(address) + " [1 1]\n") | |
69 | else: |
|
68 | else: | |
70 | status_array.append("192.168.1." + str(address) + " [0 0]\n") |
|
69 | status_array.append("192.168.1." + str(address) + " [0 0]\n") | |
71 |
|
70 | |||
72 | f = open("module_status.txt","w") |
|
71 | f = open("module_status.txt","w") | |
73 | f.writelines(status_array) |
|
72 | f.writelines(status_array) | |
74 | f.close() |
|
73 | f.close() | |
75 |
|
74 | |||
76 | def checkAntenna(self): |
|
75 | def checkAntenna(self): | |
77 |
|
76 | |||
78 | """ |
|
77 | """ | |
79 | Direccion de los modulos de las antenas: |
|
78 | Direccion de los modulos de las antenas: | |
80 |
|
79 | |||
81 | Norte : 01-16 |
|
80 | Norte : 01-16 | |
82 | Este : 17-32 |
|
81 | Este : 17-32 | |
83 | Oeste: : 33-48 |
|
82 | Oeste: : 33-48 | |
84 | Sur : 49-64 |
|
83 | Sur : 49-64 | |
85 |
|
84 | |||
86 | """ |
|
85 | """ | |
87 |
|
86 | |||
88 | enaModules2 = [] |
|
87 | enaModules2 = [] | |
89 |
|
88 | |||
90 | for address in range(1,65): |
|
89 | for address in range(1,65): | |
91 | if self.checkModule(address): |
|
90 | if self.checkModule(address): | |
92 | enaModules2.append(address) |
|
91 | enaModules2.append(address) | |
93 |
|
92 | |||
94 | self.__writeReport(enaModules2) |
|
93 | self.__writeReport(enaModules2) | |
95 | return enaModules2 |
|
94 | return enaModules2 | |
96 |
|
95 | |||
97 | def __ConnectionWithControlModules(self,data,cmd,id): |
|
96 | def __ConnectionWithControlModules(self,data,cmd,id): | |
98 |
|
97 | |||
99 | self.commClientObj.open_socket() |
|
98 | self.commClientObj.open_socket() | |
100 | ip = "192.168.1." + str(id) |
|
99 | ip = "192.168.1." + str(id) | |
101 | self.commClientObj.sendData(cmd, data, ip) |
|
100 | self.commClientObj.sendData(cmd, data, ip) | |
102 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() |
|
101 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() | |
103 | self.commClientObj.close_socket() |
|
102 | self.commClientObj.close_socket() | |
104 |
|
103 | |||
105 | return tmp |
|
104 | return tmp | |
106 |
|
105 | |||
107 | def __All2Blocks(self,input): |
|
106 | def __All2Blocks(self,input): | |
108 |
|
107 | |||
109 | rx_frame_lst = input.split('\n',2) |
|
108 | rx_frame_lst = input.split('\n',2) | |
110 |
|
109 | |||
111 | header = rx_frame_lst[0] + "\n" |
|
110 | header = rx_frame_lst[0] + "\n" | |
112 | control_modules_str = rx_frame_lst[2] |
|
111 | control_modules_str = rx_frame_lst[2] | |
113 | control_modules_lst = control_modules_str.split("------\n") |
|
112 | control_modules_lst = control_modules_str.split("------\n") | |
114 |
|
113 | |||
115 | return header, control_modules_lst |
|
114 | return header, control_modules_lst | |
116 |
|
115 | |||
117 |
|
116 | |||
118 | def __sendFile2Modules(self,cmd): |
|
117 | def __sendFile2Modules(self,cmd): | |
119 |
|
118 | |||
120 | #Needed for the loop |
|
119 | #Needed for the loop | |
121 | header, control_modules_lst = self.__All2Blocks(self.rx_buffer) |
|
120 | header, control_modules_lst = self.__All2Blocks(self.rx_buffer) | |
122 | correct = 0 |
|
121 | correct = 0 | |
123 |
|
122 | |||
124 | for id in range(1,65): |
|
123 | for id in range(1,65): | |
125 |
|
124 | |||
126 | if id not in self.enaModules: |
|
125 | if id not in self.enaModules: | |
127 | continue |
|
126 | continue | |
128 |
|
127 | |||
129 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": |
|
128 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": | |
130 | correct = correct + 1 |
|
129 | correct = correct + 1 | |
131 |
|
130 | |||
132 | if correct == len(self.enaModules): |
|
131 | if correct == len(self.enaModules): | |
133 | rpta = "OK" |
|
132 | rpta = "OK" | |
134 | else: |
|
133 | else: | |
135 | rpta = "Failure" |
|
134 | rpta = "Failure" | |
136 |
|
135 | |||
137 | return rpta |
|
136 | return rpta | |
138 |
|
137 | |||
139 | def __changeBeam(self, cmd): |
|
138 | def __changeBeam(self, cmd): | |
140 |
|
139 | |||
141 | correct = 0 |
|
140 | correct = 0 | |
142 | # enaModules = self.checkAntenna() |
|
141 | # enaModules = self.checkAntenna() | |
143 | # enaModules = [11,12,13,14] |
|
142 | # enaModules = [11,12,13,14] | |
144 |
|
143 | |||
145 | for id in range(1,65): |
|
144 | for id in range(1,65): | |
146 | if id not in self.enaModules: |
|
145 | if id not in self.enaModules: | |
147 | continue |
|
146 | continue | |
148 |
|
147 | |||
149 | if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK": |
|
148 | if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK": | |
150 | correct = correct + 1 |
|
149 | correct = correct + 1 | |
151 |
|
150 | |||
152 | if correct == len(self.enaModules): |
|
151 | if correct == len(self.enaModules): | |
153 | rpta = "OK" |
|
152 | rpta = "OK" | |
154 | else: |
|
153 | else: | |
155 | rpta = "Failure" |
|
154 | rpta = "Failure" | |
156 |
|
155 | |||
157 | return rpta |
|
156 | return rpta | |
158 |
|
157 | |||
159 | def __getControlModuleStatus(self, cmd): |
|
158 | def __getControlModuleStatus(self, cmd): | |
160 |
|
159 | |||
161 | all_blocks = "" |
|
160 | all_blocks = "" | |
162 | # enaModules = self.checkAntenna() |
|
161 | # enaModules = self.checkAntenna() | |
163 | # enaModules = [11,12,13,14] |
|
162 | # enaModules = [11,12,13,14] | |
164 |
|
163 | |||
165 | for id in range(1,65): |
|
164 | for id in range(1,65): | |
166 | if id not in self.enaModules: |
|
165 | if id not in self.enaModules: | |
167 | continue |
|
166 | continue | |
168 |
|
167 | |||
169 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
168 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |
170 |
|
169 | |||
171 | all_blocks = all_blocks + one_block |
|
170 | all_blocks = all_blocks + one_block | |
172 | #Using tx buffer |
|
171 | #Using tx buffer | |
173 | print all_blocks |
|
172 | print all_blocks | |
174 | self.tx_buffer = all_blocks |
|
173 | self.tx_buffer = all_blocks | |
175 |
|
174 | |||
176 | def __getConnectionStatus(self): |
|
175 | def __getConnectionStatus(self, cmd): | |
177 |
|
176 | |||
178 |
ena |
|
177 | ena = self.checkAntenna() | |
|
178 | self.enaModules = ena | |||
|
179 | ||||
|
180 | blockLst = [] | |||
179 |
|
181 | |||
180 | return enaModules |
|
182 | for id in range(1,65): | |
|
183 | if id not in self.enaModules: | |||
|
184 | continue | |||
|
185 | ||||
|
186 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |||
|
187 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |||
|
188 | #Using tx buffer | |||
|
189 | self.tx_buffer = "".join(blockLst) | |||
|
190 | print self.tx_buffer | |||
|
191 | ||||
|
192 | return self.tx_buffer | |||
181 |
|
193 | |||
182 | if __name__ == '__main__': |
|
194 | if __name__ == '__main__': | |
183 |
|
195 | |||
184 | absObj = ABSServer() |
|
196 | absObj = ABSServer() | |
185 |
|
197 | |||
186 | while 1: |
|
198 | while 1: | |
187 | absObj.waitRequest() No newline at end of file |
|
199 | absObj.waitRequest() |
General Comments 0
You need to be logged in to leave comments.
Login now