@@ -0,0 +1,66 | |||||
|
1 | Status of modules | |||
|
2 | ---------------- | |||
|
3 | 192.168.1.1 [1 1] | |||
|
4 | 192.168.1.2 [1 1] | |||
|
5 | 192.168.1.3 [0 0] | |||
|
6 | 192.168.1.4 [0 0] | |||
|
7 | 192.168.1.5 [0 0] | |||
|
8 | 192.168.1.6 [0 0] | |||
|
9 | 192.168.1.7 [0 0] | |||
|
10 | 192.168.1.8 [0 0] | |||
|
11 | 192.168.1.9 [0 0] | |||
|
12 | 192.168.1.10 [0 0] | |||
|
13 | 192.168.1.11 [0 0] | |||
|
14 | 192.168.1.12 [1 1] | |||
|
15 | 192.168.1.13 [0 0] | |||
|
16 | 192.168.1.14 [0 0] | |||
|
17 | 192.168.1.15 [0 0] | |||
|
18 | 192.168.1.16 [0 0] | |||
|
19 | 192.168.1.17 [0 0] | |||
|
20 | 192.168.1.18 [0 0] | |||
|
21 | 192.168.1.19 [0 0] | |||
|
22 | 192.168.1.20 [0 0] | |||
|
23 | 192.168.1.21 [0 0] | |||
|
24 | 192.168.1.22 [0 0] | |||
|
25 | 192.168.1.23 [1 1] | |||
|
26 | 192.168.1.24 [0 0] | |||
|
27 | 192.168.1.25 [0 0] | |||
|
28 | 192.168.1.26 [0 0] | |||
|
29 | 192.168.1.27 [0 0] | |||
|
30 | 192.168.1.28 [0 0] | |||
|
31 | 192.168.1.29 [0 0] | |||
|
32 | 192.168.1.30 [0 0] | |||
|
33 | 192.168.1.31 [0 0] | |||
|
34 | 192.168.1.32 [0 0] | |||
|
35 | 192.168.1.33 [0 0] | |||
|
36 | 192.168.1.34 [0 0] | |||
|
37 | 192.168.1.35 [0 0] | |||
|
38 | 192.168.1.36 [0 0] | |||
|
39 | 192.168.1.37 [0 0] | |||
|
40 | 192.168.1.38 [0 0] | |||
|
41 | 192.168.1.39 [0 0] | |||
|
42 | 192.168.1.40 [0 0] | |||
|
43 | 192.168.1.41 [0 0] | |||
|
44 | 192.168.1.42 [0 0] | |||
|
45 | 192.168.1.43 [0 0] | |||
|
46 | 192.168.1.44 [0 0] | |||
|
47 | 192.168.1.45 [0 0] | |||
|
48 | 192.168.1.46 [0 0] | |||
|
49 | 192.168.1.47 [0 0] | |||
|
50 | 192.168.1.48 [0 0] | |||
|
51 | 192.168.1.49 [0 0] | |||
|
52 | 192.168.1.50 [0 0] | |||
|
53 | 192.168.1.51 [0 0] | |||
|
54 | 192.168.1.52 [0 0] | |||
|
55 | 192.168.1.53 [0 0] | |||
|
56 | 192.168.1.54 [0 0] | |||
|
57 | 192.168.1.55 [0 0] | |||
|
58 | 192.168.1.56 [0 0] | |||
|
59 | 192.168.1.57 [0 0] | |||
|
60 | 192.168.1.58 [0 0] | |||
|
61 | 192.168.1.59 [0 0] | |||
|
62 | 192.168.1.60 [0 0] | |||
|
63 | 192.168.1.61 [0 0] | |||
|
64 | 192.168.1.62 [0 0] | |||
|
65 | 192.168.1.63 [0 0] | |||
|
66 | 192.168.1.64 [0 0] |
@@ -1,199 +1,239 | |||||
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, 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.enaModules = [] |
|
19 | self.enaModules = [] | |
19 |
|
20 | |||
20 | self.createObjects() |
|
21 | self.createObjects() | |
21 |
|
22 | |||
22 | def createObjects(self): |
|
23 | def createObjects(self): | |
23 |
|
24 | |||
24 | asServer = True |
|
25 | asServer = True | |
25 | 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) | |
26 | 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) | |
27 |
|
28 | |||
28 | def waitRequest(self): |
|
29 | def waitRequest(self): | |
29 |
|
30 | |||
30 | #Using rx buffer |
|
31 | #Using rx buffer | |
31 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() |
|
32 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() | |
32 |
|
33 | |||
33 | if cmd == "SNDF": |
|
34 | if cmd == "SNDF": | |
34 | datarpta = self.__sendFile2Modules(cmd = cmd) |
|
35 | datarpta = self.__sendFile2Modules(cmd = cmd) | |
35 |
|
36 | |||
36 | if cmd == "CHGB": |
|
37 | if cmd == "CHGB": | |
37 | datarpta = self.__changeBeam(cmd = cmd) |
|
38 | datarpta = self.__changeBeam(cmd = cmd) | |
38 |
|
39 | |||
39 | if cmd == "ANST": |
|
40 | if cmd == "ANST": | |
40 | self.__getControlModuleStatus(cmd = cmd) |
|
41 | self.__getControlModuleStatus(cmd = cmd) | |
41 | #Using tx buffer |
|
42 | #Using tx buffer | |
42 | datarpta = self.tx_buffer |
|
43 | datarpta = self.tx_buffer | |
43 |
|
44 | |||
44 | if cmd == "NTST": |
|
45 | if cmd == "NTST": | |
45 | #Using tx buffer |
|
46 | #Using tx buffer | |
46 | datarpta = self.__getConnectionStatus(cmd = cmd) |
|
47 | datarpta = self.__getConnectionStatus(cmd = cmd) | |
47 |
|
48 | |||
48 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) |
|
49 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) | |
49 |
|
50 | |||
50 | def checkModule(self, address): |
|
51 | def checkModule(self, address): | |
51 |
|
52 | |||
52 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" |
|
53 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" | |
53 | status = os.system(cmd) |
|
54 | status = os.system(cmd) | |
54 |
|
55 | |||
55 | if status == 256: |
|
56 | if status == 256: | |
56 | return False |
|
57 | return False | |
57 |
|
58 | |||
58 | return True |
|
59 | return True | |
59 |
|
60 | |||
60 | def __writeReport(self, enaModules): |
|
61 | def __writeReport(self, enaModules): | |
61 |
|
62 | |||
62 | status_array = ["Status of modules\n"] |
|
63 | status_array = ["Status of modules\n"] | |
63 | status_array.append("----------------\n") |
|
64 | status_array.append("----------------\n") | |
64 |
|
65 | |||
65 | for address in range(1,65): |
|
66 | for address in range(1,65): | |
66 | if address in enaModules: |
|
67 | if address in enaModules: | |
67 | status_array.append("192.168.1." + str(address) + " [1 1]\n") |
|
68 | status_array.append("192.168.1." + str(address) + " [1 1]\n") | |
68 | else: |
|
69 | else: | |
69 | status_array.append("192.168.1." + str(address) + " [0 0]\n") |
|
70 | status_array.append("192.168.1." + str(address) + " [0 0]\n") | |
70 |
|
71 | |||
71 | f = open("module_status.txt","w") |
|
72 | f = open("module_status.txt","w") | |
72 | f.writelines(status_array) |
|
73 | f.writelines(status_array) | |
73 | f.close() |
|
74 | f.close() | |
74 |
|
75 | |||
75 | def checkAntenna(self): |
|
76 | def checkAntenna(self): | |
76 |
|
77 | |||
77 | """ |
|
78 | """ | |
78 | Direccion de los modulos de las antenas: |
|
79 | Direccion de los modulos de las antenas: | |
79 |
|
80 | |||
80 | Norte : 01-16 |
|
81 | Norte : 01-16 | |
81 | Este : 17-32 |
|
82 | Este : 17-32 | |
82 | Oeste: : 33-48 |
|
83 | Oeste: : 33-48 | |
83 | Sur : 49-64 |
|
84 | Sur : 49-64 | |
84 |
|
85 | |||
85 | """ |
|
86 | """ | |
86 |
|
87 | |||
87 | enaModules2 = [] |
|
88 | enaModules2 = [] | |
88 |
|
89 | |||
89 | for address in range(1,65): |
|
90 | for address in range(1,65): | |
90 | if self.checkModule(address): |
|
91 | if self.checkModule(address): | |
91 | enaModules2.append(address) |
|
92 | enaModules2.append(address) | |
92 |
|
93 | |||
93 | self.__writeReport(enaModules2) |
|
94 | self.__writeReport(enaModules2) | |
94 | return enaModules2 |
|
95 | return enaModules2 | |
95 |
|
96 | |||
96 | def __ConnectionWithControlModules(self,data,cmd,id): |
|
97 | def __ConnectionWithControlModules(self,data,cmd,id): | |
97 |
|
98 | |||
98 | self.commClientObj.open_socket() |
|
99 | self.commClientObj.open_socket() | |
99 | ip = "192.168.1." + str(id) |
|
100 | ip = "192.168.1." + str(id) | |
100 | self.commClientObj.sendData(cmd, data, ip) |
|
101 | self.commClientObj.sendData(cmd, data, ip) | |
101 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() |
|
102 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() | |
102 | self.commClientObj.close_socket() |
|
103 | self.commClientObj.close_socket() | |
103 |
|
104 | |||
104 | return tmp |
|
105 | return tmp | |
105 |
|
106 | |||
106 | def __All2Blocks(self,input): |
|
107 | def __All2Blocks(self,input): | |
107 |
|
108 | |||
108 | rx_frame_lst = input.split('\n',2) |
|
109 | rx_frame_lst = input.split('\n',2) | |
109 |
|
110 | |||
110 | header = rx_frame_lst[0] + "\n" |
|
111 | header = rx_frame_lst[0] + "\n" | |
111 | control_modules_str = rx_frame_lst[2] |
|
112 | control_modules_str = rx_frame_lst[2] | |
112 | control_modules_lst = control_modules_str.split("------\n") |
|
113 | control_modules_lst = control_modules_str.split("------\n") | |
113 |
|
114 | |||
114 | return header, control_modules_lst |
|
115 | return header, control_modules_lst | |
115 |
|
116 | |||
116 |
|
117 | |||
117 | def __sendFile2Modules(self,cmd): |
|
118 | def __sendFile2Modules(self,cmd): | |
118 |
|
119 | |||
119 | #Needed for the loop |
|
120 | #Needed for the loop | |
120 | header, control_modules_lst = self.__All2Blocks(self.rx_buffer) |
|
121 | header, control_modules_lst = self.__All2Blocks(self.rx_buffer) | |
121 | correct = 0 |
|
122 | correct = 0 | |
122 |
|
123 | |||
123 | for id in range(1,65): |
|
124 | for id in range(1,65): | |
124 |
|
125 | |||
125 | if id not in self.enaModules: |
|
126 | if id not in self.enaModules: | |
126 | continue |
|
127 | continue | |
127 |
|
128 | |||
128 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": |
|
129 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": | |
129 | correct = correct + 1 |
|
130 | correct = correct + 1 | |
130 |
|
131 | |||
131 | if correct == len(self.enaModules): |
|
132 | if correct == len(self.enaModules): | |
132 | rpta = "OK" |
|
133 | rpta = "OK" | |
133 | else: |
|
134 | else: | |
134 | rpta = "Failure" |
|
135 | rpta = "Failure" | |
135 |
|
136 | |||
136 | return rpta |
|
137 | return rpta | |
137 |
|
138 | |||
138 | def __changeBeam(self, cmd): |
|
139 | def __changeBeam(self, cmd): | |
139 |
|
140 | |||
140 | correct = 0 |
|
141 | correct = 0 | |
141 | # enaModules = self.checkAntenna() |
|
142 | # enaModules = self.checkAntenna() | |
142 | # enaModules = [11,12,13,14] |
|
143 | # enaModules = [11,12,13,14] | |
143 |
|
144 | |||
144 | for id in range(1,65): |
|
145 | for id in range(1,65): | |
145 | if id not in self.enaModules: |
|
146 | if id not in self.enaModules: | |
146 | continue |
|
147 | continue | |
147 |
|
148 | |||
148 | if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK": |
|
149 | if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK": | |
149 | correct = correct + 1 |
|
150 | correct = correct + 1 | |
150 |
|
151 | |||
151 | if correct == len(self.enaModules): |
|
152 | if correct == len(self.enaModules): | |
152 | rpta = "OK" |
|
153 | rpta = "OK" | |
153 | else: |
|
154 | else: | |
154 | rpta = "Failure" |
|
155 | rpta = "Failure" | |
155 |
|
156 | |||
156 | return rpta |
|
157 | return rpta | |
157 |
|
158 | |||
158 | def __getControlModuleStatus(self, cmd): |
|
159 | def __getControlModuleStatus(self, cmd): | |
159 |
|
160 | |||
160 | all_blocks = "" |
|
161 | all_blocks = "" | |
161 | # enaModules = self.checkAntenna() |
|
162 | # enaModules = self.checkAntenna() | |
162 | # enaModules = [11,12,13,14] |
|
163 | # enaModules = [11,12,13,14] | |
163 |
|
164 | |||
164 | for id in range(1,65): |
|
165 | for id in range(1,65): | |
165 | if id not in self.enaModules: |
|
166 | if id not in self.enaModules: | |
166 | continue |
|
167 | continue | |
167 |
|
168 | |||
168 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
169 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |
169 |
|
170 | |||
170 | all_blocks = all_blocks + one_block |
|
171 | all_blocks = all_blocks + one_block | |
171 | #Using tx buffer |
|
172 | #Using tx buffer | |
172 | print all_blocks |
|
173 | print all_blocks | |
173 | self.tx_buffer = all_blocks |
|
174 | self.tx_buffer = all_blocks | |
174 |
|
175 | |||
175 | def __getConnectionStatus(self, cmd): |
|
176 | def __getConnectionStatus(self, cmd): | |
176 |
|
177 | |||
177 | ena = self.checkAntenna() |
|
178 | ena = self.checkAntenna() | |
178 | self.enaModules = ena |
|
179 | self.enaModules = ena | |
179 |
|
180 | |||
180 | blockLst = [] |
|
181 | blockLst = [] | |
181 |
|
182 | |||
182 | for id in range(1,65): |
|
183 | for id in range(1,65): | |
183 | if id not in self.enaModules: |
|
184 | if id not in self.enaModules: | |
184 | continue |
|
185 | continue | |
185 |
|
186 | |||
186 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
187 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |
187 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") |
|
188 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |
188 | #Using tx buffer |
|
189 | #Using tx buffer | |
189 | self.tx_buffer = "".join(blockLst) |
|
190 | self.tx_buffer = "".join(blockLst) | |
190 | print self.tx_buffer |
|
191 | print self.tx_buffer | |
191 |
|
192 | |||
192 | return self.tx_buffer |
|
193 | return self.tx_buffer | |
193 |
|
194 | |||
|
195 | def getConnectionStatus(self, cmd): | |||
|
196 | ||||
|
197 | ena = self.checkAntenna() | |||
|
198 | self.enaModules = ena | |||
|
199 | ||||
|
200 | blockLst = [] | |||
|
201 | ||||
|
202 | for id in range(1,65): | |||
|
203 | if id not in self.enaModules: | |||
|
204 | continue | |||
|
205 | ||||
|
206 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) | |||
|
207 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") | |||
|
208 | #Using tx buffer | |||
|
209 | self.tx_buffer = "".join(blockLst) | |||
|
210 | print self.tx_buffer | |||
|
211 | ||||
|
212 | return self.tx_buffer | |||
|
213 | ||||
|
214 | def getControlModuleStatus(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 | return all_blocks | |||
|
232 | ||||
|
233 | ||||
194 | if __name__ == '__main__': |
|
234 | if __name__ == '__main__': | |
195 |
|
235 | |||
196 | absObj = ABSServer() |
|
236 | absObj = ABSServer() | |
197 |
|
237 | |||
198 | while 1: |
|
238 | while 1: | |
199 | absObj.waitRequest() No newline at end of file |
|
239 | absObj.waitRequest() |
General Comments 0
You need to be logged in to leave comments.
Login now