2 # GoodFET Client Library
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
11 from GoodFET import GoodFET;
12 from intelhex import IntelHex;
14 class GoodFETConsole():
15 """An interactive goodfet driver."""
17 def __init__(self, client):
24 sys.stdout.write("gf% ");
28 #for cmd in sys.stdin:
30 cmd=sys.stdin.readline();
35 def handle(self, str):
36 """Handle a command string. First word is command."""
37 #Lines beginning with # are comments.
38 if(str[0]=="#"): return;
39 #Lines beginning with ! are Python.
42 exec(str.lstrip('!'));
44 print sys.exc_info()[0];
46 #Backtick (`) indicates shell commands.
48 os.system(str.lstrip('`'));
50 #By this point, we're looking at a GoodFET command.
55 eval("self.CMD%s(args)" % args[0])
57 print sys.exc_info()[0];
58 #print "Unknown command '%s'." % args[0];
59 def CMDinfo(self,args):
60 print self.client.infostring()
61 def CMDlock(self,args):
64 def CMDerase(self,args):
67 def CMDtest(self,args):
70 def CMDstatus(self,args):
71 print self.client.status();
73 def CMDhalt(self,args):
74 print self.client.halt();
75 def CMDresume(self,args):
76 print self.client.resume();
77 def CMDpeek(self,args):
82 adr= self.client.name2adr(adr);
84 print "0x%08x:= 0x%04x" % (
85 adr, self.client.peek16(adr,
87 def CMDflash(self,args):
89 self.client.flash(self.expandfilename(file));
90 def CMDdump(self,args):
92 self.client.dump(self.expandfilename(file));
93 def CMDwhere(self,args):
94 pc=self.client.getpc();
95 print "PC=0x%04X" % pc;
96 def CMDchip(self,args):
97 cmd="self.client.CMD%s()" % args[1];
102 print sys.exc_info()[0];
103 print "Chip-specific command failed.";
104 def expandfilename(self,filename):
105 if(filename[0]=='~'):
106 return "%s%s" % (os.environ.get("HOME"),filename.lstrip('~'));