mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 18:08:30 -04:00
AP_HAL_PX4: UARTDriver: fix writting with failures
When the buffer wraps and we do it in 2 steps, we can't actually do the second part if it fails or if we wrote less bytes than we intended, otherwise we will corrupt the data being sent. While at it, just like in the write case, explain why we are stopping.
This commit is contained in:
parent
4346f1dd83
commit
4df627693d
@ -445,8 +445,15 @@ void PX4UARTDriver::_timer_tick(void)
|
||||
const auto n_vec = _writebuf.peekiovec(vec, n);
|
||||
for (int i = 0; i < n_vec; i++) {
|
||||
ret = _write_fd(vec[i].data, (uint16_t)vec[i].len);
|
||||
if (ret > 0)
|
||||
_writebuf.advance(ret);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
_writebuf.advance(ret);
|
||||
|
||||
/* We wrote less than we asked for, stop */
|
||||
if ((unsigned)ret != vec[i].len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
perf_end(_perf_uart);
|
||||
}
|
||||
@ -458,11 +465,15 @@ void PX4UARTDriver::_timer_tick(void)
|
||||
const auto n_vec = _readbuf.reserve(vec, _readbuf.space());
|
||||
for (int i = 0; i < n_vec; i++) {
|
||||
ret = _read_fd(vec[i].data, vec[i].len);
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
_readbuf.commit((unsigned)ret);
|
||||
if ((unsigned)ret < vec[i].len)
|
||||
|
||||
/* stop reading as we read less than we asked for */
|
||||
if ((unsigned)ret < vec[i].len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
perf_end(_perf_uart);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user