Skip to main content
Patrick Chwalek
Associate III
February 2, 2021
Question

For the BLE_DataThroughput example, in dts.c, when receiving an event of EVT_BLUE_GATT_ATTRIBUTE_MODIFIED and trying to find out which characteristic is the one being modified, why do the handles have an integer added to them prior to the comparison?

  • February 2, 2021
  • 2 replies
  • 1757 views

The code in question is below. You can see that each of the characteristic handles have an integer added to them prior to the comparison (i.e., + 2, + 5, +1). Why?

 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
 {
 attribute_modified = (aci_gatt_attribute_modified_event_rp0*) blue_evt->data;
 if (attribute_modified->Attr_Handle == (aDataTransferContext.DataTransferTxCharHdle + 2))
 {
 /**
 * Notify to application to start measurement
 */
 if (attribute_modified->Attr_Data[0] & DTS_STM_NOTIFICATION_MASK)
 {
 APP_DBG_MSG("notification enabled\n");
 Notification.Evt_Opcode = DTS_STM__NOTIFICATION_ENABLED;
 DTS_Notification(&Notification);
 }
 else
 {
 APP_DBG_MSG("notification disabled\n");
 Notification.Evt_Opcode = DTS_STM_NOTIFICATION_DISABLED;
 DTS_Notification(&Notification);
 }
 }
 //if (attribute_modified->Attr_Handle == (aDataTransferContext.DataTransferTxChar3Hdle + 2))
 if (attribute_modified->Attr_Handle == (aDataTransferContext.DataTransferTxChar3Hdle + 5))
 {
 /**
 * Notify to application to start measurement
 */
 if (attribute_modified->Attr_Data[0] & DTS_STM_NOTIFICATION_MASK)
 {
 APP_DBG_MSG("notification enabled\n");
 Notification.Evt_Opcode = DTC_NOTIFICATION_ENABLED;
 DTS_Notification(&Notification);
 }
 else
 {
 APP_DBG_MSG("notification disabled\n");
 Notification.Evt_Opcode = DTC_NOTIFICATION_DISABLED;
 DTS_Notification(&Notification);
 }
 }
 if(attribute_modified->Attr_Handle == (aDataTransferContext.DataTransferRxCharHdle + 1))
 {
 return_value = SVCCTL_EvtAckFlowEnable;
 
 Notification.Evt_Opcode = DTS_STM_DATA_RECEIVED;
 Notification.DataTransfered.Length=attribute_modified->Attr_Data_Length;
 DTS_Notification(&Notification); 
 }
 }
 break;
 case EVT_BLUE_GATT_TX_POOL_AVAILABLE:
 Resume_Notification();
 break; 
 
 case EVT_BLUE_GATT_WRITE_PERMIT_REQ:
 APP_DBG_MSG("write permit req\r\n");
 write_permit_req = (aci_gatt_write_permit_req_event_rp0 *) blue_evt->data;
 aci_gatt_write_resp( write_permit_req->Connection_Handle, write_permit_req->Attribute_Handle, 0, 0, write_permit_req->Data_Length, write_permit_req->Data); 
 break;

This topic has been closed for replies.

2 replies

mkrug
Associate III
August 6, 2021

Hi Patrick,

I actually have the same question that you raised. So why is a value added to the handle before the comparision? Did you receive an answer?

Best Regards

Markus

Patrick Chwalek
Associate III
August 6, 2021

Unfortunately, I have not-- I still don't understand why that's done.

Targo
Associate
January 16, 2023

Hi @Patrick Chwalek​ and @Community member​,

Have either of you managed to find an answer yet? Or any reference to what integers need to be added in any documentation?

Best Regards,

Targo

Patrick Chwalek
Associate III
January 17, 2023

Hi @Targo​ , I have not found an answer. My solution to this is a bit brute force.

  1. Setup all the characteristics for the service
  2. Connect to service via secondary device
  3. Send data to specific characteristics
  4. Add a breakpoint in the handler for that service
  5. Check the value of attribute_modified->Attr_Handle and then hardcode the if statement with the correct offset
Targo
Associate
January 19, 2023

Hi @Patrick Chwalek​ , thank you. I guess I will have to do the same.

In the latest version of "ble_gatt_aci.h" above the function "aci_gatt_add_char" I did see this:

"

The command returns the handle of the declaration attribute. The attribute

 * that holds the Characteristic Value is always allocated at the next handle

 * (Char_Handle + 1). The Characteristic Value is immediately followed, in

 * order, by:

 * - the Server Characteristic Configuration descriptor if CHAR_PROP_BROADCAST

 * is selected;

 * - the Client Characteristic Configuration descriptor if CHAR_PROP_NOTIFY or

 * CHAR_PROP_INDICATE properties is selected;

 * - the Characteristic Extended Properties descriptor if CHAR_PROP_EXT is

 * selected.

 * For instance, if CHAR_PROP_NOTIFY is selected but not CHAR_PROP_BROADCAST

 * nor CHAR_PROP_EXT, then the Client Characteristic Configuration attribute

 * handle is Char_Handle + 2.

"

Although I don't fully understand it.