Add flush to the BLE UART Service

If only buffer-full events and LF characters trigger the flush of
the send buffer then only line-based communication can be
implemented over the BLE UART Service. This patch extends the
service API by adding an explicit `flush` method to force sending
the buffer contents, thus enabling protocols with short (e.g.,
single character) messages.
pull/5268/head
Akos Kiss 2017-08-29 18:53:21 +02:00 committed by adbridge
parent 93d78c6218
commit 2fd13bffca
1 changed files with 13 additions and 0 deletions

View File

@ -140,6 +140,19 @@ public:
return write(str, strlen(str));
}
/**
* Flush sendBuffer, i.e., forcefully write its contents to the UART RX
* characteristic even if the buffer is not full.
*/
void flush() {
if (ble.getGapState().connected) {
if (sendBufferIndex != 0) {
ble.gattServer().write(getRXCharacteristicHandle(), static_cast<const uint8_t *>(sendBuffer), sendBufferIndex);
sendBufferIndex = 0;
}
}
}
/**
* Override for Stream::_putc().
* @param c