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