X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=b37b319f58c5b269c396e55f7edf882009e2aaf2;hp=ef218333005c155af87cb76312e79ffba3475219;hb=a3e65c0394e0c8e551cc5309f7e4cdc7b9a39dc3;hpb=5ea4c9f824eed5226b9939b4f28fe1fda9c14dda diff --git a/client/GoodFET.py b/client/GoodFET.py index ef21833..b37b319 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -11,10 +11,10 @@ import sqlite3; fmt = ("B", " 0: port = glob_list[0]; + if port is None: + glob_list = glob.glob("/dev/ttyU0"); + if len(glob_list) > 0: + port = glob_list[0]; if os.name=='nt': from scanwin32 import winScan; scan=winScan(); @@ -102,10 +106,13 @@ class GoodFET: #Do nothing. a=1; + baud=115200; + if(os.environ.get("platform")=='arduino'): + baud=19200; #Slower, for now. self.serialport = serial.Serial( port, #9600, - 115200, + baud, parity = serial.PARITY_NONE, timeout=timeout ) @@ -114,8 +121,12 @@ class GoodFET: attempts=0; connected=0; while connected==0: + #print "Got %s" % self.data; while self.verb!=0x7F or self.data!="http://goodfet.sf.net/": - #print "Resyncing."; + if attemptlimit is not None and attempts >= attemptlimit: + return + elif attempts>2: + print "Resyncing."; self.serialport.flushInput() self.serialport.flushOutput() #Explicitly set RTS and DTR to halt board. @@ -126,7 +137,10 @@ class GoodFET: #TelosB reset, prefer software to I2C SPST Switch. if(os.environ.get("platform")=='telosb'): + #print "TelosB Reset"; self.telosBReset(); + + #self.serialport.write(chr(0x80)); #self.serialport.write(chr(0x80)); #self.serialport.write(chr(0x80)); @@ -139,18 +153,23 @@ class GoodFET: attempts=attempts+1; self.readcmd(); #Read the first command. #Here we have a connection, but maybe not a good one. + #print "We have a connection." connected=1; olds=self.infostring(); clocking=self.monitorclocking(); + #if(os.environ.get("platform")!='arduino'): for foo in range(1,30): if not self.monitorecho(): - if self.verbose: print "Comm error on %i try, resyncing out of %s." % (foo, - clocking); - connected=0; - break; + if self.verbose: + print "Comm error on %i try, resyncing out of %s." % (foo, + clocking); + connected=0; + break; if self.verbose: print "Connected after %02i attempts." % attempts; self.mon_connected(); self.serialport.setTimeout(12); + def serClose(self): + self.serialport.close(); def telosSetSCL(self, level): self.serialport.setRTS(not level) def telosSetSDA(self, level): @@ -372,7 +391,8 @@ class GoodFET: return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8); def eeprompeek(self,address): """Read a word of memory from the monitor.""" - return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8); + print "EEPROM peeking not supported for the monitor."; + #return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8); def peekbysym(self,name): """Read a value by its symbol name.""" #TODO include memory in symbol. @@ -395,11 +415,17 @@ class GoodFET: return value; def setsecret(self,value): """Set a secret word for later retreival. Used by glitcher.""" - self.eeprompoke(0,value); - self.eeprompoke(1,value); + #self.eeprompoke(0,value); + #self.eeprompoke(1,value); + print "Secret setting is not yet suppored for this target."; + print "Aborting."; + def getsecret(self): """Get a secret word. Used by glitcher.""" - self.eeprompeek(0); + #self.eeprompeek(0); + print "Secret getting is not yet suppored for this target."; + print "Aborting."; + sys.exit(); def dumpmem(self,begin,end): i=begin; @@ -476,7 +502,7 @@ class GoodFET: data="The quick brown fox jumped over the lazy dog."; self.writecmd(self.MONITORAPP,0x81,len(data),data); if self.data!=data: - if self.verbose: print "Comm error recognized by monitorecho()."; + print "Comm error recognized by monitorecho(), got:\n%s" % self.data; return 0; return 1; @@ -512,14 +538,20 @@ class GoodFET: self.MONpoke16(0x56, clock); def monitorgetclock(self): """Get the clocking value.""" + if(os.environ.get("platform")=='arduino'): + return 0xDEAD; + #Check for MSP430 before peeking this. return self.MONpeek16(0x56); # The following functions ought to be implemented in # every client. def infostring(self): - a=self.MONpeek8(0xff0); - b=self.MONpeek8(0xff1); - return "%02x%02x" % (a,b); + if(os.environ.get("platform")=='arduino'): + return "Arduino"; + else: + a=self.MONpeek8(0xff0); + b=self.MONpeek8(0xff1); + return "%02x%02x" % (a,b); def lock(self): print "Locking Unsupported."; def erase(self):