mirror of https://github.com/ARMmbed/mbed-os.git
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
parent
93d78c6218
commit
2fd13bffca
|
@ -140,6 +140,19 @@ public:
|
||||||
return write(str, strlen(str));
|
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().
|
* Override for Stream::_putc().
|
||||||
* @param c
|
* @param c
|
||||||
|
|
Loading…
Reference in New Issue