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% ");
26 cmd=sys.stdin.readline();
29 def handle(self, str):
30 """Handle a command string. First word is command."""
31 #Lines beginning with # are comments.
32 if(str[0]=="#"): return;
33 #Lines beginning with ! are Python.
36 exec(str.lstrip('!'));
38 print sys.exc_info()[0];
40 #Backtick (`) indicates shell commands.
42 os.system(str.lstrip('`'));
44 #By this point, we're looking at a GoodFET command.
49 eval("self.CMD%s(args)" % args[0])
51 print sys.exc_info()[0];
52 #print "Unknown command '%s'." % args[0];
53 def CMDinfo(self,args):
54 print self.client.infostring()
55 def CMDlock(self,args):
58 def CMDerase(self,args):
61 def CMDtest(self,args):
64 def CMDstatus(self,args):
65 print self.client.status();
67 def CMDpeek(self,args):
72 print "0x%08x:= 0x%04x" % (adr, self.client.peek16(adr,memory));
73 def CMDflash(self,args):
75 self.client.flash(self.expandfilename(file));
76 def expandfilename(self,filename):
78 return "%s%s" % (os.environ.get("HOME"),filename.lstrip('~'));