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 comments.
55 if(str[0]=="#"): return;
56 #Lines beginning with ! are Python.
59 exec(str.lstrip('!'));
61 print sys.exc_info()[0];
63 #Backtick (`) indicates shell commands.
65 os.system(str.lstrip('`'));
67 #By this point, we're looking at a GoodFET command.
72 eval("self.CMD%s(args)" % args[0])
74 print sys.exc_info()[0];
75 #print "Unknown command '%s'." % args[0];
76 def CMDinfo(self,args):
77 print self.client.infostring()
78 def CMDlock(self,args):
81 def CMDerase(self,args):
84 def CMDtest(self,args):
87 def CMDstatus(self,args):
88 print self.client.status();
90 def CMDhalt(self,args):
91 print self.client.halt();
92 def CMDresume(self,args):
93 print self.client.resume();
94 def CMDpeek(self,args):
99 adr= self.client.name2adr(adr);
101 print "0x%08x:= 0x%04x" % (
102 adr, self.client.peek16(adr,
104 def CMDflash(self,args):
106 self.client.flash(self.expandfilename(file));
107 def CMDdump(self,args):
109 self.client.dump(self.expandfilename(file));
110 def CMDwhere(self,args):
111 pc=self.client.getpc();
112 print "PC=0x%04X" % pc;
113 def CMDchip(self,args):
114 cmd="self.client.CMD%s()" % args[1];
119 print sys.exc_info()[0];
120 print "Chip-specific command failed.";
121 def expandfilename(self,filename):
122 if(filename[0]=='~'):
123 return "%s%s" % (os.environ.get("HOME"),filename.lstrip('~'));