X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=18a3eb1a952ec1a6eb73707ef1e9d184438875aa;hp=af24201cbcd74b8db97c041bdc157678e7487484;hb=f4a6b415e762bcdc560f3ea655851d16f483ea5a;hpb=1706a7f4cfa73ed716b56f5b0322bfb67b560ade diff --git a/client/GoodFET.py b/client/GoodFET.py index af24201..18a3eb1 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -50,40 +50,52 @@ class GoodFET: def getbuffer(self,size=0x1c00): writecmd(0,0xC2,[size&0xFF,(size>>16)&0xFF]); print "Got %02x%02x buffer size." % (self.data[1],self.data[0]); - def writecmd(self, app, verb, count=0, data=[], blocks=1): + def writecmd(self, app, verb, count=0, data=[]): """Write a command and some data to the GoodFET.""" self.serialport.write(chr(app)); self.serialport.write(chr(verb)); - self.serialport.write(chr(count)); + + + #little endian 16-bit length + self.serialport.write(chr(count&0xFF)); + self.serialport.write(chr(count>>8)); + #print "count=%02x, len(data)=%04x" % (count,len(data)); if count!=0: for d in data: self.serialport.write(chr(d)); + #self.serialport.flushOutput(); + #self.serialport.flushInput(); + + if not self.besilent: - #print "Reading reply to %02x/%02x." % (app,verb); - self.readcmd(blocks); - #print "Read reply." - + self.readcmd(); + besilent=0; app=0; verb=0; count=0; data=""; - def readcmd(self,blocks=1): + def readcmd(self): """Read a reply from the GoodFET.""" while 1: + #print "Reading..."; self.app=ord(self.serialport.read(1)); + #print "APP=%2x" % self.app; self.verb=ord(self.serialport.read(1)); - self.count=ord(self.serialport.read(1)); - self.data=self.serialport.read(self.count*blocks); - #print "READ %02x %02x %02x " % (self.app, self.verb, self.count); + #print "VERB=%02x" % self.verb; + self.count=( + ord(self.serialport.read(1)) + +(ord(self.serialport.read(1))<<8) + ); #Debugging string; print, but wait. if self.app==0xFF and self.verb==0xFF: - print "DEBUG %s" % self.data; + print "DEBUG %s" % self.serialport.read(self.count); else: + self.data=self.serialport.read(self.count); return self.data; #Monitor stuff