From 1d1af5fd6895a3dac34ebd76f750f7b890015701 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Jul 2018 09:36:45 +1000 Subject: [PATCH] HAL_Linux: don't clear buffers on no baud change --- libraries/AP_HAL_Linux/UARTDriver.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libraries/AP_HAL_Linux/UARTDriver.cpp b/libraries/AP_HAL_Linux/UARTDriver.cpp index f8308ddaa1..0955f3a0a4 100644 --- a/libraries/AP_HAL_Linux/UARTDriver.cpp +++ b/libraries/AP_HAL_Linux/UARTDriver.cpp @@ -86,9 +86,20 @@ void UARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS) _device->set_speed(b); - _baudrate = b; + bool clear_buffers = false; + if (b != 0) { + if (_baudrate != b && hal.console != this) { + clear_buffers = true; + } + _baudrate = b; + } _allocate_buffers(rxS, txS); + + if (clear_buffers) { + _readbuf.clear(); + _writebuf.clear(); + } } void UARTDriver::_allocate_buffers(uint16_t rxS, uint16_t txS) @@ -108,10 +119,6 @@ void UARTDriver::_allocate_buffers(uint16_t rxS, uint16_t txS) if (_writebuf.set_size(txS) && _readbuf.set_size(rxS)) { _initialised = true; } - if (hal.console != this) { // don't clear USB buffers (allows early startup messages to escape) - _readbuf.clear(); - _writebuf.clear(); - } } void UARTDriver::_deallocate_buffers()