# SVN changeset patch # User imanay # Date 2013-02-22 21:15:07.415986 # Revision 87 Improve readability of the server3 Index: trunk/absroot/source/abspy/abscontrol/server3.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/server3.py b/trunk/absroot/source/abspy/abscontrol/server3.py --- a/trunk/absroot/source/abspy/abscontrol/server3.py (revision 86) +++ b/trunk/absroot/source/abspy/abscontrol/server3.py (revision 87) @@ -4,7 +4,8 @@ class ABSServer: - def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): +# def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): + def __init__(self,ipSource="localhost", ipDestino="100.100.12.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): self.ipSource = ipSource self.ipDestino = ipDestino @@ -93,36 +94,61 @@ 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 - rx_frame_list = self.rx_buffer.split('\n',2) + header, control_modules_lst = self.__All2Blocks(self.rx_buffer) correct = 0 - failure = 0 - header = rx_frame_list[0] + "\n" - str_control_modules = rx_frame_list[2] - - lst_control_modules = str_control_modules.split("------\n") - -# enaModules = self.checkAntenna() -# enaModules = [11,12,13,14] for id in range(1,65): if id not in self.enaModules: continue - #tcp client needed - self.commClientObj.open_socket() - ip = "192.168.1." + str(id) - self.commClientObj.sendData(cmd, header + lst_control_modules[id-1], ip) - ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() - self.commClientObj.close_socket() - if tmp == "OK": + if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": correct = correct + 1 - else: - failure = failure + 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" @@ -130,11 +156,10 @@ rpta = "Failure" return rpta - - def __changeBeam(self, cmd): - - correct = 0 - failure = 0 + + def __getControlModuleStatus(self, cmd): + + all_blocks = "" # enaModules = self.checkAntenna() # enaModules = [11,12,13,14] @@ -142,43 +167,11 @@ if id not in self.enaModules: continue - self.commClientObj.open_socket() - ip = "192.168.1." + str(id) - self.commClientObj.sendData(cmd, self.rx_buffer, ip) - ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() - self.commClientObj.close_socket() + one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) - if tmp == "OK": - correct = correct + 1 - else: - failure = failure + 1 - - if correct == len(self.enaModules): - rpta = "OK" - else: - rpta = "Failure" - - return rpta - - def __getControlModuleStatus(self, cmd): - - content_str = "" -# enaModules = self.checkAntenna() -# enaModules = [11,12,13,14] - - for id in range(1,65): - if id not in self.enaModules: - continue - - self.commClientObj.open_socket() - ip = "192.168.1." + str(id) - self.commClientObj.sendData(cmd, self.rx_buffer, ip) - ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() - self.commClientObj.close_socket() - - content_str = content_str + tmp + all_blocks = all_blocks + one_block #Using tx buffer - self.tx_buffer = content_str + self.tx_buffer = all_blocks def __getConnectionStatus(self):