📄 spiftest.c
字号:
} if ((ioctl(dfd,TIOCMGET,&obs)) == FAIL) { send_message(0, ERROR, tiocmget_err, sp_dev_name[dev_num]); exit(errno); } /* Masked out DTR line since spif driver v1.2 returned its value and older driver doesn't */ obs &= DTR_MASK; /* now compare */ if (testid[SP_96]) { exp = TIOCM_LE | TIOCM_CTS | TIOCM_CAR; } else exp = TIOCM_LE | TIOCM_CTS | TIOCM_CAR | TIOCM_DSR; if (exp != obs) { send_message(0, ERROR, "Expected (0x%x): ", exp); get_modem_bits(exp); send_message(0, ERROR, "Observed (0x%x): ", obs); get_modem_bits(obs); send_message(0, ERROR, modemloop_test_err, sp_dev_name[dev_num]); exit(CMP_ERROR); } /* Now clear DTR and RTS */ exp = TIOCM_LE; modem = TIOCM_DTR|TIOCM_RTS; if ((ioctl(dfd,TIOCMBIC,&modem)) == FAIL) { send_message(0, ERROR, tiocmbic_err, sp_dev_name[dev_num]); exit(errno); } if ((ioctl(dfd,TIOCMGET,&obs)) == FAIL) { send_message(0, ERROR, tiocmget_err, sp_dev_name[dev_num]); exit(errno); } if (exp != obs) { send_message(0, ERROR, "Expected (0x%x): ", exp); get_modem_bits(exp); send_message(0, ERROR, "Observed (0x%x): ", obs); get_modem_bits(obs); send_message(0, ERROR, modemloop_test_err, sp_dev_name[dev_num]); exit(CMP_ERROR); } close(dfd); } } TRACE_OUT} /* modem_loopback *//* * echo_tty - * * Continually read and write to device selected (with a tty connected) * until ETX character is received or when the timeout (two minutes) * is reached. Note that VMIN is set to one character and VTIME is 0. * No flow control is necessary for this test. */voidecho_tty(){ int fd; int done = 0, rl = 0, wl = 0; u_char ch; func_name = "echo_tty"; TRACE_IN alarm(120); signal(SIGALRM, data_timeout); for (dev_num = 0; dev_num < TOTAL_IO_PORTS; dev_num++) { if (sp_ports[dev_num].selected) { strcpy(device_name, sp_dev_name[dev_num]); send_message(0,VERBOSE, testing_msg, device_name); if ((fd = open(sp_dev_name[dev_num], O_RDWR)) == FAIL) { send_message(0, ERROR, open_err_msg, sp_dev_name[dev_num]); exit(errno); } if (ioctl(fd, TIOCEXCL, 0) == FAIL) { send_message(0, ERROR, device_open, sp_dev_name[dev_num]); exit(errno); } sp_ports[dev_num].fd = fd; enable_softcar(dev_num); set_termios(dev_num); /* Open the serial port and continually reading from it * Echo mode will echo the character to TTY terminal. */ while (!done) { if ((rl = read(fd, &ch, 1)) == FAIL) { send_message(0, ERROR, read_err_msg, sp_dev_name[dev_num]); exit(errno); } if (ch == ETX) { send_message(0, VERBOSE, end_echotty); done++; } else { if ((wl = write(fd, &ch, rl)) == FAIL) { send_message(0, ERROR, write_err_msg, sp_dev_name[dev_num]); exit(errno); } send_message(0, TRACE, "ch = 0x%x [%c]\n",ch&0x0ff,ch); } } alarm(0); flush_io(dev_num); close(sp_ports[dev_num].fd); } } TRACE_OUT} /* echo_tty *//* * print_pp_file - * * Check the printer state and print out appropriate messages. * Flush the printer. * * Print a ascii file to the parallel port. Do it the simpliest way * without having to count the characters or do many writes. Write * new line at beginning and new page at the end of print. No need * to set termios for the printer. * */voidprint_pp_file(){ int fd; int lc, cc, wl; int brd; u_char u_ascii[49]; u_char l_ascii[49]; u_char np = '\f'; func_name = "print_pp_file"; TRACE_IN strcpy(u_ascii, "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO\n\r"); strcpy(l_ascii, "PQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n\r"); for (brd = 0; brd < MAX_BOARDS; brd++) { if (spif[brd] == ON) { strcpy(device_name, pp_dev_name[brd]); send_message(0,VERBOSE, testing_msg, device_name); if ((fd = open(pp_dev_name[brd], O_RDWR)) < 0) { send_message(0, ERROR, open_err_msg, pp_dev_name[brd]); exit(errno); } if (ioctl(fd, TIOCEXCL, 0) == FAIL) { send_message(0, ERROR, device_open, pp_dev_name[brd]); exit(errno); } /* Get status of the printer (actual status, not what driver think it is) * for now terminate when error occurs. */ if (ioctl(fd, STC_GPPC, &pd) == FAIL) { send_message(0, ERROR, stc_gppc, pp_dev_name[brd]); exit(errno); } if (!(pd.state & (PP_SELECT<<PP_SHIFT))) { send_message(0, ERROR, offline_err, pp_dev_name[brd]); exit(errno); } if (pd.state & (PP_PAPER_OUT<<PP_SHIFT)) { send_message(0, ERROR, paper_out_err, pp_dev_name[brd]); exit(errno); } if (pd.state & (PP_BUSY<<PP_SHIFT)) { send_message(0, ERROR, busy_err, pp_dev_name[brd]); exit(errno); } if (pd.state & (PP_ERROR<<PP_SHIFT)) { send_message(0, ERROR, pp_err, pp_dev_name[brd]); exit(errno); } /* If the printer is ready, start sending data, check * for end of line and end of page. */ for (lc = 0; lc < PSIZE; lc++) { if ((wl = write(fd, u_ascii, strlen(u_ascii))) != strlen(u_ascii)) { send_message(0, ERROR, write_err_msg, pp_dev_name[brd]); exit(errno); } if ((wl = write(fd, l_ascii, strlen(l_ascii))) != strlen(l_ascii)) { send_message(0, ERROR, write_err_msg, pp_dev_name[brd]); exit(errno); } send_message(0, TRACE, "PRINT, %s: upper ascii=%s, len = %d\n", pp_dev_name[brd], u_ascii, strlen(u_ascii)); send_message(0, TRACE, "PRINT, %s: lower ascii=%s, len = %d\n", pp_dev_name[brd], l_ascii, strlen(l_ascii)); } if ((wl = write(fd, &np, 1)) == FAIL) { send_message(0, ERROR, write_err_msg, pp_dev_name[brd]); exit(errno); } close(fd); flush_io(brd|PP_LINE); } } TRACE_OUT} /* print_pp_file */static voidwait_pid_update(pid)int pid;{ int i; for (i = 0; i < TOTAL_IO_PORTS; i++) { if (rw_child_pid[i].rpid == pid) { rw_child_pid[i].rstatus = PASS; } else if (rw_child_pid[i].wpid == pid) { rw_child_pid[i].wstatus = PASS; } }}voidrw_loop(){ int fd; int i, bytes, rc = 0, wc = 0, acc = 0; u_long *exp, *obs; char tina[4]; func_name = "rw_loop"; TRACE_IN alarm(TIMEOUT); signal(SIGALRM, data_timeout); if (!testid[INTERNAL]) send_message(0, VERBOSE, test_name, dataloop_test); /* Now perform local loopback */ fd = sp_ports[dev_num].fd; exp = (u_long *) malloc(sizeof(long)); obs = (u_long *) malloc(sizeof(long)); *exp = data; *obs = 0; send_message(0, TRACE, "INITIALLY, exp = 0x%x obs = 0x%x\n", *exp, *obs); for (bytes = 0; bytes < MAX_RUNS; bytes++) { if ((wc = write(fd, exp, sizeof(long))) < 0) { send_message(0, ERROR, write_err_msg, sp_dev_name[dev_num]); exit(errno); } acc = 0; for (i = 0; (i < RETRIES) && (rc != sizeof(long)); i++) { alarm(TIMEOUT); if ((acc = read(fd, &tina[rc], sizeof(long)-rc)) < 0) { send_message(0, ERROR, read_err_msg, sp_dev_name[dev_num]); exit(errno); } else rc += acc; } bcopy(tina, obs, 4); /* Adjust expected value depening on character size */ switch (csize) { case 5: *exp &= 0x1f1f1f1f; break; case 6: *exp &= 0x3f3f3f3f; break; case 7: *exp &= 0x7f7f7f7f; break; } send_message(0, TRACE, "%s: exp=0x%x obs=0x%x\n", sp_dev_name[dev_num], *exp, *obs); if (wc != rc) { send_message(0, ERROR, mismatch_err_msg, wc, rc); if (testid[INTERNAL]) { send_message(0, ERROR, internal_test_err, sp_dev_name[dev_num]); exit(CMP_ERROR); } else { send_message(0, ERROR, data_test_err, sp_dev_name[dev_num]); exit(CMP_ERROR); } } if (*exp != *obs) { send_message(0, ERROR, compare_err_msg, *exp, *obs); send_message(0, ERROR, internal_test_err, sp_dev_name[dev_num]); exit(CMP_ERROR); } } alarm(0); flush_io(dev_num); TRACE_OUT } /* rw_loop *//* * get_brd_num - * * Get the board number from the serial port device number. * This is necessary for ioctl that requires to open the board * device. */ int get_brd_num(port) int port; { return(port/MAX_TERMS); }/* * enable_softcar - * * Enable soft carrier detect so if driver sees CD * in transition, won't close port. */void enable_softcar(port)int port;{ func_name = "enable_softcar"; TRACE_IN if (ioctl(sp_ports[port].fd, STC_GDEFAULTS, &sd) == FAIL) { send_message(0, ERROR, stc_gdefaults, sp_dev_name[port]); exit(errno); } send_message(0, TRACE, "before, sd.flags on %s = 0x%x\n", sp_dev_name[port],sd.flags); sd.flags |= SOFT_CARR; if (ioctl(sp_ports[port].fd, STC_SDEFAULTS, &sd) == FAIL) { send_message(0, ERROR, stc_sdefaults, sp_dev_name[port]); exit(errno); } send_message(0, TRACE, "after, sd.flags on %s = 0x%x\n", sp_dev_name[port],sd.flags); TRACE_OUT}/* * flush_io - * * Flush the serial/parallel port. Have to use SPC/S driver specific * ioctl for this instead of TCFLSH because there is a bug in the * sunos 4.1 (so I was told). To flush the printer port, the line * number used is the printer port number ored with 64. For serial * port, make sure the the port number is relative to each SPC/S * board (0-7). */voidflush_io(port)int port;{ int fd, brd; func_name = "flush_io"; TRACE_IN if (port < PP_LINE) { brd = get_brd_num(port); } else { brd = port ^ PP_LINE; } if ((fd=open(spif_dev_name[brd],O_RDWR|O_NDELAY)) != FAIL) { if (port < PP_LINE) /* serial port */ sd.line_no = port % MAX_TERMS; else /* parallel printer port */ sd.line_no = port; sd.op = STC_CFLUSH; if (ioctl(fd, STC_DCONTROL, &sd) == FAIL) { send_message(0, ERROR, stc_dcontrol, dev_name); exit(errno); } else send_message(0, TRACE, "Ioctl STC_CFLUSH on %s done\n", dev_name); } else { send_message(0, ERROR, open_err_msg, dev_name); exit(errno); } TRACE_OUT}voidsigint_handler(){ int pgrpid; send_message(0, ERROR, "Interrupted!\n"); if (kill(0,SIGTERM) != 0) { send_message(0, ERROR, "Can't kill all processes\n"); exit(errno); }}voidget_modem_bits(bits) int bits;{ char msignal[256]; if (bits & TIOCM_LE) strcpy(msignal, "TIOCM_LE "); if (bits & TIOCM_DTR) strcat(msignal, "TIOCM_DTR "); if (bits & TIOCM_RTS) strcat(msignal, "TIOCM_RTS "); if (bits & TIOCM_ST) strcat(msignal, "TIOCM_ST "); if (bits & TIOCM_SR) strcat(msignal, "TIOCM_SR "); if (bits & TIOCM_CTS) strcat(msignal, "TIOCM_CTS "); if (bits & TIOCM_CAR) strcat(msignal, "TIOCM_CAR "); if (bits & TIOCM_RI) strcat(msignal, "TIOCM_RI "); if (bits & TIOCM_DSR) strcat(msignal, "TIOCM_DSR "); send_message(0, ERROR, msignal);}static voiddata_timeout(){ if (current_test == DB_25 || current_test == SP_96) send_message(0, ERROR, lp_err_msg, sp_dev_name[dev_num]); if (current_test == ECHO_TTY) send_message(0, ERROR, tty_err_msg, sp_dev_name[dev_num]); if (current_test == INTERNAL) send_message(0, ERROR, timeout_err, sp_dev_name[dev_num]); exit(TIMEOUT_ERROR);}/* * clean_up(), contains necessary code to clean up resources before exiting. * Note: this function is always required in order to link with sdrtns.c * successfully. */clean_up(){ int i; func_name = "clean_up"; TRACE_IN TRACE_OUT return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -