Improve readability with getHandle inline
Fork of BLE_API by
Diff: services/UARTService.h
- Revision:
- 257:6be2b4b0cd71
- Parent:
- 244:0e9201b67e2f
--- a/services/UARTService.h Tue Dec 02 02:51:52 2014 +0000 +++ b/services/UARTService.h Mon Jan 12 14:49:53 2015 -0800 @@ -23,17 +23,21 @@ #include "UUID.h" #include "BLEDevice.h" -extern const uint8_t UARTServiceBaseUUID[LENGTH_OF_LONG_UUID]; +extern const uint8_t UARTServiceBaseUUID[LENGTH_OF_LONG_UUID]; extern const uint16_t UARTServiceShortUUID; extern const uint16_t UARTServiceTXCharacteristicShortUUID; extern const uint16_t UARTServiceRXCharacteristicShortUUID; -extern const uint8_t UARTServiceUUID[LENGTH_OF_LONG_UUID]; -extern const uint8_t UARTServiceUUID_reversed[LENGTH_OF_LONG_UUID]; +extern const uint8_t UARTServiceUUID[LENGTH_OF_LONG_UUID]; +extern const uint8_t UARTServiceUUID_reversed[LENGTH_OF_LONG_UUID]; -extern const uint8_t UARTServiceTXCharacteristicUUID[LENGTH_OF_LONG_UUID]; -extern const uint8_t UARTServiceRXCharacteristicUUID[LENGTH_OF_LONG_UUID]; +extern const uint8_t UARTServiceTXCharacteristicUUID[LENGTH_OF_LONG_UUID]; +extern const uint8_t UARTServiceRXCharacteristicUUID[LENGTH_OF_LONG_UUID]; +/** +* @class UARTService +* @brief BLE Service to enable UART over BLE +*/ class UARTService { public: /**< Maximum length of data (in bytes) that can be transmitted by the UART service module to the peer. */ @@ -41,6 +45,11 @@ static const unsigned BLE_UART_SERVICE_MAX_DATA_LEN = (GATT_MTU_SIZE_DEFAULT - 3); public: + + /** + * @param[ref] ble + * BLEDevice object for the underlying controller. + */ UARTService(BLEDevice &_ble) : ble(_ble), receiveBuffer(), @@ -73,8 +82,6 @@ } /** - * Override for Stream::write(). - * * 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 @@ -91,15 +98,15 @@ * @param length Amount of characters to be appended. * @return Amount of characters appended to the rxCharacteristic. */ - ssize_t write(const void* _buffer, size_t length) { - size_t origLength = length; - const uint8_t *buffer = static_cast<const uint8_t *>(_buffer); + ssize_t write(const void *_buffer, size_t length) { + size_t origLength = length; + const uint8_t *buffer = static_cast<const uint8_t *>(_buffer); if (ble.getGapState().connected) { unsigned bufferIndex = 0; while (length) { unsigned bytesRemainingInSendBuffer = BLE_UART_SERVICE_MAX_DATA_LEN - sendBufferIndex; - unsigned bytesToCopy = (length < bytesRemainingInSendBuffer) ? length : bytesRemainingInSendBuffer; + unsigned bytesToCopy = (length < bytesRemainingInSendBuffer) ? length : bytesRemainingInSendBuffer; /* copy bytes into sendBuffer */ memcpy(&sendBuffer[sendBufferIndex], &buffer[bufferIndex], bytesToCopy); @@ -131,6 +138,11 @@ return (write(&c, 1) == 1) ? 1 : EOF; } + /** + * Override for Stream::_getc() + * @return + * The character read. + */ int _getc() { if (receiveBufferIndex == numBytesReceived) { return EOF; @@ -178,4 +190,4 @@ * application. */ }; -#endif /* #ifndef __BLE_UART_SERVICE_H__*/ +#endif /* #ifndef __BLE_UART_SERVICE_H__*/ \ No newline at end of file