@@ -1,77 +1,86 | |||
|
1 | 1 | import library3 |
|
2 | 2 | |
|
3 | 3 | class ABSClient: |
|
4 | 4 | |
|
5 | 5 | def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000): |
|
6 | 6 | |
|
7 | 7 | self.ipSource = ipSource |
|
8 | 8 | self.iDSource = iDSource |
|
9 | 9 | self.ipDestino = ipDestino |
|
10 | 10 | self.iDDestino = iDDestino |
|
11 | 11 | self.portDestino = portDestino |
|
12 | 12 | |
|
13 | 13 | self.createObjects() |
|
14 | 14 | |
|
15 | 15 | def createObjects(self): |
|
16 | 16 | |
|
17 | 17 | self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino) |
|
18 | self.wFiles = library3.FilesStuff() | |
|
18 | # self.wFiles = library3.FilesStuff() | |
|
19 | 19 | |
|
20 | 20 | def __ConnectionWithCentralControl(self, cmd, data): |
|
21 | 21 | |
|
22 | 22 | self.commObj.open_socket() |
|
23 | 23 | self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino) |
|
24 | 24 | ipSource, ipDestino, cmd, output = self.commObj.waitData() |
|
25 | 25 | self.commObj.close_socket() |
|
26 | 26 | |
|
27 | 27 | return output |
|
28 | 28 | |
|
29 | def abs2ControlModuleFormatFile(self, filename): | |
|
30 | ||
|
31 | #From matriz to control module format | |
|
32 | self.wFiles.toCentralControlFormat(filename) | |
|
33 | FileName = "CentralControlFormat.txt" | |
|
34 | F_Obj = open(FileName,"r") | |
|
35 | FileList = F_Obj.readlines() | |
|
36 | F_Obj.close() | |
|
37 | FileStr = "".join(FileList) | |
|
38 | ||
|
39 | return FileStr | |
|
29 | # def abs2ControlModuleFormatFile(self, filename): | |
|
30 | # | |
|
31 | # #From matriz to control module format | |
|
32 | # self.wFiles.toCentralControlFormat(filename) | |
|
33 | # FileName = "CentralControlFormat.txt" | |
|
34 | # F_Obj = open(FileName,"r") | |
|
35 | # FileList = F_Obj.readlines() | |
|
36 | # F_Obj.close() | |
|
37 | # FileStr = "".join(FileList) | |
|
38 | # | |
|
39 | # return FileStr | |
|
40 | 40 | |
|
41 | 41 | def sendFile(self, filename): |
|
42 | 42 | |
|
43 | data = self.abs2ControlModuleFormatFile(filename) | |
|
44 | ||
|
43 | # data = self.abs2ControlModuleFormatFile(filename) | |
|
44 | data = self.__readFile(filename) | |
|
45 | 45 | self.__ConnectionWithCentralControl(cmd = "SNDF", data = data) |
|
46 | 46 | |
|
47 | 47 | def changeBeam(self, newBeam): |
|
48 | 48 | |
|
49 | 49 | self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam) |
|
50 | 50 | |
|
51 | 51 | def __writeFile(self, filename, data): |
|
52 | 52 | |
|
53 | 53 | fobj = open(filename,"w") |
|
54 | 54 | fobj.writelines(data) |
|
55 | 55 | fobj.close() |
|
56 | ||
|
57 | def __readFile(self, filename): | |
|
58 | ||
|
59 | fobj = open(filename,"r") | |
|
60 | listData = fobj.readlines() | |
|
61 | fobj.close() | |
|
62 | data = "".join(listData) | |
|
63 | return data | |
|
64 | ||
|
56 | 65 | |
|
57 | 66 | def getControlModuleStatus(self, data): |
|
58 | 67 | |
|
59 | 68 | data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data) |
|
60 | 69 | self.__writeFile("report.txt", data) |
|
61 | 70 | |
|
62 | 71 | def getControlModulePhase(self, data): |
|
63 | 72 | |
|
64 | 73 | data = self.__ConnectionWithCentralControl(cmd = "ANPH", data = data) |
|
65 | 74 | # self.__writeFile("report.txt", data) |
|
66 | 75 | |
|
67 | 76 | def getConnectionStatus(self): |
|
68 | 77 | |
|
69 | 78 | data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none") |
|
70 | 79 | self.__writeFile("connection_status.txt", data) |
|
71 | 80 | |
|
72 | 81 | if __name__ == '__main__': |
|
73 | 82 | |
|
74 | 83 | filename = "experimento1.abs" |
|
75 | 84 | |
|
76 | 85 | absObj = ABSClient() |
|
77 | 86 | absObj.sendFile(filename) |
@@ -1,262 +1,287 | |||
|
1 | 1 | import os |
|
2 | 2 | import library3 |
|
3 | 3 | import time |
|
4 | 4 | |
|
5 | 5 | class ABSServer: |
|
6 | 6 | |
|
7 | 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 | 17 | # self.rx_buffer = "default" |
|
18 | 18 | self.rx_buffer = rx_buffer |
|
19 | 19 | self.enaModules = [] |
|
20 | 20 | |
|
21 | 21 | self.createObjects() |
|
22 | 22 | |
|
23 | 23 | def createObjects(self): |
|
24 | 24 | |
|
25 | 25 | asServer = True |
|
26 | 26 | self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) |
|
27 | 27 | self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) |
|
28 | self.wFiles = library3.FilesStuff() | |
|
28 | 29 | |
|
29 | 30 | def waitRequest(self): |
|
30 | 31 | |
|
31 | 32 | #Using rx buffer |
|
32 | 33 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() |
|
33 | 34 | |
|
34 | 35 | if cmd == "SNDF": |
|
35 | 36 | datarpta = self.__sendFile2Modules(cmd = cmd) |
|
36 | 37 | |
|
37 | 38 | if cmd == "CHGB": |
|
38 | 39 | datarpta = self.__changeBeam(cmd = cmd) |
|
39 | 40 | |
|
40 | 41 | if cmd == "ANST": |
|
41 | 42 | self.__getControlModuleStatus(cmd = cmd) |
|
42 | 43 | #Using tx buffer |
|
43 | 44 | datarpta = self.tx_buffer |
|
44 | 45 | |
|
45 | 46 | if cmd == "ANPH": |
|
46 | 47 | self.__getControlModulePhase(cmd = cmd) |
|
47 | 48 | #Using tx buffer |
|
48 | 49 | datarpta = self.tx_buffer |
|
49 | 50 | |
|
50 | 51 | if cmd == "NTST": |
|
51 | 52 | #Using tx buffer |
|
52 | 53 | datarpta = self.__getConnectionStatus(cmd = cmd) |
|
53 | 54 | |
|
54 | 55 | self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) |
|
55 | 56 | |
|
56 | 57 | def checkModule(self, address): |
|
57 | 58 | |
|
58 | 59 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" |
|
59 | 60 | status = os.system(cmd) |
|
60 | 61 | |
|
61 | 62 | if status == 256: |
|
62 | 63 | return False |
|
63 | 64 | |
|
64 | 65 | return True |
|
65 | 66 | |
|
66 | 67 | def __writeReport(self, enaModules): |
|
67 | 68 | |
|
68 | 69 | status_array = ["Status of modules\n"] |
|
69 | 70 | status_array.append("----------------\n") |
|
70 | 71 | |
|
71 | 72 | for address in range(1,65): |
|
72 | 73 | if address in enaModules: |
|
73 | 74 | status_array.append("192.168.1." + str(address) + " [1 1]\n") |
|
74 | 75 | else: |
|
75 | 76 | status_array.append("192.168.1." + str(address) + " [0 0]\n") |
|
76 | 77 | |
|
77 |
f = |
|
|
78 |
f.writel |
|
|
79 | f.close() | |
|
80 | ||
|
78 | filename = "module_status.txt" | |
|
79 | self.__writeFile(filename,status_array) | |
|
80 | # f = open("module_status.txt","w") | |
|
81 | # f.writelines(status_array) | |
|
82 | # f.close() | |
|
83 | ||
|
84 | ||
|
85 | def __writeFile(self, filename, data): | |
|
86 | ||
|
87 | fobj = open(filename,"w") | |
|
88 | fobj.writelines(data) | |
|
89 | fobj.close() | |
|
90 | ||
|
81 | 91 | def checkAntenna(self): |
|
82 | 92 | |
|
83 | 93 | """ |
|
84 | 94 | Direccion de los modulos de las antenas: |
|
85 | 95 | |
|
86 | 96 | Norte : 01-16 |
|
87 | 97 | Este : 17-32 |
|
88 | 98 | Oeste: : 33-48 |
|
89 | 99 | Sur : 49-64 |
|
90 | 100 | |
|
91 | 101 | """ |
|
92 | 102 | |
|
93 | 103 | enaModules2 = [] |
|
94 | 104 | |
|
95 | 105 | for address in range(1,65): |
|
96 | 106 | if self.checkModule(address): |
|
97 | 107 | enaModules2.append(address) |
|
98 | 108 | |
|
99 | 109 | self.__writeReport(enaModules2) |
|
100 | 110 | return enaModules2 |
|
101 | 111 | |
|
102 | 112 | def __ConnectionWithControlModules(self,data,cmd,id): |
|
103 | 113 | |
|
104 | 114 | self.commClientObj.open_socket() |
|
105 | 115 | ip = "192.168.1." + str(id) |
|
106 | 116 | self.commClientObj.sendData(cmd, data, ip) |
|
107 | 117 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() |
|
108 | 118 | self.commClientObj.close_socket() |
|
109 | 119 | |
|
110 |
return tmp |
|
|
120 | return tmp | |
|
121 | ||
|
122 | def abs2ControlModuleFormatFile(self, filename): | |
|
123 | ||
|
124 | #From matriz to control module format | |
|
125 | self.wFiles.toCentralControlFormat(filename) | |
|
126 | FileName = "CentralControlFormat.txt" | |
|
127 | F_Obj = open(FileName,"r") | |
|
128 | FileList = F_Obj.readlines() | |
|
129 | F_Obj.close() | |
|
130 | FileStr = "".join(FileList) | |
|
131 | ||
|
132 | return FileStr | |
|
111 | 133 | |
|
112 | 134 | def __All2Blocks(self,input): |
|
113 | 135 | |
|
114 | 136 | rx_frame_lst = input.split('\n',2) |
|
115 | 137 | |
|
116 | 138 | header = rx_frame_lst[0] + "\n" |
|
117 | 139 | control_modules_str = rx_frame_lst[2] |
|
118 | 140 | control_modules_lst = control_modules_str.split("------\n") |
|
119 | 141 | |
|
120 | 142 | return header, control_modules_lst |
|
121 | 143 | |
|
122 | 144 | |
|
123 | 145 | def __sendFile2Modules(self,cmd): |
|
124 | ||
|
146 | ||
|
147 | filename = "tmp.txt" | |
|
148 | self.__writeFile(filename,self.rx_buffer) | |
|
149 | data = self.abs2ControlModuleFormatFile(filename) | |
|
125 | 150 | #Needed for the loop |
|
126 |
header, control_modules_lst = self.__All2Blocks( |
|
|
151 | header, control_modules_lst = self.__All2Blocks(data) | |
|
127 | 152 | correct = 0 |
|
128 | 153 | |
|
129 | 154 | for id in range(1,65): |
|
130 | 155 | |
|
131 | 156 | if id not in self.enaModules: |
|
132 | 157 | continue |
|
133 | 158 | |
|
134 | 159 | if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": |
|
135 | 160 | correct = correct + 1 |
|
136 | 161 | |
|
137 | 162 | if correct == len(self.enaModules): |
|
138 | 163 | rpta = "OK" |
|
139 | 164 | else: |
|
140 | 165 | rpta = "Failure" |
|
141 | 166 | |
|
142 | 167 | return rpta |
|
143 | 168 | |
|
144 | 169 | def __changeBeam(self, cmd): |
|
145 | 170 | |
|
146 | 171 | correct = 0 |
|
147 | 172 | # enaModules = self.checkAntenna() |
|
148 | 173 | # enaModules = [11,12,13,14] |
|
149 | 174 | |
|
150 | 175 | for id in range(1,65): |
|
151 | 176 | if id not in self.enaModules: |
|
152 | 177 | continue |
|
153 | 178 | |
|
154 | 179 | if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK": |
|
155 | 180 | correct = correct + 1 |
|
156 | 181 | |
|
157 | 182 | if correct == len(self.enaModules): |
|
158 | 183 | rpta = "OK" |
|
159 | 184 | else: |
|
160 | 185 | rpta = "Failure" |
|
161 | 186 | |
|
162 | 187 | return rpta |
|
163 | 188 | |
|
164 | 189 | def __getControlModuleStatus(self, cmd): |
|
165 | 190 | |
|
166 | 191 | all_blocks = "" |
|
167 | 192 | # enaModules = self.checkAntenna() |
|
168 | 193 | # enaModules = [11,12,13,14] |
|
169 | 194 | |
|
170 | 195 | for id in range(1,65): |
|
171 | 196 | if id not in self.enaModules: |
|
172 | 197 | continue |
|
173 | 198 | |
|
174 | 199 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
175 | 200 | |
|
176 | 201 | all_blocks = all_blocks + one_block |
|
177 | 202 | #Using tx buffer |
|
178 | 203 | print all_blocks |
|
179 | 204 | self.tx_buffer = all_blocks |
|
180 | 205 | |
|
181 | 206 | def __getControlModulePhase(self, cmd): |
|
182 | 207 | |
|
183 | 208 | all_blocks = "" |
|
184 | 209 | # enaModules = self.checkAntenna() |
|
185 | 210 | # enaModules = [11,12,13,14] |
|
186 | 211 | |
|
187 | 212 | for id in range(1,65): |
|
188 | 213 | if id not in self.enaModules: |
|
189 | 214 | continue |
|
190 | 215 | |
|
191 | 216 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
192 | 217 | |
|
193 | 218 | all_blocks = all_blocks + one_block |
|
194 | 219 | #Using tx buffer |
|
195 | 220 | print all_blocks |
|
196 | 221 | self.tx_buffer = all_blocks |
|
197 | 222 | |
|
198 | 223 | def __getConnectionStatus(self, cmd): |
|
199 | 224 | |
|
200 | 225 | ena = self.checkAntenna() |
|
201 | 226 | print ena |
|
202 | 227 | self.enaModules = ena |
|
203 | 228 | |
|
204 | 229 | blockLst = [] |
|
205 | 230 | |
|
206 | 231 | for id in range(1,65): |
|
207 | 232 | if id not in self.enaModules: |
|
208 | 233 | continue |
|
209 | 234 | |
|
210 | 235 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
211 | 236 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") |
|
212 | 237 | #Using tx buffer |
|
213 | 238 | self.tx_buffer = "".join(blockLst) |
|
214 | 239 | print self.tx_buffer |
|
215 | 240 | |
|
216 | 241 | return self.tx_buffer |
|
217 | 242 | |
|
218 | 243 | def getConnectionStatus(self, cmd): |
|
219 | 244 | |
|
220 | 245 | ena = self.checkAntenna() |
|
221 | 246 | self.enaModules = ena |
|
222 | 247 | |
|
223 | 248 | blockLst = [] |
|
224 | 249 | |
|
225 | 250 | for id in range(1,65): |
|
226 | 251 | if id not in self.enaModules: |
|
227 | 252 | continue |
|
228 | 253 | |
|
229 | 254 | blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
230 | 255 | blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") |
|
231 | 256 | #Using tx buffer |
|
232 | 257 | self.tx_buffer = "".join(blockLst) |
|
233 | 258 | print self.tx_buffer |
|
234 | 259 | |
|
235 | 260 | return self.tx_buffer |
|
236 | 261 | |
|
237 | 262 | def getControlModuleStatus(self, cmd): |
|
238 | 263 | |
|
239 | 264 | all_blocks = "" |
|
240 | 265 | # enaModules = self.checkAntenna() |
|
241 | 266 | # enaModules = [11,12,13,14] |
|
242 | 267 | |
|
243 | 268 | for id in range(1,65): |
|
244 | 269 | if id not in self.enaModules: |
|
245 | 270 | continue |
|
246 | 271 | |
|
247 | 272 | one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) |
|
248 | 273 | |
|
249 | 274 | all_blocks = all_blocks + one_block |
|
250 | 275 | #Using tx buffer |
|
251 | 276 | print all_blocks |
|
252 | 277 | self.tx_buffer = all_blocks |
|
253 | 278 | |
|
254 | 279 | return all_blocks |
|
255 | 280 | |
|
256 | 281 | |
|
257 | 282 | if __name__ == '__main__': |
|
258 | 283 | |
|
259 | 284 | absObj = ABSServer() |
|
260 | 285 | |
|
261 | 286 | while 1: |
|
262 | 287 | absObj.waitRequest() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now