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