Advertisement
eriasu

Protocolo Sony

Oct 20th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import struct
  3. def leer_estructura(file):
  4.     file.seek(0,2)
  5.     fin_archivo= file.tell()
  6.     file.seek(0,0)
  7.     Tramas=[]
  8.     while (file.tell() < fin_archivo):
  9.         datos_leidos = file.read(26)
  10.         trama_simple = struct.unpack("H H H H H H H H H H H H H", datos_leidos)
  11.         Tramas.append(trama_simple)
  12.     file.close()
  13.     return Tramas
  14. def Dispositivo(trama):
  15.     Dispositivo=[]
  16.     Dispositivo_bin=""
  17.     for e in range (1,6):
  18.         if trama[e]>=90:
  19.             Dispositivo.append(1)
  20.         else:
  21.             Dispositivo.append(0)
  22.     for a in range(5):
  23.         Dispositivo_bin=Dispositivo_bin+str(Dispositivo[a])
  24.     Dispositivo_decifrado=int(Dispositivo_bin,2)
  25.     return str(Dispositivo_decifrado)
  26.  
  27. def Boton(trama):
  28.     Boton = []
  29.     Boton_bin=""
  30.     for x in range(6,13):
  31.         if trama[x]>=90:
  32.            Boton.append(1)
  33.         else:
  34.             Boton.append(0)
  35.     for n in range(7):
  36.         Boton_bin=Boton_bin+str(Boton[n])
  37.     Boton_decifrado=int(Boton_bin,2)
  38.     return str(Boton_decifrado)
  39. def Decodificado(Estructura,file):
  40.     no_sony=open("no_control_sony.txt","w")
  41.    
  42.    
  43.     for i in range (0,len(Estructura)):
  44.         trama=Estructura[i]
  45.         init = trama[0]
  46.         if init >200 and init<270:
  47.             ingreso = "Init "+str(init)+"\n"
  48.             file.write(ingreso)
  49.             ingreso="Dispositivo "+Dispositivo(trama)+"\n"
  50.             file.write(ingreso)
  51.             ingreso="Boton presionado "+Boton(trama)+"\n"
  52.             file.write(ingreso)
  53.         else:
  54.             no_sony.write("Init no control sony: "+str(trama[0])+"\n")
  55.             no_sony.write("Dispositivo: "+Dispositivo(trama)+"\n")
  56.             no_sony.write("Boton Presionado: "+Boton(trama)+"\n")
  57.            
  58.     no_sony.close()    
  59. def main():
  60.     Archivo_a_decodificar = open("sony.dat","rb")
  61.     Control = open("Control.txt","w")
  62.     Control.write("Control Sony y su Protocolo\n")
  63.     Estructura=leer_estructura(Archivo_a_decodificar)
  64.     Decodificado(Estructura,Control)
  65.     Control.close()
  66. if __name__ == '__main__':
  67.     main()
  68.    
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement