# SVN changeset patch # User jsalyrosas # Date 2013-05-15 17:04:45.257080 # Revision 166 - Eliminando error por duplicidad con el nombre del paquete: abscontrol y la aplicacion web con django. El nuevo nombre aplicado es bin. Index: trunk/absroot/source/abspy/abscontrol =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol b/trunk/absroot/source/abspy/abscontrol deleted file mode 10644 --- a/trunk/absroot/source/abspy/abscontrol (revision 165) +++ /dev/null (revision 166) Index: trunk/absroot/source/abspy/bin/__init__.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/__init__.py b/trunk/absroot/source/abspy/bin/__init__.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/__init__.py (revision 166) Index: trunk/absroot/source/abspy/bin/client.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/client.py b/trunk/absroot/source/abspy/bin/client.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/client.py (revision 166) @@ -0,0 +1,488 @@ +# 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="192.168.1.117", portDestino=7000): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + + self.createObjects() + + def createObjects(self): + + self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino) + + def sendFile(self, filename): + + #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.sendData(cmd="SNDF", data=data) + self.commObj.waitData() + + def changeBeam(self, newBeam): + + self.commObj.sendData(cmd="CHGB", data=newBeam) + self.commObj.waitData() + + def __writeFile(self, filename, data): + + fobj = open(filename,"w") + fobj.writelines(data) + fobj.close() + + def getStatus(self, data): + + self.commObj.sendData(cmd="ANST", data = data) + ipSource, ipDestino, cmd, data = self.commObj.waitData() + self.__writeFile("report.txt", data) + +########## + + 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 == '1': + nombre2 = lst[fin+1:] + nombre2[-1]='s' + nombre2 = lst2string(nombre2) + return nombre2 + 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 CapturaValoresEnArchivo2(path,polarizacion='up'): + fichero =open(path,'r') + cnt=0 + lstup=[] + lstdw=[] + for cadena in fichero: + cnt=cnt+1 + if cnt==1: + nu01=cadena[1:4] + nu02=cadena[5:8] + nu03=cadena[9:12] + nu04=cadena[13:16] + eu01=cadena[17:20] + eu02=cadena[21:24] + eu03=cadena[25:28] + eu04=cadena[29:32] + if cnt==2: + nu05=cadena[1:4] + nu06=cadena[5:8] + nu07=cadena[9:12] + nu08=cadena[13:16] + eu05=cadena[17:20] + eu06=cadena[21:24] + eu07=cadena[25:28] + eu08=cadena[29:32] + if cnt==3: + nu09=cadena[1:4] + nu10=cadena[5:8] + nu11=cadena[9:12] + nu12=cadena[13:16] + eu09=cadena[17:20] + eu10=cadena[21:24] + eu11=cadena[25:28] + eu12=cadena[29:32] + if cnt==4: + nu13=cadena[1:4] + nu14=cadena[5:8] + nu15=cadena[9:12] + nu16=cadena[13:16] + eu13=cadena[17:20] + eu14=cadena[21:24] + eu15=cadena[25:28] + eu16=cadena[29:32] + if cnt==5: + wu01=cadena[1:4] + wu02=cadena[5:8] + wu03=cadena[9:12] + wu04=cadena[13:16] + su01=cadena[17:20] + su02=cadena[21:24] + su03=cadena[25:28] + su04=cadena[29:32] + if cnt==6: + wu05=cadena[1:4] + wu06=cadena[5:8] + wu07=cadena[9:12] + wu08=cadena[13:16] + su05=cadena[17:20] + su06=cadena[21:24] + su07=cadena[25:28] + su08=cadena[29:32] + if cnt==7: + wu09=cadena[1:4] + wu10=cadena[5:8] + wu11=cadena[9:12] + wu12=cadena[13:16] + su09=cadena[17:20] + su10=cadena[21:24] + su11=cadena[25:28] + su12=cadena[29:32] + if cnt==8: + wu13=cadena[1:4] + wu14=cadena[5:8] + wu15=cadena[9:12] + wu16=cadena[13:16] + su13=cadena[17:20] + su14=cadena[21:24] + su15=cadena[25:28] + su16=cadena[29:32] + if cnt==9: + nd01=cadena[1:4] + nd02=cadena[5:8] + nd03=cadena[9:12] + nd04=cadena[13:16] + ed01=cadena[17:20] + ed02=cadena[21:24] + ed03=cadena[25:28] + ed04=cadena[29:32] + if cnt==10: + nd05=cadena[1:4] + nd06=cadena[5:8] + nd07=cadena[9:12] + nd08=cadena[13:16] + ed05=cadena[17:20] + ed06=cadena[21:24] + ed07=cadena[25:28] + ed08=cadena[29:32] + if cnt==11: + nd09=cadena[1:4] + nd10=cadena[5:8] + nd11=cadena[9:12] + nd12=cadena[13:16] + ed09=cadena[17:20] + ed10=cadena[21:24] + ed11=cadena[25:28] + ed12=cadena[29:32] + if cnt==12: + nd13=cadena[1:4] + nd14=cadena[5:8] + nd15=cadena[9:12] + nd16=cadena[13:16] + ed13=cadena[17:20] + ed14=cadena[21:24] + ed15=cadena[25:28] + ed16=cadena[29:32] + if cnt==13: + wd01=cadena[1:4] + wd02=cadena[5:8] + wd03=cadena[9:12] + wd04=cadena[13:16] + sd01=cadena[17:20] + sd02=cadena[21:24] + sd03=cadena[25:28] + sd04=cadena[29:32] + if cnt==14: + wd05=cadena[1:4] + wd06=cadena[5:8] + wd07=cadena[9:12] + wd08=cadena[13:16] + sd05=cadena[17:20] + sd06=cadena[21:24] + sd07=cadena[25:28] + sd08=cadena[29:32] + if cnt==15: + wd09=cadena[1:4] + wd10=cadena[5:8] + wd11=cadena[9:12] + wd12=cadena[13:16] + sd09=cadena[17:20] + sd10=cadena[21:24] + sd11=cadena[25:28] + sd12=cadena[29:32] + if cnt==16: + wd13=cadena[1:4] + wd14=cadena[5:8] + wd15=cadena[9:12] + wd16=cadena[13:16] + sd13=cadena[17:20] + sd14=cadena[21:24] + sd15=cadena[25:28] + sd16=cadena[29:32] + lst_n_up=[nu01,nu02,nu03,nu04,nu05,nu06,nu07,nu08,nu09,nu10,nu11,nu12,nu13,nu14,nu15,nu16] + lst_n_dw=[nd01,nd02,nd03,nd04,nd05,nd06,nd07,nd08,nd09,nd10,nd11,nd12,nd13,nd14,nd15,nd16] + lst_s_up=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] + lst_s_dw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] + lst_w_up=[wu01,wu02,wu03,wu04,wu05,wu06,wu07,wu08,wu09,wu10,wu11,wu12,wu13,wu14,wu15,wu16] + lst_w_dw=[wd01,wd02,wd03,wd04,wd05,wd06,wd07,wd08,wd09,wd10,wd11,wd12,wd13,wd14,wd15,wd16] + lst_e_up=[eu01,eu02,eu03,eu04,eu05,eu06,eu07,eu08,eu09,eu10,eu11,eu12,eu13,eu14,eu15,eu16] + lst_e_dw=[ed01,ed02,ed03,ed04,ed05,ed06,ed07,ed08,ed09,ed10,ed11,ed12,ed13,ed14,ed15,ed16] + + lstup = lst_s_up + lst_w_up + lst_n_up + lst_e_up + lstdw = lst_s_dw + lst_w_dw + lst_n_up + lst_e_up + + 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 CreaFormatoFinal2(): + 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,65): + + if i<10: + nmod = '0'+str(i) + else: nmod = str(i) + + fichero.write("ABS_" + nmod+'\n') + + for j in range(1,ne+1): + ruta=CarpetaDeTrabajo+str(j)+'.txt' + lu=CapturaValoresEnArchivo2(ruta,polarizacion='up') + ld=CapturaValoresEnArchivo2(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() + CreaFormatoFinal2() + EliminaArchivosEnLaCarpeta() + +########## + +if __name__ == '__main__': + + filename = "experimento1.abs" + + absObj = ABSClient() + absObj.sendFile(filename) +# absObj.changeBeam("0") +# absObj.changeBeam("1") +# absObj.changeBeam("2") +# absObj.changeBeam("3") +# absObj.changeBeam("4") +# absObj.changeBeam("5") +# absObj.changeBeam("6") +# absObj.changeBeam("7") +# absObj.getStatus(5) \ No newline at end of file Index: trunk/absroot/source/abspy/bin/client2.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/client2.py b/trunk/absroot/source/abspy/bin/client2.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/client2.py (revision 166) @@ -0,0 +1,500 @@ +# imports needed for the file convertion +import os +import sys +import time +import numpy as np + +import library2 + +class ABSClient: + + def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + + self.createObjects() + + def createObjects(self): + + self.commObj = library2.TCPComm(self.ipSource, self.ipDestino, self.portDestino) + + def sendFile(self, filename): + + #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.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.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.close_socket() + + def __writeFile(self, filename, data): + + fobj = open(filename,"w") + fobj.writelines(data) + fobj.close() + + def getStatus(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.close_socket() + self.__writeFile("report.txt", data) + +########## + + 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 == '1': + nombre2 = lst[fin+1:] + nombre2[-1]='s' + nombre2 = lst2string(nombre2) + return nombre2 + 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 CapturaValoresEnArchivo2(path,polarizacion='up'): + fichero =open(path,'r') + cnt=0 + lstup=[] + lstdw=[] + for cadena in fichero: + cnt=cnt+1 + if cnt==1: + nu01=cadena[1:4] + nu02=cadena[5:8] + nu03=cadena[9:12] + nu04=cadena[13:16] + eu01=cadena[17:20] + eu02=cadena[21:24] + eu03=cadena[25:28] + eu04=cadena[29:32] + if cnt==2: + nu05=cadena[1:4] + nu06=cadena[5:8] + nu07=cadena[9:12] + nu08=cadena[13:16] + eu05=cadena[17:20] + eu06=cadena[21:24] + eu07=cadena[25:28] + eu08=cadena[29:32] + if cnt==3: + nu09=cadena[1:4] + nu10=cadena[5:8] + nu11=cadena[9:12] + nu12=cadena[13:16] + eu09=cadena[17:20] + eu10=cadena[21:24] + eu11=cadena[25:28] + eu12=cadena[29:32] + if cnt==4: + nu13=cadena[1:4] + nu14=cadena[5:8] + nu15=cadena[9:12] + nu16=cadena[13:16] + eu13=cadena[17:20] + eu14=cadena[21:24] + eu15=cadena[25:28] + eu16=cadena[29:32] + if cnt==5: + wu01=cadena[1:4] + wu02=cadena[5:8] + wu03=cadena[9:12] + wu04=cadena[13:16] + su01=cadena[17:20] + su02=cadena[21:24] + su03=cadena[25:28] + su04=cadena[29:32] + if cnt==6: + wu05=cadena[1:4] + wu06=cadena[5:8] + wu07=cadena[9:12] + wu08=cadena[13:16] + su05=cadena[17:20] + su06=cadena[21:24] + su07=cadena[25:28] + su08=cadena[29:32] + if cnt==7: + wu09=cadena[1:4] + wu10=cadena[5:8] + wu11=cadena[9:12] + wu12=cadena[13:16] + su09=cadena[17:20] + su10=cadena[21:24] + su11=cadena[25:28] + su12=cadena[29:32] + if cnt==8: + wu13=cadena[1:4] + wu14=cadena[5:8] + wu15=cadena[9:12] + wu16=cadena[13:16] + su13=cadena[17:20] + su14=cadena[21:24] + su15=cadena[25:28] + su16=cadena[29:32] + if cnt==9: + nd01=cadena[1:4] + nd02=cadena[5:8] + nd03=cadena[9:12] + nd04=cadena[13:16] + ed01=cadena[17:20] + ed02=cadena[21:24] + ed03=cadena[25:28] + ed04=cadena[29:32] + if cnt==10: + nd05=cadena[1:4] + nd06=cadena[5:8] + nd07=cadena[9:12] + nd08=cadena[13:16] + ed05=cadena[17:20] + ed06=cadena[21:24] + ed07=cadena[25:28] + ed08=cadena[29:32] + if cnt==11: + nd09=cadena[1:4] + nd10=cadena[5:8] + nd11=cadena[9:12] + nd12=cadena[13:16] + ed09=cadena[17:20] + ed10=cadena[21:24] + ed11=cadena[25:28] + ed12=cadena[29:32] + if cnt==12: + nd13=cadena[1:4] + nd14=cadena[5:8] + nd15=cadena[9:12] + nd16=cadena[13:16] + ed13=cadena[17:20] + ed14=cadena[21:24] + ed15=cadena[25:28] + ed16=cadena[29:32] + if cnt==13: + wd01=cadena[1:4] + wd02=cadena[5:8] + wd03=cadena[9:12] + wd04=cadena[13:16] + sd01=cadena[17:20] + sd02=cadena[21:24] + sd03=cadena[25:28] + sd04=cadena[29:32] + if cnt==14: + wd05=cadena[1:4] + wd06=cadena[5:8] + wd07=cadena[9:12] + wd08=cadena[13:16] + sd05=cadena[17:20] + sd06=cadena[21:24] + sd07=cadena[25:28] + sd08=cadena[29:32] + if cnt==15: + wd09=cadena[1:4] + wd10=cadena[5:8] + wd11=cadena[9:12] + wd12=cadena[13:16] + sd09=cadena[17:20] + sd10=cadena[21:24] + sd11=cadena[25:28] + sd12=cadena[29:32] + if cnt==16: + wd13=cadena[1:4] + wd14=cadena[5:8] + wd15=cadena[9:12] + wd16=cadena[13:16] + sd13=cadena[17:20] + sd14=cadena[21:24] + sd15=cadena[25:28] + sd16=cadena[29:32] + lst_n_up=[nu01,nu02,nu03,nu04,nu05,nu06,nu07,nu08,nu09,nu10,nu11,nu12,nu13,nu14,nu15,nu16] + lst_n_dw=[nd01,nd02,nd03,nd04,nd05,nd06,nd07,nd08,nd09,nd10,nd11,nd12,nd13,nd14,nd15,nd16] + lst_s_up=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] + lst_s_dw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] + lst_w_up=[wu01,wu02,wu03,wu04,wu05,wu06,wu07,wu08,wu09,wu10,wu11,wu12,wu13,wu14,wu15,wu16] + lst_w_dw=[wd01,wd02,wd03,wd04,wd05,wd06,wd07,wd08,wd09,wd10,wd11,wd12,wd13,wd14,wd15,wd16] + lst_e_up=[eu01,eu02,eu03,eu04,eu05,eu06,eu07,eu08,eu09,eu10,eu11,eu12,eu13,eu14,eu15,eu16] + lst_e_dw=[ed01,ed02,ed03,ed04,ed05,ed06,ed07,ed08,ed09,ed10,ed11,ed12,ed13,ed14,ed15,ed16] + + lstup = lst_s_up + lst_w_up + lst_n_up + lst_e_up + lstdw = lst_s_dw + lst_w_dw + lst_n_up + lst_e_up + + 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 CreaFormatoFinal2(): + 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,65): + + if i<10: + nmod = '0'+str(i) + else: nmod = str(i) + + fichero.write("ABS_" + nmod+'\n') + + for j in range(1,ne+1): + ruta=CarpetaDeTrabajo+str(j)+'.txt' + lu=CapturaValoresEnArchivo2(ruta,polarizacion='up') + ld=CapturaValoresEnArchivo2(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() + CreaFormatoFinal2() + EliminaArchivosEnLaCarpeta() + +########## + +if __name__ == '__main__': + + filename = "experimento1.abs" + + absObj = ABSClient() +# absObj.sendFile(filename) +# absObj.changeBeam("0") + absObj.changeBeam("1") +# absObj.changeBeam("2") +# absObj.changeBeam("3") +# absObj.changeBeam("4") +# absObj.changeBeam("5") +# absObj.changeBeam("6") +# absObj.changeBeam("7") +# absObj.getStatus(5) \ No newline at end of file Index: trunk/absroot/source/abspy/bin/client3.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/client3.py b/trunk/absroot/source/abspy/bin/client3.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/client3.py (revision 166) @@ -0,0 +1,97 @@ +import library3 +import os.path + +class ABSClient(object): + + def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000): + + self.ipSource = ipSource + self.iDSource = iDSource + self.ipDestino = ipDestino + self.iDDestino = iDDestino + self.portDestino = portDestino + + self.createObjects() + + def createObjects(self): + + self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino) + #self.wFiles = library3.FilesStuff() + + def __ConnectionWithCentralControl(self, cmd, data): + + self.commObj.open_socket() + self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino) + ipSource, ipDestino, cmd, output = self.commObj.waitData() + self.commObj.close_socket() + + return output + +# 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) +# +# return FileStr + + def sendFile(self, filename): + + data = self.__readFile(filename) + self.__ConnectionWithCentralControl(cmd = "SNDF", data = data) + + def changeBeam(self, newBeam): + + self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam) + + def __writeFile(self, filename, data): + + fobj = open(filename,"w") + fobj.writelines(data) + fobj.close() + + def __readFile(self, filename): + + fobj = open(filename,"r") + listData = fobj.readlines() + fobj.close() + tmp = "".join(listData) + #Adding filename to the begining of the data + newfilename = os.path.split(filename)[1] + #data = filename + '\n' + tmp + data = newfilename + '\n' + tmp + return data + + + def getControlModuleStatus(self, data): + + data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data) + self.__writeFile("report.txt", data) + + def getControlModulePhase(self, opt, u = "50", pw = "10"): + + if opt == '0': + data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/') + elif opt == '1': + data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/') + elif opt == '2': + data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/') + else: + data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/') +# self.__writeFile("report.txt", data) + + def getConnectionStatus(self): + + data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none") + self.__writeFile("connection_status.txt", data) + +if __name__ == '__main__': + + filename = "experimento1.abs" + + absObj = ABSClient() + absObj.sendFile(filename) Index: trunk/absroot/source/abspy/bin/experimento1.abs =================================================================== diff --git a/trunk/absroot/source/abspy/bin/experimento1.abs b/trunk/absroot/source/abspy/bin/experimento1.abs new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/experimento1.abs (revision 166) @@ -0,0 +1,231 @@ + title ='MST-ISR 2009 (NS-Up)' + + #Experiments = 12 + +1 = + [[0.5,0.5,0.5,0.5,1.5,0.5,0.5,0.5],$ + [2.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0],$ + [0.0,0.5,0.5,0.5,0.0,0.5,0.5,0.5],$ + [3.5,0.5,0.5,0.5,2.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,2.0,3.0,0.0,1.0],$ + [1.0,1.0,1.0,1.0,3.0,0.0,1.0,2.0],$ + [0.5,0.5,0.5,0.5,0.0,1.0,2.0,3.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,0.5,0.5,1.0,1.0,1.0,1.0,1.0],$ + [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0],$ + [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]] + +2 = + [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0,1.0,1.0,0.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,2.0,3.0,0.0,1.0],$ + [0.5,0.5,0.5,1.0,3.0,0.0,1.0,2.0],$ + [1.0,1.0,1.0,1.0,0.0,1.0,2.0,3.0],$ + [0.5,0.5,0.5,0.5,1.0,2.0,3.0,0.0]] + + [[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],$ + [1.0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0,3.0,3.0],$ + [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ + [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.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,3.0,3.0,3.0,3.0],$ + [0.5,0.5,0.5,1.0,3.0,3.0,3.0,3.0],$ + [1.0,1.0,1.0,1.0,3.0,3.0,3.0,3.0],$ + [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]] + +12 = + [[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]] + + [[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/bin/library.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/library.py b/trunk/absroot/source/abspy/bin/library.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/library.py (revision 166) @@ -0,0 +1,209 @@ +#import tftpy +import socket + +class UDPComm: + + __HEADER = "ABS" + + def __init__(self, ipSource, ipDestino, portDestino, asServer=False): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + self.addr = (ipDestino,portDestino) + self.answer = "none" #test + self.mode = "none" + + + self.openSocket(asServer) + + def openSocket(self, asServer): + + #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() + self.mode = "server" + else: + self.configAsClient() + self.mode = "client" + + def configAsClient(self): + #Configurar broadcast + self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + + def configAsServer(self): + + self.socket_c.bind(self.addr) + print "\nServer initialized" + + def waitData(self, nbytes = 16384): + + print "\nWaiting some data" + trama_rx, self.answer = self.socket_c.recvfrom(nbytes) + print "\nThis socket has received some data from:" + print self.answer + ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) + + return ipSource, ipDestino, cmd, data + + def sendData(self, cmd, data): + + if self.portDestino == 7000: + trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":" + else: + trama_tx = data + + if self.mode == "client": + destiny = self.addr + else: + destiny = self.answer + # Send messages + if(self.socket_c.sendto(trama_tx, destiny)): + print "Sending message:[" + trama_tx + "] to " + str(destiny) + + def __getTrama(self, trama): + + 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 + +class TCPComm: + + __HEADER = "JRO" + __TYPE = "ABS" + + def __init__(self, ipSource, ipDestino, portDestino, asServer=False): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + self.addr = (ipDestino,portDestino) + + self.sc = "none" + self.answer = "none" #test + self.mode = "none" + self.len = 0 + self.crc = 0 + + self.openSocket(asServer) + + def openSocket(self, asServer): + + #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) +# self.socket_c = socket.socket() +# self.socket_c.connect((self.ipDestino, self.portDestino)) + + if asServer: + self.socket_c = socket.socket() +# self.configAsServer() + self.socket_c.bind(self.addr) + self.mode = "server" + else: +# self.configAsClient() + self.mode = "client" #Socket is opened at the sendData function + +# def configAsClient(self): + #Buscar broadcast TCP +# self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) +# self.socket_c.connect(self.addr) +# pass + +# def configAsServer(self): +# +# self.socket_c.bind(self.addr) + + def waitData(self, nbytes = 1024): + + print "\nWaiting some client." + + if self.mode == "client": + # 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 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.mode == "client": + 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 __getTrama(self, trama): + + FrameList = trama.split(':') + + header = FrameList[0] + TypeOfInstrument = FrameList[1] + ipSource = FrameList[2] + ipDestino = FrameList[3] + len = FrameList[4] + cmd = FrameList[5] + data = FrameList[6] + crc = FrameList[7] + trash = FrameList[8] + + return ipSource, ipDestino, cmd, data + + def close_socket(self): + self.socket_c.close() + + def open_socket(self): + self.socket_c = socket.socket() + +#class FTPComm: +# +# ftp_servidor = 'ftp.servidor.com' +# ftp_usuario = 'miusuario' +# ftp_clave = 'miclave' +# ftp_raiz = '/public_html' +# +# def __init__(self): +# +# self.client = tftpy.TftpClient(self.ftp_servidor, '69') +# +# +# def sendFile(self, filename): +# +# self.client.upload(filename) +# +#if __name__ == '__main__': +# +# obj = FTPComm() + + + \ No newline at end of file Index: trunk/absroot/source/abspy/bin/library2.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/library2.py b/trunk/absroot/source/abspy/bin/library2.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/library2.py (revision 166) @@ -0,0 +1,165 @@ +import socket + +class TCPComm: + + __HEADER = "JRO" + __TYPE = "ABS" + + def __init__(self, ipSource, ipDestino, portDestino, asServer=False): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + self.addr = (ipDestino,portDestino) + + self.sc = "none" + self.answer = "none" #test + self.asServer = False + self.len = 0 + self.crc = 0 + + self.openSocket(asServer) + + def openSocket(self, asServer): + + #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) +# self.socket_c = socket.socket() +# self.socket_c.connect((self.ipDestino, self.portDestino)) + + if asServer: + self.socket_c = socket.socket() +# self.configAsServer() + self.socket_c.bind(self.addr) + self.asServer = True + else: +# self.configAsClient() + self.asServer = False #Socket is opened at the sendData function + +# def configAsClient(self): + #Buscar broadcast TCP +# self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) +# self.socket_c.connect(self.addr) +# pass + +# def configAsServer(self): +# +# self.socket_c.bind(self.addr) + + def waitData(self, nbytes = 1024): + + 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): + + print "\nWaiting some client." + 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 from: " + str(self.answer) + + ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) + + return ipSource, ipDestino, cmd, data + + def waitClient(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 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): + + trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ + ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" + + if self.asServer == True: + self.SendAsServer(trama_tx) + else: + self.SendAsClient(ipDestino, trama_tx) + + def SendAsServer(self, trama_tx): + + self.sc.send(trama_tx) + print "Sending message:[" + trama_tx + "] to: " + str(self.answer) + + + def SendAsClient(self, ipDestino, trama_tx): + + self.socket_c.connect((ipDestino, self.portDestino)) + self.socket_c.send(trama_tx) + print "Sending message:[" + trama_tx + "] to: " + ipDestino + + def __getTrama(self, trama): + + FrameList = trama.split(':') + + header = FrameList[0] + TypeOfInstrument = FrameList[1] + ipSource = FrameList[2] + ipDestino = FrameList[3] + len = FrameList[4] + cmd = FrameList[5] + data = FrameList[6] + crc = FrameList[7] + trash = FrameList[8] + + return ipSource, ipDestino, cmd, data + + def close_socket(self): + self.socket_c.close() + + def open_socket(self): + self.socket_c = socket.socket() \ No newline at end of file Index: trunk/absroot/source/abspy/bin/library3.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/library3.py b/trunk/absroot/source/abspy/bin/library3.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/library3.py (revision 166) @@ -0,0 +1,537 @@ +# Needed for the FilesStuff class +import os +import numpy as np +# Needed for the TCPComm class +import socket + +class TCPComm: + + __HEADER = "JRO" + __TYPE = "ABS" + + def __init__(self, ipSource, iDSource, ipDestino, iDDestino, portDestino, asServer=False): + + self.ipSource = ipSource + self.iDSource = iDSource + self.ipDestino = ipDestino + self.iDDestino = iDDestino + self.portDestino = portDestino + self.addr = (ipDestino,portDestino) + + self.sc = "none" + self.answer = "none" #test + self.asServer = False + self.len = "000000" + self.crc = "0" + + self.openSocket(asServer) + + def openSocket(self, asServer): + + #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) +# self.socket_c = socket.socket() +# self.socket_c.connect((self.ipDestino, self.portDestino)) + + if asServer: + self.socket_c = socket.socket() +# self.configAsServer() + self.socket_c.bind(self.addr) + self.asServer = True + else: +# self.configAsClient() + self.asServer = False #Socket is opened at the sendData function + +# def configAsClient(self): + #Buscar broadcast TCP +# self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) +# self.socket_c.connect(self.addr) +# pass + +# def configAsServer(self): +# +# self.socket_c.bind(self.addr) + + def waitData(self): + if self.asServer == True: + trama_rx, l = self.waitAsServer() + else: + trama_rx, l = self.waitAsClient() + + ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx, l) + + return ipSource, ipDestino, cmd, data + + def waitAsClient2(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) + + return trama_rx + + def waitAsServer2(self, nbytes = 1024): + print "\nWaiting some client." + 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 from: " + str(self.answer) + + return trama_rx + + def waitAsServer(self, nbytes = 1024): + print "\nWaiting some client." + self.socket_c.listen(1) + sc, addr = self.socket_c.accept() + self.sc = sc + self.answer = addr + # Big data through ethernet + cnt = 0; + first = 0; + trama_rx = "" + while True: + tmp = self.sc.recv(nbytes) + trama_rx = trama_rx + tmp + cnt = len(trama_rx) + if first == 0: + first = 1 + lng = int(trama_rx[20:26]) + frm_lng= lng + 31 # 31 bytes are fixed and added to the data size to get the frame size + if cnt == frm_lng: + break + + print "\nThis socket has received some data from: " + str(self.answer) + + return trama_rx, lng + + def waitAsClient(self, nbytes = 1024): + print "\nWaiting the server." + # Short data through ethernet + try: + trama_rx = self.socket_c.recv(nbytes) + lng = int(trama_rx[20:26]) + except: + print "Waiting error" + trama_rx = "Error" + lng = 0 + else: + print "\nThis socket has received this data: " + str(trama_rx) + + return trama_rx, lng + + def sendData2(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" + + if self.asServer == True: + self.SendAsServer(trama_tx) + else: + self.SendAsClient(ipDestino, trama_tx) + + def sendData(self, cmd, data, ipDestino): + + trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ + self.iDDestino + self.len + str(cmd) + str(data) + self.crc + + self.len = self.int2str(len(data)) + + trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ + self.iDDestino + self.len + str(cmd) + str(data) + self.crc + + if self.asServer == True: + self.SendAsServer(trama_tx) + else: + self.SendAsClient(ipDestino, trama_tx) + + def SendAsServer(self, trama_tx): + + self.sc.send(trama_tx) + print "Sending message:[" + trama_tx + "] to: " + str(self.answer) + + + def SendAsClient(self, ipDestino, trama_tx): + + try: + self.socket_c.connect((ipDestino, self.portDestino)) + except: + print "Connection error with:" + ipDestino + else: + self.socket_c.send(trama_tx) + print "Sending message:[" + trama_tx + "] to: " + ipDestino + + def __getTrama2(self, trama): + + FrameList = trama.split(':') + + header = FrameList[0] + TypeOfInstrument = FrameList[1] + ipSource = FrameList[2] + ipDestino = FrameList[3] + len = FrameList[4] + cmd = FrameList[5] + data = FrameList[6] + crc = FrameList[7] + trash = FrameList[8] + + return ipSource, ipDestino, cmd, data + + def __getTrama(self, trama, l): + + header = trama[0:3] + TypeOfInstrument = trama[3:6] + ipSource = trama[6:13] + ipDestino = trama[13:20] + len = trama[20:26] + cmd = trama[26:30] + data = trama[30:30+int(l)] + crc = trama[30+ int(l):] + + return ipSource, ipDestino, cmd, data + + def close_socket(self): + self.socket_c.close() + + def open_socket(self): + self.socket_c = socket.socket() + + def int2str(self, n): + + str_n = str(n) + l_n = len(str_n) + if l_n == 1: + str_n = "00000" + str_n + elif l_n == 2: + str_n = "0000" + str_n + elif l_n == 3: + str_n = "000" + str_n + elif l_n == 4: + str_n = "00" + str_n + elif l_n == 5: + str_n = "0" + str_n + return str_n + +class FilesStuff(): + + def lst2string(self, lst): + string='' + for i in lst: + string=string+i + return string + + def string2lst(self, string): + lst = [] + for i in string: + lst.append(i) + return lst + + + def file1(self, filename, type): + lst = self.string2lst(filename) + fin = -1 + t = len(lst) + for i in np.arange(-1,-t,-1): + if lst[i]=='/': + fin=i + break + if type == '1': + nombre2 = lst[fin+1:] + nombre2[-1]='s' + nombre2 = self.lst2string(nombre2) + return nombre2 + if type == '2': + nombre2 = lst[fin+1:] + nombre2[-1]='1' + nombre2 = self.lst2string(nombre2) + return nombre2 + + + def EliminaSaltoDeLinea(self,cadena): + i = 0 + for elemento in cadena: + if elemento =='\n' or elemento =='\r': + pass + else: + i=i+1 + return cadena [:i] + + def NumeroDeExperimentos(self, 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(self, numero): + if numero%2==0: return 'par' + elif numero%2==1: return 'impar' + + def EvaluaCadena(self,cadena): + if len(cadena)>35: + if cadena[-1]=='$': + return cadena[-35:-2] + elif cadena[-1]==']': + return cadena[-34:-1] + else: + return None + + def GuardaEnLista(self,path): + fichero=open(path,'r') + lista=[] + for cadena in fichero: + cadena = self.EliminaSaltoDeLinea(cadena) + cadena = self.EvaluaCadena(cadena) + if cadena != None: + lista.append(cadena) + fichero.close() + return lista + + def CreaFicherosPrevios(self, path, archivo): + vector = self.GuardaEnLista(archivo) + for i in range(1,self.NumeroDeExperimentos(archivo)+1): + fichero =open(path + str(i)+ '.txt','w') + for j in range(0,16): + fichero.write(vector[j+16*(i-1)]+'\n') + fichero.close() + + def CapturaValoresEnArchivo(self, path, polarizacion='up'): + fichero =open(path,'r') + cnt=0 + lstup=[] + lstdw=[] + for cadena in fichero: + cnt=cnt+1 + if cnt==1: + nu01=cadena[1:4] + nu02=cadena[5:8] + nu03=cadena[9:12] + nu04=cadena[13:16] + eu01=cadena[17:20] + eu02=cadena[21:24] + eu03=cadena[25:28] + eu04=cadena[29:32] + if cnt==2: + nu05=cadena[1:4] + nu06=cadena[5:8] + nu07=cadena[9:12] + nu08=cadena[13:16] + eu05=cadena[17:20] + eu06=cadena[21:24] + eu07=cadena[25:28] + eu08=cadena[29:32] + if cnt==3: + nu09=cadena[1:4] + nu10=cadena[5:8] + nu11=cadena[9:12] + nu12=cadena[13:16] + eu09=cadena[17:20] + eu10=cadena[21:24] + eu11=cadena[25:28] + eu12=cadena[29:32] + if cnt==4: + nu13=cadena[1:4] + nu14=cadena[5:8] + nu15=cadena[9:12] + nu16=cadena[13:16] + eu13=cadena[17:20] + eu14=cadena[21:24] + eu15=cadena[25:28] + eu16=cadena[29:32] + if cnt==5: + wu01=cadena[1:4] + wu02=cadena[5:8] + wu03=cadena[9:12] + wu04=cadena[13:16] + su01=cadena[17:20] + su02=cadena[21:24] + su03=cadena[25:28] + su04=cadena[29:32] + if cnt==6: + wu05=cadena[1:4] + wu06=cadena[5:8] + wu07=cadena[9:12] + wu08=cadena[13:16] + su05=cadena[17:20] + su06=cadena[21:24] + su07=cadena[25:28] + su08=cadena[29:32] + if cnt==7: + wu09=cadena[1:4] + wu10=cadena[5:8] + wu11=cadena[9:12] + wu12=cadena[13:16] + su09=cadena[17:20] + su10=cadena[21:24] + su11=cadena[25:28] + su12=cadena[29:32] + if cnt==8: + wu13=cadena[1:4] + wu14=cadena[5:8] + wu15=cadena[9:12] + wu16=cadena[13:16] + su13=cadena[17:20] + su14=cadena[21:24] + su15=cadena[25:28] + su16=cadena[29:32] + if cnt==9: + nd01=cadena[1:4] + nd02=cadena[5:8] + nd03=cadena[9:12] + nd04=cadena[13:16] + ed01=cadena[17:20] + ed02=cadena[21:24] + ed03=cadena[25:28] + ed04=cadena[29:32] + if cnt==10: + nd05=cadena[1:4] + nd06=cadena[5:8] + nd07=cadena[9:12] + nd08=cadena[13:16] + ed05=cadena[17:20] + ed06=cadena[21:24] + ed07=cadena[25:28] + ed08=cadena[29:32] + if cnt==11: + nd09=cadena[1:4] + nd10=cadena[5:8] + nd11=cadena[9:12] + nd12=cadena[13:16] + ed09=cadena[17:20] + ed10=cadena[21:24] + ed11=cadena[25:28] + ed12=cadena[29:32] + if cnt==12: + nd13=cadena[1:4] + nd14=cadena[5:8] + nd15=cadena[9:12] + nd16=cadena[13:16] + ed13=cadena[17:20] + ed14=cadena[21:24] + ed15=cadena[25:28] + ed16=cadena[29:32] + if cnt==13: + wd01=cadena[1:4] + wd02=cadena[5:8] + wd03=cadena[9:12] + wd04=cadena[13:16] + sd01=cadena[17:20] + sd02=cadena[21:24] + sd03=cadena[25:28] + sd04=cadena[29:32] + if cnt==14: + wd05=cadena[1:4] + wd06=cadena[5:8] + wd07=cadena[9:12] + wd08=cadena[13:16] + sd05=cadena[17:20] + sd06=cadena[21:24] + sd07=cadena[25:28] + sd08=cadena[29:32] + if cnt==15: + wd09=cadena[1:4] + wd10=cadena[5:8] + wd11=cadena[9:12] + wd12=cadena[13:16] + sd09=cadena[17:20] + sd10=cadena[21:24] + sd11=cadena[25:28] + sd12=cadena[29:32] + if cnt==16: + wd13=cadena[1:4] + wd14=cadena[5:8] + wd15=cadena[9:12] + wd16=cadena[13:16] + sd13=cadena[17:20] + sd14=cadena[21:24] + sd15=cadena[25:28] + sd16=cadena[29:32] + blck_1_up = [nu01,nu02,nu03,nu04,eu01,eu02,eu03,eu04,nu05,nu06,nu07,nu08,eu05,eu06,eu07,eu08] + blck_1_dw = [nd01,nd02,nd03,nd04,ed01,ed02,ed03,ed04,nd05,nd06,nd07,nd08,ed05,ed06,ed07,ed08] + blck_2_up = [nu09,nu10,nu11,nu12,eu09,eu10,eu11,eu12,nu13,nu14,nu15,nu16,eu13,eu14,eu15,eu16] + blck_2_dw = [nd09,nd10,nd11,nd12,ed09,ed10,ed11,ed12,nd13,nd14,nd15,nd16,ed13,ed14,ed15,ed16] + blck_3_up = [wu01,wu02,wu03,wu04,su01,su02,su03,su04,wu05,wu06,wu07,wu08,su05,su06,su07,su08] + blck_3_dw = [wd01,wd02,wd03,wd04,sd01,sd02,sd03,sd04,wd05,wd06,wd07,wd08,sd05,sd06,sd07,sd08] + blck_4_up = [wu09,wu10,wu11,wu12,su09,su10,su11,su12,wu13,wu14,wu15,wu16,su13,su14,su15,su16] + blck_4_dw = [wd09,wd10,wd11,wd12,sd09,sd10,sd11,sd12,wd13,wd14,wd15,wd16,sd13,sd14,sd15,sd16] + + lstup = blck_1_up + blck_2_up + blck_3_up + blck_4_up + lstdw = blck_1_dw + blck_2_dw + blck_3_dw + blck_4_dw + + if polarizacion=='up': + return lstup + elif polarizacion=='dw': + return lstdw + fichero.close() + + def CreaFormatoFinal(self, path, filename): + ne=self.NumeroDeExperimentos(filename) + + #nombre01 = file1(archivo,'1') + nombre02 = self.file1(filename,'2') + fichero=open(path + 'CentralControlFormat.txt','w') + fichero.write(nombre02+'\n') + fichero.write(str(ne)+'\n') + + for i in range(1,65): + + if i<10: + nmod = '0'+str(i) + else: nmod = str(i) + + fichero.write("ABS_" + nmod+'\n') + + for j in range(1,ne+1): + ruta=path+str(j)+'.txt' + lu=self.CapturaValoresEnArchivo(ruta,polarizacion='up') + ld=self.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(self, path, filename): + ne=self.NumeroDeExperimentos(filename) + for i in range(1,ne+1): + os.remove(path + str(i)+'.txt') + + + def toCentralControlFormat(self, filename): + """ Funcion que genera un archivo para el control central""" + + path = os.getcwd() + '/' + self.CreaFicherosPrevios(path, filename) + self.CreaFormatoFinal(path, filename) + self.EliminaArchivosEnLaCarpeta(path, filename) Index: trunk/absroot/source/abspy/bin/module_status.txt =================================================================== diff --git a/trunk/absroot/source/abspy/bin/module_status.txt b/trunk/absroot/source/abspy/bin/module_status.txt new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/module_status.txt (revision 166) @@ -0,0 +1,66 @@ +Status of modules +---------------- +192.168.1.1 [1 1] +192.168.1.2 [0 0] +192.168.1.3 [0 0] +192.168.1.4 [0 0] +192.168.1.5 [0 0] +192.168.1.6 [0 0] +192.168.1.7 [0 0] +192.168.1.8 [0 0] +192.168.1.9 [0 0] +192.168.1.10 [0 0] +192.168.1.11 [0 0] +192.168.1.12 [0 0] +192.168.1.13 [0 0] +192.168.1.14 [0 0] +192.168.1.15 [0 0] +192.168.1.16 [0 0] +192.168.1.17 [0 0] +192.168.1.18 [0 0] +192.168.1.19 [0 0] +192.168.1.20 [0 0] +192.168.1.21 [0 0] +192.168.1.22 [0 0] +192.168.1.23 [0 0] +192.168.1.24 [0 0] +192.168.1.25 [0 0] +192.168.1.26 [0 0] +192.168.1.27 [0 0] +192.168.1.28 [0 0] +192.168.1.29 [0 0] +192.168.1.30 [0 0] +192.168.1.31 [0 0] +192.168.1.32 [0 0] +192.168.1.33 [0 0] +192.168.1.34 [0 0] +192.168.1.35 [0 0] +192.168.1.36 [0 0] +192.168.1.37 [0 0] +192.168.1.38 [0 0] +192.168.1.39 [0 0] +192.168.1.40 [0 0] +192.168.1.41 [0 0] +192.168.1.42 [0 0] +192.168.1.43 [0 0] +192.168.1.44 [0 0] +192.168.1.45 [0 0] +192.168.1.46 [0 0] +192.168.1.47 [0 0] +192.168.1.48 [0 0] +192.168.1.49 [0 0] +192.168.1.50 [0 0] +192.168.1.51 [0 0] +192.168.1.52 [0 0] +192.168.1.53 [0 0] +192.168.1.54 [0 0] +192.168.1.55 [0 0] +192.168.1.56 [0 0] +192.168.1.57 [0 0] +192.168.1.58 [0 0] +192.168.1.59 [0 0] +192.168.1.60 [0 0] +192.168.1.61 [0 0] +192.168.1.62 [0 0] +192.168.1.63 [0 0] +192.168.1.64 [0 0] Index: trunk/absroot/source/abspy/bin/server.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/server.py b/trunk/absroot/source/abspy/bin/server.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/server.py (revision 166) @@ -0,0 +1,281 @@ +import os +import library +import time + +class ABSServer: + + def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.255", portDestino2=5500, ftpPortDestino=None): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + + self.ipDestino2 = ipDestino2 + self.portDestino2 = portDestino2 + + self.ftpPortDestino = ftpPortDestino + self.experiment_name = "default" + self.tx_buffer = "default" + + self.createObjects() + + def createObjects(self): + + 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) + + + def waitRequest(self): + + ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData() + + datarpta = "OK" + + if cmd == "SNDF": + self.sendFile2Modules() + pass + + if cmd == "CHGB": + self.changeBeam() + + if cmd == "ANST": + self.getStatus(mode=3) + datarpta = self.tx_buffer + + self.commServerObj.sendData(cmd=cmd, data=datarpta) + + 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(base + i + 1) + " [1 1]\n") + 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 + + """ + + enaModules = [] + + for address in range(1,65): + if self.checkModule(address): + enaModules.append(address) + + self.__writeReport(enaModules) + return enaModules + + def sendFile2Modules(self): + + #Needed for the loop + rx_frame_list = self.datarx.split('\n',2) + + self.experiment_name = rx_frame_list[0] + experiment_number = rx_frame_list[1] + str_control_modules = rx_frame_list[2] + + lst_control_modules = str_control_modules.split("------\n") + + enaModules = self.checkAntenna() + + for address in range(1,65): + + if address not in enaModules: + continue + + self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1]) + + cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name + print cmd + os.system(cmd) + + self.__loadFile() + + def __writeModuleFile(self, filename, str): + + fobj = open(filename,"w") + fobj.write(filename + "\n") + fobj.write("------\n") + fobj.write(str) + fobj.write("------\n") + fobj.close() + + def __readModuleFile(self, filename): + + fobj1 = open(filename,"r") + file_list_1 = fobj1.readlines() + fobj1.close() + content_str = ''.join(file_list_1[2:-1]) + + return content_str + + def __loadFile(self): + + #Working with the UDP socket + self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") + self.commClientObj.sendData("none", "CAMBIA:0:") + + def changeBeam(self): + + #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0") + self.commClientObj.sendData("none", "CAMBIA:" + self.datarx + ":") + + def getStatus(self,mode): + + if mode == 1: + self.__getStsMode1() + elif mode == 2: + self.__getStsMode2() + else: + self.__getStsMode3() + + + def __getStsMode1(self): + #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") + self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") + seconds = int (self.datarx) + # Give 5 seconds to the control modules + time.sleep(seconds) + # Checking the module connection + module_list = self.connection_status(10) + #Generating the complete report + module = 1 + number_of_modules = 16 + filename1 = "Verificacion" + filename2 = "report.txt" + fobj2 = open(filename2,"w") + fobj2.write("Verification_file\n") + fobj2.write("-----------------\n") + fobj2.close() + while module <= number_of_modules: + if module_list[module -1] == "1": + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1 + print cmd + os.system(cmd) + # Getting data from the control module file + fobj1 = open(filename1,"r") + file_list_1 = fobj1.readlines() + fobj1.close() + content = file_list_1[2:-1] + # + fobj2 = open(filename2,"a") + if base == 10: + fobj2.write("S" + str(module) + "\n") + else: + fobj2.write("N" + str(module) + "\n") + fobj2.writelines(content) + fobj2.write("------\n") + fobj2.close() + module = module + 1 + + def __getStsMode2(self): + + #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") + self.commClientObj.sendData("CHEQUEO:" + self.datarx + ":") + seconds = int (self.datarx) + # Give 5 seconds to the control modules + time.sleep(seconds) + # Checking the module connection + enaModules = self.checkAntenna() + #Generating the complete report + filename1 = "Verificacion" + line1 = "Verification_file\n" + line2 = "-----------------\n" + report_list = [line1, line2] + + for address in range(1,65): + + if address not in enaModules: + continue + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1 + print cmd + os.system(cmd) + #Sub_header + report_list.append("ABS_" + str(address) + "\n") + # Content + fobj1 = open(filename1,"r") + file_list_1 = fobj1.readlines() + fobj1.close() + content = ''.join(file_list_1[2:-1]) + report_list.append(content) + #Ending + report_list.append("------\n") + #print "\nFinalizado" + self.tx_buffer = ''.join(report_list) + + def __AddingHeader(self,content_list, title): + + line1 = title + "\n" + line2 = "-----------------\n" + header_list = [line1, line2] + verification_list = header_list + content_list + # Arming the frame + self.tx_buffer = ''.join(verification_list) + + def __getModuleFile(self, filename): + + enaModules = self.checkAntenna() + content_list = [] + for address in range(1,65): + + if address not in enaModules: + continue + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename + print cmd + os.system(cmd) + #Sub_header + content_list.append("ABS_" + str(address) + "\n") + # From module file to list + content_str = self.__readModuleFile(filename) + content_list.append(content_str) + content_list.append("------\n") + + self.__AddingHeader(content_list, title = "Verification_file") + + def __getStsMode3(self): + + self.commClientObj.sendData("none", "CHEQUEO:" + self.datarx + ":") + seconds = int (self.datarx) + # Give 5 seconds to the control modules + time.sleep(seconds) + + self.__getModuleFile(filename = "Verificacion") + + +if __name__ == '__main__': + + absObj = ABSServer() + + while 1: + absObj.waitRequest() \ No newline at end of file Index: trunk/absroot/source/abspy/bin/server2.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/server2.py b/trunk/absroot/source/abspy/bin/server2.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/server2.py (revision 166) @@ -0,0 +1,369 @@ +import os +import library2 +import time + +class ABSServer: + + def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + + self.ipDestino2 = ipDestino2 + self.portDestino2 = portDestino2 + + self.tx_buffer = "default" + self.rx_buffer = "default" + + self.createObjects() + + def createObjects(self): + + asServer = True + self.commServerObj = library2.TCPComm("Central_Control", self.ipDestino, self.portDestino, asServer) + self.commClientObj = library2.TCPComm("Central_Control", self.ipDestino2, self.portDestino2) + + def waitRequest(self): + +# Using rx buffer + ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer() + + if cmd == "SNDF": + datarpta = self.sendFile2Modules(mode=2, cmd = cmd) + + if cmd == "CHGB": + datarpta = self.changeBeam(cmd = cmd) + + if cmd == "ANST": + self.getStatus(mode=4, cmd = cmd) +# Using tx buffer + datarpta = self.tx_buffer + + self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource) + + 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 + + """ + + enaModules = [] + + for address in range(1,65): + if self.checkModule(address): + enaModules.append(address) + + self.__writeReport(enaModules) + return enaModules + + def sendFile2Modules(self, mode, cmd): + + if mode == 1: + self.__sendFile2Modules1() + else: + self.__sendFile2Modules2(cmd) + + def __sendFile2Modules1(self): + + #Needed for the loop + rx_frame_list = self.rx_buffer.split('\n',2) + + self.experiment_name = rx_frame_list[0] + experiment_number = rx_frame_list[1] + str_control_modules = rx_frame_list[2] + + lst_control_modules = str_control_modules.split("------\n") + +# enaModules = self.checkAntenna() + enaModules = [11,12,13,14] + + for address in range(1,65): + + if address not in enaModules: + continue + + self.__writeModuleFile(self.experiment_name, lst_control_modules[address-1]) + + cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c put " + self.experiment_name + print cmd + os.system(cmd) + + self.__loadFile() + + def __sendFile2Modules2(self,cmd): + + #Needed for the loop + rx_frame_list = self.rx_buffer.split('\n',2) + 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 enaModules: + continue + #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.close_socket() + + if tmp == "OK": + correct = correct + 1 + else: + failure = failure + 1 + + if correct == len(enaModules): + rpta = "OK" + else: + rpta = "Failure" + + return rpta + + + def __writeModuleFile(self, filename, str): + + fobj = open(filename,"w") + fobj.write(filename + "\n") + fobj.write("------\n") + fobj.write(str) + fobj.write("------\n") + fobj.close() + + def __readModuleFile(self, filename): + + fobj1 = open(filename,"r") + file_list_1 = fobj1.readlines() + fobj1.close() + content_str = ''.join(file_list_1[2:-1]) + + return content_str + + def __loadFile(self): + + #Working with the UDP socket + self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") + self.commClientObj.sendData("none", "CAMBIA:0:") + + def changeBeam(self, cmd): + + correct = 0 + failure = 0 +# enaModules = self.checkAntenna() + enaModules = [11,12,13,14] + + for id in range(1,65): + if id not in enaModules: + continue + + self.commClientObj.open_socket() + ip = "192.168.1." + str(id) + self.commClientObj.sendData2(cmd, self.rx_buffer, ip) +# ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() + ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() + self.commClientObj.close_socket() + + if tmp == "OK": + correct = correct + 1 + else: + failure = failure + 1 + + if correct == len(enaModules): + rpta = "OK" + else: + rpta = "Failure" + + return rpta + + def getStatus(self, mode, cmd): + + if mode == 1: + self.__getStsMode1() + elif mode == 2: + self.__getStsMode2() + elif mode == 3: + self.__getStsMode3() + else: + self.__getStsMode4(cmd) + + + def __getStsMode1(self): + #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") + self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") + seconds = int (self.rx_buffer) + # Give 5 seconds to the control modules + time.sleep(seconds) + # Checking the module connection + module_list = self.connection_status(10) + #Generating the complete report + module = 1 + number_of_modules = 16 + filename1 = "Verificacion" + filename2 = "report.txt" + fobj2 = open(filename2,"w") + fobj2.write("Verification_file\n") + fobj2.write("-----------------\n") + fobj2.close() + while module <= number_of_modules: + if module_list[module -1] == "1": + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(base + module) +" 69 -c get " + filename1 + print cmd + os.system(cmd) + # Getting data from the control module file + fobj1 = open(filename1,"r") + file_list_1 = fobj1.readlines() + fobj1.close() + content = file_list_1[2:-1] + # + fobj2 = open(filename2,"a") + if base == 10: + fobj2.write("S" + str(module) + "\n") + else: + fobj2.write("N" + str(module) + "\n") + fobj2.writelines(content) + fobj2.write("------\n") + fobj2.close() + module = module + 1 + + def __getStsMode2(self): + + #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") + self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") + seconds = int (self.rx_buffer) + # Give 5 seconds to the control modules + time.sleep(seconds) + # Checking the module connection + enaModules = self.checkAntenna() + #Generating the complete report + filename1 = "Verificacion" + line1 = "Verification_file\n" + line2 = "-----------------\n" + report_list = [line1, line2] + + for address in range(1,65): + + if address not in enaModules: + continue + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename1 + print cmd + os.system(cmd) + #Sub_header + report_list.append("ABS_" + str(address) + "\n") + # Content + fobj1 = open(filename1,"r") + file_list_1 = fobj1.readlines() + fobj1.close() + content = ''.join(file_list_1[2:-1]) + report_list.append(content) + #Ending + report_list.append("------\n") + #print "\nFinalizado" + self.tx_buffer = ''.join(report_list) + + def __AddingHeader(self,content_list, title): + + line1 = title + "\n" + line2 = "-----------------\n" + header_list = [line1, line2] + verification_list = header_list + content_list + # Arming the frame + self.tx_buffer = ''.join(verification_list) + + def __getModuleFile(self, filename): + + enaModules = self.checkAntenna() + content_list = [] + for address in range(1,65): + + if address not in enaModules: + continue + #Preparing and doing the tftp command + cmd = "tftp -m binary 192.168.1."+ str(address) +" 69 -c get " + filename + print cmd + os.system(cmd) + #Sub_header + content_list.append("ABS_" + str(address) + "\n") + # From module file to list + content_str = self.__readModuleFile(filename) + content_list.append(content_str) + content_list.append("------\n") + + self.__AddingHeader(content_list, title = "Verification_file") + + def __getStsMode3(self): + + self.commClientObj.sendData("none", "CHEQUEO:" + self.rx_buffer + ":") + seconds = int (self.rx_buffer) + # Give 5 seconds to the control modules + time.sleep(seconds) + + self.__getModuleFile(filename = "Verificacion") + + def __getStsMode4(self, cmd): + + content_str = "" +# enaModules = self.checkAntenna() + enaModules = [11,12,13,14] + + for id in range(1,65): + if id not in enaModules: + continue + + 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.close_socket() + + content_str = content_str + tmp +# self.__AddingHeader(content_list, title = "Verification_file") +#Using tx buffer + self.tx_buffer = content_str + +if __name__ == '__main__': + + absObj = ABSServer() + + while 1: + absObj.waitRequest() \ No newline at end of file Index: trunk/absroot/source/abspy/bin/server3.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/server3.py b/trunk/absroot/source/abspy/bin/server3.py new file mode 10644 --- /dev/null (revision 0) +++ b/trunk/absroot/source/abspy/bin/server3.py (revision 166) @@ -0,0 +1,399 @@ +import os +import library3 +import time +import threading + +class ABSServer: + + def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500, rx_buffer = "default"): + + self.ipSource = ipSource + self.ipDestino = ipDestino + self.portDestino = portDestino + + self.ipDestino2 = ipDestino2 + self.portDestino2 = portDestino2 + + self.tx_buffer = "default" +# self.rx_buffer = "default" + self.rx_buffer = rx_buffer + self.enaModules = [] + self.bits = [] + self.phase = [] + self.txFile = [] + self.rxFile = [] + + self.createObjects() + + print "Checking control modules, please wait ..." + self.enaModules = self.checkAntenna() + print "Starting automatic control module status." + self.__StartingAutomaticControlModules() + self.__AutomaticControlModules() + + def createObjects(self): + + asServer = True + 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) + self.wFiles = library3.FilesStuff() + + def waitRequest(self): + + #Using rx buffer +# ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData() + ipSource, ipDestino, cmd, rx_buffer = self.commServerObj.waitData() + + if cmd == "SNDF": + datarpta = self.__sendFile2Modules(cmd = cmd, rx_buffer = rx_buffer) + + if cmd == "GETF": + datarpta = self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) + + if cmd == "CHGB": + datarpta = self.__changeBeam(cmd = cmd, rx_buffer = rx_buffer) + + if cmd == "ANST": + datarpta = self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) + + if cmd == "BGPH": + datarpta = self.__getControlModuleBigPhase(cmd = cmd, rx_buffer = rx_buffer) + + if cmd == "LWPH": + datarpta = self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) + + if cmd == "NTST": + datarpta = self.__getConnectionStatus(cmd = cmd, rx_buffer = rx_buffer) + + self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) + + 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") + + filename = "module_status.txt" + self.__writeFile(filename,status_array) +# f = open("module_status.txt","w") +# f.writelines(status_array) +# f.close() + + + def __CreateFile(self, filename): + + fobj = open(filename,"w") + fobj.close() + + def __writeNewFile(self, filename, data): + + fobj = open(filename,"w") + fobj.writelines(data) + fobj.close() + + def __writeFile(self, filename, data): + + fobj = open(filename,"a") + fobj.writelines(data) + fobj.close() + + def checkAntenna(self): + + """ + Direccion de los modulos de las antenas: + + Norte : 01-16 + Este : 17-32 + Oeste: : 33-48 + Sur : 49-64 + + """ + + enaModules2 = [] + + for address in range(1,65): + if self.checkModule(address): + enaModules2.append(address) + + 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 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) + + return FileStr + + 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, rx_buffer): + +# rx_buffer_lst = self.rx_buffer.split('\n',1) + rx_buffer_lst = rx_buffer.split('\n',1) + #Getting the filename from the begining of data + filename = rx_buffer_lst[0] + tmp = rx_buffer_lst[1] + self.__writeFile(filename,tmp) + data = self.abs2ControlModuleFormatFile(filename) + #Needed for the loop + header, control_modules_lst = self.__All2Blocks(data) + correct = 0 + + for id in range(1,65): + + if id not in self.enaModules: + continue + + if self.__ConnectionWithControlModules(header + control_modules_lst[id-1], cmd, id) == "OK": + correct = correct + 1 + + if correct == len(self.enaModules): + rpta = "OK" + else: + rpta = "Failure" + + return rpta + + def __getFileFromModules(self, cmd, rx_buffer): + + 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] + self.rxFile.insert(id-1, file) + + def __changeBeam(self, cmd, rx_buffer): + + 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(rx_buffer,cmd,id) == "OK": + correct = correct + 1 + + if correct == len(self.enaModules): + rpta = "OK" + else: + rpta = "Failure" + + return rpta + + def __getControlModuleStatus(self, cmd, rx_buffer): + +# all_blocks = "" +# all_blocks = [] +# enaModules = self.checkAntenna() +# enaModules = [11,12,13,14] + + for id in range(1,65): + if id not in self.enaModules: + continue + + bits = self.__ConnectionWithControlModules(rx_buffer,cmd,id) + del self.bits[id-1] + self.bits.insert(id-1, bits) + +# all_blocks.append(one_block) + #Using tx buffer + +# return all_blocks + + def __getControlModuleBigPhase(self, cmd, rx_buffer): + +# all_blocks = "" + all_blocks = [] +# enaModules = self.checkAntenna() +# enaModules = [11,12,13,14] + + for id in range(1,65): + if id not in self.enaModules: + continue + + one_block = self.__ConnectionWithControlModules(rx_buffer,cmd,id) + +# all_blocks = all_blocks + one_block + all_blocks.append(one_block) + #Using tx buffer + return all_blocks + + def __getControlModuleLowPhase(self, cmd, rx_buffer): + +# all_blocks = "" +# all_blocks = [] +# enaModules = self.checkAntenna() +# enaModules = [11,12,13,14] + + for id in range(1,65): + if id not in self.enaModules: + continue + + 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) + #Using tx buffer +# return all_blocks + + def __getConnectionStatus(self, cmd, rx_buffer): + + ena = self.checkAntenna() + print ena + self.enaModules = ena + + blockLst = [] + + for id in range(1,65): + if id not in self.enaModules: + continue + + blockStr = self.__ConnectionWithControlModules(rx_buffer,cmd,id) + blockLst.append(blockStr + ", 192.168.1." + str(id) + "\n") + #Using tx buffer + all_blocks = "".join(blockLst) + + return all_blocks + + 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 + + def getControlModuleStatus(self, cmd): + + all_blocks = "" +# enaModules = self.checkAntenna() +# enaModules = [11,12,13,14] + + for id in range(1,65): + if id not in self.enaModules: + continue + + one_block = self.__ConnectionWithControlModules(self.rx_buffer,cmd,id) + + all_blocks = all_blocks + one_block + #Using tx buffer + print all_blocks + self.tx_buffer = all_blocks + + return all_blocks + + 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)) + + def __AutomaticControlModules(self): + + cmd = "GETF" + rx_buffer = "experimento1.ab1" + "\n" + self.__getFileFromModules(cmd = cmd, rx_buffer = rx_buffer) + + print self.rxFile + + cmd = "ANST" + rx_buffer = "1" + self.__getControlModuleStatus(cmd = cmd, rx_buffer = rx_buffer) + + cmd = "LWPH" + rx_buffer = "0" + self.__getControlModuleLowPhase(cmd = cmd, rx_buffer = rx_buffer) + print "Saving file..." + + + print self.bits + print self.phase + + self.__WritingMonitoringFile() + + threading.Timer(60, self.__AutomaticControlModules).start() + + 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') + +if __name__ == '__main__': + + absObj = ABSServer() + + while 1: + absObj.waitRequest() \ No newline at end of file Index: trunk/absroot/source/abspy/scripts/changeBeam.py =================================================================== diff --git a/trunk/absroot/source/abspy/scripts/changeBeam.py b/trunk/absroot/source/abspy/scripts/changeBeam.py --- a/trunk/absroot/source/abspy/scripts/changeBeam.py (revision 165) +++ b/trunk/absroot/source/abspy/scripts/changeBeam.py (revision 166) @@ -1,9 +1,9 @@ import optparse, os, sys -pathFile = os.getcwd() +pathFile = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.split(pathFile)[0]) -from abscontrol.client3 import ABSClient +from bin.client3 import ABSClient class changeBeam(object): @@ -16,7 +16,6 @@ usage = "::::::::::::\n" - if __name__ == '__main__': Index: trunk/absroot/source/abspy/scripts/sendFile.py =================================================================== diff --git a/trunk/absroot/source/abspy/scripts/sendFile.py b/trunk/absroot/source/abspy/scripts/sendFile.py --- a/trunk/absroot/source/abspy/scripts/sendFile.py (revision 165) +++ b/trunk/absroot/source/abspy/scripts/sendFile.py (revision 166) @@ -1,10 +1,10 @@ import optparse, os, sys -pathFile = os.getcwd() +pathFile = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.split(pathFile)[0]) -from abscontrol.client3 import ABSClient +from bin.client3 import ABSClient class sendFile(object): @@ -15,12 +15,11 @@ if os.path.exists(filename): absObj = ABSClient(ipDestino="10.10.10.97") absObj.sendFile(filename) - pass + #pass else: print "No file" usage = "::::::::::::\n" - if __name__ == '__main__':