# SVN changeset patch # User imanay # Date 2012-11-07 20:45:48.808431 # Revision 28 Modificaciones a scripts python de cliente y servidor UDP Index: trunk/absroot/source/abspy/abscontrol/client.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/client.py b/trunk/absroot/source/abspy/abscontrol/client.py --- a/trunk/absroot/source/abspy/abscontrol/client.py (revision 27) +++ b/trunk/absroot/source/abspy/abscontrol/client.py (revision 28) @@ -1,8 +1,14 @@ +# imports needed for the file convertion +import os +import sys +import time +import numpy as np + import library class ABSClient: - def __init__(self,ipSource="localhost", ipDestino="abscontrol.jro.pe", portDestino=5509): + def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000): self.ipSource = ipSource self.ipDestino = ipDestino @@ -13,25 +19,236 @@ def createObjects(self): self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino) - + def sendFile(self, filename): - fp = open(filename) - data = fp.read() - - commObj.sendTxRxCommand(cmd="SND", data=data) + #From matriz to control module format + self.FuncionMaestra_GeneraFormatoControlCentral(filename) + FileName = "FormatoControlCentral.txt" + F_Obj = open(FileName,"r") + FileList = F_Obj.readlines() + F_Obj.close() + FileStr = "".join(FileList) + data = FileStr + + self.commObj.sendTxRxCommand(cmd="SNDF", data=data) def changeBeam(self, newBeam): - commObj.sendTxRxCommand(cmd="CHG", data=newBeam) + self.commObj.sendTxRxCommand(cmd="CHGB", data=newBeam) def getStatus(self): - commObj.sendTxRxCommand(cmd="ANST", data="ABS") + self.commObj.sendTxRxCommand(cmd="ANST", data="ABS") + +########## + + def FuncionMaestra_GeneraFormatoControlCentral(self,archivo): + """ Funcion que genera un archivo para el control central""" + + # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/' + CarpetaDeTrabajo = os.getcwd() + '/' + #print CarpetaDeTrabajo + #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/' + + def lst2string(lst): + string='' + for i in lst: + string=string+i + return string + + def string2lst(string): + lst = [] + for i in string: + lst.append(i) + return lst + + + def file1(string, type): + lst = string2lst(archivo) + fin = -1 + t = len(lst) + for i in np.arange(-1,-t,-1): + if lst[i]=='/': + fin=i + break + if type == '2': + nombre2 = lst[fin+1:] + nombre2[-1]='1' + nombre2 = lst2string(nombre2) + return nombre2 + + + def EliminaSaltoDeLinea(cadena): + i = 0 + for elemento in cadena: + if elemento =='\n' or elemento =='\r': + pass + else: + i=i+1 + return cadena [:i] + + def NumeroDeExperimentos(path): + fichero1=open(path,'r') + cont=0 + for cadena in fichero1: + cont=cont+1 + if cont==3: + nexp='' + pos=0 + for elemento in cadena: + pos=pos+1 + if elemento=='=': + nexp=int(cadena[pos:]) + return nexp + fichero1.close() + + def Paridad(numero): + if numero%2==0: return 'par' + elif numero%2==1: return 'impar' + + def EvaluaCadena(cadena): + if len(cadena)>35: + if cadena[-1]=='$': + return cadena[-35:-2] + elif cadena[-1]==']': + return cadena[-34:-1] + else: + return None + + def GuardaEnLista(path): + fichero=open(path,'r') + lista=[] + for cadena in fichero: + cadena = EliminaSaltoDeLinea(cadena) + cadena = EvaluaCadena(cadena) + if cadena != None: + lista.append(cadena) + fichero.close() + return lista + + def CreaFicherosPrevios(): + vector = GuardaEnLista(archivo) + for i in range(1,NumeroDeExperimentos(archivo)+1): + fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w') + for j in range(0,16): + fichero.write(vector[j+16*(i-1)]+'\n') + fichero.close() + + def CapturaValoresEnArchivo(path,polarizacion='up'): + fichero =open(path,'r') + cnt=0 + lstup=[] + lstdw=[] + for cadena in fichero: + cnt=cnt+1 + if cnt==5: + su01=cadena[17:20] + su02=cadena[21:24] + su03=cadena[25:28] + su04=cadena[29:32] + if cnt==6: + su05=cadena[17:20] + su06=cadena[21:24] + su07=cadena[25:28] + su08=cadena[29:32] + if cnt==7: + su09=cadena[17:20] + su10=cadena[21:24] + su11=cadena[25:28] + su12=cadena[29:32] + if cnt==8: + su13=cadena[17:20] + su14=cadena[21:24] + su15=cadena[25:28] + su16=cadena[29:32] + if cnt==13: + sd01=cadena[17:20] + sd02=cadena[21:24] + sd03=cadena[25:28] + sd04=cadena[29:32] + if cnt==14: + sd05=cadena[17:20] + sd06=cadena[21:24] + sd07=cadena[25:28] + sd08=cadena[29:32] + if cnt==15: + sd09=cadena[17:20] + sd10=cadena[21:24] + sd11=cadena[25:28] + sd12=cadena[29:32] + if cnt==16: + sd13=cadena[17:20] + sd14=cadena[21:24] + sd15=cadena[25:28] + sd16=cadena[29:32] + lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] + lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] + if polarizacion=='up': + return lstup + elif polarizacion=='dw': + return lstdw + fichero.close() + + def CreaFormatoFinal(): + ne=NumeroDeExperimentos(archivo) + + #nombre01 = file1(archivo,'1') + nombre02 = file1(archivo,'2') + fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') + fichero.write(nombre02+'\n') + fichero.write(str(ne)+'\n') + for i in range(1,17): + + if i<10: + nmod = '0'+str(i) + else: nmod = str(i) + + + fichero.write('S'+nmod+'\n') + for j in range(1,ne+1): + ruta=CarpetaDeTrabajo+str(j)+'.txt' + lu=CapturaValoresEnArchivo(ruta,polarizacion='up') + ld=CapturaValoresEnArchivo(ruta,polarizacion='dw') + part1='' + part2='' + if lu[i-1]=='1.0': part1='000' + if lu[i-1]=='2.0': part1='001' + if lu[i-1]=='3.0': part1='010' + if lu[i-1]=='0.0': part1='011' + if lu[i-1]=='0.5': part1='100' + if lu[i-1]=='1.5': part1='101' + if lu[i-1]=='2.5': part1='110' + if lu[i-1]=='3.5': part1='111' + if ld[i-1]=='1.0': part2='000' + if ld[i-1]=='2.0': part2='001' + if ld[i-1]=='3.0': part2='010' + if ld[i-1]=='0.0': part2='011' + if ld[i-1]=='0.5': part2='100' + if ld[i-1]=='1.5': part2='101' + if ld[i-1]=='2.5': part2='110' + if ld[i-1]=='3.5': part2='111' + fichero.write(part1+part2+'\n') + fichero.write('------'+'\n') + fichero.close() + + def EliminaArchivosEnLaCarpeta(): + ne=NumeroDeExperimentos(archivo) + for i in range(1,ne+1): + os.remove(CarpetaDeTrabajo+str(i)+'.txt') + + CreaFicherosPrevios() + CreaFormatoFinal() + EliminaArchivosEnLaCarpeta() + +########## if __name__ == '__main__': - filename = "miarchivo.txt" + filename = "experimento1.abs" absObj = ABSClient() - absObj.sendFile(filename) \ No newline at end of file + #absObj.sendFile(filename) + #absObj.changeBeam("6") + #absObj.changeBeam("2") + absObj.changeBeam("7") \ No newline at end of file Index: trunk/absroot/source/abspy/abscontrol/experimento1.abs =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/experimento1.abs b/trunk/absroot/source/abspy/abscontrol/experimento1.abs new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/abscontrol/experimento1.abs (revision 28) @@ -0,0 +1,231 @@ + title ='MST-ISR 2009 (NS-Up)' + + #Experiments = 12 + +1 = + [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ + [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,1.0,1.0,2.0,3.0,0.0],$ + [0.5,0.5,0.5,1.0,3.0,2.0,1.0,0.0],$ + [1.0,1.0,1.0,1.0,0.5,1.5,2.5,3.5],$ + [0.5,0.5,0.5,0.5,2.5,1.5,0.5,0.0]] + + [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ + [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ + [0.5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0,0.0],$ + [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ + [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]] + + [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ + [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ + [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0],$ + [1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0],$ + [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]] Index: trunk/absroot/source/abspy/abscontrol/library.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/library.py b/trunk/absroot/source/abspy/abscontrol/library.py --- a/trunk/absroot/source/abspy/abscontrol/library.py (revision 27) +++ b/trunk/absroot/source/abspy/abscontrol/library.py (revision 28) @@ -84,18 +84,20 @@ __HEADER = "ABS" - def __init__(self, ipSource, ipDestino, portDestino=1520, asServer=False): + def __init__(self, ipSource, ipDestino, portDestino, asServer=False): self.ipSource = ipSource self.ipDestino = ipDestino self.portDestino = portDestino + self.addr = (ipDestino,portDestino) self.openSocket(asServer) def openSocket(self, asServer): - self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) - self.socket_c.connect((self.ipDestino, self.portDestino)) + #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) + self.socket_c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0) +# self.socket_c.connect((self.ipDestino, self.portDestino)) if asServer: self.configAsServer() @@ -103,52 +105,74 @@ self.configAsClient() def configAsClient(self): - #Configurar broadcast - self.commObj = UDPClient() - + self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + def configAsServer(self): - self.commObj = UDPServer() + self.socket_c.bind(self.addr) + print "\nServer initialized" def waitRequest(self, nbytes): + + trama_rx, add = self.socket_c.recvfrom(nbytes) + print "\nServer has received a data" + ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) + + return ipSource, ipDestino, cmd, data + + def sendData(self,TxFrame): + + # Send messages + if(self.socket_c.sendto(TxFrame, self.addr)): + print "Sending message:[" + TxFrame + "]" + + data_rx, server_rx = self.socket_c.recvfrom(16) + + print "Data received ", data_rx, server_rx + + # Close socket + self.socket_c.close() + + def sendTxRxCommand(self, cmd, data, nbytes = 16384): + + self.sendRequest(cmd, data) + + #time.sleep(1) + + # ipSource_rx, ipDestino_rx, cmd_rx, data_rx = self.getRpta(nbytes) + + # if not(self.ipSource == ipDestino_rx): + # print "Error" + + # return data_rx + + def sendRequest(self, cmd, data): + + trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":" + #self.socket_c.send(trama_tx) + # Send messages + if(self.socket_c.sendto(trama_tx, self.addr)): + print "Sending message:[" + trama_tx + "]" + + + def getRpta(self, nbytes): trama_rx = self.socket_c.recv(nbytes) ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) return ipSource, ipDestino, cmd, data - - def sendTxRxCommand(self, cmd, data, nbytes): - - self.sendRequest(cmd, data) - - time.sleep(1) - - ipSource_rx, ipDestino_rx, cmd_rx, data_rx = self.getRpta(nbytes) - - if not(self.ipSource == ipDestino_rx): - print "Error" - - return data_rx - - def sendRequest(self, cmd, data): - - trama_tx = self.__HEADER + str(self.ipSource) + str(self.ipDestino) + str(cmd) + str(data) - self.socket_c.send(trama_tx) - - def getRpta(self, nbytes): - - trama_rx = self.socket_c.recv(nbytes) - ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) - - return ipSource, ipDestino, cmd, data def __getTrama(self, trama): - ipSource = trama[5:15] - ipDestino = trama[15:24] - cmd = trama[24:30] - data = trama[30:-1] + FrameList = trama.split(':') + + header = FrameList[0] + ipSource = FrameList[1] + ipDestino = FrameList[2] + cmd = FrameList[3] + data = FrameList[4] + trash = FrameList[5] return ipSource, ipDestino, cmd, data Index: trunk/absroot/source/abspy/abscontrol/server.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/server.py b/trunk/absroot/source/abspy/abscontrol/server.py --- a/trunk/absroot/source/abspy/abscontrol/server.py (revision 27) +++ b/trunk/absroot/source/abspy/abscontrol/server.py (revision 28) @@ -1,8 +1,9 @@ +import os import library class ABSServer: - def __init__(self,ipSource="localhost", ipDestino="abscontrol.jro.pe", portDestino=5509, ipDestino2=None, portDestino2=None, ftpPortDestino=None): + def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None): self.ipSource = ipSource self.ipDestino = ipDestino @@ -20,43 +21,108 @@ asServer = True self.commServerObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino, asServer) self.commClientObj = library.UDPComm(self.ipSource, self.ipDestino2, self.portDestino2) - self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino) + #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino) - def waitRequest(self): + def waitRequest(self,nbytes = 16384): - ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitRequest() + ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitRequest(nbytes) - if cmd == "SND": - self.sendFile() + if cmd == "SNDF": + self.sendFile(10) - if cmd == "CHG": + if cmd == "CHGB": self.changeBeam() if cmd == "ANST": self.getStatus() + def EliminaSaltoDeLinea(cadena): + i = 0 + for elemento in cadena: + if elemento =='\n' or elemento =='\r': + pass + else: + i=i+1 + return cadena [:i] + + def connection_status(self,base): + #File creation is neccesary? + number_of_modules = 16 + #base = 10 + # Variables for the report + status_array = ["Status of modules\n"] + status_array.append("----------------\n") + # Variables for the program + module_list = [] + + for i in range(number_of_modules): + cmd = "ping -c 1 -w 1 192.168.1."+ str(base + i + 1) + " >> /dev/null" + status = os.system(cmd) + if status == 256: + status_array.append("192.168.1." + str(base + i + 1) + " [0 0]\n") #Un-connected + module_list.append("0") + else: + status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n") + module_list.append("1") + # Generating a file report + if base == 10: + fobj = open("module_status_S.txt","w") + else: + fobj = open("module_status_N.txt","w") + fobj.writelines(status_array) + fobj.close() + # For the program + return module_list - def sendFile(self, filename = "/test/archivoabs.dat"): + def sendFile(self, base): + + #Needed for the file creation + file_list = self.datarx + #Needed for the loop + rx_frame_list = self.datarx.split('\n') - id = '------' - modules = split(self.datarx, id) - - fp = open(filename, 'w') - fp.write(self.datarx) - fp.close() - - self.ftpCommObj.sendFile(filename) - rpta = self.commClientObj.sendTxRxCommand(cmd='CARGA', data=filename) + experiment_name = rx_frame_list[0] + experiment_number = rx_frame_list[1] + #Setting variables of the loop + i =3 + module = 1 + number_of_modules = 16 + number_of_beams = int (experiment_number) + module_list = self.connection_status(10) + #Loop for creating and sending the control module files + while module <= number_of_modules: + #Generating the control modules files + fobj = open(experiment_name,"w") + fobj.write(experiment_name + "\n") + fobj.write("------\n") + fobj.writelines(file_list[i:i + number_of_beams + 1]) + fobj.close() + if module_list[module -1] == "1": + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c put " + experiment_name + print cmd + os.system(cmd) + #Updating variables of the loop + i = i + number_of_beams + 2 + module += 1 + #Working with the UDP socket + #self.commClientObj.sendData("CARGA:experimento1.ab1:") + self.commClientObj.sendData("CARGA:" + experiment_name + ":") + +# +# self.ftpCommObj.sendFile(filename) +# rpta = self.commClientObj.sendTxRxCommand(cmd='CARGA', data=filename) def changeBeam(self): - rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0") + #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0") + self.commClientObj.sendData("CAMBIA:" + self.datarx + ":") def getStatus(self): - rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") - + #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") + self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") if __name__ == '__main__':