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