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