BLE Service to enable UART over BLE. More...
#include <UARTService.h>
Public Member Functions | |
UARTService (BLE &_ble) | |
uint16_t | getTXCharacteristicHandle () |
Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service. More... | |
uint16_t | getRXCharacteristicHandle () |
Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service. More... | |
size_t | write (const void *_buffer, size_t length) |
We attempt to collect bytes before pushing them to the UART RX characteristic; writing to the RX characteristic then generates notifications for the client. More... | |
size_t | writeString (const char *str) |
Helper function to write out strings. More... | |
void | flush () |
Flush sendBuffer, i.e., forcefully write its contents to the UART RX characteristic even if the buffer is not full. More... | |
int | _putc (int c) |
Override for Stream::_putc(). More... | |
int | _getc () |
Override for Stream::_getc(). More... | |
Static Public Attributes | |
static const unsigned | BLE_UART_SERVICE_MAX_DATA_LEN = (BLE_GATT_MTU_SIZE_DEFAULT - 3) |
Maximum length of data (in bytes) that the UART service module can transmit to the peer. More... | |
Protected Member Functions | |
void | onDataWritten (const GattWriteCallbackParams *params) |
This callback allows the UART service to receive updates to the txCharacteristic. More... | |
Protected Attributes | |
uint8_t | receiveBuffer [BLE_UART_SERVICE_MAX_DATA_LEN] |
The local buffer into which we receive inbound data before forwarding it to the application. More... | |
uint8_t | sendBuffer [BLE_UART_SERVICE_MAX_DATA_LEN] |
The local buffer into which outbound data is accumulated before being pushed to the rxCharacteristic. More... | |
GattCharacteristic | txCharacteristic |
From the point of view of the external client, this is the characteristic they'd write into in order to communicate with this application. More... | |
GattCharacteristic | rxCharacteristic |
From the point of view of the external client, this is the characteristic they'd read from in order to receive the bytes transmitted by this application. More... | |
BLE Service to enable UART over BLE.
Definition at line 56 of file UARTService.h.
UARTService | ( | BLE & | _ble | ) |
_ble | BLE object for the underlying controller. |
Definition at line 67 of file UARTService.h.
int _getc | ( | ) |
Override for Stream::_getc().
Definition at line 182 of file UARTService.h.
int _putc | ( | int | c | ) |
Override for Stream::_putc().
c | This function writes the character c, cast to an unsigned char, to stream. |
Definition at line 173 of file UARTService.h.
void flush | ( | ) |
Flush sendBuffer, i.e., forcefully write its contents to the UART RX characteristic even if the buffer is not full.
Definition at line 157 of file UARTService.h.
uint16_t getRXCharacteristicHandle | ( | ) |
Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service.
Definition at line 94 of file UARTService.h.
uint16_t getTXCharacteristicHandle | ( | ) |
Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service.
Definition at line 87 of file UARTService.h.
|
protected |
This callback allows the UART service to receive updates to the txCharacteristic.
The application should forward the call to this function from the global onDataWritten() callback handler; if that's not used, this method can be used as a callback directly.
Definition at line 197 of file UARTService.h.
size_t write | ( | const void * | _buffer, |
size_t | length | ||
) |
We attempt to collect bytes before pushing them to the UART RX characteristic; writing to the RX characteristic then generates notifications for the client.
Updates made in quick succession to a notification-generating characteristic result in data being buffered in the Bluetooth stack as notifications are sent out. The stack has its limits for this buffering - typically a small number under 10. Collecting data into the sendBuffer buffer helps mitigate the rate of updates. But we shouldn't buffer a large amount of data before updating the characteristic, otherwise the client needs to turn around and make a long read request; this is because notifications include only the first 20 bytes of the updated data.
_buffer | The received update. |
length | Number of characters to be appended. |
Definition at line 115 of file UARTService.h.
size_t writeString | ( | const char * | str | ) |
Helper function to write out strings.
str | The received string. |
Definition at line 149 of file UARTService.h.
|
static |
Maximum length of data (in bytes) that the UART service module can transmit to the peer.
Definition at line 59 of file UARTService.h.
|
protected |
The local buffer into which we receive inbound data before forwarding it to the application.
Definition at line 211 of file UARTService.h.
|
protected |
From the point of view of the external client, this is the characteristic they'd read from in order to receive the bytes transmitted by this application.
Definition at line 224 of file UARTService.h.
|
protected |
The local buffer into which outbound data is accumulated before being pushed to the rxCharacteristic.
Definition at line 215 of file UARTService.h.
|
protected |
From the point of view of the external client, this is the characteristic they'd write into in order to communicate with this application.
Definition at line 222 of file UARTService.h.