14 #define HAS_GETOPT_LONG 1
16 #define MEM_BUF_LEN 0x40000
18 unsigned char mem_buf[MEM_BUF_LEN];
20 int rs232_loop_test(char *sdev, int baud, int flowc);
22 struct termios init_saved_termios;
30 printf("usage: tohit <parameters> <send_file>\n");
31 printf(" -d, --sdev <name> name of RS232 device [%s]\n",tohit_sdev);
32 printf(" -B, --baud <num> RS232 baudrate [%d]\n",tohit_baud);
33 printf(" -f, --flowc-rts flow control\n");
34 printf(" -V, --version show version\n");
35 printf(" -h, --help this usage screen\n");
38 int main(int argc, char **argv)
42 static struct option long_opts[] = {
43 { "sdev", 1, 0, 'd' },
44 { "baud", 1, 0, 'B' },
45 { "flowc-rts",0, 0, 'f' },
46 { "version",0,0, 'V' },
47 { "help", 0, 0, 'h' },
55 #ifndef HAS_GETOPT_LONG
56 while ((opt = getopt(argc, argv, "d:B:fVh")) != EOF)
58 while ((opt = getopt_long(argc, argv, "d:B:fVh",
59 &long_opts[0], NULL)) != EOF)
66 tohit_baud = strtol(optarg,NULL,0);
72 fputs("tohit pre alpha\n", stdout);
77 exit(opt == 'h' ? 0 : 1);
82 /*tcgetattr(0, &init_saved_termios);*/
83 initscr(); cbreak(); noecho();
84 nonl(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE);
85 nodelay(stdscr, TRUE);
87 ret=rs232_loop_test(tohit_sdev,tohit_baud,flowc);
95 int rs232_loop_test(char *sdev, int baud, int flowc)
99 unsigned char *pout=NULL, *pin=NULL, uc;
100 int cntout=0,cntin=0, cnt;
101 int i, test_loop_fl=0;
107 /* Open RS232 device */
108 if ((fd = open(sdev, O_RDWR | O_NONBLOCK)) == -1) {
109 printf("Error openning %s\n",sdev);
113 /* Set RS232 device mode and speed */
114 if(rs232_setmode(fd,baud,0,flowc)<0){
115 printf("Error in rs232_setmode\n");
120 rs232_sendch(int fd,unsigned char c);
122 rs232_test(int fd,int time);
125 mvprintw(/*y*/2,/*x*/2,"Test of RS-232 transfers");
134 if(cnt>MEM_BUF_LEN) cnt=MEM_BUF_LEN;
141 mvprintw(/*y*/11,/*x*/0,"Loop test : %s",
143 mvprintw(/*y*/9,/*x*/0," ");
144 mvprintw(/*y*/10,/*x*/0," ");
153 if(write(fd, pout, 1) == 1) {
159 if(read(fd, &uc, 1) == 1) {
162 mvprintw(/*y*/9,/*x*/0,"Diff : %02X != %02X",uc,*pin);
163 mvprintw(/*y*/10,/*x*/0,"Errors : %4d",errorcnt);
169 if(!cntin&&!cntout) {
170 mvprintw(/*y*/11,/*x*/0,"Loop test : %s",
171 errorcnt?"Failed ":"Passed ");
177 mvprintw(/*y*/8,/*x*/0,"Cnt Out: %6d In : %6d %s",
178 cntout,cntin,stopin?"Stop":" ");
180 } while(c!=KEY_F(10));