mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-29 17:34:07 +08:00
gps read optimization
This commit is contained in:
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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user