Commit cee52d31 authored by Christian Eichler's avatar Christian Eichler
Browse files

Implement verbose output for xmccomm.c

parent 07277700
......@@ -15,6 +15,18 @@
#define streq(A,B) (!strcmp(A,B))
static void print_ok() {
printf(SHELL_ESC"[;32;02m[ok] "SHELL_ESC"[m");
}
static void print_er() {
printf(SHELL_ESC"[;31;02m[ER] "SHELL_ESC"[m");
}
static void print_vb(char *msg) {
printf(SHELL_ESC"[;36;02m[vb] "SHELL_ESC"[m%s", msg);
}
static bool recv_response(FILE *fh, char *buf, size_t buf_size) {
int pos = 0;
......@@ -46,12 +58,20 @@ static bool recv_response(FILE *fh, char *buf, size_t buf_size) {
static int connect_tty(char *tty) {
bool exists = false;
unsigned retry = 0;
do {
print_vb("");
printf("open('%s') try %u\n", tty, retry);
++retry;
struct stat sbuf;
int res = stat(tty, &sbuf);
exists = (0 == res);
} while(!exists && errno != EACCES);
if(!exists) {
usleep(500 * 1000);
}
} while(!exists && errno != EACCES && retry < 10);
int fd = open(tty, O_RDWR | O_NOCTTY);
if(-1 == fd) {
......@@ -60,6 +80,8 @@ static int connect_tty(char *tty) {
fprintf(stderr, "Make sure current user `%s` is in group `dialout`\n", getlogin());
}
exit(EXIT_FAILURE);
} else {
print_vb(""); printf("%s successfully opened\n", tty);
}
// setup control structure
......@@ -158,14 +180,6 @@ static void resp_eic(bool success, char *resp) {
printf("Instruction Cache now enabled!");
}
static void print_ok() {
printf(SHELL_ESC"[;32;02m[ok] "SHELL_ESC"[m");
}
static void print_er() {
printf(SHELL_ESC"[;31;02m[ER] "SHELL_ESC"[m");
}
static void response_loop(FILE *fh, void (*cb)(bool, char*)) {
bool done = false;
char buf[128];
......@@ -223,10 +237,12 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
print_vb("Requesting device info...\n");
fprintf(fh, "inf \n");
fflush(fh);
response_loop(fh, resp_inf);
print_vb("Sending user commands...\n");
for(int i = 2; i < argc; ++i) {
struct command *cmd = NULL;
......@@ -242,6 +258,8 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
print_vb(""); printf("Sending command '%s'...\n", argv[i]);
fprintf(fh, "%s \n", argv[i]);
fflush(fh);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment