[Ccom-develop] ccom/src comunix.c,1.2,1.3
Brought to you by:
chrisan,
rasmusmyklebust
From: Christer S. <ch...@us...> - 2005-09-18 17:15:56
|
Update of /cvsroot/ccomx/ccom/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21771/src Modified Files: comunix.c Log Message: removed dbug printouts Index: comunix.c =================================================================== RCS file: /cvsroot/ccomx/ccom/src/comunix.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comunix.c 16 Feb 2004 07:20:20 -0000 1.2 --- comunix.c 18 Sep 2005 17:15:44 -0000 1.3 *************** *** 1,150 **** ! /* Module COMUNIX ! This module contains the asynchronous commounication basics for ! UNIX only. */ ! #include <allegro.h> ! #ifdef ALLEGRO_UNIX ! ! #include <cgui.h> ! #include <termios.h> ! #include <sys/types.h> ! #include <sys/stat.h> ! #include <unistd.h> ! ! #include "common.h" ! #include "comx.h" ! #include "labldata.h" ! #include "dialser.ht" ! ! #define NR_FILE_ALTERANTIVES 6 ! static int OpenPort(t_serport *port) ! { ! static char *file_names[NR_FILE_ALTERANTIVES][4]={ ! {"/dev/tts/0", "/dev/tts/1", "/dev/tts/2", "/dev/tts/3"}, ! {"/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3"}, ! {"/dev/ttyf1", "/dev/ttyf2", "/dev/ttyf3", "/dev/ttyf4"}, ! {"/dev/ttya", "/dev/ttyb", "/dev/ttyc", "/dev/ttyd"}, ! {"/dev/tty1p0", "/dev/tty2p0", "/dev/tty3p0", "/dev/tty4p0"}, ! {"/dev/tty01", "/dev/tty02", "/dev/tty03", "/dev/tty04"}}; ! int i; ! ! if (port->fd > 0) ! return 1; ! if (port->fd < 0) ! return 0; ! for (i=0; i<NR_FILE_ALTERANTIVES; i++) { ! struct stat buf; ! if (stat(file_names[i][port->portno], &buf) == 0) { ! /* File exists */ ! port->fd = open(file_names[i][port->portno], O_RDWR | O_NOCTTY | O_NDELAY); ! if (port->fd > 0) { ! fcntl(port->fd, F_SETFL, FNDELAY); ! return 1; ! } else { ! static const char * const * txt; ! char s[1000]; ! int nr; ! txt = LoadCompiledTexts(ccom_labels, "dialser", &nr); ! sprintf(s, txt[L_ERROR_ACCESS_RIGHTS], port->portno+1, file_names[i][port->portno]); ! Req("", s); ! } ! } ! } ! return 0; ! } ! ! extern int _CcomReadPort(t_serport *port, unsigned char *c, unsigned char *error) ! { ! int n = 0; ! ! if (port->fd == 0) ! OpenPort(port); ! *error = 0; ! n = read(port->fd, &c, 1); ! if (n < 0) { ! n = 0; ! *error = 1; ! } ! if (n) { ! char s[100]; ! sprintf(s, "number:%2x|OK", n); ! Req("",s);} ! return n; ! } ! ! extern int _CcomWritePort(t_serport *port, int c) ! { ! int n = 0; ! ! if (port->fd == 0) ! OpenPort(port); ! n = write(port->fd, &c, 1); ! return n; ! } ! ! extern void _CcomSetBaud(t_serport *port) ! { ! struct termios options; ! int baud; ! ! tcgetattr(port->fd, &options); ! switch (port->baud_rate) { ! case 50: baud = B50; break; ! case 75: baud = B75; break; ! case 110: baud = B110; break; ! case 134: baud = B134; break; ! case 150: baud = B150; break; ! case 200: baud = B200; break; ! case 300: baud = B300; break; ! case 600: baud = B600; break; ! case 1200: baud = B1200; break; ! case 1800: baud = B1800; break; ! case 2400: baud = B2400; break; ! case 4800: baud = B4800; break; ! case 9600: baud = B9600; break; ! case 19200: baud = B19200; break; ! case 38400: baud = B38400; break; ! case 57600: baud = B57600; break; ! case 115200: baud = B115200; break; ! case 230400: baud = B230400; break; ! default: baud = B0; break; ! } ! cfsetispeed(&options, baud); ! cfsetospeed(&options, baud); ! options.c_cflag |= (CLOCAL | CREAD); ! tcsetattr(port->fd, TCSANOW, &options); ! } ! ! extern void _CcomApplySettingsToPort(t_serport *port) ! { ! struct termios options; ! ! tcgetattr(port->fd, &options); ! options.c_cflag &= ~CSIZE; ! options.c_cflag &= ~CSTOPB; ! options.c_cflag &= ~PARENB; ! options.c_cflag &= ~PARODD; ! options.c_iflag &= ~(INPCK | ISTRIP); ! switch (port->nobits) { ! case 5: options.c_cflag |= CS5; break; ! case 6: options.c_cflag |= CS6; break; ! case 7: options.c_cflag |= CS7; break; ! default: options.c_cflag |= CS8; break; ! } ! if (port->parityena) { ! options.c_cflag |= PARENB; ! options.c_iflag |= INPCK | ISTRIP; ! } ! if (port->parity==0) ! options.c_cflag |= PARODD; ! if (port->stopbits==2) ! options.c_cflag |= CSTOPB; ! options.c_cflag |= CLOCAL | CREAD; ! options.c_lflag &= ~ICANON | ECHO | ECHOE | ISIG; ! options.c_oflag &= ~OPOST; ! tcsetattr(port->fd, TCSANOW, &options); ! } ! ! extern void _CcomLoopBackMode(t_serport *port, int mode) ! { ! } ! #endif --- 1,146 ---- ! /* Module COMUNIX ! This module contains the asynchronous commounication basics for ! UNIX only. */ ! #include <allegro.h> ! #ifdef ALLEGRO_UNIX ! ! #include <cgui.h> ! #include <termios.h> ! #include <sys/types.h> ! #include <sys/stat.h> ! #include <unistd.h> ! ! #include "common.h" ! #include "comx.h" ! #include "labldata.h" ! #include "dialser.ht" ! ! #define NR_FILE_ALTERANTIVES 6 ! static int OpenPort(t_serport *port) ! { ! static char *file_names[NR_FILE_ALTERANTIVES][4]={ ! {"/dev/tts/0", "/dev/tts/1", "/dev/tts/2", "/dev/tts/3"}, ! {"/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3"}, ! {"/dev/ttyf1", "/dev/ttyf2", "/dev/ttyf3", "/dev/ttyf4"}, ! {"/dev/ttya", "/dev/ttyb", "/dev/ttyc", "/dev/ttyd"}, ! {"/dev/tty1p0", "/dev/tty2p0", "/dev/tty3p0", "/dev/tty4p0"}, ! {"/dev/tty01", "/dev/tty02", "/dev/tty03", "/dev/tty04"}}; ! int i; ! ! if (port->fd > 0) ! return 1; ! if (port->fd < 0) ! return 0; ! for (i=0; i<NR_FILE_ALTERANTIVES; i++) { ! struct stat buf; ! if (stat(file_names[i][port->portno], &buf) == 0) { ! /* File exists */ ! port->fd = open(file_names[i][port->portno], O_RDWR | O_NOCTTY | O_NDELAY); ! if (port->fd > 0) { ! fcntl(port->fd, F_SETFL, FNDELAY); ! return 1; ! } else { ! static const char * const * txt; ! char s[1000]; ! int nr; ! txt = LoadCompiledTexts(ccom_labels, "dialser", &nr); ! sprintf(s, txt[L_ERROR_ACCESS_RIGHTS], port->portno+1, file_names[i][port->portno]); ! Req("", s); ! } ! } ! } ! return 0; ! } ! ! extern int _CcomReadPort(t_serport *port, unsigned char *c, unsigned char *error) ! { ! int n = 0; ! ! if (port->fd == 0) ! OpenPort(port); ! *error = 0; ! n = read(port->fd, &c, 1); ! if (n < 0) { ! n = 0; ! *error = 1; ! } ! return n; ! } ! ! extern int _CcomWritePort(t_serport *port, int c) ! { ! int n = 0; ! ! if (port->fd == 0) ! OpenPort(port); ! n = write(port->fd, &c, 1); ! return n; ! } ! ! extern void _CcomSetBaud(t_serport *port) ! { ! struct termios options; ! int baud; ! ! tcgetattr(port->fd, &options); ! switch (port->baud_rate) { ! case 50: baud = B50; break; ! case 75: baud = B75; break; ! case 110: baud = B110; break; ! case 134: baud = B134; break; ! case 150: baud = B150; break; ! case 200: baud = B200; break; ! case 300: baud = B300; break; ! case 600: baud = B600; break; ! case 1200: baud = B1200; break; ! case 1800: baud = B1800; break; ! case 2400: baud = B2400; break; ! case 4800: baud = B4800; break; ! case 9600: baud = B9600; break; ! case 19200: baud = B19200; break; ! case 38400: baud = B38400; break; ! case 57600: baud = B57600; break; ! case 115200: baud = B115200; break; ! case 230400: baud = B230400; break; ! default: baud = B0; break; ! } ! cfsetispeed(&options, baud); ! cfsetospeed(&options, baud); ! options.c_cflag |= (CLOCAL | CREAD); ! tcsetattr(port->fd, TCSANOW, &options); ! } ! ! extern void _CcomApplySettingsToPort(t_serport *port) ! { ! struct termios options; ! ! tcgetattr(port->fd, &options); ! options.c_cflag &= ~CSIZE; ! options.c_cflag &= ~CSTOPB; ! options.c_cflag &= ~PARENB; ! options.c_cflag &= ~PARODD; ! options.c_iflag &= ~(INPCK | ISTRIP); ! switch (port->nobits) { ! case 5: options.c_cflag |= CS5; break; ! case 6: options.c_cflag |= CS6; break; ! case 7: options.c_cflag |= CS7; break; ! default: options.c_cflag |= CS8; break; ! } ! if (port->parityena) { ! options.c_cflag |= PARENB; ! options.c_iflag |= INPCK | ISTRIP; ! } ! if (port->parity==0) ! options.c_cflag |= PARODD; ! if (port->stopbits==2) ! options.c_cflag |= CSTOPB; ! options.c_cflag |= CLOCAL | CREAD; ! options.c_lflag &= ~ICANON | ECHO | ECHOE | ISIG; ! options.c_oflag &= ~OPOST; ! tcsetattr(port->fd, TCSANOW, &options); ! } ! ! extern void _CcomLoopBackMode(t_serport *port, int mode) ! { ! } ! #endif |