Skip to content

Jira 916 913 BLESubscribed, BLEUnsubscribed Event Handlers are not called #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions libraries/CurieBLE/src/internal/BLECallbacks.cpp
Original file line number Diff line number Diff line change
@@ -27,6 +27,11 @@
#include "BLEDeviceManager.h"
#include "BLEProfileManager.h"

#include "BLECallbacks.h"

#include <atomic.h>
#include "../src/services/ble/conn_internal.h"

// GATT Server Only
ssize_t profile_read_process(bt_conn_t *conn,
const bt_gatt_attr_t *attr,
@@ -123,8 +128,6 @@ uint8_t profile_notify_process (bt_conn_t *conn,
bt_gatt_subscribe_params_t *params,
const void *data, uint16_t length)
{
//BLEPeripheralHelper* peripheral = BLECentralRole::instance()->peripheral(conn);// Find peripheral by bt_conn
//BLEAttribute* notifyatt = peripheral->attribute(params); // Find attribute by params
BLECharacteristicImp* chrc = NULL;
BLEDevice bleDevice(bt_conn_get_dst(conn));
chrc = BLEProfileManager::instance()->characteristic(bleDevice, params->value_handle);
@@ -146,7 +149,6 @@ uint8_t profile_discover_process(bt_conn_t *conn,
uint8_t ret = BT_GATT_ITER_STOP;
pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
ret = BLEProfileManager::instance()->discoverResponseProc(conn, attr, params);
pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
return ret;
}

@@ -237,7 +239,6 @@ void bleConnectEventHandler(bt_conn_t *conn,
p->handleConnectEvent(conn, err);
}


void bleDisconnectEventHandler(bt_conn_t *conn,
uint8_t reason,
void *param)
@@ -283,3 +284,14 @@ void ble_on_write_no_rsp_complete(struct bt_conn *conn, uint8_t err,
BLECharacteristicImp::writeResponseReceived(conn, err, data);
}

void prfile_cccd_cfg_changed(void *user_data, uint16_t value)
{
if (NULL == user_data)
return;
pr_debug(LOG_MODULE_BLE, "%s-%d: ccc userdata %p", __FUNCTION__, __LINE__, user_data);

BLECharacteristicImp *blecharacteritic = (BLECharacteristicImp *)user_data;
blecharacteritic->cccdValueChanged();
}


2 changes: 2 additions & 0 deletions libraries/CurieBLE/src/internal/BLECallbacks.h
Original file line number Diff line number Diff line change
@@ -89,5 +89,7 @@ uint8_t profile_characteristic_read_rsp_process(bt_conn_t *conn,
const void *data,
uint16_t length);

void prfile_cccd_cfg_changed(void *user_data, uint16_t value);

#endif

38 changes: 35 additions & 3 deletions libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp
Original file line number Diff line number Diff line change
@@ -71,6 +71,10 @@ BLECharacteristicImp::BLECharacteristicImp(const bt_uuid_t* uuid,

_ccc_value.cfg = &_ccc_cfg;
_ccc_value.cfg_len = 1;
_ccc_value.user_data = (void *)this;
_ccc_value.cfg_changed = prfile_cccd_cfg_changed;
_ccc_value.value = 0;

if (BLERead & properties)
{
_gatt_chrc.properties |= BT_GATT_CHRC_READ;
@@ -139,6 +143,10 @@ BLECharacteristicImp::BLECharacteristicImp(BLECharacteristic& characteristic,

_ccc_value.cfg = &_ccc_cfg;
_ccc_value.cfg_len = 1;
_ccc_value.user_data = (void *)this;
_ccc_value.cfg_changed = prfile_cccd_cfg_changed;
_ccc_value.value = 0;

if (BLERead & properties)
{
_gatt_chrc.properties |= BT_GATT_CHRC_READ;
@@ -433,11 +441,13 @@ bool BLECharacteristicImp::unsubscribe(void)
// Enable CCCD to allow peripheral send Notification/Indication
retval = bt_gatt_unsubscribe(conn, &_sub_params);
bt_conn_unref(conn);
if (0 == retval)
if (0 != retval)
{
_subscribed = false;
return false;
}
return _subscribed;

_subscribed = false;
return true;
}

bool BLECharacteristicImp::subscribe(void)
@@ -1070,4 +1080,26 @@ uint8_t BLECharacteristicImp::discoverResponseProc(bt_conn_t *conn,
return retVal;
}

void BLECharacteristicImp::cccdValueChanged()
{

enum BLECharacteristicEvent event = BLEUnsubscribed;
if (subscribed())
{
event = BLESubscribed;
}

if (_event_handlers[event])
{
BLECharacteristic chrcTmp(this, &_ble_device);
_event_handlers[event](_ble_device, chrcTmp);
}

if (_oldevent_handlers[event])
{
BLECharacteristic chrcTmp(this, &_ble_device);
BLECentral central(_ble_device);
_oldevent_handlers[event](central, chrcTmp);
}
}

7 changes: 1 addition & 6 deletions libraries/CurieBLE/src/internal/BLECharacteristicImp.h
Original file line number Diff line number Diff line change
@@ -20,11 +20,6 @@
#ifndef _BLE_CHARACTERISTICIMP_H_INCLUDED
#define _BLE_CHARACTERISTICIMP_H_INCLUDED

//#include "BLECommon.h"

//#include "BLEDevice.h"
//#include "BLEDescriptor.h"

#include "CurieBLE.h"
#include "BLEDescriptorImp.h"

@@ -172,7 +167,7 @@ class BLECharacteristicImp: public BLEAttribute{
static void writeResponseReceived(struct bt_conn *conn,
uint8_t err,
const void *data);

void cccdValueChanged();
int descriptorCount() const;
uint8_t discoverResponseProc(bt_conn_t *conn,
const bt_gatt_attr_t *attr,
3 changes: 2 additions & 1 deletion system/libarc32_arduino101/drivers/bluetooth/gatt.h
Original file line number Diff line number Diff line change
@@ -513,7 +513,8 @@ struct _bt_gatt_ccc {
struct bt_gatt_ccc_cfg *cfg;
size_t cfg_len;
uint16_t value;
void (*cfg_changed)(uint16_t value);
void *user_data;
void (*cfg_changed)(void *user_data, uint16_t value);
};

/** @brief Read Client Characteristic Configuration Attribute helper.
4 changes: 2 additions & 2 deletions system/libarc32_arduino101/framework/src/services/ble/gatt.c
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ static void gatt_ccc_changed(struct _bt_gatt_ccc *ccc)
if (value != ccc->value) {
ccc->value = value;
if (ccc->cfg_changed)
ccc->cfg_changed(value);
ccc->cfg_changed(ccc->user_data, value);
}
}

@@ -811,7 +811,7 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, void *user_data)
memset(&ccc->value, 0, sizeof(ccc->value));

if (ccc->cfg_changed) {
ccc->cfg_changed(ccc->value);
ccc->cfg_changed(ccc->user_data, ccc->value);
}

BT_DBG("ccc %p reseted", ccc);
Binary file modified variants/arduino_101/libarc32drv_arduino101.a
Binary file not shown.