3 posts / 0 new
Last post
gcblair
Offline
Last seen:4 years 7 months ago
Master
加入:2014-09-08 10:21
notifications

Hi,

I have multiple characteristics in one service and they all have notifcations that need to be enabled/disabled

I see that when enabling the notification in the sample128 example, it globablly sets notifications on in
gattc_write_cmd_ind_handler,
sample128_env.feature |= PRF_CLI_START_NTF;

This approach doesn't seem right if I have more than one notifyable characteristic.
How should I deal with this exactly? Should there be a flag for each characteristic? Are there any examples?

Matthieu ANTOINE
Offline
Last seen:4 years 2 months ago
Expert
加入:2014-01-14 14:51
Hi,

Hi,

In "gattc_write_cmd_ind_handler()", you can use "param->handle" parameter to discriminate which characteristic has to be addressed:

if (param->handle == sample128_env.sample128_shdl + SAMPLE128_1_IDX_VAL) char_code = SAMPLE128_1_CHAR;
if (param->handle == sample128_env.sample128_shdl + SAMPLE128_2_IDX_CFG) char_code = SAMPLE128_2_CFG;

"SAMPLE128_1_IDX_VAL" and "SAMPLE128_2_IDX_CFG" are defined in "sample128.h". If you have more characteristics that are notifyable, you would have "SAMPLE128_3_IDX_CFG" for example. Then you can discriminate the destination.

Matt.

gcblair
Offline
Last seen:4 years 7 months ago
Master
加入:2014-09-08 10:21
Hi,

Hi,
I suppose the configuration characteristic itself can be used to tell if the notifications are enabled or not. In that case, what is the use of sample128_env.feature?
It seems to me that instead of

if((sample128_service_env.feature & PRF_CLI_START_NTF))
{
// Send notification through GATT
prf_server_send_event((prf_env_struct *)&sample128_service_env, false, sample128_service_env.seebo_service_shdl + param->handle_offset);
}

这应该是使用instead. I.e. check the config characteristic to see if notifies are enabled.

if((attmdb_att_get_value(param->handle, sizeof(uint16), (uint8 *)¶m->value[0]) & PRF_CLI_START_NTF)) //checks if the characteristic config has notify enabled
{
// Send notification through GATT
prf_server_send_event((prf_env_struct *)&sample128_service_env, false, sample128_service_env.seebo_service_shdl + param->handle_offset);
}