int AsyncTCPSocketNormal::Send(const void* pv, size_t cb, talk_base::DiffServCodePoint dscp) { if (cb > kBufSize) { SetError(EMSGSIZE); return -1; } // If we are blocking on send, then silently drop this packet if (!IsOutBufferEmpty()) return static_cast<int>(cb); //PacketLength pkt_len = HostToNetwork16(static_cast<PacketLength>(cb)); //AppendToOutBuffer(&pkt_len, kPacketLenSize); AppendToOutBuffer(pv, cb); int res = FlushOutBuffer(); if (res <= 0) { // drop packet if we made no progress ClearOutBuffer(); return res; } // We claim to have sent the whole thing, even if we only sent partial return static_cast<int>(cb); }
int SerialDevice::openPort(std::string device, int baud, int Parity, int StopBits) { int BAUD, DATABITS, STOPBITS, PARITYON, PARITY; struct termios config; // Adapt baud to termios.h baudrate enum switch(baud) { case 57600: BAUD = B57600; break; case 38400: BAUD = B38400; break; case 19200: BAUD = B19200; break; case 9600: default: //If incorrect value is entered, baud will be defaulted to 9600 BAUD = B9600; break; } switch (Parity) { case 0: default: //none PARITYON = 0; PARITY = 0; break; case 1: //odd PARITYON = PARENB; PARITY = PARODD; break; case 2: //even PARITYON = PARENB; PARITY = 0; break; } device = device.insert(0,"/dev/"); /// inserts '/dev/' infront of device name /// attempt to open the serial device fd_ = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY); /// open(2) returns <0 if the port could NOT be opened if (fd_ == -1 ) { return -1; } /// linux serial port stuff // int flags; // flags = fcntl(m_fd,F_GETFL,0); fcntl(fd_, F_SETFL, 0);// flags | O_NONBLOCK); /// O_NONBLOCK makes read return even if there is no data tcgetattr(fd_, &config); /// sets serial port baudrate cfsetispeed(&config, BAUD); /// for input cfsetospeed(&config, BAUD); /// for output /// adjust stop bits STOPBITS = StopBits; /// set data to 8-bit DATABITS = CS8; /// load configuration. tcsetattr(3) returns <0 if error // //config.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //Raw mode (no processing) config.c_cflag &= ~CRTSCTS; //Disable hw flow ctrl config.c_cflag = BAUD | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD; config.c_iflag |= INPCK | ISTRIP ; // Enable parity checking and take away partiy bit config.c_iflag &= ~(IXON | IXOFF | IXANY ); //SW flow control disabled config.c_oflag = 0; config.c_lflag |= ICANON | ISIG ; /// Canonical mode //config.c_cc[VMIN] = 32; // config.c_cc[VTIME] = 1; //timeout after 3s without receiving new characters*/ /// load configuration. tcsetattr(3) returns <0 if error if(tcsetattr(fd_, TCSANOW, &config) < 0) { return -1; } /// alles richtig! FlushInBuffer(); FlushOutBuffer(); PutString("E\n"); return 0; }