@@ -1,280 +1,281 | |||
|
1 | 1 | import os No newline at end of file |
|
2 | 2 | import library No newline at end of file |
|
3 | 3 | import time No newline at end of file |
|
4 | 4 | No newline at end of file |
|
5 | 5 | class ABSServer: No newline at end of file |
|
6 | 6 | |
|
7 | No newline at end of file | |
|
7 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.100", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None): No newline at end of file | |
|
8 | 8 | No newline at end of file |
|
9 | 9 | self.ipSource = ipSource No newline at end of file |
|
10 | 10 | self.ipDestino = ipDestino No newline at end of file |
|
11 | 11 | self.portDestino = portDestino No newline at end of file |
|
12 | 12 | No newline at end of file |
|
13 | 13 | self.ipDestino2 = ipDestino2 No newline at end of file |
|
14 | 14 | self.portDestino2 = portDestino2 No newline at end of file |
|
15 | 15 | No newline at end of file |
|
16 | 16 | self.ftpPortDestino = ftpPortDestino No newline at end of file |
|
17 | 17 | self.experiment_name = "default" No newline at end of file |
|
18 | 18 | self.tx_buffer = "default" No newline at end of file |
|
19 | 19 | No newline at end of file |
|
20 | 20 | self.createObjects() No newline at end of file |
|
21 | 21 | No newline at end of file |
|
22 | 22 | def createObjects(self): No newline at end of file |
|
23 | 23 | No newline at end of file |
|
24 | 24 | asServer = True No newline at end of file |
|
25 | 25 | self.commServerObj = library.TCPComm(self.ipSource, self.ipDestino, self.portDestino, asServer) |
|
26 | No newline at end of file | |
|
26 | self.commClientObj = library.TCPComm(self.ipSource, self.ipDestino2, self.portDestino2) No newline at end of file | |
|
27 | 27 | #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino) No newline at end of file |
|
28 | 28 | No newline at end of file |
|
29 | 29 | No newline at end of file |
|
30 | 30 | def waitRequest(self): No newline at end of file |
|
31 | 31 | No newline at end of file |
|
32 | 32 | ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData() No newline at end of file |
|
33 | 33 | No newline at end of file |
|
34 | 34 | datarpta = "OK" No newline at end of file |
|
35 | 35 | No newline at end of file |
|
36 | 36 | if cmd == "SNDF": |
|
37 | No newline at end of file | |
|
37 | self.sendFile2Modules() No newline at end of file | |
|
No newline at end of file | ||
|
38 | pass No newline at end of file | |
|
38 | 39 | No newline at end of file |
|
39 | 40 | if cmd == "CHGB": No newline at end of file |
|
40 | 41 | self.changeBeam() No newline at end of file |
|
41 | 42 | No newline at end of file |
|
42 | 43 | if cmd == "ANST": No newline at end of file |
|
43 | 44 | self.getStatus(mode=3) No newline at end of file |
|
44 | 45 | datarpta = self.tx_buffer No newline at end of file |
|
45 | 46 | No newline at end of file |
|
46 | 47 | self.commServerObj.sendData(cmd=cmd, data=datarpta) No newline at end of file |
|
47 | 48 | No newline at end of file |
|
48 | 49 | def checkModule(self, address): No newline at end of file |
|
49 | 50 | No newline at end of file |
|
50 | 51 | cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" No newline at end of file |
|
51 | 52 | status = os.system(cmd) No newline at end of file |
|
52 | 53 | No newline at end of file |
|
53 | 54 | if status == 256: No newline at end of file |
|
54 | 55 | return False No newline at end of file |
|
55 | 56 | No newline at end of file |
|
56 | 57 | return True No newline at end of file |
|
57 | 58 | No newline at end of file |
|
58 | 59 | def __writeReport(self, enaModules): No newline at end of file |
|
59 | 60 | No newline at end of file |
|
60 | 61 | status_array = ["Status of modules\n"] No newline at end of file |
|
61 | 62 | status_array.append("----------------\n") No newline at end of file |
|
62 | 63 | No newline at end of file |
|
63 | 64 | for address in range(1,65): No newline at end of file |
|
64 | 65 | if address in enaModules: No newline at end of file |
|
65 | 66 | # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n") No newline at end of file |
|
66 | 67 | status_array.append("192.168.1." + str(address) + " [1 1]\n") No newline at end of file |
|
67 | 68 | else: No newline at end of file |
|
68 | 69 | status_array.append("192.168.1." + str(address) + " [0 0]\n") No newline at end of file |
|
69 | 70 | No newline at end of file |
|
70 | 71 | f = open("module_status.txt","w") No newline at end of file |
|
71 | 72 | f.writelines(status_array) No newline at end of file |
|
72 | 73 | f.close() No newline at end of file |
|
73 | 74 | No newline at end of file |
|
74 | 75 | def checkAntenna(self): No newline at end of file |
|
75 | 76 | No newline at end of file |
|
76 | 77 | """ No newline at end of file |
|
77 | 78 | Direccion de los modulos de las antenas: No newline at end of file |
|
78 | 79 | No newline at end of file |
|
79 | 80 | Norte : 01-16 No newline at end of file |
|
80 | 81 | Este : 17-32 No newline at end of file |
|
81 | 82 | Oeste: : 33-48 No newline at end of file |
|
82 | 83 | Sur : 49-64 No newline at end of file |
|
83 | 84 | No newline at end of file |
|
84 | 85 | """ No newline at end of file |
|
85 | 86 | No newline at end of file |
|
86 | 87 | enaModules = [] No newline at end of file |
|
87 | 88 | No newline at end of file |
|
88 | 89 | for address in range(1,65): No newline at end of file |
|
89 | 90 | if self.checkModule(address): No newline at end of file |
|
90 | 91 | enaModules.append(address) No newline at end of file |
|
91 | 92 | No newline at end of file |
|
92 | 93 | self.__writeReport(enaModules) No newline at end of file |
|
93 | 94 | return enaModules No newline at end of file |
|
94 | 95 | No newline at end of file |
|
95 | 96 | def sendFile2Modules(self): No newline at end of file |
|
96 | 97 | No newline at end of file |
|
97 | 98 | #Needed for the loop No newline at end of file |
|
98 | 99 | rx_frame_list = self.datarx.split('\n',2) No newline at end of file |
|
99 | 100 | No newline at end of file |
|
100 | 101 | self.experiment_name = rx_frame_list[0] No newline at end of file |
|
101 | 102 | experiment_number = rx_frame_list[1] No newline at end of file |
|
102 | 103 | str_control_modules = rx_frame_list[2] No newline at end of file |
|
103 | 104 | No newline at end of file |
|
104 | 105 | lst_control_modules = str_control_modules.split("------\n") No newline at end of file |
|
105 | 106 | No newline at end of file |
|
106 | 107 | enaModules = self.checkAntenna() No newline at end of file |
|
107 | 108 | No newline at end of file |
|
108 | 109 | for address in range(1,65): No newline at end of file |
|
109 | 110 | No newline at end of file |
|
110 | 111 | if address not in enaModules: No newline at end of file |
|
111 | 112 | continue No newline at end of file |
|
112 | 113 | No newline at end of file |
|
113 | 114 | self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1]) No newline at end of file |
|
114 | 115 | No newline at end of file |
|
115 | 116 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name No newline at end of file |
|
116 | 117 | print cmd No newline at end of file |
|
117 | 118 | os.system(cmd) No newline at end of file |
|
118 | 119 | No newline at end of file |
|
119 | 120 | self.__loadFile() No newline at end of file |
|
120 | 121 | No newline at end of file |
|
121 | 122 | def __writeModuleFile(self, filename, str): No newline at end of file |
|
122 | 123 | No newline at end of file |
|
123 | 124 | fobj = open(filename,"w") No newline at end of file |
|
124 | 125 | fobj.write(filename + "\n") No newline at end of file |
|
125 | 126 | fobj.write("------\n") No newline at end of file |
|
126 | 127 | fobj.write(str) No newline at end of file |
|
127 | 128 | fobj.write("------\n") No newline at end of file |
|
128 | 129 | fobj.close() No newline at end of file |
|
129 | 130 | No newline at end of file |
|
130 | 131 | def __readModuleFile(self, filename): No newline at end of file |
|
131 | 132 | No newline at end of file |
|
132 | 133 | fobj1 = open(filename,"r") No newline at end of file |
|
133 | 134 | file_list_1 = fobj1.readlines() No newline at end of file |
|
134 | 135 | fobj1.close() No newline at end of file |
|
135 | 136 | content_str = ''.join(file_list_1[2:-1]) No newline at end of file |
|
136 | 137 | No newline at end of file |
|
137 | 138 | return content_str No newline at end of file |
|
138 | 139 | No newline at end of file |
|
139 | 140 | def __loadFile(self): No newline at end of file |
|
140 | 141 | No newline at end of file |
|
141 | 142 | #Working with the UDP socket No newline at end of file |
|
142 | 143 | self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") No newline at end of file |
|
143 | 144 | self.commClientObj.sendData("none", "CAMBIA:0:") No newline at end of file |
|
144 | 145 | No newline at end of file |
|
145 | 146 | def changeBeam(self): No newline at end of file |
|
146 | 147 | No newline at end of file |
|
147 | 148 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0") No newline at end of file |
|
148 | 149 | self.commClientObj.sendData("none", "CAMBIA:" + self.datarx + ":") No newline at end of file |
|
149 | 150 | No newline at end of file |
|
150 | 151 | def getStatus(self,mode): No newline at end of file |
|
151 | 152 | No newline at end of file |
|
152 | 153 | if mode == 1: No newline at end of file |
|
153 | 154 | self.__getStsMode1() No newline at end of file |
|
154 | 155 | elif mode == 2: No newline at end of file |
|
155 | 156 | self.__getStsMode2() No newline at end of file |
|
156 | 157 | else: No newline at end of file |
|
157 | 158 | self.__getStsMode3() No newline at end of file |
|
158 | 159 | No newline at end of file |
|
159 | 160 | No newline at end of file |
|
160 | 161 | def __getStsMode1(self): No newline at end of file |
|
161 | 162 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") No newline at end of file |
|
162 | 163 | self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") No newline at end of file |
|
163 | 164 | seconds = int (self.datarx) No newline at end of file |
|
164 | 165 | # Give 5 seconds to the control modules No newline at end of file |
|
165 | 166 | time.sleep(seconds) No newline at end of file |
|
166 | 167 | # Checking the module connection No newline at end of file |
|
167 | 168 | module_list = self.connection_status(10) No newline at end of file |
|
168 | 169 | #Generating the complete report No newline at end of file |
|
169 | 170 | module = 1 No newline at end of file |
|
170 | 171 | number_of_modules = 16 No newline at end of file |
|
171 | 172 | filename1 = "Verificacion" No newline at end of file |
|
172 | 173 | filename2 = "report.txt" No newline at end of file |
|
173 | 174 | fobj2 = open(filename2,"w") No newline at end of file |
|
174 | 175 | fobj2.write("Verification_file\n") No newline at end of file |
|
175 | 176 | fobj2.write("-----------------\n") No newline at end of file |
|
176 | 177 | fobj2.close() No newline at end of file |
|
177 | 178 | while module <= number_of_modules: No newline at end of file |
|
178 | 179 | if module_list[module -1] == "1": No newline at end of file |
|
179 | 180 | #Preparing and doing the tftp command No newline at end of file |
|
180 | 181 | cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1 No newline at end of file |
|
181 | 182 | print cmd No newline at end of file |
|
182 | 183 | os.system(cmd) No newline at end of file |
|
183 | 184 | # Getting data from the control module file No newline at end of file |
|
184 | 185 | fobj1 = open(filename1,"r") No newline at end of file |
|
185 | 186 | file_list_1 = fobj1.readlines() No newline at end of file |
|
186 | 187 | fobj1.close() No newline at end of file |
|
187 | 188 | content = file_list_1[2:-1] No newline at end of file |
|
188 | 189 | # No newline at end of file |
|
189 | 190 | fobj2 = open(filename2,"a") No newline at end of file |
|
190 | 191 | if base == 10: No newline at end of file |
|
191 | 192 | fobj2.write("S" + str(module) + "\n") No newline at end of file |
|
192 | 193 | else: No newline at end of file |
|
193 | 194 | fobj2.write("N" + str(module) + "\n") No newline at end of file |
|
194 | 195 | fobj2.writelines(content) No newline at end of file |
|
195 | 196 | fobj2.write("------\n") No newline at end of file |
|
196 | 197 | fobj2.close() No newline at end of file |
|
197 | 198 | module = module + 1 No newline at end of file |
|
198 | 199 | No newline at end of file |
|
199 | 200 | def __getStsMode2(self): No newline at end of file |
|
200 | 201 | No newline at end of file |
|
201 | 202 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") No newline at end of file |
|
202 | 203 | self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") No newline at end of file |
|
203 | 204 | seconds = int (self.datarx) No newline at end of file |
|
204 | 205 | # Give 5 seconds to the control modules No newline at end of file |
|
205 | 206 | time.sleep(seconds) No newline at end of file |
|
206 | 207 | # Checking the module connection No newline at end of file |
|
207 | 208 | enaModules = self.checkAntenna() No newline at end of file |
|
208 | 209 | #Generating the complete report No newline at end of file |
|
209 | 210 | filename1 = "Verificacion" No newline at end of file |
|
210 | 211 | line1 = "Verification_file\n" No newline at end of file |
|
211 | 212 | line2 = "-----------------\n" No newline at end of file |
|
212 | 213 | report_list = [line1, line2] No newline at end of file |
|
213 | 214 | No newline at end of file |
|
214 | 215 | for address in range(1,65): No newline at end of file |
|
215 | 216 | No newline at end of file |
|
216 | 217 | if address not in enaModules: No newline at end of file |
|
217 | 218 | continue No newline at end of file |
|
218 | 219 | #Preparing and doing the tftp command No newline at end of file |
|
219 | 220 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1 No newline at end of file |
|
220 | 221 | print cmd No newline at end of file |
|
221 | 222 | os.system(cmd) No newline at end of file |
|
222 | 223 | #Sub_header No newline at end of file |
|
223 | 224 | report_list.append("ABS_" + str(address) + "\n") No newline at end of file |
|
224 | 225 | # Content No newline at end of file |
|
225 | 226 | fobj1 = open(filename1,"r") No newline at end of file |
|
226 | 227 | file_list_1 = fobj1.readlines() No newline at end of file |
|
227 | 228 | fobj1.close() No newline at end of file |
|
228 | 229 | content = ''.join(file_list_1[2:-1]) No newline at end of file |
|
229 | 230 | report_list.append(content) No newline at end of file |
|
230 | 231 | #Ending No newline at end of file |
|
231 | 232 | report_list.append("------\n") No newline at end of file |
|
232 | 233 | #print "\nFinalizado" No newline at end of file |
|
233 | 234 | self.tx_buffer = ''.join(report_list) No newline at end of file |
|
234 | 235 | No newline at end of file |
|
235 | 236 | def __AddingHeader(self,content_list, title): No newline at end of file |
|
236 | 237 | No newline at end of file |
|
237 | 238 | line1 = title + "\n" No newline at end of file |
|
238 | 239 | line2 = "-----------------\n" No newline at end of file |
|
239 | 240 | header_list = [line1, line2] No newline at end of file |
|
240 | 241 | verification_list = header_list + content_list No newline at end of file |
|
241 | 242 | # Arming the frame No newline at end of file |
|
242 | 243 | self.tx_buffer = ''.join(verification_list) No newline at end of file |
|
243 | 244 | No newline at end of file |
|
244 | 245 | def __getModuleFile(self, filename): No newline at end of file |
|
245 | 246 | No newline at end of file |
|
246 | 247 | enaModules = self.checkAntenna() No newline at end of file |
|
247 | 248 | content_list = [] No newline at end of file |
|
248 | 249 | for address in range(1,65): No newline at end of file |
|
249 | 250 | No newline at end of file |
|
250 | 251 | if address not in enaModules: No newline at end of file |
|
251 | 252 | continue No newline at end of file |
|
252 | 253 | #Preparing and doing the tftp command No newline at end of file |
|
253 | 254 | cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename No newline at end of file |
|
254 | 255 | print cmd No newline at end of file |
|
255 | 256 | os.system(cmd) No newline at end of file |
|
256 | 257 | #Sub_header No newline at end of file |
|
257 | 258 | content_list.append("ABS_" + str(address) + "\n") No newline at end of file |
|
258 | 259 | # From module file to list No newline at end of file |
|
259 | 260 | content_str = self.__readModuleFile(filename) No newline at end of file |
|
260 | 261 | content_list.append(content_str) No newline at end of file |
|
261 | 262 | content_list.append("------\n") No newline at end of file |
|
262 | 263 | No newline at end of file |
|
263 | 264 | self.__AddingHeader(content_list, title = "Verification_file") No newline at end of file |
|
264 | 265 | No newline at end of file |
|
265 | 266 | def __getStsMode3(self): No newline at end of file |
|
266 | 267 | No newline at end of file |
|
267 | 268 | self.commClientObj.sendData("none", "CHEQUEO:" + self.datarx + ":") No newline at end of file |
|
268 | 269 | seconds = int (self.datarx) No newline at end of file |
|
269 | 270 | # Give 5 seconds to the control modules No newline at end of file |
|
270 | 271 | time.sleep(seconds) No newline at end of file |
|
271 | 272 | No newline at end of file |
|
272 | 273 | self.__getModuleFile(filename = "Verificacion") No newline at end of file |
|
273 | 274 | No newline at end of file |
|
274 | 275 | No newline at end of file |
|
275 | 276 | if __name__ == '__main__': No newline at end of file |
|
276 | 277 | No newline at end of file |
|
277 | 278 | absObj = ABSServer() No newline at end of file |
|
278 | 279 | No newline at end of file |
|
279 | 280 | while 1: No newline at end of file |
|
280 | 281 | absObj.waitRequest() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now