一. 我们调试中发现user_peripheral.c中的回调,一直都没有回调。(大家可以通过打印去排查)
void user_catch_rest_hndl(ke_msg_id_t const msgid,
void const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
//此处省略一部分代码。
case CUSTS1_VALUE_REQ_IND:
{
struct custs1_value_req_ind const *msg_param = (struct custs1_value_req_ind const *)param;
switch (msg_param->att_idx)
{
case SVC1_IDX_ADC_VAL_1_VAL:
{
// Increase value by one
struct custs1_value_req_rsp *rsp = KE_MSG_ALLOC_DYN(CUSTS1_VALUE_REQ_RSP,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_value_req_rsp,
DEF_SVC1_ADC_VAL_1_CHAR_LEN);
// Provide the connection index.
rsp->conidx = app_env[msg_param->conidx].conidx;
// Provide the attribute index.
rsp->att_idx = msg_param->att_idx;
// Force current length to zero.
rsp->length = DEF_SVC1_ADC_VAL_1_CHAR_LEN;
// Provide the ATT error code.
rsp->status = ATT_ERR_NO_ERROR;
// Copy value
memcpy(&rsp->value, &data[0], rsp->length);
// Send message
KE_MSG_SEND(rsp);
}
break;
//此处省略一部分代码
}
//此处省略一部分代码
}
//此处省略一部分代码
}
二. 后来发现需要在user_custs1_def.c中的属性表加上相关的权限声明(红色部分即权限声明,加上之后user_peripheral.c即可有正常回调。)
/// Full CUSTS1 Database Description - Used to add attributes into the database
const struct attm_desc_128 custs1_att_db[CUSTS1_IDX_NB] =
{
//此处省略一部分代码
// ADC Value 1 Characteristic Value
[SVC1_IDX_ADC_VAL_1_VAL] = {SVC1_ADC_VAL_1_UUID_16, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(NTF, ENABLE),
DEF_SVC1_ADC_VAL_1_CHAR_LEN|PERM(RI, ENABLE), 0, NULL},
//此处省略一部分代码
}
三. 官方参考资料,虽然没有明示需要加上“PERM(RI, ENABLE)”,但可以很明显看到这个区别。
DA14531特性读写 - 低功耗蓝牙 - 瑞萨无线连接 - 瑞萨电子工程社区
5. 创建自定义配置文件服务 — DA145XX教程 创建自定义 GATT 配置文件
在外设中启用中央连接功能启用通知时,DA14531中心无法读取外设特性值 - 低功耗蓝牙 - 瑞萨电子无线连接 - 瑞萨电子技术网络社区