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