35 #include <sys/select.h> 64 struct termios options, oldopt;
66 bzero(&options,
sizeof(
struct termios));
70 if (termbaud == (
_u32)-1)
75 cfsetispeed(&options, termbaud);
76 cfsetospeed(&options, termbaud);
79 options.c_cflag |= (CLOCAL | CREAD);
81 options.c_cflag &= ~PARENB;
82 options.c_cflag &= ~CSTOPB;
84 options.c_cflag &= ~CSIZE;
85 options.c_cflag |= CS8;
88 options.c_cflag &= ~CNEW_RTSCTS;
91 options.c_iflag &= ~(IXON | IXOFF | IXANY);
94 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
96 options.c_oflag &= ~OPOST;
105 if (tcsetattr(
serial_fd, TCSANOW, &options))
132 if (
data ==
nullptr ||
size == 0)
return 0;
140 if (ans == -1)
return tx_len;
144 }
while (tx_len <
size);
155 if (ans == -1) ans = 0;
176 size_t data_count,
_u32 timeout,
size_t* returned_size)
179 if (returned_size ==
nullptr) returned_size = (
size_t*)&
length;
184 struct timeval timeout_val;
192 timeout_val.tv_sec = timeout / 1000;
193 timeout_val.tv_usec = (timeout % 1000) * 1000;
198 if (*returned_size >= data_count)
207 int n = ::select(max_fd, &input_set,
nullptr,
nullptr, &timeout_val);
224 if (ioctl(
serial_fd, FIONREAD, returned_size) == -1)
226 if (*returned_size >= data_count)
233 timeout_val.tv_sec * 1000000 + timeout_val.tv_usec;
234 int expect_remain_time =
235 (data_count - *returned_size) * 1000000 * 8 /
_baudrate;
236 if (remain_timeout > expect_remain_time)
237 usleep(expect_remain_time);
250 if (::ioctl(
serial_fd, FIONREAD, &remaining) == -1)
return 0;
279 #define BAUD_CONV(_baud_) \ size_t rxqueue_count() override
bool bind(const char *portname, uint32_t baudrate, uint32_t flags=0) override
#define BAUD_CONV(_baud_)
static serial_rxtx * CreateRxTx()
static void ReleaseRxTx(serial_rxtx *)
volatile bool _is_serial_opened
int waitforsent(_u32 timeout=-1, size_t *returned_size=nullptr) override
int waitfordata(size_t data_count, _u32 timeout=-1, size_t *returned_size=nullptr) override
int senddata(const unsigned char *data, size_t size) override
_u32 getTermBaudBitmap(_u32 baud)
void flush(_u32 flags) override
GLuint GLsizei GLsizei * length
int waitforrecv(_u32 timeout=-1, size_t *returned_size=nullptr) override
unsigned __int32 uint32_t
GLsizei GLsizei GLenum GLenum const GLvoid * data
int recvdata(unsigned char *data, size_t size) override