X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=297111ef8696c24a16412421febb7c60eb1afc0e;hp=cbcf1c4ad963cb7fe31f2269d06d21311d93da20;hb=fb6e18b07a982eb5983f4598c5bfbb1ffaa267a7;hpb=9db7b366db7bd2535064bcdb0ae0ea89b2e6988f diff --git a/client/GoodFET.py b/client/GoodFET.py index cbcf1c4..297111e 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -6,18 +6,29 @@ # This code is ugly as sin, for bootstrapping the firmware only. # Rewrite cleanly as soon as is convenient. -import sys, time, string, cStringIO, struct -#sys.path.append("/usr/lib/tinyos") -import serial +import sys, time, string, cStringIO, struct, glob, serial, os; class GoodFET: def __init__(self, *args, **kargs): self.data=[0]; def timeout(self): - print "timout\n"; - def serInit(self, port): + print "timeout\n"; + def serInit(self, port=None): """Open the serial port""" + + if port is None: + port=os.environ.get("GOODFET"); + + if port is None: + glob_list = glob.glob("/dev/tty.usbserial*"); + if len(glob_list) > 0: + port = glob_list[0]; + if port is None: + glob_list = glob.glob("/dev/ttyUSB*"); + if len(glob_list) > 0: + port = glob_list[0]; + self.serialport = serial.Serial( port, #9600, @@ -33,8 +44,8 @@ class GoodFET: #time.sleep(1); self.readcmd(); #Read the first command. if(self.verb!=0x7F): - print "Verb is wrong. Incorrect firmware?"; - + print "Verb %02x is wrong. Incorrect firmware?" % self.verb; + #print "Connected." def writecmd(self, app, verb, count, data): """Write a command and some data to the GoodFET.""" self.serialport.write(chr(app)); @@ -69,8 +80,30 @@ class GoodFET: self.data=[address&0xff,address>>8,value]; self.writecmd(0,0x03,3,self.data); return ord(self.data[0]); + def dumpmem(self,begin,end): + i=begin; + while i