add BLEUart overflowed callback

This commit is contained in:
hathach committed 2019-09-18 12:00:02 +07:00
1 parent d2fb5785dd
commit 5a4b00fa98
2 files changed
+19 -3

No files matched your search

@@ -69,6 +69,7 @@ BLEUart::BLEUart(uint16_t fifo_depth)
_rx_cb = NULL;
_notify_cb = NULL;
_overflow_cb = NULL;
_tx_fifo = NULL;
_tx_buffered = false;
@@ -84,8 +85,15 @@ BLEUart::~BLEUart()
void BLEUart::bleuart_rxd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
{
BLEUart& svc = (BLEUart&) chr->parentService();
uint16_t wrcount = svc._rx_fifo->write(data, len);
svc._rx_fifo->write(data, len);
if ( wrcount < len )
{
LOG_LV1("MEMORY", "bleuart rxd fifo OVERFLOWED!");
// invoke overflow callback
if (svc._overflow_cb) svc._overflow_cb(conn_hdl, len - wrcount);
}
#if CFG_DEBUG >= 2
LOG_LV2("BLEUART", "RX: ");
@@ -108,6 +116,11 @@ void BLEUart::setRxCallback( rx_callback_t fp)
_rx_cb = fp;
}
void BLEUart::setRxOverflowCallback(rx_overflow_callback_t fp)
{
_overflow_cb = fp;
}
void BLEUart::setNotifyCallback(notify_callback_t fp)
{
_notify_cb = fp;
@@ -53,6 +53,7 @@ class BLEUart : public BLEService, public Stream
public:
typedef void (*rx_callback_t) (uint16_t conn_hdl);
typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled);
typedef void (*rx_overflow_callback_t) (uint16_t conn_hdl, uint16_t leftover);
BLEUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
virtual ~BLEUart();
@@ -63,6 +64,7 @@ class BLEUart : public BLEService, public Stream
bool notifyEnabled(uint16_t conn_hdl);
void setRxCallback (rx_callback_t fp);
void setRxOverflowCallback(rx_overflow_callback_t fp);
void setNotifyCallback(notify_callback_t fp);
void bufferTXD(bool enable);
@@ -106,8 +108,9 @@ class BLEUart : public BLEService, public Stream
bool _tx_buffered; // default is false
// Callbacks
rx_callback_t _rx_cb;
notify_callback_t _notify_cb;
rx_callback_t _rx_cb;
notify_callback_t _notify_cb;
rx_overflow_callback_t _overflow_cb;
// Static Method for callbacks
static void bleuart_rxd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);