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;
15 #grep CMD GoodFETConsole.py | grep def | sed s/\(sel.\*// | sed 's/def CMD//'
31 class GoodFETConsole():
32 """An interactive goodfet driver."""
34 def __init__(self, client):
41 sys.stdout.write("gf% ");
45 #for cmd in sys.stdin:
47 cmd=sys.stdin.readline();
52 def handle(self, str):
53 """Handle a command string. First word is command."""
54 #Lines beginning with ? are cries for help.
56 print "Term Commands:"
59 #Lines beginning with # are comments.
60 if(str[0]=="#"): return;
61 #Lines beginning with ! are Python.
64 exec(str.lstrip('!'));
66 print sys.exc_info()[0];
68 #Backtick (`) indicates shell commands.
70 os.system(str.lstrip('`'));
72 #By this point, we're looking at a GoodFET command.
77 eval("self.CMD%s(args)" % args[0])
79 print sys.exc_info()[0];
80 #print "Unknown command '%s'." % args[0];
81 def CMDinfo(self,args):
82 print self.client.infostring()
83 def CMDlock(self,args):
86 def CMDerase(self,args):
89 def CMDtest(self,args):
92 def CMDstatus(self,args):
93 print self.client.status();
95 def CMDhalt(self,args):
96 print self.client.halt();
97 def CMDresume(self,args):
98 print self.client.resume();
99 def CMDpeek(self,args):
104 adr= self.client.name2adr(adr);
106 print "0x%08x:= 0x%04x" % (
107 adr, self.client.peek16(adr,
109 def CMDflash(self,args):
111 self.client.flash(self.expandfilename(file));
112 def CMDdump(self,args):
114 self.client.dump(self.expandfilename(file));
115 def CMDwhere(self,args):
116 pc=self.client.getpc();
117 print "PC=0x%04X" % pc;
118 def CMDchip(self,args):
119 cmd="self.client.CMD%s()" % args[1];
124 print sys.exc_info()[0];
125 print "Chip-specific command failed.";
126 def expandfilename(self,filename):
127 if(filename[0]=='~'):
128 return "%s%s" % (os.environ.get("HOME"),filename.lstrip('~'));