#!/usr/bin/env python2.3 # # Initial rough hacky code to interface with Atmel RZ Raven Kit # # Proof-of-concept, hard-coded values, all undocumented/reverse engineered. # # Author: follower@rancidbacon.com # # License: LGPL # # Date: 15 April 2008 # # # Requires: libusb and pyusb # import usb busses = usb.busses() for bus in busses: devices = bus.devices for dev in devices: #print "Device:", dev.filename #print dev.idVendor if dev.idVendor == 0x03EB and dev.idProduct == 0x210A: print "=== Device found ===" print "Device:", dev.filename #print dev.iSerialNumber #print dir(dev) # TODO: Does the string length matter? print `dev.open().getString(dev.iProduct, 50)` # TODO: Does the string length matter? print "Serial number:", print `dev.open().getString(dev.iSerialNumber, 13)` config = dev.configurations[0] #print dir(config) intf = config.interfaces[0] #print dir(intf) alt = intf[0] #print dir(alt) handle = dev.open() handle.setConfiguration(config) handle.claimInterface(alt) #handle.setAltInterface(alt) try: print handle.bulkWrite(0x02, [0x07, 0x03]) print hex(handle.bulkRead(0x84, 1)[0]) except IndexError: print "Skip IndexError" try: # Channel: 11, Pan Id: 0xBABE print handle.bulkWrite(0x02, [0x22, 0x0B, 0xBE, 0xBA]) print hex(handle.bulkRead(0x84, 1)[0]) except IndexError: print "Skip IndexError" print handle.bulkWrite(0x02, [0x23, 0x01]) print hex(handle.bulkRead(0x84, 1)[0]) import time def constructTextMsg(remoteAddress, text): """ """ MSG_COMMAND = 0x21 packet = [MSG_COMMAND] # Note: Untested address manipulation. packet.extend((remoteAddress & 0xFF, remoteAddress >> 8)) packet.extend((0x01, 0x01, 0x01)) # Unknown content = [0x00, 0x06] # Unknown content.append(len(text)) content.extend(text) packet.append(len(content)) packet.extend(content) return packet #print [d for d in constructTextMsg(0x001B, "Forsooth")] #msg = constructTextMsg(0x001B, "Forsooth") sentText = False msg = constructTextMsg(0x001B, "Hello new Raven.") # Hmmmm, I seem to be missing every second message... while 1: #response = handle.bulkRead(0x81, 12) response = handle.bulkRead(0x81, 50) if response: print [hex(d) for d in response] if response[0] == 0x54: # TODO: process remote id also print "Remote address 0x%02x%x joined." % (response[3], response[2]) if not sentText: ## Command?, AddrL, AddrH, 0x01, 0x01, 0x01, ## Len (, 0x00/0x02, 0x06?, LEN (, T, E, X, T ) ) # print handle.bulkWrite(0x02, [0x21, 0x1b, 0x00, 0x01, 0x01, 0x01, 0x07, 0x00, 0x06, 0x04, 'H', 'O', 'W', 'D']) #print handle.bulkWrite(0x02, [0x21, 0x1b, 0x00, 0x01, 0x01, 0x01, 0x08, 0x00, 0x06, 0x05, 'H', 'O', 'W', 'D', 'Y']) ## Text message ## print handle.bulkWrite(0x02, msg) print handle.bulkWrite(0x02, msg) ## Read temperature. Result is last two bytes of response. ##print handle.bulkWrite(0x02, [0x21, 0x1b, 0x00, 0x01, 0x01, 0x01, 0x03, 0x00, 0x0f, 0x00]) print hex(handle.bulkRead(0x84, 1)[0]) sentText = True # TODO: handle 0x55 as Leave? # TODO: handle 0x53 as ??? (Message received?) if response[0] == 0x53: # This acknowledges at least text messages... print handle.bulkWrite(0x02, [0x21, 0x1b, 0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x1a]) print hex(handle.bulkRead(0x84, 1)[0]) time.sleep(1)