X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=89362dfa1249d5f1f030a7164b368056cabb441f;hp=0d32cca97be02a86b4d2d4f7bc2946d320e8a8b4;hb=f82ed46ca4aa832f487c57eb0609ef6f62c24155;hpb=5080c116b2f2b94172c597ef4f07e3f369665c61 diff --git a/client/GoodFET.py b/client/GoodFET.py index 0d32cca..89362df 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -5,7 +5,7 @@ # # This code is being rewritten and refactored. You've been warned! -import sys, time, string, cStringIO, struct, glob, serial, os; +import sys, time, string, cStringIO, struct, glob, os; import sqlite3; fmt = ("B", "= attemptlimit: return elif attempts>2: print "Resyncing."; self.serialport.flushInput() self.serialport.flushOutput() - #Explicitly set RTS and DTR to halt board. - self.serialport.setRTS(1); - self.serialport.setDTR(1); - #Drop DTR, which is !RST, low to begin the app. - self.serialport.setDTR(0); #TelosB reset, prefer software to I2C SPST Switch. if(os.environ.get("platform")=='telosb'): #print "TelosB Reset"; self.telosBReset(); + else: + #Explicitly set RTS and DTR to halt board. + self.serialport.setRTS(1); + self.serialport.setDTR(1); + #Drop DTR, which is !RST, low to begin the app. + self.serialport.setDTR(0); - #self.serialport.write(chr(0x80)); #self.serialport.write(chr(0x80)); #self.serialport.write(chr(0x80)); #self.serialport.write(chr(0x80)); - self.serialport.flushInput() - self.serialport.flushOutput() + #self.serialport.flushInput() + #self.serialport.flushOutput() #time.sleep(60); attempts=attempts+1; self.readcmd(); #Read the first command. + #print "Got %02x,%02x:'%s'" % (self.app,self.verb,self.data); #Here we have a connection, but maybe not a good one. #print "We have a connection." connected=1; @@ -280,16 +286,22 @@ class GoodFET: try: #print "Reading..."; self.app=ord(self.serialport.read(1)); - #print "APP=%2x" % self.app; + #print "APP=%02x" % self.app; self.verb=ord(self.serialport.read(1)); + + #Fixes an obscure bug in the TelosB. + if self.app==0x00: + while self.verb==0x00: + self.verb=ord(self.serialport.read(1)); + #print "VERB=%02x" % self.verb; self.count=( ord(self.serialport.read(1)) +(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: