Post-Shmoocon commit.
[goodfet] / client / GoodFET.py
index e459a91..4aec90b 100755 (executable)
@@ -150,6 +150,7 @@ class GoodFET:
                     break;
         if self.verbose: print "Connected after %02i attempts." % attempts;
         self.mon_connected();
+        self.serialport.setTimeout(12);
     def telosSetSCL(self, level):
         self.serialport.setRTS(not level)
     def telosSetSDA(self, level):
@@ -372,8 +373,17 @@ class GoodFET:
     def eeprompeek(self,address):
         """Read a word of memory from the monitor."""
         return self.peekbyte(address)+(self.peekbyte(address+1)<<8);
-    
-    def pokebyte(self,address,value):
+    def peekbysym(self,name):
+        """Read a value by its symbol name."""
+        #TODO include memory in symbol.
+        reg=self.symbols.get(name);
+        return self.peek8(reg,"data");
+    def pokebysym(self,name,val):
+        """Write a value by its symbol name."""
+        #TODO include memory in symbol.
+        reg=self.symbols.get(name);
+        return self.pokebyte(reg,val);
+    def pokebyte(self,address,value,memory="vn"):
         """Set a byte of memory by the monitor."""
         self.data=[address&0xff,address>>8,value];
         self.writecmd(0,0x03,3,self.data);
@@ -469,6 +479,30 @@ class GoodFET:
             if self.verbose: print "Comm error recognized by monitorecho().";
             return 0;
         return 1;
+
+    def monitor_info(self):
+        print "GoodFET with %s MCU" % self.infostring();
+        print "Clocked at %s" % self.monitorclocking();
+        return 1;
+
+    def monitor_list_apps(self, full=False): 
+        self.monitor_info()
+        old_value = self.besilent
+        self.besilent = True    # turn off automatic call to readcmd
+        self.writecmd(self.MONITORAPP, 0x82, 1, [int(full)]);
+        self.besilent = old_value
+        
+        # read the build date string 
+        self.readcmd()
+        print "Build Date: %s" % self.data
+        print "Firmware apps:"
+        while True:
+            self.readcmd()
+            if self.count == 0:
+                break
+            print self.data
+        return 1;
+
     def monitorclocking(self):
         """Return the 16-bit clocking value."""
         return "0x%04x" % self.monitorgetclock();
@@ -481,7 +515,7 @@ class GoodFET:
         return self.peek16(0x56);
     # The following functions ought to be implemented in
     # every client.
-
+    
     def infostring(self):
         a=self.peekbyte(0xff0);
         b=self.peekbyte(0xff1);
@@ -528,13 +562,19 @@ class GoodFET:
         return self.peekbyte(address); #monitor
     def peekword(self,address, memory="vn"):
         """Peek a natively sized word of memory."""
-        return self.peek(address); #monitor
+        return self.peek16(address); #monitor
     def peekblock(self,address,length,memory="vn"):
         """Return a block of data."""
         data=range(0,length);
         for foo in range(0,length):
             data[foo]=self.peek8(address+foo,memory);
         return data;
+    def pokeblock(self,address,bytes,memory="vn"):
+        """Poke a block of a data into memory at an address."""
+        for foo in bytes:
+            self.pokebyte(address,foo,memory);
+            address=address+1;
+        return;
     def loadsymbols(self):
         """Load symbols from a file."""
         return;