I'm trying to create two classes in C++. Each class implements different serial and its function that is called when it receives a data on the serial port.
Class 1:
int serialLn = open("/dev/ttyS2", O_RDWR | O_NONBLOCK | O_NOCTTY);
struct termios options;
struct serial_struct serInfo;
struct sigaction saio;
//Serial speed for loconet
int rate = 16666;
saio.sa_handler = loconetInterruptRX;
sigemptyset(&saio.sa_mask);
saio.sa_flags = 0;
sigaction(SIGIO,&saio,NULL);
fcntl(serialLn, F_SETFL, FASYNC);
fcntl(serialLn, F_SETOWN, getpid());
// Custom divisor
serInfo.reserved_char[0] = 0;
ioctl(serialLn, TIOCGSERIAL, &serInfo);
serInfo.flags &= ~ASYNC_SPD_MASK;
serInfo.flags |= ASYNC_SPD_CUST;
serInfo.custom_divisor = (serInfo.baud_base + (rate / 2)) / rate;
options.c_cflag = B38400 | (CS8 | CREAD);
options.c_iflag = 0;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 0;
tcsetattr(serialLn, TCSANOW, &options);
tcflush(serialLn, TCIFLUSH);
Class 2:
int serialCZ = open("/dev/ttyS1", O_RDWR | O_NONBLOCK | O_NOCTTY);
struct termios options;
struct serial_struct serInfo;
struct sigaction saio;
saio.sa_handler = cz1InterruptRX;
sigemptyset(&saio.sa_mask);
saio.sa_flags = 0;
sigaction(SIGIO, &saio, NULL);
fcntl(serialCZ, F_SETFL, FASYNC);
fcntl(serialCZ, F_SETOWN, getpid());
//Serial setting
options.c_cflag = B115200 | (CS8 | CREAD);
options.c_iflag = 0;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 0;
tcsetattr(serialCZ, TCSANOW, &options);
tcflush(serialCZ, TCIFLUSH);
The problem is: When sending data on a serial ttyS2 (class 1) the called method is cz1InterruptRX of Class 2 (and not loconetInterruptRX).
If I do not include in the execution class 2 the progam is working properly.
How can I fix?
thanks