Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Added debug (-d) option
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Zotov committed Jun 5, 2010
1 parent d3a09e9 commit 2ad8bb4
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion software/vuxprog.cpp
Expand Up @@ -58,6 +58,7 @@ const char* usage[] = {
" -i SEQ\tstart bootloader by sending SEQ to port",
" -r\t\treset device after successful programming",
" -a\t\tdump full flash including bootloader code",
" -d\t\toutput debug information",
" -F\t\tdo things which sane human wouldn't",
""
};
Expand Down Expand Up @@ -115,7 +116,7 @@ class protocol_error: public error {

class vuxboot {
public:
vuxboot(string filename, unsigned baud = 0) {
vuxboot(string filename, unsigned baud = 0) : debug(false) {
_fd = open(filename.c_str(), O_RDWR | O_NONBLOCK);
if(!_fd) throw new io_error("cannot open port");

Expand All @@ -126,6 +127,14 @@ class vuxboot {
close(_fd);
}

bool get_debug() {
return debug;
}

void set_debug(bool new_debug) {
debug = new_debug;
}

void identify() {
write("s");

Expand Down Expand Up @@ -274,19 +283,56 @@ class vuxboot {
throw new io_error("cannot read()");
}

if(debug) {
cerr << "read(";
for(int i = 0; i < retval; i++) {
char val[3];
sprintf(val, "%02X", *(data + received + i));
cerr << val << ' ';
}
for(int i = 0; i < retval; i++) {
char chr = *(data + received + i);
if(isgraph(chr))
cerr << chr;
else
cerr << '.';
}
cerr << ")" << endl;
}

received += retval;
}

return string(data, received);
}

void write(string data) {
if(debug) {
cerr << "write(";
for(int i = 0; i < data.length(); i++) {
char val[3];
sprintf(val, "%02X", data[i]);
if(i != 0)
cerr << ' ';
cerr << val;
}
for(int i = 0; i < data.length(); i++) {
char chr = data[i];
if(isgraph(chr))
cerr << chr;
else
cerr << '.';
}
cerr << ")" << endl;
}

if(::write(_fd, data.c_str(), data.length()) != data.length()) {
throw new io_error("cannot write()");
}
}

private:
bool debug;
int _fd;

bool _has_eeprom;
Expand Down Expand Up @@ -423,6 +469,7 @@ int main(int argc, char* argv[]) {
opts.option('F');
opts.option('a');
opts.option('r');
opts.option('d');

if(!opts.parse(argc, argv) || opts.has('h') || !opts.valid() || (opts.args().size() != 2 &&
(opts.args().size() != 1 || (opts.args()[0] != "r" && opts.args()[0] != "reset")))) {
Expand All @@ -435,6 +482,7 @@ int main(int argc, char* argv[]) {
bool force = opts.has('F');
bool do_reset = opts.has('r');
bool dump_all = opts.has('a');
bool debug = opts.has('d');

storage::format format = storage::ihex;
if(opts.has('f')) {
Expand All @@ -455,6 +503,7 @@ int main(int argc, char* argv[]) {

try {
vuxboot bl(port);
bl.set_debug(debug);

if(opts.has('i'))
bl.write(opts.get('i'));
Expand Down

0 comments on commit 2ad8bb4

Please sign in to comment.