X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=ec65900b599aaab1e4a8add2b2245f51b867a912;hp=a31676ce0fed9976f94e930a6300fd5c2a39d51b;hb=c8701c0a1cb2ab3a1a12ac24f17619575671df76;hpb=fa5713a93ff59ebdd126f5b7914a96b5030b32fb diff --git a/client/GoodFET.py b/client/GoodFET.py index a31676c..ec65900 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -50,22 +50,28 @@ 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)); - #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(); + #print "TX %02x %02x" % (app,verb); + #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 i in range(0,count): + #print "Converting %02x at %i" % (data[i],i) + data[i]=chr(data[i]); + outstr=''.join(data); + self.serialport.write(outstr); if not self.besilent: - self.readcmd(blocks); + self.readcmd(); besilent=0; app=0; @@ -73,7 +79,7 @@ class GoodFET: count=0; data=""; - def readcmd(self,blocks=1): + def readcmd(self): """Read a reply from the GoodFET.""" while 1: #print "Reading..."; @@ -81,16 +87,16 @@ class GoodFET: #print "APP=%2x" % self.app; self.verb=ord(self.serialport.read(1)); #print "VERB=%02x" % self.verb; - self.count=ord(self.serialport.read(1)); - #print "Waiting for %i bytes." % self.count; - - #print "READ %02x %02x %02x " % (self.app, self.verb, self.count); + 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.serialport.read(self.count); else: - self.data=self.serialport.read(self.count*blocks); + self.data=self.serialport.read(self.count); return self.data; #Monitor stuff