mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 09:22:18 +00:00
gps read optimization
This commit is contained in:
committed by
Lorenz Meier
parent
fe40e9cfae
commit
4c04b7bb53
@@ -399,9 +399,16 @@ int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout)
|
||||
* We are here because poll says there is some data, so this
|
||||
* won't block even on a blocking device. But don't read immediately
|
||||
* by 1-2 bytes, wait for some more data to save expensive read() calls.
|
||||
* If we have all requested data available, read it without waiting.
|
||||
* If more bytes are available, we'll go back to poll() again.
|
||||
*/
|
||||
usleep(GPS_WAIT_BEFORE_READ * 1000);
|
||||
int err = 0, bytesAvailable = 0;
|
||||
err = ioctl(_serial_fd, FIONREAD, (unsigned long)&bytesAvailable);
|
||||
|
||||
if ((err != 0) || (bytesAvailable < buf_length)) {
|
||||
usleep(GPS_WAIT_BEFORE_READ * 1000);
|
||||
}
|
||||
|
||||
ret = ::read(_serial_fd, buf, buf_length);
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user