enhance ada_callback, add malloc len for cleaner usage

This commit is contained in:
hathach committed 2019-02-14 12:50:17 +07:00
1 parent 333f151ff5
commit e13922c58b
11 files changed
+51 -75

No files matched your search

@@ -413,12 +413,7 @@ void BLEClientCharacteristic::_eventHandler(ble_evt_t* evt)
// use AdaCallback or invoke directly
if (_use_ada_cb.notify)
{
uint8_t* data = (uint8_t*) rtos_malloc(hvx->len);
if (!data) return;
memcpy(data, hvx->data, hvx->len);
// data is free after callback
ada_callback(data, _notify_cb, this, data, hvx->len);
ada_callback(hvx->data, hvx->len, _notify_cb, this, hvx->data, hvx->len);
}else
{
_notify_cb(this, hvx->data, hvx->len);
@@ -432,12 +427,7 @@ void BLEClientCharacteristic::_eventHandler(ble_evt_t* evt)
// use AdaCallback or invoke directly
if (_use_ada_cb.indicate)
{
uint8_t* data = (uint8_t*) rtos_malloc(hvx->len);
if (!data) return;
memcpy(data, hvx->data, hvx->len);
// data is free by callback
ada_callback(data, _indicate_cb, this, data, hvx->len);
ada_callback(hvx->data, hvx->len, _indicate_cb, this, hvx->data, hvx->len);
}else
{
_indicate_cb(this, hvx->data, hvx->len);