-// shit to avoid constant repetition
-#define CONCAT_AGAIN(A,B) A ## B
-#define CONCAT(A,B) CONCAT_AGAIN(A,B)
-
-static int set_nonblock(int fd)
-{
- int flags = fcntl(fd, F_GETFL, 0);
- if (flags == -1) {
- perror("fcntl (get)");
- return -1;
- }
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
- perror("fcntl (set)");
- return -1;
- }
- fprintf(stderr, "set %d non-blocking\n", fd);
- return 0;
-}
-
-static int set_rts(int fd, int level)
-{
- int uart_status;
-
- if (ioctl(fd, TIOCMGET, &uart_status) == -1) {
- perror("ioctl (TIOCMGET)");
- return -1;
- }
-
- if (level) {
- uart_status |= TIOCM_RTS;
- } else {
- uart_status &= ~TIOCM_RTS;
- }
-
- if (ioctl(fd, TIOCMSET, &uart_status) == -1) {
- perror("TIOCMSET");
- return -1;
- }
-
- fprintf(stderr, "set %d rts %d\n", fd, level);
-
- return 0;
-}
-
-static void set_baud_rate(int fd, int br) //TODO add some checking
-{
- struct termios options;
-
- tcgetattr(fd, &options);
- cfsetispeed(&options, br);
- cfsetospeed(&options, br);
- tcsetattr(fd, TCSANOW, &options);
-}
-
-static int tty_open(const char *port, int br)