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

xmccomm: Implement proper error handling

parent a7c0f455
......@@ -15,6 +15,8 @@
#define streq(A,B) (!strcmp(A,B))
// stty -F /dev/ttyACM0 115200
static void print_ok() {
printf(SHELL_ESC"[;32;02m[ok] "SHELL_ESC"[m");
}
......@@ -87,10 +89,9 @@ static int connect_tty(char *tty) {
// setup control structure
struct termios toptions;
tcgetattr(fd, &toptions);
cfsetispeed(&toptions, B115200);
cfsetospeed(&toptions, B115200);
if(0 != tcgetattr(fd, &toptions)) { perror("tcgetattr"); }
if(0 != cfsetispeed(&toptions, B115200)) { perror("cfsetispeed"); }
if(0 != cfsetospeed(&toptions, B115200)) { perror("cfsetospeed"); }
toptions.c_cflag &= ~PARENB; // no parity bit
toptions.c_cflag &= ~CSTOPB; // no stop bits
......@@ -110,9 +111,8 @@ static int connect_tty(char *tty) {
toptions.c_oflag &= ~OPOST; // disable postprocessing
tcsetattr(fd, TCSANOW, &toptions);
tcflush(fd, TCIFLUSH);
if(0 != tcsetattr(fd, TCSANOW, &toptions)) { perror("tcsetattr"); }
if(0 != tcflush(fd, TCIFLUSH)) { perror("tcflush"); }
return fd;
}
......@@ -169,6 +169,8 @@ static void resp_bch(bool success, char *resp) {
uint64_t cycles = strtoull(rem, NULL, 10);
printf("%lu cy / %0.2f s", cycles, (double)cycles / remote_frequency);
} else if(rem = strsw(resp, "ov")) {
printf("Overflow in input data");
} else {
printf("Unparsed: %s", resp);
}
......
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