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