Changeset 1246
- Timestamp:
- 01/16/10 10:58:30 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/csctapi/io_serial.c
r1240 r1246 160 160 { 161 161 IO_Serial *io; 162 162 163 163 io = (IO_Serial *) malloc (sizeof (IO_Serial)); 164 164 165 165 if (io != NULL) 166 166 IO_Serial_Clear (io); 167 167 168 168 return io; 169 169 } … … 171 171 bool IO_Serial_Init (IO_Serial * io, int reader_type) 172 172 { 173 if (reader[ridx].typ != R_INTERNAL)173 if (reader[ridx].typ != reader_type) 174 174 IO_Serial_InitPnP (io); 175 176 if(reader[ridx].typ !=R_INTERNAL)175 176 if(reader[ridx].typ != reader_type) 177 177 IO_Serial_Flush(); 178 178 179 179 return TRUE; 180 180 } … … 193 193 if (io->input_bitrate != 0 && io->output_bitrate != 0) //properties are already filled 194 194 return TRUE; 195 195 196 196 if (tcgetattr (reader[ridx].handle, &currtio) != 0) 197 197 return FALSE; 198 198 199 199 o_speed = cfgetospeed (&currtio); 200 200 201 201 switch (o_speed) 202 202 { … … 302 302 303 303 i_speed = cfgetispeed (&currtio); 304 304 305 305 switch (i_speed) 306 306 { … … 404 404 break; 405 405 } 406 406 407 407 switch (currtio.c_cflag & CSIZE) 408 408 { … … 420 420 break; 421 421 } 422 422 423 423 if (((currtio.c_cflag) & PARENB) == PARENB) 424 424 { … … 432 432 io->parity = PARITY_NONE; 433 433 } 434 434 435 435 if (((currtio.c_cflag) & CSTOPB) == CSTOPB) 436 436 io->stopbits = 2; 437 437 else 438 438 io->stopbits = 1; 439 439 440 440 if (ioctl (reader[ridx].handle, TIOCMGET, &mctl) < 0) 441 441 return FALSE; 442 442 443 443 io->dtr = ((mctl & TIOCM_DTR) ? IO_SERIAL_HIGH : IO_SERIAL_LOW); 444 444 io->rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW); 445 445 446 446 #ifdef DEBUG_IO 447 447 printf("IO: Getting properties: %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts); 448 448 #endif 449 449 450 450 return TRUE; 451 451 } … … 454 454 { 455 455 struct termios newtio; 456 456 457 457 #ifdef SCI_DEV 458 458 if(reader[ridx].typ == R_INTERNAL) 459 459 return FALSE; 460 460 #endif 461 461 462 462 // printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts); 463 463 memset (&newtio, 0, sizeof (newtio)); … … 480 480 int custom_baud = io->output_bitrate * reader[ridx].mhz / reader[ridx].cardmhz; 481 481 nuts.custom_divisor = (nuts.baud_base + (custom_baud/2))/ custom_baud; 482 cs_debug("custom baudrate: cardmhz=%d mhz=%d custom_baud=%d baud_base=%d divisor=%d -> effective baudrate %d", 482 cs_debug("custom baudrate: cardmhz=%d mhz=%d custom_baud=%d baud_base=%d divisor=%d -> effective baudrate %d", 483 483 reader[ridx].cardmhz, reader[ridx].mhz, custom_baud, nuts.baud_base, nuts.custom_divisor, nuts.baud_base/nuts.custom_divisor); 484 484 nuts.flags &= ~ASYNC_SPD_MASK; … … 489 489 } 490 490 #endif 491 491 492 492 /* Set the character size */ 493 493 switch (io->bits) … … 496 496 newtio.c_cflag |= CS5; 497 497 break; 498 498 499 499 case 6: 500 500 newtio.c_cflag |= CS6; 501 501 break; 502 502 503 503 case 7: 504 504 newtio.c_cflag |= CS7; 505 505 break; 506 506 507 507 case 8: 508 508 newtio.c_cflag |= CS8; 509 509 break; 510 510 } 511 511 512 512 /* Set the parity */ 513 513 switch (io->parity) … … 517 517 newtio.c_cflag |= PARODD; 518 518 break; 519 520 case PARITY_EVEN: 519 520 case PARITY_EVEN: 521 521 newtio.c_cflag |= PARENB; 522 522 newtio.c_cflag &= ~PARODD; 523 523 break; 524 524 525 525 case PARITY_NONE: 526 526 newtio.c_cflag &= ~PARENB; 527 527 break; 528 528 } 529 529 530 530 /* Set the number of stop bits */ 531 531 switch (io->stopbits) … … 538 538 break; 539 539 } 540 540 541 541 /* Selects raw (non-canonical) input and output */ 542 542 newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); … … 548 548 /* Enable receiber, hang on close, ignore control line */ 549 549 newtio.c_cflag |= CREAD | HUPCL | CLOCAL; 550 550 551 551 /* Read 1 byte minimun, no timeout specified */ 552 552 newtio.c_cc[VMIN] = 1; … … 564 564 IO_Serial_DTR_RTS(1, io->dtr == IO_SERIAL_HIGH); 565 565 IO_Serial_Ioctl_Lock(0); 566 566 567 567 #ifdef DEBUG_IO 568 568 printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts); … … 585 585 if (ioctl (reader[ridx].handle, TIOCMGET, &mctl) < 0) 586 586 return FALSE; 587 587 588 588 int dtr = ((mctl & TIOCM_DTR) ? IO_SERIAL_HIGH : IO_SERIAL_LOW); 589 589 int rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW); … … 636 636 parity == PARITY_EVEN ? "Even" : "Invalid"); 637 637 #endif 638 638 639 639 if (current_parity != parity) 640 640 { … … 647 647 tio.c_cflag |= PARODD; 648 648 break; 649 650 case PARITY_EVEN: 649 650 case PARITY_EVEN: 651 651 tio.c_cflag |= PARENB; 652 652 tio.c_cflag &= ~PARODD; 653 653 break; 654 654 655 655 case PARITY_NONE: 656 656 tio.c_cflag &= ~PARENB; … … 685 685 struct timeval tv, tv_spent; 686 686 #endif 687 687 688 688 if((reader[ridx].typ != R_INTERNAL) && (wr>0)) 689 689 { … … 691 691 int n = wr; 692 692 wr = 0; 693 693 694 694 if(!IO_Serial_Read (timeout, n, buf)) 695 695 { … … 697 697 } 698 698 } 699 699 700 700 #ifdef DEBUG_IO 701 701 printf ("IO: Receiving: "); … … 718 718 } 719 719 if(!readed) return FALSE; 720 720 721 721 data[_in_echo_read ? count/(1+io_serial_need_dummy_char) : count] = c; 722 722 #ifdef DEBUG_IO … … 736 736 } 737 737 data[_in_echo_read ? count/(1+io_serial_need_dummy_char) : count] = c; 738 738 739 739 #ifdef DEBUG_IO 740 740 printf ("%X ", c); … … 753 753 #endif 754 754 } 755 755 756 756 _in_echo_read = 0; 757 757 … … 760 760 fflush (stdout); 761 761 #endif 762 762 763 763 return TRUE; 764 764 } … … 773 773 #ifdef DEBUG_IO 774 774 unsigned i; 775 775 776 776 printf ("IO: Sending: "); 777 777 fflush (stdout); … … 779 779 /* Discard input data from previous commands */ 780 780 // tcflush (reader[ridx].handle, TCIFLUSH); 781 781 782 782 for (count = 0; count < size; count += to_send) 783 783 { … … 786 786 // else 787 787 to_send = (delay? 1: size); 788 788 789 789 if (IO_Serial_WaitToWrite (delay, 1000)) 790 790 { … … 807 807 return FALSE; 808 808 } 809 809 810 810 if(reader[ridx].typ != R_INTERNAL) 811 811 wr += to_send; 812 812 813 813 #ifdef DEBUG_IO 814 814 for (i=0; i<(1+io_serial_need_dummy_char)*to_send; i++) … … 827 827 } 828 828 } 829 829 830 830 #ifdef DEBUG_IO 831 831 printf ("\n"); 832 832 fflush (stdout); 833 833 #endif 834 834 835 835 return TRUE; 836 836 } … … 838 838 bool IO_Serial_Close (IO_Serial * io) 839 839 { 840 840 841 841 #ifdef DEBUG_IO 842 842 printf ("IO: Clossing serial port %s\n", reader[ridx].device); 843 843 #endif 844 844 845 845 #if defined(TUXBOX) && defined(PPC) 846 846 close(fdmc); … … 848 848 if (close (reader[ridx].handle) != 0) 849 849 return FALSE; 850 850 851 851 IO_Serial_Clear (io); 852 852 853 853 return TRUE; 854 854 } … … 927 927 int select_ret; 928 928 int in_fd; 929 929 930 930 if (delay_ms > 0) 931 931 { 932 932 #ifdef HAVE_NANOSLEEP 933 933 struct timespec req_ts; 934 934 935 935 req_ts.tv_sec = delay_ms / 1000; 936 936 req_ts.tv_nsec = (delay_ms % 1000) * 1000000L; … … 940 940 #endif 941 941 } 942 942 943 943 in_fd=reader[ridx].handle; 944 944 945 945 FD_ZERO(&rfds); 946 946 FD_SET(in_fd, &rfds); 947 947 948 948 FD_ZERO(&erfds); 949 949 FD_SET(in_fd, &erfds); 950 950 951 951 tv.tv_sec = timeout_ms/1000; 952 952 tv.tv_usec = (timeout_ms % 1000) * 1000L; … … 978 978 int select_ret; 979 979 int out_fd; 980 980 981 981 #ifdef SCI_DEV 982 982 if(reader[ridx].typ == R_INTERNAL) 983 983 return TRUE; 984 984 #endif 985 985 986 986 if (delay_ms > 0) 987 987 { 988 988 #ifdef HAVE_NANOSLEEP 989 989 struct timespec req_ts; 990 990 991 991 req_ts.tv_sec = delay_ms / 1000; 992 992 req_ts.tv_nsec = (delay_ms % 1000) * 1000000L; … … 998 998 999 999 out_fd=reader[ridx].handle; 1000 1000 1001 1001 FD_ZERO(&wfds); 1002 1002 FD_SET(out_fd, &wfds); 1003 1003 1004 1004 FD_ZERO(&ewfds); 1005 1005 FD_SET(out_fd, &ewfds); 1006 1006 1007 1007 tv.tv_sec = timeout_ms/1000L; 1008 1008 tv.tv_usec = (timeout_ms % 1000) * 1000L; … … 1027 1027 1028 1028 return(FD_ISSET(out_fd,&wfds)); 1029 1029 1030 1030 } 1031 1031 … … 1057 1057 io->dtr = IO_SERIAL_HIGH; 1058 1058 io->rts = IO_SERIAL_LOW; 1059 1059 1060 1060 if (!IO_Serial_SetPropertiesOld (io)) 1061 1061 return FALSE; … … 1067 1067 return TRUE; 1068 1068 } 1069 1069
Note:
See TracChangeset
for help on using the changeset viewer.