version 1.1, 2012/07/10 08:02:27 |
version 1.2, 2012/07/10 08:16:27 |
|
|
const char *line, *errstr; |
const char *line, *errstr; |
char *tmp; |
char *tmp; |
int opt, speed, i, ch; |
int opt, speed, i, ch; |
struct termios tio; |
|
static char sbuf[12]; |
static char sbuf[12]; |
|
|
line = "/dev/cua00"; |
line = "/dev/cua00"; |
|
|
if (ioctl(line_fd, TIOCEXCL) != 0) |
if (ioctl(line_fd, TIOCEXCL) != 0) |
err(1, "ioctl(TIOCEXCL)"); |
err(1, "ioctl(TIOCEXCL)"); |
|
|
cfmakeraw(&tio); |
if (set_line(speed) != 0) |
tio.c_iflag = 0; |
exit(1); |
tio.c_oflag = 0; |
|
tio.c_lflag = 0; |
|
tio.c_cflag = CREAD|CS8; |
|
tio.c_cc[VMIN] = 1; |
|
tio.c_cc[VTIME] = 0; |
|
cfsetspeed(&tio, speed); |
|
if (tcsetattr(line_fd, TCSAFLUSH, &tio) != 0) |
|
err(1, "tcsetattr"); |
|
|
|
if (isatty(STDIN_FILENO) && tcgetattr(STDIN_FILENO, &saved_tio) != 0) |
if (isatty(STDIN_FILENO) && tcgetattr(STDIN_FILENO, &saved_tio) != 0) |
err(1, "tcgetattr"); |
err(1, "tcgetattr"); |
|
|
|
|
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tio) != 0) |
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tio) != 0) |
err(1, "tcsetattr"); |
err(1, "tcsetattr"); |
|
} |
|
|
|
int |
|
set_line(int speed) |
|
{ |
|
struct termios tio; |
|
|
|
cfmakeraw(&tio); |
|
tio.c_iflag = 0; |
|
tio.c_oflag = 0; |
|
tio.c_lflag = 0; |
|
tio.c_cflag = CREAD|CS8; |
|
tio.c_cc[VMIN] = 1; |
|
tio.c_cc[VTIME] = 0; |
|
cfsetspeed(&tio, speed); |
|
if (tcsetattr(line_fd, TCSAFLUSH, &tio) != 0) { |
|
warn("tcsetattr"); |
|
return (-1); |
|
} |
|
return (0); |
} |
} |
|
|
void |
void |