Minor fixes

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

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.
uint16_t getRXCharacteristicHandle ()
 Note: TX and RX characteristics are to be interpreted from the viewpoint of the GATT client using this service.
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 will then generate notifications for the client.
size_t writeString (const char *str)
 Helper function to write out strings.
int _putc (int c)
 Override for Stream::_putc()
int _getc ()
 Override for Stream::_getc()

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 can be transmitted by the UART service module to the peer.

Protected Member Functions

void onDataWritten (const GattWriteCallbackParams *params)
 This callback allows the UART service to receive updates to the txCharacteristic.

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.
uint8_t sendBuffer [BLE_UART_SERVICE_MAX_DATA_LEN]
 The local buffer into which outbound data is accumulated before being pushed to the rxCharacteristic.
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.
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.

Detailed Description

BLE Service to enable UART over BLE.

Definition at line 41 of file UARTService.h.


Constructor & Destructor Documentation

UARTService ( BLE _ble )
Parameters:
ref]ble BLE object for the underlying controller.

Definition at line 52 of file UARTService.h.


Member Function Documentation

int _getc (  )

Override for Stream::_getc()

Returns:
The character read.

Definition at line 154 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 145 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 79 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 72 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; or if that's not used, this method can be used as a callback directly.

Definition at line 169 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 will then generate notifications for the client.

Updates made in quick succession to a notification-generating characteristic will result in data being buffered in the bluetooth stack as notifications are sent out. The stack will have 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 will need 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
lengthAmount of characters to be appended.
Returns:
Amount of characters appended to the rxCharacteristic.

Definition at line 100 of file UARTService.h.

size_t writeString ( const char *  str )

Helper function to write out strings.

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

Definition at line 134 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 can be transmitted by the UART service module to the peer.

Definition at line 44 of file UARTService.h.

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

Definition at line 183 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 196 of file UARTService.h.

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

Definition at line 187 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 194 of file UARTService.h.