# SVN changeset patch # User imanay # Date 2013-02-13 19:24:09.682946 # Revision 85 Changes on waitData function: library, server and client Index: trunk/absroot/source/abspy/abscontrol/client3.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/client3.py b/trunk/absroot/source/abspy/abscontrol/client3.py --- a/trunk/absroot/source/abspy/abscontrol/client3.py (revision 84) +++ b/trunk/absroot/source/abspy/abscontrol/client3.py (revision 85) @@ -31,20 +31,16 @@ FileStr = "".join(FileList) data = FileStr - self.commObj.open_socket() -# self.commObj.sendData(cmd="SNDF", data=data, id = 117) - self.commObj.sendData2(cmd="SNDF", data=data, ipDestino = self.ipDestino) -# self.commObj.waitData() - self.commObj.waitClient() + self.commObj.open_socket() + self.commObj.sendData(cmd="SNDF", data=data, ipDestino = self.ipDestino) + self.commObj.waitData() self.commObj.close_socket() def changeBeam(self, newBeam): self.commObj.open_socket() -# self.commObj.sendData(cmd="CHGB", data=newBeam, id = 117) - self.commObj.sendData2(cmd="CHGB", data=newBeam, ipDestino = self.ipDestino) -# self.commObj.waitData() - self.commObj.waitClient() + self.commObj.sendData(cmd="CHGB", data=newBeam, ipDestino = self.ipDestino) + self.commObj.waitData() self.commObj.close_socket() def __writeFile(self, filename, data): @@ -55,19 +51,17 @@ def getControlModuleStatus(self, data): - self.commObj.open_socket() -# self.commObj.sendData(cmd="ANST", data = data, id = 117) - self.commObj.sendData2(cmd="ANST", data = data, ipDestino = self.ipDestino) -# ipSource, ipDestino, cmd, data = self.commObj.waitData() - ipSource, ipDestino, cmd, data = self.commObj.waitClient() + self.commObj.open_socket() + self.commObj.sendData(cmd="ANST", data = data, ipDestino = self.ipDestino) + ipSource, ipDestino, cmd, data = self.commObj.waitData() self.commObj.close_socket() self.__writeFile("report.txt", data) def getConnectionStatus(self): self.commObj.open_socket() - self.commObj.sendData2(cmd="NTST", data = "none", ipDestino = "192.168.1.117") - ipSource, ipDestino, cmd, data = self.commObj.waitClient() + self.commObj.sendData(cmd="NTST", data = "none", ipDestino = "192.168.1.117") + ipSource, ipDestino, cmd, data = self.commObj.waitData() self.commObj.close_socket() self.__writeFile("connection_status.txt", data) Index: trunk/absroot/source/abspy/abscontrol/library3.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/library3.py b/trunk/absroot/source/abspy/abscontrol/library3.py --- a/trunk/absroot/source/abspy/abscontrol/library3.py (revision 84) +++ b/trunk/absroot/source/abspy/abscontrol/library3.py (revision 85) @@ -45,34 +45,17 @@ # # self.socket_c.bind(self.addr) - def waitData(self, nbytes = 1024): + def waitData(self): + if self.asServer == True: + trama_rx = self.waitAsServer() + else: + trama_rx = self.waitAsClient() - print "\nWaiting some client." - - if self.asServer == False: - # Short data through ethernet - trama_rx = self.socket_c.recv(nbytes) - else: - self.socket_c.listen(1) - sc, addr = self.socket_c.accept() - self.sc = sc - self.answer = addr - # Big data through ethernet - trama_rx = "" - while True: - tmp = self.sc.recv(nbytes) - trama_rx = trama_rx + tmp - if trama_rx[-4:] == "quit": - break - - print "\nThis socket has received some data." - ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) return ipSource, ipDestino, cmd, data - - def waitServer(self, nbytes = 1024): - + + def waitAsServer(self, nbytes = 1024): print "\nWaiting some client." self.socket_c.listen(1) sc, addr = self.socket_c.accept() @@ -87,40 +70,18 @@ break print "\nThis socket has received some data from: " + str(self.answer) - - ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) - return ipSource, ipDestino, cmd, data - - def waitClient(self, nbytes = 1024): + return trama_rx + def waitAsClient(self, nbytes = 1024): print "\nWaiting the server." # Short data through ethernet trama_rx = self.socket_c.recv(nbytes) - print "\nThis socket has received this data: " + str(trama_rx) - ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) + return trama_rx - return ipSource, ipDestino, cmd, data - - def sendData(self, cmd, data, id): - - trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + \ - ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) - - if self.portDestino == 7000: - trama_tx = trama_tx + ":" + "quit" - # Send messages - if self.asServer == False: - host = "192.168.1." + str(id) - self.socket_c.connect((host, self.portDestino)) - self.socket_c.send(trama_tx) - else: - self.sc.send(trama_tx) - print "Sending message:[" + trama_tx + "]" - - def sendData2(self, cmd, data, ipDestino): + def sendData(self, cmd, data, ipDestino): trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" 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 84) +++ b/trunk/absroot/source/abspy/abscontrol/server3.py (revision 85) @@ -28,7 +28,7 @@ def waitRequest(self): #Using rx buffer - ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer() + ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() if cmd == "SNDF": datarpta = self.__sendFile2Modules(cmd = cmd) @@ -46,7 +46,7 @@ #Using tx buffer datarpta = self.enaModules - self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource) + self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) def checkModule(self, address): @@ -115,8 +115,8 @@ #tcp client needed self.commClientObj.open_socket() ip = "192.168.1." + str(id) - self.commClientObj.sendData2(cmd, header + lst_control_modules[id-1], ip) - ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() + 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": @@ -144,8 +144,8 @@ self.commClientObj.open_socket() ip = "192.168.1." + str(id) - self.commClientObj.sendData2(cmd, self.rx_buffer, ip) - ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() + self.commClientObj.sendData(cmd, self.rx_buffer, ip) + ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() self.commClientObj.close_socket() if tmp == "OK": @@ -172,8 +172,8 @@ self.commClientObj.open_socket() ip = "192.168.1." + str(id) - self.commClientObj.sendData2(cmd, self.rx_buffer, ip) - ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() + self.commClientObj.sendData(cmd, self.rx_buffer, ip) + ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() self.commClientObj.close_socket() content_str = content_str + tmp