English
Language : 

AN91162 Datasheet, PDF (28/43 Pages) Ramtron International Corporation – Creating a BLE Custom Profile
Creating a BLE Custom Profile
Attribute Handles for Custom Service
In BLE communication, both the GATT client and the GATT server access data on attributes (services, characteristics, or
descriptors) by using an attribute handle. This attribute handle is a 16-bit value that uniquely identifies the attribute after
establishing a connection.
For custom services and characteristics added to the BLE Component, the value of these handles is generated by the
Component and can be found in the generated file BLE_custom.h as #defines. For the BLE custom services added in this
project (RGB LED), the handles generated are as shown in Figure 35:
Figure 35. Attribute Handle Data Structure for Custom Services
The RGB LED service supports both reads and writes on the same characteristic with the attribute handle of value 0x000E.
Handle Write Requests
For the RGB LED characteristic, the GATT client sends a Write request with four bytes of data. This data is received as part of
the CYBLE_EVT_GATTS_WRITE_REQ event in the general event callback function. The attribute handle of the received
data is compared with that of the RGB LED Control characteristic. If they match, the following actions are taken:
1. The four bytes of data are extracted and stored in an array.
2. The RGB LED update function (UpdateRGBLED) is called to update the onboard LED color.
3. The RGB Control characteristic update function (UpdateRGBcharacteristic) is called to update the internal GATT
database value.
4. Irrespective of whether the attribute handle matches RGB LED Control Characteristic handle, a write response is sent
back to the Client device using the BLE function CyBle_GattsWriteRsp, so that the client knows that the data was
received.
Place the following code under CYBLE_EVT_GATTS_WRITE_REQ event:
case CYBLE_EVT_GATTS_WRITE_REQ:
/* Extract the Write data sent by Client */
wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam;
/* If the attribute handle of the characteristic written to
* is equal to that of RGB_LED characteristic, then extract
* the RGB LED data */
if(CYBLE_RGB_LED_RGB_LED_CONTROL_CHAR_HANDLE ==
wrReqParam->handleValPair.attrHandle)
{
/* Store RGB LED data in local array */
RGBledData[RED_INDEX] =
wrReqParam->handleValPair.value.val[RED_INDEX];
RGBledData[GREEN_INDEX] =
wrReqParam->handleValPair.value.val[GREEN_INDEX];
RGBledData[BLUE_INDEX] =
wrReqParam->handleValPair.value.val[BLUE_INDEX];
RGBledData[INTENSITY_INDEX] =
wrReqParam->handleValPair.value.val[INTENSITY_INDEX];
www.cypress.com
Document No. 001-91162 Rev. *A
28