Beispiel #1
0
/****************************************************************************** 
##Function Name: CyBle_GattsWriteEventHandler
*******************************************************************************

Summary:
 Handles the Write Request Event for GATT service.

Parameters:
 *eventParam: The pointer to the data structure specified by the event.

Return:
 * CYBLE_GATT_ERR_CODE_T: An API result returns one of the following status 
    values
 * CYBLE_GATT_ERR_NONE - Write is successful.

******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_GattsWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;
    
    /* Client Characteristic Configuration descriptor write request */
    if(eventParam->handleValPair.attrHandle == cyBle_gatts.cccdHandle)
    {
        /* Store value to database */
        gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 0u, 
                        &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);
        
        if(CYBLE_GATT_ERR_NONE == gattErr)
        {
            if(CYBLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
            {
                CyBle_ApplCallback((uint32)CYBLE_EVT_GATTS_INDICATION_ENABLED, eventParam);
            }
            else
            {
                CyBle_ApplCallback((uint32)CYBLE_EVT_GATTS_INDICATION_DISABLED, eventParam);
            }
        }
        cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
    }
    return (gattErr);
}
Beispiel #2
0
/******************************************************************************
##Function Name: CyBle_BcscDiscoverCharDescriptorsEventHandler
*******************************************************************************

Summary:
 This function is called on receiving a CYBLE_EVT_GATTC_FIND_INFO_RSP event.
 Based on the descriptor UUID, an appropriate data structure is populated using
 the data received as part of the callback.

Parameters:
 *discDescrInfo: The pointer to a descriptor information structure.

Return:
 None.

******************************************************************************/
void CyBle_BcscDiscoverCharDescriptorsEventHandler(CYBLE_DISC_DESCR_INFO_T *discDescrInfo)
{
    CYBLE_BCS_DESCR_INDEX_T locDescIndex;

    switch(discDescrInfo->uuid.uuid16)
    {
    case CYBLE_UUID_CHAR_CLIENT_CONFIG:
        locDescIndex = CYBLE_BCS_CCCD;
        break;
    default:
        /* Not supported descriptor */
        locDescIndex = CYBLE_BCS_DESCR_COUNT;
        break;
    }

    if(locDescIndex < CYBLE_BCS_DESCR_COUNT)
    {
        if(cyBle_bcsc.bodyCompositionMeasurementCccdHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            cyBle_bcsc.bodyCompositionMeasurementCccdHandle = discDescrInfo->descrHandle;

        }
        else    /* Duplication of descriptor */
        {
            CyBle_ApplCallback(CYBLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo->uuid);
        }
    }
}
/****************************************************************************** 
##Function Name: CyBle_HrscDiscoverCharacteristicsEventHandler
*******************************************************************************

Summary:
 This function is called on receiving a CYBLE_EVT_GATTC_READ_BY_TYPE_RSP
 event. Based on the service UUID, an appropriate data structure is populated
 using the data received as part of the callback.

Parameters:
 *discCharInfo: The pointer to a characteristic information structure.

Return:
 None

******************************************************************************/
void CyBle_HrscDiscoverCharacteristicsEventHandler(CYBLE_DISC_CHAR_INFO_T *discCharInfo)
{
    /* Heart Rate Service characteristics UUIDs */
    static const CYBLE_UUID16 cyBle_hrscCharUuid[CYBLE_HRS_CHAR_COUNT] =
    {
        CYBLE_UUID_CHAR_HR_MSRMT,
        CYBLE_UUID_CHAR_BODY_SENSOR_LOC,
        CYBLE_UUID_CHAR_HR_CNTRL_POINT
    };
    uint8 i;
    
    for(i = 0u; i < (uint8) CYBLE_HRS_CHAR_COUNT; i++)
    {
        if(cyBle_hrscCharUuid[i] == discCharInfo->uuid.uuid16)
        {
            if(cyBle_hrsc.charInfo[i].valueHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
            {
                cyBle_hrsc.charInfo[i].valueHandle = discCharInfo->valueHandle;
                cyBle_hrsc.charInfo[i].properties = discCharInfo->properties;
            }
            else
            {
                CyBle_ApplCallback(CYBLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo->uuid);
            }
        }
    }
}
Beispiel #4
0
/******************************************************************************
##Function Name: CyBle_HtscDiscoverCharDescriptorsEventHandler
*******************************************************************************

Summary:
 This function is called on receiving a CYBLE_EVT_GATTC_FIND_INFO_RSP event.
 Based on the descriptor UUID, an appropriate data structure is populated using
 the data received as part of the callback.

Parameters:
 discoveryCharIndex: The characteristic index which is discovered.
 *discDescrInfo: The pointer to a descriptor information structure.

Return:
 None

******************************************************************************/
void CyBle_HtscDiscoverCharDescriptorsEventHandler(CYBLE_HTS_CHAR_INDEX_T discoveryCharIndex, 
                                                   CYBLE_DISC_DESCR_INFO_T *discDescrInfo)
{
    CYBLE_HTS_DESCR_INDEX_T locDescIndex;

    if(CYBLE_UUID_CHAR_CLIENT_CONFIG == discDescrInfo->uuid.uuid16)
    {
        locDescIndex = CYBLE_HTS_CCCD;
    }
    else if(CYBLE_UUID_CHAR_VALID_RANGE == discDescrInfo->uuid.uuid16)
    {
        locDescIndex = CYBLE_HTS_VRD;
    }
    else    /* Not supported descriptor */
    {
        locDescIndex = CYBLE_HTS_DESCR_COUNT;
    }

    if(locDescIndex < CYBLE_HTS_DESCR_COUNT)
    {
        if(cyBle_htsc.charInfo[discoveryCharIndex].descrHandle[locDescIndex] == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            cyBle_htsc.charInfo[discoveryCharIndex].descrHandle[locDescIndex] = discDescrInfo->descrHandle;
        }
        else    /* Duplication of descriptor */
        {
            CyBle_ApplCallback(CYBLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo->uuid);
        }
    }
}
Beispiel #5
0
/******************************************************************************
##Function Name: CyBle_GattcIndicationEventHandler
*******************************************************************************

Summary:
 Handles the Indication Event.

Parameters:
 *eventParam: The pointer to the data structure specified by the event.

Return:
 None.

******************************************************************************/
void CyBle_GattcIndicationEventHandler(CYBLE_GATTC_HANDLE_VALUE_IND_PARAM_T *eventParam)
{
    if(cyBle_gattc.serviceChanged.valueHandle == eventParam->handleValPair.attrHandle)
    {
        CyBle_ApplCallback((uint32)CYBLE_EVT_GATTC_INDICATION, eventParam);
        cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
    }
}
/****************************************************************************** 
##Function Name: CyBle_HrscDiscoverCharDescriptorsEventHandler
*******************************************************************************

Summary:
 This function is called on receiving a CYBLE_EVT_GATTC_READ_BY_TYPE_RSP
 event. Based on the service UUID, an appropriate data structure is populated
 using the data received as part of the callback.

Parameters:
 *discCharInfo: The pointer to a characteristic information structure.

Return:
 None

******************************************************************************/
void CyBle_HrscDiscoverCharDescriptorsEventHandler(CYBLE_DISC_DESCR_INFO_T * discDescrInfo)
{
    if(CYBLE_UUID_CHAR_CLIENT_CONFIG == discDescrInfo->uuid.uuid16)
    {
        if(cyBle_hrsc.hrmCccdHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            cyBle_hrsc.hrmCccdHandle = discDescrInfo->descrHandle;
        }
        else    /* Duplication of descriptor */
        {
            CyBle_ApplCallback(CYBLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo->uuid);
        }
    }
}
Beispiel #7
0
/******************************************************************************
##Function Name: CyBle_BlscDiscoverCharDescriptorsEventHandler
*******************************************************************************

Summary:
 This function is called on receiving a "CYBLE_EVT_GATTC_READ_BY_TYPE_RSP"
 event. Based on the service UUID, an appropriate data structure is populated
 using the data received as part of the callback.

Parameters:
 *discCharInfo:  the pointer to a characteristic information structure.

Return:
 None

******************************************************************************/
void CyBle_BlscDiscoverCharDescriptorsEventHandler(CYBLE_DISC_DESCR_INFO_T * discDescrInfo)
{
    if(CYBLE_UUID_CHAR_CLIENT_CONFIG == discDescrInfo->uuid.uuid16)
    {
        uint8 descrIdx = cyBle_disCount - CYBLE_SCDI_BLS_BPM;
        
        if(cyBle_blsc.charInfo[descrIdx].cccdHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            cyBle_blsc.charInfo[descrIdx].cccdHandle = discDescrInfo->descrHandle;
        }
        else    /* Duplication of descriptor */
        {
            CyBle_ApplCallback(CYBLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo->uuid);
        }
    }
}
Beispiel #8
0
/******************************************************************************
##Function Name: CyBle_GlscDiscoverCharacteristicsEventHandler
*******************************************************************************

Summary:
 This function is called on receiving a CYBLE_EVT_GATTC_READ_BY_TYPE_RSP
 event. Based on the service UUID, an appropriate data structure is populated
 using the data received as part of the callback.

Parameters:
 *discCharInfo: The pointer to a characteristic information structure.

Return:
 None

******************************************************************************/
void CyBle_GlscDiscoverCharacteristicsEventHandler(CYBLE_DISC_CHAR_INFO_T *discCharInfo)
{
    /* Glucose Service characteristics UUIDs */
    static const CYBLE_UUID16 cyBle_glscCharUuid[CYBLE_GLS_CHAR_COUNT] =
    {
        CYBLE_UUID_CHAR_GLUCOSE_MSRMNT,
        CYBLE_UUID_CHAR_GL_MSRMT_CTX,
        CYBLE_UUID_CHAR_GL_FEATURE,
        CYBLE_UUID_CHAR_RACP
    };
    static CYBLE_GATT_DB_ATTR_HANDLE_T *glsLastEndHandle = NULL;
    uint8 i;
    
    /* Update last characteristic endHandle to declaration handle of this characteristic */
    if(glsLastEndHandle != NULL)
    {
        *glsLastEndHandle = discCharInfo->charDeclHandle - 1u;
        glsLastEndHandle = NULL;
    }
    
    for(i = 0u; i < (uint8) CYBLE_GLS_CHAR_COUNT; i++)
    {
        if(cyBle_glscCharUuid[i] == discCharInfo->uuid.uuid16)
        {
            if(cyBle_glsc.charInfo[i].valueHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
            {
                cyBle_glsc.charInfo[i].valueHandle = discCharInfo->valueHandle;
                cyBle_glsc.charInfo[i].properties = discCharInfo->properties;
                glsLastEndHandle = &cyBle_glsc.charInfo[i].endHandle;
            }
            else
            {
                CyBle_ApplCallback(CYBLE_EVT_GATTC_CHAR_DUPLICATION, &discCharInfo->uuid);
            }
        }
    }
    
    /* Init characteristic endHandle to Service endHandle.
       Characteristic endHandle will be updated to the declaration
       Handler of the following characteristic,
       in the following characteristic discovery procedure. */
    if(glsLastEndHandle != NULL)
    {
        *glsLastEndHandle = cyBle_serverInfo[CYBLE_SRVI_GLS].range.endHandle;
    }
}
/******************************************************************************
* Function Name: CyBle_AnsDiscoverCharDescriptorsEventHandler
***************************************************************************//**
* 
*  This function is called on receiving a CYBLE_EVT_GATTC_FIND_INFO_RSP event. 
*  This event is generated when a server successfully sends the data for 
*  CYBLE_EVT_GATTC_FIND_INFO_REQ. Based on the service UUID, an appropriate data 
*  structure is populated to the service with a service callback.
* 
*  \param CYBLE_DISC_DESCR_INFO_T * discCharInfo: The pointer to a characteristic 
*                                           information structure.
* 
******************************************************************************/
void CyBle_AnscDiscoverCharDescriptorsEventHandler(CYBLE_DISC_DESCR_INFO_T * discDescrInfo)
{
    if(discDescrInfo->uuid.uuid16 == CYBLE_UUID_CHAR_CLIENT_CONFIG)
    {
        if(cyBle_ansc.characteristics[CYBLE_ANS_NEW_ALERT].descriptors[CYBLE_ANS_CCCD] ==
            CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            cyBle_ansc.characteristics[CYBLE_ANS_NEW_ALERT].descriptors[CYBLE_ANS_CCCD] =
                discDescrInfo->descrHandle;
        }
        else if(cyBle_ansc.characteristics[CYBLE_ANS_UNREAD_ALERT_STATUS].descriptors[CYBLE_ANS_CCCD] ==
            CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            cyBle_ansc.characteristics[CYBLE_ANS_UNREAD_ALERT_STATUS].descriptors[CYBLE_ANS_CCCD] =
                discDescrInfo->descrHandle;
        }
        else    /* Duplication of descriptor */
        {
            CyBle_ApplCallback((uint32)CYBLE_EVT_GATTC_DESCR_DUPLICATION, &discDescrInfo->uuid);
        }
    }
}
/****************************************************************************** 
##Function Name: CyBle_HrssWriteEventHandler
*******************************************************************************

Summary:
 Handles the Heart Rate Measurement Client Configuration Characteristic
 Descriptor Write Event or Control Point Characteristic Write Event.

Parameters:
 void *eventParam: The pointer to the data structure specified by the event.

Return:
 None

******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_HrssWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    uint32 eventCode = 0u;
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;
    CYBLE_HRS_CHAR_VALUE_T locCharIndex;

    locCharIndex.connHandle = eventParam->connHandle;
    locCharIndex.value = NULL;
    
    if(eventParam->handleValPair.attrHandle == cyBle_hrss.hrmCccdHandle)
    {
        locCharIndex.charIndex = CYBLE_HRS_HRM;
        /* Heart Rate Measurement characteristic descriptor write request */
        if(CYBLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
        {
            eventCode = (uint32)CYBLE_EVT_HRSS_NOTIFICATION_ENABLED;
        }
        else
        {
            eventCode = (uint32)CYBLE_EVT_HRSS_NOTIFICATION_DISABLED;
        }
    #if((CYBLE_GAP_ROLE_PERIPHERAL || CYBLE_GAP_ROLE_CENTRAL) && (CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES))
        /* Set flag to store bonding data to flash */
        cyBle_pendingFlashWrite |= CYBLE_PENDING_CCCD_FLASH_WRITE_BIT;
    #endif /* (CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES) */
        
        cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
    }
    else if(eventParam->handleValPair.attrHandle == cyBle_hrss.charHandle[CYBLE_HRS_CPT])
    {
        locCharIndex.charIndex = CYBLE_HRS_CPT;
        /* Heart Rate Control Point characteristic write request */
        if(CYBLE_HRS_RESET_ENERGY_EXPENDED == eventParam->handleValPair.value.val[0u])
        {
            eventCode = (uint32)CYBLE_EVT_HRSS_ENERGY_EXPENDED_RESET;
        }
        else
        {
            gattErr = CYBLE_GATT_ERR_HEART_RATE_CONTROL_POINT_NOT_SUPPORTED;
        }
        
        cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
    }
    else
    {
        /* Heart Rate Service doesn't support any other write requests */
    }

    if(0u != eventCode)
    {
        gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 0u, 
                    &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);
        
        if(CYBLE_GATT_ERR_NONE == gattErr)
        {
            if(NULL != CyBle_HrsApplCallback)
            {
                CyBle_HrsApplCallback(eventCode, &locCharIndex);
            }
            else
            {
                CyBle_ApplCallback(CYBLE_EVT_GATTS_WRITE_REQ, eventParam);
            }
        }
    }

    return (gattErr);
}