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):
23 sys.stdout.write("gf% ");
27 #for cmd in sys.stdin:
29 cmd=sys.stdin.readline();
34 def handle(self, str):
35 """Handle a command string. First word is command."""
36 #Lines beginning with # are comments.
37 if(str[0]=="#"): return;
38 #Lines beginning with ! are Python.
41 exec(str.lstrip('!'));
43 print sys.exc_info()[0];
45 #Backtick (`) indicates shell commands.
47 os.system(str.lstrip('`'));
49 #By this point, we're looking at a GoodFET command.
54 eval("self.CMD%s(args)" % args[0])
56 print sys.exc_info()[0];
57 #print "Unknown command '%s'." % args[0];
58 def CMDinfo(self,args):
59 print self.client.infostring()
60 def CMDlock(self,args):
63 def CMDerase(self,args):
66 def CMDtest(self,args):
69 def CMDstatus(self,args):
70 print self.client.status();
72 def CMDhalt(self,args):
73 print self.client.halt();
74 def CMDresume(self,args):
75 print self.client.resume();
76 def CMDpeek(self,args):
81 print "0x%08x:= 0x%04x" % (adr, self.client.peek16(adr,memory));
82 def CMDflash(self,args):
84 self.client.flash(self.expandfilename(file));
85 def CMDwhere(self,args):
86 pc=self.client.getpc();
87 print "PC=0x%04X" % pc;
88 def CMDchip(self,args):
89 cmd="self.client.CMD%s()" % args[1];
94 print sys.exc_info()[0];
95 print "Chip-specific command failed.";
96 def expandfilename(self,filename):
98 return "%s%s" % (os.environ.get("HOME"),filename.lstrip('~'));