How to change value while a central tries to read a specific characteristic?

了解更多FAQsTutorials

8个职位/0个新职位
Last post
Offline
Last seen:6 months 1 week ago
加入:2018-04-19 13:53
How to change value while a central tries to read a specific characteristic?

您好,对话框,我需要更新值当中心尝试读取特定特征的值时,我已经在user\u custs1\u def.c文件的数据库定义中应用了RI选项,如下所示:
// Time Characteristic Value
[SVC1\u IDX\u TIME\u VAL]={
SVC1_TIME_UUID_128, ATT_UUID_128_LEN, PERM(RD,ENABLE)|PERM(WR, ENABLE) | PERM(WRITE_REQ, ENABLE),
PERM(RI,ENABLE)| DEF|u SVC1|u TIME|u CHAR|LEN
},
But i still not catch the msg on gattc_read_req_ind_handler() function in cust1_task.c file.
此外,我发现如果我应用RI选项,我就不能成功地写值。

设备:
PM_Dialog
Offline
Last seen:6小时54分钟前
Staff
加入:2018-02-08 11:03
嗨,嗯,

嗨,嗯,

Could you please check the following previous post on the forum?

https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bluetooth-low-energy-%E2%80%93-software/changing-value-database-dinamically

我跟随那篇文章,在ADC1特性的值中添加PERM(RI,ENABLE)。通过这样做,我能够在尝试读取ADC值1特征时触发cust1\u task.h的gattc\u read\u req\u ind\u handler()函数。我建议您检查DISS配置文件的实现,该配置文件使用类似的选项,并且在读取DISS特性时是否触发DISS\U task.h的gattc\u read\u req\u ind\u handler()函数。

Thanks, PM_Dialog

Offline
Last seen:6 months 1 week ago
加入:2018-04-19 13:53
Hi Dialog:

Hi Dialog:
我有进一步的研究,我发现如果我加上PERM(RI,ENABLE),问题是我只能一旦触发gattc\u read\u req\u ind\u handler()函数,如果我再次读取,它不会触发。更重要的问题是如果我试图执行attmdb_att_set_value(...)function , it will return a status of 0x06 (ATT_ERR_REQUEST_NOT_SUPPORTED). It means that if my charactoristic apply write permission like this:PERM(RD,ENABLE)|PERM(WR, ENABLE) | PERM(WRITE_REQ, ENABLE), I can not set the charactoristic value.

PM_Dialog
Offline
Last seen:6小时54分钟前
Staff
加入:2018-02-08 11:03
嗨,嗯,

嗨,嗯,

On my setup and modified the ADC value characteristic and added the extra permissions that you mentioned, I don’t see what you are mentioning on the post. Just to be clear on that, there is no implementation on the SDK side that will handle this kind of transaction, that means that you will have to take care of the code in the gattc_read_req_ind_handler() since the SDK profile doesn’t convey any message towards the application in order to be aware that somebody read from that specific characteristic. So, regarding the fact that the callback occurs only once, how you are able to determine this ? Are you using breakpoints ? In case the break point hits once, then the link will be lost, and the central on the other side will delay as long as the supervision timeout until it realizes that he is not able to find the slave and issue a disconnection. In the case that the gattc_read_req_ind_handler() didn’t occur after one read the device would be disconnected after 30 seconds (which I don’t think is the case on your side), the reason for the disconnection would be that the confirmation message from the slave wouldn’t be sent. In the case of the SDK this is not the case since when you have the RI feature enabled you always get a slave response even if this is an error due to the incomplete custom profile for handling the RI case. So I trust that the callback occurs, tested that on my side. Regarding the attmdb_att_set_value(), you won’t need this, I suppose that what you would like to implement is that every time you get a read indication you would like to send a different value to the master, so in order to do that you will have to implement it on the gattc_read_req_ind_handler() callback, that means that as soon as the gattc_read_req_ind_handler() is triggered you should perform whatever tasks you would like to compute the value and then allocate and send a GATTC_READ_CFM message that will contain the value that you would like to send to the master (the value should be copied to the cfm->value struct). Please check the example below.

cfm=KE\u MSG\u ALLOC\u DYN(GATTC\u READ\u cfm,src\u id,dest\u id,GATTC\u READ\u cfm,length);

cfm->handle = param->handle;

cfm->status = GAP_ERR_NO_ERROR;

cfm->长度=2;

if (status == GAP_ERR_NO_ERROR)

{

test++;

memcpy(cfm->value,&test,2);

}

ke_msg_send(cfm);

测试是一个全局变量,每次读取特定特征时都应增加该变量。

Thanks, PM_Dialog

Offline
Last seen:6 months 1 week ago
加入:2018-04-19 13:53
嗨,对话:

嗨,对话:
We test as your code and find that just update client characteristic configuration value (test at lightblue.) and the attribute value always "No value".
根据gattc\u read\u req\u ind\u handler(custs1\u task)中的代码,要更新的值来自custs1\u get\u ccc\u value(conidx,att\u idx),它的长度总是2,但是
attribute value can as long as 20.Is there something wrong ?
Some code of gattc_read_req_ind_handler:
//如果找到属性,则状态为GAP\u ERR\u NO\u ERROR
if (status == GAP_ERR_NO_ERROR)
{
const struct cust_prf_func_callbacks *callbacks = custs_get_func_callbacks(TASK_ID_CUSTS1);

if (callbacks->att_db[att_idx].uuid_size == ATT_UUID_16_LEN &&
*(uint16_t *)callbacks->att_db[att_idx].uuid == ATT_DESC_CLIENT_CHAR_CFG)
{
ccc_val = custs1_get_ccc_value(conidx, att_idx);
length = 2;
}
else
{
status = PRF_APP_ERROR;
}
}
//发送读取响应
cfm=KE\u MSG\u ALLOC\u DYN(GATTC\u READ\u cfm,src\u id,dest\u id,GATTC\u READ\u cfm,length);
cfm->handle = param->handle;
cfm->status = status;
cfm->长度=长度;

if (status == GAP_ERR_NO_ERROR)
{
memcpy(cfm->value, &ccc_val, length);
}
ke_msg_send(cfm);

PM_Dialog
Offline
Last seen:6小时54分钟前
Staff
加入:2018-02-08 11:03
嗨,嗯,

嗨,嗯,

Let me try to check and replicate your issue and I will let you know as soon as possible.

Thanks, PM_Dialog

PM_Dialog
Offline
Last seen:6小时54分钟前
Staff
加入:2018-02-08 11:03
嗨,嗯,

嗨,嗯,

The Client Characteristic Configuration length is 2 bytes, and they used for enabling either notifications or indications. I am not able to understand what you mean that the attribute always has “No value”. In case of attribute value characteristics, the max length is 20 bytes (23 - 3 =20bytes) without MTU exchange. There isn’t something wrong, but be aware that the attribute value is 20 because you are not using the MTU exchange.

Thanks, PM_Dialog

Offline
Last seen:6 months 1 week ago
加入:2018-04-19 13:53
Hi ,Dialog:

Hi ,Dialog:
我的意思是,我用浅蓝色来读取字符,如果我为字符设置一个值(attmdb\u att\u set\u value(…)),我将得到一个十六进制值,否则它将返回“No value”,然后如果我按read again按钮,它将再次读取遥控器,现在它将再次返回一个值,但是这个值等于第一个值,我想设置或更改返回值,而浅蓝色每次都读取字符值。