"""py-bluez class for emulating py-serial."""
def __init__(self,btaddr):
import bluetooth;
- while btaddr==None or btaddr=="none" or btaddr=="bluetooth":
+ if btaddr==None or btaddr=="none" or btaddr=="bluetooth":
print "performing inquiry..."
nearby_devices = bluetooth.discover_devices(lookup_names = True)
print "found %d devices" % len(nearby_devices)
print " %s - '%s'" % (addr, name)
if name=='FireFly-A6BD':
btaddr=addr;
+ print "Please set $GOODFET to the address of your device.";
+ sys.exit();
print "Identified GoodFET at %s" % btaddr;
- # BlueFET doesn't run the Service Discovery Protocol.
- # Instead we manually use the portnumber.
+ # Manually use the portnumber.
port=1;
print "Connecting to %s on port %i." % (btaddr, port);
def write(self,msg):
"""Send traffic."""
- return self.sock.send(msg);
- def read(self,len):
+ import time;
+ self.sock.send(msg);
+ #time.sleep(0.1);
+ return;
+ def read(self,length):
"""Read traffic."""
- return self.sock.recv(len);
+ data="";
+ while len(data)<length:
+ data=data+self.sock.recv(length-len(data));
+ return data;
class GoodFET:
"""GoodFET Client Library"""
+(ord(self.serialport.read(1))<<8)
);
- #if self.verbose:
- #print "Rx: ( 0x%02x, 0x%02x, 0x%04x )" % ( self.app, self.verb, self.count )
+ if self.verbose:
+ print "Rx: ( 0x%02x, 0x%02x, 0x%04x )" % ( self.app, self.verb, self.count )
#Debugging string; print, but wait.
if self.app==0xFF: