int setup_serial_port() { struct termios newtio; char serialPort[32]; ini_gets("sms","usbserial","/dev/ttyUSB0", serialPort, sizeof(serialPort), inifile); info("Using serial device %s", serialPort); g_serial_fd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY); die_if(g_serial_fd < 0, "Unable to open the serial port %s",serialPort); if(flock(g_serial_fd, LOCK_EX | LOCK_NB) == -1) { close(g_serial_fd); die_strerror("Serial port %s in use", serialPort); } bzero(&newtio, sizeof(newtio)); newtio.c_cflag = getBaud() | CRTSCTS | CS8 | CLOCAL | CREAD | O_NDELAY; // uncomment next line to disable hardware handshake newtio.c_cflag &= ~CRTSCTS; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = 0; newtio.c_cc[VTIME] = 1; newtio.c_cc[VMIN] = 0; /* no blocking read */ tcflush(g_serial_fd, TCIOFLUSH); tcsetattr(g_serial_fd, TCSANOW, &newtio); return g_serial_fd; }
static void start_wire_server_thread(struct wire_server *wire_server) { pthread_t thread; /* pthread thread handle */ int err; DEBUGP("start_wire_server_thread\n"); if ((err = pthread_create(&thread, NULL, wire_server_thread, wire_server)) != 0) { die_strerror("pthread_create", err); } }