BleSerialPeripheralRK
|
Main class for BLE UART funtionality. More...
#include <BleSerialPeripheralRK.h>
Public Member Functions | |
BleSerialPeripheralBase (uint8_t *txBuf, size_t txBufSize, uint8_t *rxBuf, size_t rxBufSize) | |
Construct an object with passed-in buffers. More... | |
virtual | ~BleSerialPeripheralBase () |
Destructor. More... | |
void | setup () |
You must call this from setup() to initialize the object. | |
void | loop () |
You must call this from loop() to process outgoing data. | |
void | advertise () |
Call this to advertise the BLE UART service. More... | |
BleUuid | getServiceUuid () const |
Get the service UUID for the UART service. More... | |
void | lock () |
Obtain a mutex lock on the TX buffer. More... | |
void | unlock () |
Release the mutex lock on the TX buffer. More... | |
virtual int | available () |
Override for Stream class, returns the number of bytes that can be read right now. | |
virtual int | read () |
Override for the Stream class, reads a byte of data from the input ring buffer. | |
virtual int | peek () |
Override for the Stream class, reads a byte of data, but leaves it in the buffer so read() will get the same byte of data. | |
virtual void | flush () |
Override for the Stream class. Currently does nothing. | |
virtual size_t | write (uint8_t data) |
Virtual override from the Print class. Writes a byte of data. More... | |
size_t | getRxLost () const |
void | clearRxLost () |
Clears the rxLost counter. | |
size_t | getTxLost () const |
void | clearTxLost () |
Clears the txLost counter. | |
size_t | getTxMaxWrite () const |
Get the maximum chunk size to send. The default is 236 bytes. | |
void | setTxMaxWrite (size_t value) |
Set the maximum chunk size to send. More... | |
Public Member Functions inherited from Stream | |
void | setTimeout (system_tick_t timeout) |
Sets the read timeout (default: 1000 milliseconds) More... | |
bool | find (char *target) |
Reads data from the stream until the target string is found. More... | |
bool | find (char *target, size_t length) |
Reads data from the stream until the target string is found. More... | |
bool | findUntil (char *target, char *terminator) |
Reads data from the stream until the target string is found or the terminator string is found. More... | |
bool | findUntil (char *target, size_t targetLen, char *terminate, size_t termLen) |
Reads data from the stream until the target string is found or the terminator string is found. More... | |
long | parseInt () |
returns the first valid (long) integer value from the current position More... | |
float | parseFloat () |
returns the first valid float value from the current position More... | |
size_t | readBytes (char *buffer, size_t length) |
Read chars from stream into buffer. More... | |
size_t | readBytesUntil (char terminator, char *buffer, size_t length) |
Read chars from stream into buffer until the character terminator is found. More... | |
String | readString () |
Reads the remainder of the file into a string. | |
String | readStringUntil (char terminator) |
Reads the remainder of the file into a string or until terminator is found. More... | |
Public Member Functions inherited from Print | |
int | getWriteError () |
Return the last error code. 0 means no error. | |
void | clearWriteError () |
Clear the last error code to 0. | |
size_t | write (const char *str) |
Write a null-terminated c-string the stream or file. More... | |
virtual size_t | write (const uint8_t *buffer, size_t size) |
Write a bytes specified by a buffer and length to the stream or file. More... | |
size_t | print (const char[]) |
Print a null-terminated array of char variables (a c-string) to the stream or file. | |
size_t | print (char) |
Print a single character to the stream or file. | |
size_t | print (unsigned char value, int base=DEC) |
Print an unsigned char (byte value, 8 bits) in the specified base to the stream or file. More... | |
size_t | print (int value, int base=DEC) |
Print an int (32 bit integer) the specified base to the stream or file. More... | |
size_t | print (unsigned int value, int base=DEC) |
Print an unsigned int (32 bit unsigned integer) the specified base to the stream or file. More... | |
size_t | print (long value, int base=DEC) |
Print a long (32 bit integer) the specified base to the stream or file. More... | |
size_t | print (unsigned long value, int base=DEC) |
Print a unsigned long (32 bit unsigned integer) the specified base to the stream or file. More... | |
size_t | print (double value, int dec=2) |
Print a double floating point value to the stream or file. More... | |
size_t | print (const Printable &) |
Print an object derived from Printable to the stream or file. | |
size_t | println (const char[]) |
Print a null-terminated array of char variables (a c-string) plus a CRLF end-of-line terminator to the stream or file. | |
size_t | println (char value) |
Print a single character plus a CRLF end-of-line terminator to the stream or file. | |
size_t | println (unsigned char value, int base=DEC) |
Print an unsigned char (byte value. 8 bits) in the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (int value, int base=DEC) |
Print an int (32 bit integer) the specified base to plus a CRLF end-of-line terminator the stream or file. More... | |
size_t | println (unsigned int value, int base=DEC) |
Print an unsigned int (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (long value, int base=DEC) |
Print a long (32 bit signed integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (unsigned long value, int base=DEC) |
Print a unsigned long (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (double value, int dec=2) |
Print a double floating point value plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (const Printable &) |
Print an object derived from Printable plus a CRLF end-of-line terminator to the stream or file. | |
size_t | println (void) |
Print a CRLF end-of-line terminator to the stream or file. | |
template<typename... Args> | |
size_t | printf (const char *format, Args... args) |
Print using printf-style formatting to the stream or file. More... | |
template<typename... Args> | |
size_t | printlnf (const char *format, Args... args) |
Print using printf-style formatting plus a CRLF end-of-line terminator to the stream or file. More... | |
Main class for BLE UART funtionality.
Normally you'll instantiate a BleSerialPeripheralStatic as a global variable instead of using this class.
You can only have one instance of this object per device!
Note: This method subclasses Stream.
BleSerialPeripheralBase::BleSerialPeripheralBase | ( | uint8_t * | txBuf, |
size_t | txBufSize, | ||
uint8_t * | rxBuf, | ||
size_t | rxBufSize | ||
) |
Construct an object with passed-in buffers.
txBuf | Pointer to buffer for tx (this device to the other device) |
txBufSize | Size of the buffer in bytes |
rxBuf | Pointer to the buffer for rx (the other device to this device) |
rxBufSize | Size of the buffer in bytes |
Normally you'd use BleSerialPeripheralStatic as a global variable, but in unusual cases you can construct the object with this constructor and pass in the buffers to use.
|
virtual |
Destructor.
You normally instantiate this object as a global variable so you won't be deleting it. The buffers you passed in are not freed!
void BleSerialPeripheralBase::advertise | ( | ) |
Call this to advertise the BLE UART service.
If you have multiple services you want to advertise, instead of calling this method use getServiceUuid() to get the UUID of the UART service and add it to your advertising data.
|
inline |
Get the number of receive bytes lost because the receive buffer was full.
Data is received asynchronously by BLE. If you do not empty the data from loop fast enough or use too small of a buffer, the data will be lost. The rxLost counter is the number of bytes that have been lost.
BleUuid BleSerialPeripheralBase::getServiceUuid | ( | ) | const |
Get the service UUID for the UART service.
This is used if you advertise multiple services.
|
inline |
Get the number of transmit bytes lost because the transmit buffer was full.
Data can be written from other threads and is buffered in the txBuf. During loop(), the data is sent (in chunks up to txMaxWrite bytes). If you write more data than can fit in the txBuf, then the data is lost and the txLost counter is incremented.
void BleSerialPeripheralBase::lock | ( | ) |
Obtain a mutex lock on the TX buffer.
This is used internally, you should not normally need to call this.
|
inline |
Set the maximum chunk size to send.
value | The value in bytes to set. |
It set larger than 244, any data larger than that will be silently discarded. If your BLE central implementation does not want that much data at once, set it lower.
Note that during loop all of the outstanding data up to txMaxWrite bytes will be sent. If there are fewer than txMaxWrite byte then the smaller amount of data will be sent; it does not wait around for more data.
Even if you write multiple small writes using write() or print() methods they will be bunched up into more efficient larger writes.
void BleSerialPeripheralBase::unlock | ( | ) |
Release the mutex lock on the TX buffer.
This is used internally, you should not normally need to call this.
|
virtual |
Virtual override from the Print class. Writes a byte of data.
data | The byte to write |
Note that writes are accumulated in the txBuf, then sent out in bunches from the loop thread. If you overflow the txBuf, then the data is discarded and -1 is returned. The txLost counter is incremented as well.
Implements Print.