Beispiel #1
0
int main(int argc, char* argv[])
{
	if(argc<2)
	{
                printf("Argument is not correct\n");
		return 0;
	}
	int fd = open_port(argv[1]);
	int fd_tty = open_terminal();
	configure_port(fd);
	configure_terminal(fd_tty);
	char rec=' ',rec_tty=' ';
	while(fd!=-1 && fd_tty!=-1)
	{
		int data=read(fd,&rec,1);
		int data_tty=read(fd_tty,&rec_tty,1);
		if(data>0)
			printf("%c",rec);
		if(data_tty>0)
                        printf("%c",rec_tty);
		if(rec_tty=='q')
			break;
		rec=' ';rec_tty=' ';
	}
	close(fd);
	close(fd_tty);	
	return(0);
}
Beispiel #2
0
int main(int argc, char **argv)
{
	struct timeval timeout;
	fd_set readfds;

	handle_cmd_line(argc, argv);

	in = dup(0);
	out = dup(1);
	terminal = open(terminal_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (terminal == -1) {
		perror("Failed to open terminal");
		exit(3);
	}

	configure_terminal(speed);
	configure_input();

	setup_signal_handlers();
	escape_state = 0;
	for (;;) {
		FD_ZERO(&readfds);
		FD_SET(terminal, &readfds);
		FD_SET(in, &readfds);

		timeout.tv_sec  = 0;
		timeout.tv_usec = 500000;

		if (select(FD_SETSIZE, &readfds, NULL, NULL, &timeout) == -1) {
			break;
		} else {
			if (FD_ISSET(terminal, &readfds) &&
			    transfer_from_terminal() == false)
				break;

			if (FD_ISSET(in, &readfds) &&
			    transfer_to_terminal() == false)
				break;
		}
	}

	unconfigure_input();
	if (opt_reset)
		write(out, RESET_SEQUENCE, sizeof(RESET_SEQUENCE));

	close(terminal);
	close(in);
	close(out);

	return 0;
}