##// END OF EJS Templates
Monitoring test
Monitoring test

File last commit:

r261:262
r261:262
Show More
server3.py
585 lines | 17.5 KiB | text/x-python | PythonLexer
Implementation of the central control module using TCP
r74 import os
import library3
import time
starting with threads.
r171 from threading import Thread
automatic check of the antenna
r149 import threading
starting with threads.
r171 import Queue
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
r247
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 = 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 ..."
starting with threads.
r171 self.enaModules = self.checkAntenna()
ABS Server without automatic monitoring.
r202 print '\nThis modules are present : ' + str(self.enaModules) + '\n'
# print "Starting automatic control module status."
r216 self.__StartingAutomaticControlModules()
ABS Server without automatic monitoring.
r202 # 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":
r220 datarpta = self.__getControlModuleStatus_old(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
Monitoring test
r244 if cmd == "MNTR":
r250 datarpta = self.__getControlModuleStatus_new(cmd = cmd, type = rx_buffer)
Monitoring test
r244
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
starting with threads.
r171 def __checkModule(self, address):
Implementation of the central control module using TCP
r74
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()
starting with threads.
r171 def __checkAntenna(self):
Implementation of the central control module using TCP
r74
"""
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
starting with threads.
r171 def checkModule(self, arg, queue):
cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null"
status = os.system(cmd)
if status == 256:
result = "failed"
else:
result = "ok"
queue.put({arg: result})
def checkAntenna(self):
ABS Server without automatic monitoring.
r202 iD = range(1,65)
starting with threads.
r171 q = Queue.Queue()
threads = []
tOut = []
modules = []
for argument in iD:
t = Thread(target=self.checkModule, args=(argument, q))
t.start()
threads.append(t)
for t in threads:
t.join()
for _ in range(len(iD)):
tOut.append(q.get())
for i in tOut:
if i.values()[0] == 'ok':
modules.append(i.keys()[0])
return modules
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]
Monitoring test
r261 self.__writeNewFile(filename,tmp)
changes to integrate to the web interface
r138 data = self.abs2ControlModuleFormatFile(filename)
Monitoring test
r260
print data
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]
r233 self.rxFile.insert(id-1, file)
r237 return self.rxFile
getting file from the control module
r160
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
r217 return self.bits
Monitoring test
r244
r250 def __getControlModuleStatus_new(self, cmd, type):
Monitoring test
r253 cm_lst = self.__gettingDataFromControlModules(cmd = cmd, rx_buffer = type)
Monitoring test
r251 out_str = self.__processingCMdata(in_data = cm_lst, type = type)
r250
Monitoring test
r251 return out_str
Monitoring test
r244
r250 def __gettingDataFromControlModules(self, cmd, rx_buffer):
Monitoring test
r244 for id in range(1,65):
if id not in self.enaModules:
continue
r250 cm = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
del self.test[id-1]
self.test.insert(id-1, cm)
return self.test
r247
r250 def __processingCMdata(self,in_data, type):
if (type == "0") or (type == "1") or (type == "2"):
out_str = "".join(in_data)
r247 elif type == "3":
Monitoring test
r255 out_str = self.__TwoComparation(in_lst = in_data)
r247 else:
Monitoring test
r255 out_str = self.__ThreeComparation(in_lst = in_data)
Monitoring test
r244
r247 return out_str
Monitoring test
r244
r247 def __TwoComparation(self, in_lst):
r250
Monitoring test
r251 file = []
relay = []
status = []
mode = '0'
cnt = 0
if mode == '0':
for i in in_lst:
Monitoring test
r254 if len(i) == 7:
Monitoring test
r251 file.append("xxxxxx")
relay.append("xxxxxx")
else:
Monitoring test
r256 file.append(i[16:22])
relay.append(i[23:29])
Monitoring test
r251 #Loop to generate a status
for i in range(64):
if file[i] == "xxxxxx":
status.append("xx")
continue
if cmp(file[i],relay[i]) == 0:
cnt = cnt + 1
if cmp(file[i][0:3],relay[i][0:3]) == 0:
cnt = cnt + 1
if cmp(file[i][3:6],relay[i][3:6]) == 0:
cnt = cnt + 2
r248
Monitoring test
r251 if cnt == 4:
status.append("00")
elif cnt == 0:
status.append("11")
elif cnt == 1:
status.append("11")
else:
status.append("01")
else:
cm_up =[]
cm_dw =[]
relay_up =[]
relay_dw =[]
for i in in_lst:
if len(i) == 8:
relay_up.append("-")
relay_dw.append("-")
cm_up.append("-")
cm_dw.append("-")
continue
relay_up.append(i[14:17])
relay_dw.append(i[17:20])
cm_up.append(i[21:24])
cm_dw.append(i[24:27])
comp_up = []
comp_dw = []
for i in range(64):
if len(relay_up == 1):
comp_up.append('x')
else:
if cmp(relay_up[i], cm_up[i]) == 0:
comp_up.append('0')
else:
comp_up.append('1')
for i in range(64):
if len(relay_dw == 1):
comp_dw.append('x')
else:
if cmp(relay_dw[i], cm_dw[i]) == 0:
comp_dw.append('0')
else:
comp_dw.append('1')
# Example:
# comp_up = [1,0,x,1,1,1 ..,1,0,1,x]
#
print comp_up
print comp_dw
r247
Monitoring test
r251 #Doing final format
return self.__FinalFormat(data1 = file, data2 = relay, data3 = status)
def __FinalFormat(self,data1,data2,data3):
header = "Device\tFile\tRelay\tStatus\n"
body = ""
r250 for i in range(64):
Monitoring test
r251 if i<9:
device = "CM0" + str(i+1)
r248 else:
Monitoring test
r251 device = "CM" + str(i+1)
line = device + '\t' + data1[i] + '\t' + data2[i] + '\t' + data3[i] + '\n'
body = body + line
r248
Monitoring test
r251 report = header + body
return report
r247 def __ThreeComparation(self, in_lst):
pass
Monitoring test
r244
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
r221 def __getControlModuleStatus_old(self, cmd, rx_buffer):
r123
all_blocks = ""
# enaModules = self.checkAntenna()
# enaModules = [11,12,13,14]
for id in range(1,65):
if id not in self.enaModules:
continue
r221 one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id)
r123
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))
r250 self.test = list("------\n" for i in range(64))
r158
automatic check of the antenna
r149 def __AutomaticControlModules(self):
r123
ABS Server without automatic monitoring.
r202 # cmd = "GETF"
# rx_buffer = "experimento1.ab1" + "\n"
# self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer)
#
# print self.rxFile
getting file from the control module
r160
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')
Monitoring test
r251
r158
Implementation of the central control module using TCP
r74 if __name__ == '__main__':
absObj = ABSServer()
while 1:
absObj.waitRequest()