From 48747be494e0b70de771cf2e03ef4b3899138841 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Jul 2018 09:36:55 +1000 Subject: [PATCH] HAL_VRBrain: don't clear buffers on no baud change --- libraries/AP_HAL_VRBRAIN/UARTDriver.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/AP_HAL_VRBRAIN/UARTDriver.cpp b/libraries/AP_HAL_VRBRAIN/UARTDriver.cpp index 5fc48e6ed5..6e0d2e97d7 100644 --- a/libraries/AP_HAL_VRBRAIN/UARTDriver.cpp +++ b/libraries/AP_HAL_VRBRAIN/UARTDriver.cpp @@ -77,15 +77,24 @@ void VRBRAINUARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS) _initialised = false; _readbuf.set_size(rxS); } - if (hal.console != this) { // don't clear USB buffers (allows early startup messages to escape) - _readbuf.clear(); - } + bool clear_buffers = false; + if (b != 0) { + // clear buffers on baudrate change, but not on the console (which is usually USB) + if (_baudrate != b && hal.console != this) { + clear_buffers = true; + } + _baudrate = b; + } if (b != 0) { _baudrate = b; } + if (clear_buffers) { + _readbuf.clear(); + } + /* allocate the write buffer */ @@ -96,7 +105,8 @@ void VRBRAINUARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS) _initialised = false; _writebuf.set_size(txS); } - if (hal.console != this) { // don't clear USB buffers (allows early startup messages to escape) + + if (clear_buffers) { _writebuf.clear(); }