Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
UARTService Class Reference

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...
 

Detailed Description

BLE Service to enable UART over BLE.

Deprecated:
This service is deprecated, and no replacement is currently available.

Definition at line 56 of file UARTService.h.

Constructor & Destructor Documentation

UARTService ( BLE _ble)
Parameters
_bleBLE object for the underlying controller.

Definition at line 67 of file UARTService.h.

Member Function Documentation

int _getc ( )

Override for Stream::_getc().

Returns
The character read.

Definition at line 182 of file UARTService.h.

int _putc ( int  c)

Override for Stream::_putc().

Parameters
cThis function writes the character c, cast to an unsigned char, to stream.
Returns
The character written as an unsigned char cast to an int or EOF on error.

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.

void onDataWritten ( const GattWriteCallbackParams params)
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.

Parameters
_bufferThe received update.
lengthNumber of characters to be appended.
Returns
Number of characters appended to the rxCharacteristic.

Definition at line 115 of file UARTService.h.

size_t writeString ( const char *  str)

Helper function to write out strings.

Parameters
strThe received string.
Returns
Number of characters appended to the rxCharacteristic.

Definition at line 149 of file UARTService.h.

Field Documentation

const unsigned BLE_UART_SERVICE_MAX_DATA_LEN = (BLE_GATT_MTU_SIZE_DEFAULT - 3)
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.

uint8_t receiveBuffer[BLE_UART_SERVICE_MAX_DATA_LEN]
protected

The local buffer into which we receive inbound data before forwarding it to the application.

Definition at line 211 of file UARTService.h.

GattCharacteristic rxCharacteristic
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.

uint8_t sendBuffer[BLE_UART_SERVICE_MAX_DATA_LEN]
protected

The local buffer into which outbound data is accumulated before being pushed to the rxCharacteristic.

Definition at line 215 of file UARTService.h.

GattCharacteristic txCharacteristic
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.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.