##// END OF EJS Templates
- Verificando el resultado del envio del archivo abs mediante la API cliente del proyecto.
- Verificando el resultado del envio del archivo abs mediante la API cliente del proyecto.

File last commit:

r168:169
r170:171
Show More
server3.py
399 lines | 12.2 KiB | text/x-python | PythonLexer
Implementation of the central control module using TCP
r74 import os
import library3
import time
automatic check of the antenna
r149 import threading
Implementation of the central control module using TCP
r74
class ABSServer:
r123 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"):
Implementation of the central control module using TCP
r74
self.ipSource = ipSource
self.ipDestino = ipDestino
self.portDestino = portDestino
self.ipDestino2 = ipDestino2
self.portDestino2 = portDestino2
self.tx_buffer = "default"
r123 # self.rx_buffer = "default"
self.rx_buffer = rx_buffer
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 self.enaModules = []
r158 self.bits = []
self.phase = []
self.txFile = []
self.rxFile = []
Implementation of the central control module using TCP
r74
self.createObjects()
automatic check of the antenna
r149 print "Checking control modules, please wait ..."
Client changes to return answer to the web page.
r168 # self.enaModules = self.checkAntenna()
self.enaModules = [1,12]
automatic check of the antenna
r149 print "Starting automatic control module status."
r158 self.__StartingAutomaticControlModules()
automatic check of the antenna
r149 self.__AutomaticControlModules()
automatic check of the antenna
r148
Implementation of the central control module using TCP
r74 def createObjects(self):
asServer = True
Trying frame without semicolon.
r101 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)
changes to integrate to the web interface
r138 self.wFiles = library3.FilesStuff()
Implementation of the central control module using TCP
r74
def waitRequest(self):
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 #Using rx buffer
automatic check of the antenna
r149 # ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData()
Implementation of the central control module using TCP
r74
if cmd == "SNDF":
automatic check of the antenna
r149 datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer)
getting file from the control module
r160
if cmd == "GETF":
datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
Implementation of the central control module using TCP
r74 if cmd == "CHGB":
automatic check of the antenna
r149 datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer)
Implementation of the central control module using TCP
r74
if cmd == "ANST":
automatic check of the antenna
r149 datarpta = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79
ABS Monitoring changes
r146 if cmd == "BGPH":
automatic check of the antenna
r149 datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer)
ABS Monitoring changes
r146
if cmd == "LWPH":
automatic check of the antenna
r149 datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
ABS Monitoring changes
r146
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 if cmd == "NTST":
automatic check of the antenna
r149 datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer)
Implementation of the central control module using TCP
r74
Changes on waitData function: library, server and client
r84 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
Implementation of the central control module using TCP
r74
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")
changes to integrate to the web interface
r138 filename = "module_status.txt"
self.__writeFile(filename,status_array)
# f = open("module_status.txt","w")
# f.writelines(status_array)
# f.close()
Implementation of the central control module using TCP
r74
changes to integrate to the web interface
r138
r158 def __CreateFile(self, filename):
changes to integrate to the web interface
r138
fobj = open(filename,"w")
r158 fobj.close()
def __writeNewFile(self, filename, data):
fobj = open(filename,"w")
changes to integrate to the web interface
r138 fobj.writelines(data)
fobj.close()
r158
def __writeFile(self, filename, data):
fobj = open(filename,"a")
fobj.writelines(data)
fobj.close()
Implementation of the central control module using TCP
r74 def checkAntenna(self):
"""
Direccion de los modulos de las antenas:
Norte : 01-16
Este : 17-32
Oeste: : 33-48
Sur : 49-64
"""
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 enaModules2 = []
Implementation of the central control module using TCP
r74
for address in range(1,65):
if self.checkModule(address):
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 enaModules2.append(address)
Implementation of the central control module using TCP
r74
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 self.__writeReport(enaModules2)
return enaModules2
Improve readability of the server3
r86
def __ConnectionWithControlModules(self,data,cmd,id):
Implementation of the central control module using TCP
r74
Improve readability of the server3
r86 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()
changes to integrate to the web interface
r138 return tmp
Improve readability of the server3
r86
changes to integrate to the web interface
r138 def abs2ControlModuleFormatFile(self, filename):
#From matriz to control module format
self.wFiles.toCentralControlFormat(filename)
FileName = "CentralControlFormat.txt"
F_Obj = open(FileName,"r")
FileList = F_Obj.readlines()
F_Obj.close()
FileStr = "".join(FileList)
getting file from the control module
r160 return FileStr
changes to integrate to the web interface
r138
Improve readability of the server3
r86 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
automatic check of the antenna
r149 def __sendFile2Modules(self,cmd, rx_buffer):
changes to integrate to the web interface
r138
automatic check of the antenna
r149 # rx_buffer_lst = self.rx_buffer.split('\n',1)
rx_buffer_lst = rx_buffer.split('\n',1)
changes to integrate to the web interface
r141 #Getting the filename from the begining of data
changes to integrate to the web interface
r139 filename = rx_buffer_lst[0]
tmp = rx_buffer_lst[1]
self.__writeFile(filename,tmp)
changes to integrate to the web interface
r138 data = self.abs2ControlModuleFormatFile(filename)
Implementation of the central control module using TCP
r74 #Needed for the loop
changes to integrate to the web interface
r138 header, control_modules_lst = self.__All2Blocks(data)
Implementation of the central control module using TCP
r74 correct = 0
for id in range(1,65):
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 if id not in self.enaModules:
Implementation of the central control module using TCP
r74 continue
Improve readability of the server3
r86 if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK":
Implementation of the central control module using TCP
r74 correct = correct + 1
Improve readability of the server3
r86
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 if correct == len(self.enaModules):
Implementation of the central control module using TCP
r74 rpta = "OK"
else:
rpta = "Failure"
return rpta
getting file from the control module
r160
def __getFileFromModules(self, cmd, rx_buffer):
Improve readability of the server3
r86
getting file from the control module
r160 for id in range(1,65):
if id not in self.enaModules:
continue
file = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
del self.rxFile[id-1]
self.rxFile.insert(id-1, file)
automatic check of the antenna
r149 def __changeBeam(self, cmd, rx_buffer):
Implementation of the central control module using TCP
r74
correct = 0
# enaModules = self.checkAntenna()
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 # enaModules = [11,12,13,14]
Implementation of the central control module using TCP
r74
for id in range(1,65):
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 if id not in self.enaModules:
Implementation of the central control module using TCP
r74 continue
automatic check of the antenna
r149 if self.__ConnectionWithControlModules(rx_buffer,cmd,id) == "OK":
Implementation of the central control module using TCP
r74 correct = correct + 1
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 if correct == len(self.enaModules):
Implementation of the central control module using TCP
r74 rpta = "OK"
else:
rpta = "Failure"
return rpta
Improve readability of the server3
r86
automatic check of the antenna
r149 def __getControlModuleStatus(self, cmd, rx_buffer):
Implementation of the central control module using TCP
r74
r158 # all_blocks = ""
# all_blocks = []
Implementation of the central control module using TCP
r74 # enaModules = self.checkAntenna()
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 # enaModules = [11,12,13,14]
Implementation of the central control module using TCP
r74
for id in range(1,65):
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 if id not in self.enaModules:
Implementation of the central control module using TCP
r74 continue
r158 bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
del self.bits[id-1]
self.bits.insert(id-1, bits)
Implementation of the central control module using TCP
r74
r158 # all_blocks.append(one_block)
Implementation of the central control module using TCP
r74 #Using tx buffer
r127
r158 # return all_blocks
automatic check of the antenna
r149
def __getControlModuleBigPhase(self, cmd, rx_buffer):
Implementation of the central control module using TCP
r74
r158 # all_blocks = ""
all_blocks = []
r127 # enaModules = self.checkAntenna()
# enaModules = [11,12,13,14]
for id in range(1,65):
if id not in self.enaModules:
continue
automatic check of the antenna
r149 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
r127
r158 # all_blocks = all_blocks + one_block
all_blocks.append(one_block)
r127 #Using tx buffer
automatic check of the antenna
r149 return all_blocks
ABS Monitoring changes
r146
automatic check of the antenna
r149 def __getControlModuleLowPhase(self, cmd, rx_buffer):
ABS Monitoring changes
r146
r158 # all_blocks = ""
# all_blocks = []
ABS Monitoring changes
r146 # enaModules = self.checkAntenna()
# enaModules = [11,12,13,14]
r127
ABS Monitoring changes
r146 for id in range(1,65):
if id not in self.enaModules:
continue
r158 phase = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
del self.phase[id-1]
self.phase.insert(id-1, phase)
# all_blocks = all_blocks + one_block
# all_blocks.append(one_block)
ABS Monitoring changes
r146 #Using tx buffer
r158 # return all_blocks
ABS Monitoring changes
r146
automatic check of the antenna
r149 def __getConnectionStatus(self, cmd, rx_buffer):
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79
r112 ena = self.checkAntenna()
r127 print ena
r112 self.enaModules = ena
blockLst = []
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79
r112 for id in range(1,65):
if id not in self.enaModules:
continue
automatic check of the antenna
r149 blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
r112 blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n")
#Using tx buffer
automatic check of the antenna
r149 all_blocks = "".join(blockLst)
r112
automatic check of the antenna
r149 return all_blocks
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79
r123 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
automatic check of the antenna
r149
r158 def __StartingAutomaticControlModules(self):
#Starting file
self.__CreateFile("Monitoring.txt")
# data = "MOD.\t BITS\t\t PHASE\n"
# self.__writeFile("Monitoring.txt", data)
#Starting lists
self.txFile = list("------\n------\n------\n" for i in range(64))
self.rxFile = list("------\n------\n------\n" for i in range(64))
self.bits = list("------\n------\n------\n" for i in range(64))
self.phase = list("----- -----\n----- -----\n----- -----\n" for i in range(64))
automatic check of the antenna
r149 def __AutomaticControlModules(self):
r123
getting file from the control module
r160 cmd = "GETF"
rx_buffer = "experimento1.ab1" + "\n"
self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
print self.rxFile
automatic check of the antenna
r149 cmd = "ANST"
rx_buffer = "1"
r158 self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer)
r123
automatic check of the antenna
r149 cmd = "LWPH"
rx_buffer = "0"
r158 self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer)
print "Saving file..."
getting file from the control module
r160
r158 print self.bits
print self.phase
self.__WritingMonitoringFile()
getting file from the control module
r160 threading.Timer(60, self.__AutomaticControlModules).start()
automatic check of the antenna
r149
r158 def __WritingMonitoringFile(self):
filename = "Monitoring.txt"
data = '===============================' + '\n'
self.__writeFile(filename, data)
data = time.strftime('\t' + "%d%b%Y %I:%M:%S %p" + '\n', time.localtime())
self.__writeFile(filename, data)
data = "MOD.\t BITS\t\t PHASE\n"
self.__writeFile(filename, data)
data = '===============================' + '\n'
self.__writeFile(filename, data)
for i in range(64):
tmp = self.bits[i].split('\n',3)
self.__writeFile(filename, ' ' + str(i + 1) + '\t\t' + tmp[2])
tmp = self.phase[i].split('\n',3)
self.__writeFile(filename, '\t\t' + tmp[2] + '\n')
Implementation of the central control module using TCP
r74 if __name__ == '__main__':
absObj = ABSServer()
while 1:
absObj.waitRequest()