cancel
Showing results for 
Search instead for 
Did you mean: 

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?

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;

6 REPLIES 6
mkrug
Associate III

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

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

Targo
Associate II

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

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

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.

So the thought here is that the offset depends on the attribute with which the characteristic is set? I have yet to try modifying the attributes and checking the offset.