Skip to content

Commit d7e38bb

Browse files
committed
Fix Notification can't send out
1. Change the callback and data structure. 2. Removed some unused code
1 parent 3fc493d commit d7e38bb

File tree

7 files changed

+18
-96
lines changed

7 files changed

+18
-96
lines changed

Diff for: libraries/CurieBLE/src/internal/BLECallbacks.cpp

+8-82
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ uint8_t profile_notify_process (bt_conn_t *conn,
128128
bt_gatt_subscribe_params_t *params,
129129
const void *data, uint16_t length)
130130
{
131-
//BLEPeripheralHelper* peripheral = BLECentralRole::instance()->peripheral(conn);// Find peripheral by bt_conn
132-
//BLEAttribute* notifyatt = peripheral->attribute(params); // Find attribute by params
133131
BLECharacteristicImp* chrc = NULL;
134132
BLEDevice bleDevice(bt_conn_get_dst(conn));
135133
chrc = BLEProfileManager::instance()->characteristic(bleDevice, params->value_handle);
@@ -151,7 +149,6 @@ uint8_t profile_discover_process(bt_conn_t *conn,
151149
uint8_t ret = BT_GATT_ITER_STOP;
152150
pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
153151
ret = BLEProfileManager::instance()->discoverResponseProc(conn, attr, params);
154-
pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
155152
return ret;
156153
}
157154

@@ -242,69 +239,13 @@ void bleConnectEventHandler(bt_conn_t *conn,
242239
p->handleConnectEvent(conn, err);
243240
}
244241

245-
static uint8_t ble_gatt_disconnected_cb(const struct bt_gatt_attr *attr, void *user_data)
246-
{
247-
struct bt_conn *conn = (struct bt_conn *)user_data;
248-
struct _bt_gatt_ccc *ccc;
249-
size_t i;
250-
251-
/* Check attribute user_data must be of type struct _bt_gatt_ccc */
252-
if (attr->write != profile_gatt_attr_write_ccc) {
253-
return BT_GATT_ITER_CONTINUE;
254-
}
255-
256-
ccc = (struct _bt_gatt_ccc *)attr->user_data;
257-
/* If already disabled skip */
258-
if (!ccc->value) {
259-
return BT_GATT_ITER_CONTINUE;
260-
}
261-
262-
for (i = 0; i < ccc->cfg_len; i++)
263-
{
264-
/* Ignore configurations with disabled value */
265-
if (!ccc->cfg[i].value)
266-
{
267-
continue;
268-
}
269-
270-
if (bt_addr_le_cmp(&conn->le.dst, &ccc->cfg[i].peer))
271-
{
272-
struct bt_conn *tmp;
273-
274-
/* Skip if there is another peer connected */
275-
tmp = bt_conn_lookup_addr_le(&ccc->cfg[i].peer);
276-
if (tmp) {
277-
if (tmp->state == BT_CONN_CONNECTED) {
278-
bt_conn_unref(tmp);
279-
return BT_GATT_ITER_CONTINUE;
280-
}
281-
282-
bt_conn_unref(tmp);
283-
}
284-
}
285-
}
286-
287-
/* Reset value while disconnected */
288-
memset(&ccc->value, 0, sizeof(ccc->value));
289-
290-
if (ccc->cfg_changed) {
291-
ccc->cfg_changed(ccc->value);
292-
}
293-
294-
pr_debug(LOG_MODULE_BLE, "ccc %p reseted", ccc);
295-
296-
return BT_GATT_ITER_CONTINUE;
297-
}
298-
299-
300242
void bleDisconnectEventHandler(bt_conn_t *conn,
301243
uint8_t reason,
302244
void *param)
303245
{
304246
BLEDeviceManager* p = (BLEDeviceManager*)param;
305247

306248
pr_info(LOG_MODULE_BLE, "Connect lost. Reason: %d", reason);
307-
bt_gatt_foreach_attr(0x0001, 0xffff, ble_gatt_disconnected_cb, conn);
308249

309250
p->handleDisconnectEvent(conn, reason);
310251
}
@@ -343,29 +284,14 @@ void ble_on_write_no_rsp_complete(struct bt_conn *conn, uint8_t err,
343284
BLECharacteristicImp::writeResponseReceived(conn, err, data);
344285
}
345286

346-
ssize_t profile_gatt_attr_write_ccc(struct bt_conn *conn,
347-
const struct bt_gatt_attr *attr,
348-
const void *buf,
349-
uint16_t len,
350-
uint16_t offset)
287+
void prfile_cccd_cfg_changed(void *user_data, uint16_t value)
351288
{
352-
struct _bt_gatt_ccc *ccc = (struct _bt_gatt_ccc *)attr->user_data;
353-
const uint16_t *data = (const uint16_t *)buf;
354-
bool cccdChanged = (ccc->value != *data);
355-
ssize_t retValue = bt_gatt_attr_write_ccc(conn, attr, buf, len, offset);
356-
if (cccdChanged)
357-
{
358-
// Find characteristic and do notification
359-
const struct bt_gatt_attr *attrChrc = attr - 1;
360-
BLEAttribute *bleattr = (BLEAttribute *)attrChrc->user_data;
361-
BLEAttributeType type = bleattr->type();
362-
pr_debug(LOG_MODULE_BLE, "The Attribute type:%d", type);
363-
if (BLETypeCharacteristic == type)
364-
{
365-
BLECharacteristicImp *blecharacteritic = (BLECharacteristicImp*)bleattr;
366-
blecharacteritic->cccdValueChanged();
367-
}
368-
}
369-
return retValue;
289+
if (NULL == user_data)
290+
return;
291+
pr_debug(LOG_MODULE_BLE, "%s-%d: ccc userdata %p", __FUNCTION__, __LINE__, user_data);
292+
293+
BLECharacteristicImp *blecharacteritic = (BLECharacteristicImp *)user_data;
294+
blecharacteritic->cccdValueChanged();
370295
}
371296

297+

Diff for: libraries/CurieBLE/src/internal/BLECallbacks.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ uint8_t profile_characteristic_read_rsp_process(bt_conn_t *conn,
8989
const void *data,
9090
uint16_t length);
9191

92-
ssize_t profile_gatt_attr_write_ccc(struct bt_conn *conn,
93-
const struct bt_gatt_attr *attr,
94-
const void *buf,
95-
uint16_t len,
96-
uint16_t offset);
92+
void prfile_cccd_cfg_changed(void *user_data, uint16_t value);
9793

9894
#endif
9995

Diff for: libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ BLECharacteristicImp::BLECharacteristicImp(const bt_uuid_t* uuid,
7171

7272
_ccc_value.cfg = &_ccc_cfg;
7373
_ccc_value.cfg_len = 1;
74+
_ccc_value.user_data = (void *)this;
75+
_ccc_value.cfg_changed = prfile_cccd_cfg_changed;
76+
_ccc_value.value = 0;
77+
7478
if (BLERead & properties)
7579
{
7680
_gatt_chrc.properties |= BT_GATT_CHRC_READ;
@@ -804,7 +808,7 @@ int BLECharacteristicImp::updateProfile(bt_gatt_attr_t *attr_start, int& index)
804808
start->uuid = this->getClientCharacteristicConfigUuid();
805809
start->perm = BT_GATT_PERM_READ | BT_GATT_PERM_WRITE;
806810
start->read = bt_gatt_attr_read_ccc;
807-
start->write = profile_gatt_attr_write_ccc;
811+
start->write = bt_gatt_attr_write_ccc;
808812
start->user_data = this->getCccCfg();
809813

810814
pr_info(LOG_MODULE_BLE, "cccd-%p", start);

Diff for: libraries/CurieBLE/src/internal/BLECharacteristicImp.h

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
#ifndef _BLE_CHARACTERISTICIMP_H_INCLUDED
2121
#define _BLE_CHARACTERISTICIMP_H_INCLUDED
2222

23-
//#include "BLECommon.h"
24-
25-
//#include "BLEDevice.h"
26-
//#include "BLEDescriptor.h"
27-
2823
#include "CurieBLE.h"
2924
#include "BLEDescriptorImp.h"
3025

Diff for: system/libarc32_arduino101/drivers/bluetooth/gatt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ struct _bt_gatt_ccc {
513513
struct bt_gatt_ccc_cfg *cfg;
514514
size_t cfg_len;
515515
uint16_t value;
516-
void (*cfg_changed)(uint16_t value);
516+
void *user_data;
517+
void (*cfg_changed)(void *user_data, uint16_t value);
517518
};
518519

519520
/** @brief Read Client Characteristic Configuration Attribute helper.

Diff for: system/libarc32_arduino101/framework/src/services/ble/gatt.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void gatt_ccc_changed(struct _bt_gatt_ccc *ccc)
434434
if (value != ccc->value) {
435435
ccc->value = value;
436436
if (ccc->cfg_changed)
437-
ccc->cfg_changed(value);
437+
ccc->cfg_changed(ccc->user_data, value);
438438
}
439439
}
440440

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

813813
if (ccc->cfg_changed) {
814-
ccc->cfg_changed(ccc->value);
814+
ccc->cfg_changed(ccc->user_data, ccc->value);
815815
}
816816

817817
BT_DBG("ccc %p reseted", ccc);

Diff for: variants/arduino_101/libarc32drv_arduino101.a

599 KB
Binary file not shown.

0 commit comments

Comments
 (0)