Advertisement
Guest User

433Mhz wtf python

a guest
Mar 21st, 2014
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import usb.core
  3. import usb.util
  4. import sys
  5. import struct
  6.  
  7. # source: http://androbuntu.googlecode.com/svn-history/r84/trunk/ubudroid-server/pycm19a/pycm19a.py
  8. def init_remotes(outEp):
  9.     cr12init1 = [ 0x020, 0x034, 0x0cb, 0x058, 0x0a7 ]
  10.     cr12init2 = [ 0x080, 0x001, 0x000, 0x020, 0x014 ]
  11.     cr12init3 = [ 0x080, 0x001, 0x000, 0x000, 0x014, 0x024, 0x020, 0x020 ]
  12.     writeRes = outEp.write(cr12init1)
  13.     writeRes = outEp.write(cr12init2)
  14.     writeRes = outEp.write(cr12init3)
  15.  
  16. def sendData(lsdata,outEP):
  17.      outEP.write(lsdata,10000)
  18.  
  19. def getEndPointInfo(configs):
  20.     for interface in configs:
  21.         print "Configuration"
  22.         for endpoint in interface:
  23.             print "Endpoint"
  24.             print "======================================"
  25.             print "Direction = " + str(usb.util.endpoint_direction(endpoint.bEndpointAddress))
  26.             print "Type = " + str(usb.util.endpoint_type(endpoint.bEndpointAddress))
  27.             print endpoint.bLength
  28.             print endpoint.bDescriptorType
  29.             print endpoint.bmAttributes
  30.             print endpoint.wMaxPacketSize
  31.             print endpoint.bInterval
  32.             print endpoint.bRefresh
  33.             print endpoint.bSynchAddress
  34.  
  35. dev = usb.core.find(idVendor=0x10c4, idProduct=0x8668)
  36.  
  37. if dev is None:
  38.     print "USBDevice not found"
  39. else:
  40.     print "Found RF module"
  41.     if dev.is_kernel_driver_active(0):
  42.         print "detaching kernel driver"
  43.         dev.detach_kernel_driver(0)
  44.     dev.set_configuration()
  45.     cfg = dev.get_active_configuration()#this thing only has one config
  46.     for i in cfg:
  47.         print i.bInterfaceNumber
  48.         interface_number = i.bInterfaceNumber
  49.     alternate_settting = usb.control.get_interface(dev, interface_number)
  50.     intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number, bAlternateSetting = alternate_settting)
  51.         ep_tx = usb.util.find_descriptor(intf,
  52.              # match the first OUT endpoint
  53.              custom_match = \
  54.                  lambda e: \
  55.                      usb.util.endpoint_direction(e.bEndpointAddress) == \
  56.                      usb.util.ENDPOINT_OUT
  57.          )
  58.  
  59.     ep_rx = usb.util.find_descriptor(intf,
  60.              # match the first OUT endpoint
  61.              custom_match = \
  62.                  lambda e: \
  63.                      usb.util.endpoint_direction(e.bEndpointAddress) == \
  64.                      usb.util.ENDPOINT_IN
  65.          )
  66.  
  67.     assert ep_tx is not None
  68.     assert ep_rx is not None
  69.  
  70.     #getEndPointInfo(cfg)
  71.  
  72.     init_remotes(ep_tx)
  73.         while True:
  74.         ep_tx.write([0x02,0x02, 0x07, 0x20])
  75.         init_remotes(ep_tx)
  76. #       try:
  77. #           data = ep_rx.read(1)
  78. #           print data
  79. #           time.sleep(0.1)
  80. #       except usb.USBError:
  81. #           print "."
  82. #               pass
  83. #       if len(line)>0:
  84. #           sendData([ 0x080, 0x001, 0x000, 0x000, 0x014, 0x024, 0x020, 0x020 ],ep_rx)
  85. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement