Skip to content

Commit 8035ddc

Browse files
committed
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.
1 parent e4d0e12 commit 8035ddc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

features/FEATURE_BLE/ble/services/UARTService.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ class UARTService {
140140
return write(str, strlen(str));
141141
}
142142

143+
/**
144+
* Flush sendBuffer, i.e., forcefully write its contents to the UART RX
145+
* characteristic even if the buffer is not full.
146+
*/
147+
void flush() {
148+
if (ble.getGapState().connected) {
149+
if (sendBufferIndex != 0) {
150+
ble.gattServer().write(getRXCharacteristicHandle(), static_cast<const uint8_t *>(sendBuffer), sendBufferIndex);
151+
sendBufferIndex = 0;
152+
}
153+
}
154+
}
155+
143156
/**
144157
* Override for Stream::_putc().
145158
* @param c

0 commit comments

Comments
 (0)