##// END OF EJS Templates
- Corregida la vista view para visualizar el perfil con el patron 1 por defecto.
- Corregida la vista view para visualizar el perfil con el patron 1 por defecto.

File last commit:

r123:124
r126:127
Show More
server3.py
238 lines | 6.7 KiB | text/x-python | PythonLexer
import os
import library3
import time
class ABSServer:
def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
self.ipSource = ipSource
self.ipDestino = ipDestino
self.portDestino = portDestino
self.ipDestino2 = ipDestino2
self.portDestino2 = portDestino2
self.tx_buffer = "default"
# self.rx_buffer = "default"
self.rx_buffer = rx_buffer
self.enaModules = []
self.createObjects()
def createObjects(self):
asServer = True
self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer)
self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2)
def waitRequest(self):
#Using rx buffer
ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
if cmd == "SNDF":
datarpta = self.__sendFile2Modules(cmd = cmd)
if cmd == "CHGB":
datarpta = self.__changeBeam(cmd = cmd)
if cmd == "ANST":
self.__getControlModuleStatus(cmd = cmd)
#Using tx buffer
datarpta = self.tx_buffer
if cmd == "NTST":
#Using tx buffer
datarpta = self.__getConnectionStatus(cmd = cmd)
self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
def checkModule(self, address):
cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null"
status = os.system(cmd)
if status == 256:
return False
return True
def __writeReport(self, enaModules):
status_array = ["Status of modules\n"]
status_array.append("----------------\n")
for address in range(1,65):
if address in enaModules:
status_array.append("192.168.1." + str(address) + " [1 1]\n")
else:
status_array.append("192.168.1." + str(address) + " [0 0]\n")
f = open("module_status.txt","w")
f.writelines(status_array)
f.close()
def checkAntenna(self):
"""
Direccion de los modulos de las antenas:
Norte : 01-16
Este : 17-32
Oeste: : 33-48
Sur : 49-64
"""
enaModules2 = []
for address in range(1,65):
if self.checkModule(address):
enaModules2.append(address)
self.__writeReport(enaModules2)
return enaModules2
def __ConnectionWithControlModules(self,data,cmd,id):
self.commClientObj.open_socket()
ip = "192.168.1." + str(id)
self.commClientObj.sendData(cmd, data, ip)
ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
self.commClientObj.close_socket()
return tmp
def __All2Blocks(self,input):
rx_frame_lst = input.split('\n',2)
header = rx_frame_lst[0] + "\n"
control_modules_str = rx_frame_lst[2]
control_modules_lst = control_modules_str.split("------\n")
return header, control_modules_lst
def __sendFile2Modules(self,cmd):
#Needed for the loop
header, control_modules_lst = self.__All2Blocks(self.rx_buffer)
correct = 0
for id in range(1,65):
if id not in self.enaModules:
continue
if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
correct = correct + 1
if correct == len(self.enaModules):
rpta = "OK"
else:
rpta = "Failure"
return rpta
def __changeBeam(self, cmd):
correct = 0
# enaModules = self.checkAntenna()
# enaModules = [11,12,13,14]
for id in range(1,65):
if id not in self.enaModules:
continue
if self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) == "OK":
correct = correct + 1
if correct == len(self.enaModules):
rpta = "OK"
else:
rpta = "Failure"
return rpta
def __getControlModuleStatus(self, cmd):
all_blocks = ""
# enaModules = self.checkAntenna()
# enaModules = [11,12,13,14]
for id in range(1,65):
if id not in self.enaModules:
continue
one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
all_blocks = all_blocks + one_block
#Using tx buffer
print all_blocks
self.tx_buffer = all_blocks
def __getConnectionStatus(self, cmd):
ena = self.checkAntenna()
self.enaModules = ena
blockLst = []
for id in range(1,65):
if id not in self.enaModules:
continue
blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
#Using tx buffer
self.tx_buffer = "".join(blockLst)
print self.tx_buffer
return self.tx_buffer
def getConnectionStatus(self, cmd):
ena = self.checkAntenna()
self.enaModules = ena
blockLst = []
for id in range(1,65):
if id not in self.enaModules:
continue
blockStr = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
#Using tx buffer
self.tx_buffer = "".join(blockLst)
print self.tx_buffer
return self.tx_buffer
def getControlModuleStatus(self, cmd):
all_blocks = ""
# enaModules = self.checkAntenna()
# enaModules = [11,12,13,14]
for id in range(1,65):
if id not in self.enaModules:
continue
one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
all_blocks = all_blocks + one_block
#Using tx buffer
print all_blocks
self.tx_buffer = all_blocks
return all_blocks
if __name__ == '__main__':
absObj = ABSServer()
while 1:
absObj.waitRequest()