Skip to content

Commit 5a4b00f

Browse files
committed
add BLEUart overflowed callback
1 parent d2fb578 commit 5a4b00f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

libraries/Bluefruit52Lib/src/services/BLEUart.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ BLEUart::BLEUart(uint16_t fifo_depth)
6969

7070
_rx_cb = NULL;
7171
_notify_cb = NULL;
72+
_overflow_cb = NULL;
7273

7374
_tx_fifo = NULL;
7475
_tx_buffered = false;
@@ -84,8 +85,15 @@ BLEUart::~BLEUart()
8485
void BLEUart::bleuart_rxd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
8586
{
8687
BLEUart& svc = (BLEUart&) chr->parentService();
88+
uint16_t wrcount = svc._rx_fifo->write(data, len);
8789

88-
svc._rx_fifo->write(data, len);
90+
if ( wrcount < len )
91+
{
92+
LOG_LV1("MEMORY", "bleuart rxd fifo OVERFLOWED!");
93+
94+
// invoke overflow callback
95+
if (svc._overflow_cb) svc._overflow_cb(conn_hdl, len - wrcount);
96+
}
8997

9098
#if CFG_DEBUG >= 2
9199
LOG_LV2("BLEUART", "RX: ");
@@ -108,6 +116,11 @@ void BLEUart::setRxCallback( rx_callback_t fp)
108116
_rx_cb = fp;
109117
}
110118

119+
void BLEUart::setRxOverflowCallback(rx_overflow_callback_t fp)
120+
{
121+
_overflow_cb = fp;
122+
}
123+
111124
void BLEUart::setNotifyCallback(notify_callback_t fp)
112125
{
113126
_notify_cb = fp;

libraries/Bluefruit52Lib/src/services/BLEUart.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class BLEUart : public BLEService, public Stream
5353
public:
5454
typedef void (*rx_callback_t) (uint16_t conn_hdl);
5555
typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled);
56+
typedef void (*rx_overflow_callback_t) (uint16_t conn_hdl, uint16_t leftover);
5657

5758
BLEUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
5859
virtual ~BLEUart();
@@ -63,6 +64,7 @@ class BLEUart : public BLEService, public Stream
6364
bool notifyEnabled(uint16_t conn_hdl);
6465

6566
void setRxCallback (rx_callback_t fp);
67+
void setRxOverflowCallback(rx_overflow_callback_t fp);
6668
void setNotifyCallback(notify_callback_t fp);
6769

6870
void bufferTXD(bool enable);
@@ -106,8 +108,9 @@ class BLEUart : public BLEService, public Stream
106108
bool _tx_buffered; // default is false
107109

108110
// Callbacks
109-
rx_callback_t _rx_cb;
110-
notify_callback_t _notify_cb;
111+
rx_callback_t _rx_cb;
112+
notify_callback_t _notify_cb;
113+
rx_overflow_callback_t _overflow_cb;
111114

112115
// Static Method for callbacks
113116
static void bleuart_rxd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);

0 commit comments

Comments
 (0)