int cambri_init(void) { int ret = 0; int c, i; for (c = 0; c < NUM_CAMBRIS; c++) { const char* name = get_tty_name(c); int fd = -1; if (name) fd = open(name, O_RDWR | O_NOCTTY); if (!name || fd < 0) { cambri_fds[c] = 0; ret++; } else { cambri_fds[c] = fd; struct termios tty = {}; tcgetattr(fd, &tty); tty.c_lflag = 0; tty.c_oflag = 0; tty.c_iflag = 0; tty.c_cflag = CS8 | CLOCAL | CREAD; tty.c_cc[VTIME] = 1; // 0.1 s read timeout tty.c_cc[VMIN] = 0; // non-blocking cfsetospeed(&tty, B115200); cfsetispeed(&tty, B115200); tcsetattr(fd, TCSANOW, &tty); // enable profile 4 only char buf[1024] = {}; for (i = 1; i <= 6; i++) { cambri_write(c, "en_profile %d %d", i, i == PROFILE); if (cambri_read(c, buf, sizeof(buf)) == 0) { error(1, 0, "cambri_init"); } } } } cambri_log = fopen("cambri.log", "w"); fprintf(cambri_log, " time "); for (i = 0; i < NUM_CAMBRIS * 8; i++) fprintf(cambri_log, " | %5d", (i/8+1) * 1000 + i%8+1); fprintf(cambri_log, "\n"); fprintf(cambri_log, "-----------"); for (i = 0; i < NUM_CAMBRIS * 8; i++) fprintf(cambri_log, "-+------"); fprintf(cambri_log, "\n"); fflush(cambri_log); status_log = fopen("status.log", "w"); return ret; }
int main(void) { char ctermid_name[L_ctermid]; ctermid(ctermid_name); /* * Most UNIX systems use /dev/tty as the ame of the controlling terminal, so * this function is intended to aid portability to other operating systems. */ printf("The name of the controller terminal is: \"%s\" " "(max len = %d)\n\n", ctermid_name, L_ctermid); printf("Testing to see which file descriptors refer to a terminal:\n"); printf("fd 0: %s\n", get_tty_name(STDIN_FILENO)); printf("fd 1: %s\n", get_tty_name(STDOUT_FILENO)); printf("fd 2: %s\n", get_tty_name(STDERR_FILENO)); printf("\nUse redirection (e.g. ./ttyinfo.o < /etc/passwd 2> /dev/null)\n" "to see how the results may change\n"); return 0; }