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 CMDpeek(self,args):
77 print "0x%08x:= 0x%04x" % (adr, self.client.peek16(adr,memory));
78 def CMDflash(self,args):
80 self.client.flash(self.expandfilename(file));
81 def CMDchip(self,args):
82 cmd="self.client.CMD%s()" % args[1];
87 print sys.exc_info()[0];
88 print "Chip-specific command failed.";
89 def expandfilename(self,filename):
91 return "%s%s" % (os.environ.get("HOME"),filename.lstrip('~'));