Skip to content

Commit 940e902

Browse files
committed
BLECharacteristic falls back to immed call if ada callback failed
1 parent 31ed8a4 commit 940e902

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

libraries/Bluefruit52Lib/src/BLECharacteristic.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
361361
{
362362
ble_gatts_evt_read_t * rd_req = &request->request.read;
363363

364-
if ( _use_ada_cb.read_authorize )
365-
{
366-
ada_callback(rd_req, sizeof(*rd_req), _rd_authorize_cb, conn_hdl, this, rd_req);
367-
}
368-
else
364+
if ( !(_use_ada_cb.read_authorize &&
365+
ada_callback(rd_req, sizeof(*rd_req), _rd_authorize_cb, conn_hdl, this, rd_req)) )
369366
{
370367
_rd_authorize_cb(conn_hdl, this, rd_req);
371368
}
@@ -382,10 +379,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
382379
// Write Request with authorization
383380
if (_wr_authorize_cb != NULL)
384381
{
385-
if ( _use_ada_cb.write_authorize )
386-
{
387-
ada_callback(wr_req, sizeof(*wr_req), _wr_authorize_cb, conn_hdl, this, wr_req);
388-
}else
382+
if ( !(_use_ada_cb.write_authorize &&
383+
ada_callback(wr_req, sizeof(*wr_req), _wr_authorize_cb, conn_hdl, this, wr_req)) )
389384
{
390385
_wr_authorize_cb(conn_hdl, this, wr_req);
391386
}
@@ -435,13 +430,12 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
435430

436431
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
437432

438-
// Long write complete, call write callback if set
439433
if (_wr_cb)
440434
{
441-
if (_use_ada_cb.write)
442-
{
443-
ada_callback(_long_wr.buffer, _long_wr.count, _wr_cb, conn_hdl, this, _long_wr.buffer, _long_wr.count);
444-
}else
435+
// Long write complete, call write callback if set
436+
// If using ada callback but failed --> invoke callback immediately
437+
if ( !(_use_ada_cb.write &&
438+
ada_callback(_long_wr.buffer, _long_wr.count, _wr_cb, conn_hdl, this, _long_wr.buffer, _long_wr.count)) )
445439
{
446440
_wr_cb(conn_hdl, this, _long_wr.buffer, _long_wr.count);
447441
}
@@ -476,10 +470,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
476470

477471
if (_wr_cb)
478472
{
479-
if (_use_ada_cb.write)
480-
{
481-
ada_callback(request->data, request->len, _wr_cb, conn_hdl, this, request->data, request->len);
482-
}else
473+
if ( !(_use_ada_cb.write &&
474+
ada_callback(request->data, request->len, _wr_cb, conn_hdl, this, request->data, request->len)) )
483475
{
484476
_wr_cb(conn_hdl, this, request->data, request->len);
485477
}
@@ -496,11 +488,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
496488

497489
if (_cccd_wr_cb)
498490
{
499-
if ( _use_ada_cb.cccd_write )
500-
{
501-
ada_callback(NULL, 0, _cccd_wr_cb, conn_hdl, this, value);
502-
}
503-
else
491+
if ( !(_use_ada_cb.cccd_write &&
492+
ada_callback(NULL, 0, _cccd_wr_cb, conn_hdl, this, value)) )
504493
{
505494
_cccd_wr_cb(conn_hdl, this, value);
506495
}

libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,8 @@ void BLEClientCharacteristic::_eventHandler(ble_evt_t* evt)
411411
if (_notify_cb)
412412
{
413413
// use AdaCallback or invoke directly
414-
if (_use_ada_cb.notify)
415-
{
416-
ada_callback(hvx->data, hvx->len, _notify_cb, this, hvx->data, hvx->len);
417-
}else
414+
if ( !(_use_ada_cb.notify &&
415+
ada_callback(hvx->data, hvx->len, _notify_cb, this, hvx->data, hvx->len)) )
418416
{
419417
_notify_cb(this, hvx->data, hvx->len);
420418
}
@@ -425,10 +423,8 @@ void BLEClientCharacteristic::_eventHandler(ble_evt_t* evt)
425423
if (_indicate_cb)
426424
{
427425
// use AdaCallback or invoke directly
428-
if (_use_ada_cb.indicate)
429-
{
430-
ada_callback(hvx->data, hvx->len, _indicate_cb, this, hvx->data, hvx->len);
431-
}else
426+
if ( !(_use_ada_cb.indicate &&
427+
ada_callback(hvx->data, hvx->len, _indicate_cb, this, hvx->data, hvx->len)) )
432428
{
433429
_indicate_cb(this, hvx->data, hvx->len);
434430
}

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bk
131131
bool bond_save_keys (uint8_t role, uint16_t conn_hdl, bond_keys_t* bkeys)
132132
{
133133
// queue to execute in Ada Callback thread
134-
ada_callback(bkeys, sizeof(bond_keys_t), bond_save_keys_dfr, role, conn_hdl, bkeys);
135-
136-
return true;
134+
return ada_callback(bkeys, sizeof(bond_keys_t), bond_save_keys_dfr, role, conn_hdl, bkeys);
137135
}
138136

139137
bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys)
@@ -190,9 +188,7 @@ bool bond_save_cccd (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
190188
VERIFY(ediv != 0xFFFF);
191189

192190
// queue to execute in Ada Callback thread
193-
ada_callback(NULL, 0, bond_save_cccd_dfr, role, conn_hdl, ediv);
194-
195-
return true;
191+
return ada_callback(NULL, 0, bond_save_cccd_dfr, role, conn_hdl, ediv);
196192
}
197193

198194
bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)

0 commit comments

Comments
 (0)