#include #include #include #include #include #include #include #include #include "IR_Device.h" IR_Device::IR_Device() { fd = -1; fd=open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK, 0); if(fd!=-1) set_ser_param(); } int IR_Device::set_ser_param() { /* see: man termios(3) */ struct termios options; tcgetattr(fd, &options); #if 0 cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); #endif cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); options.c_cflag &= ~PARENB; options.c_cflag |= CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; /* disable hardware flow control - would be */ options.c_cflag &= ~CRTSCTS; options.c_cflag |= CREAD; options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_iflag=(IMAXBEL | IGNBRK); options.c_oflag=0; options.c_cc[VTIME]='\0'; options.c_cc[VMIN]='\0'; tcsetattr(fd, TCSANOW, &options); /* Flush serial */ ioctl(fd, TCFLSH, 0); return 0; } IR_Device::~IR_Device() { close(fd); } int IR_Device::in(BYTE *palavra) { int i; for(i=0;i<100;i++) { if(read(fd,palavra,1)==1) return 0; } return -1; } int IR_Device::out(BYTE palavra) { if(write(fd, &palavra, 1)!=1) return -1; else return 0; } int IR_Device::get_baud(int *retorno){ *retorno = 9600; return 0; } int IR_Device::set_baud(int valor){ return 0; } int IR_Device::get_status(int *status){ *status = 0; return 0; }