##// END OF EJS Templates
changes with frame corrected
changes with frame corrected

File last commit:

r108:109
r108:109
Show More
server3.py
186 lines | 5.2 KiB | text/x-python | PythonLexer
Implementation of the central control module using TCP
r74 import os
import library3
import time
class ABSServer:
server3 init
r87 def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500):
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"
self.rx_buffer = "default"
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 self.enaModules = []
Implementation of the central control module using TCP
r74
self.createObjects()
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)
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
Changes on waitData function: library, server and client
r84 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
Implementation of the central control module using TCP
r74
if cmd == "SNDF":
datarpta = self.__sendFile2Modules(cmd = cmd)
if cmd == "CHGB":
datarpta = self.__changeBeam(cmd = cmd)
if cmd == "ANST":
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 self.__getControlModuleStatus(cmd = cmd)
#Using tx buffer
Implementation of the central control module using TCP
r74 datarpta = self.tx_buffer
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79
if cmd == "NTST":
self.enaModules = self.__getConnectionStatus()
#Using tx buffer
datarpta = self.enaModules
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")
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
"""
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()
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
Implementation of the central control module using TCP
r74 def __sendFile2Modules(self,cmd):
#Needed for the loop
Improve readability of the server3
r86 header, control_modules_lst = self.__All2Blocks(self.rx_buffer)
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
Improve readability of the server3
r86
Implementation of the central control module using TCP
r74 def __changeBeam(self, cmd):
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
Improve readability of the server3
r86 if self.__ConnectionWithControlModules(self.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
Modificaciones de control central de la funcion de estado de conexion de los modulos de control.
r79 def __getControlModuleStatus(self, cmd):
Implementation of the central control module using TCP
r74
Improve readability of the server3
r86 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
Improve readability of the server3
r86 one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id)
Implementation of the central control module using TCP
r74
Improve readability of the server3
r86 all_blocks = all_blocks + one_block
Implementation of the central control module using TCP
r74 #Using tx buffer
changes with frame corrected
r108 print all_blocks
Improve readability of the server3
r86 self.tx_buffer = all_blocks
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 def __getConnectionStatus(self):
enaModules = self.checkAntenna()
return enaModules
Implementation of the central control module using TCP
r74 if __name__ == '__main__':
absObj = ABSServer()
while 1:
absObj.waitRequest()