/****************************************************************************** ##Function Name: CyBle_HrssSendNotification ******************************************************************************* Summary: Sends notification of a specified Heart Rate Service characteristic value to the Client device. No response is expected. The CYBLE_EVT_HRSC_NOTIFICATION event is received by the peer device, on invoking this function. Parameters: connHandle: The connection handle which consist of the device ID and ATT connection ID. charIndex: The index of a service characteristic. attrSize: The size of the characteristic value attribute. The Heart Rate Measurement characteristic has a 20 byte length (by default). The Body Sensor Location and Control Point characteristic both have 1 byte length. *attrValue: The pointer to the characteristic value data that should be sent to the client device. Return: Return value is of type CYBLE_API_RESULT_T. * CYBLE_ERROR_OK - The request handled successfully * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted * CYBLE_ERROR_INVALID_STATE - Connection with the client is not established * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. * CYBLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. ******************************************************************************/ CYBLE_API_RESULT_T CyBle_HrssSendNotification(CYBLE_CONN_HANDLE_T connHandle, CYBLE_HRS_CHAR_INDEX_T charIndex, uint8 attrSize, uint8 *attrValue) { CYBLE_API_RESULT_T apiResult; CYBLE_GATTS_HANDLE_VALUE_NTF_T ntfReqParam; /* Send Notification if it is enabled and connected */ if(CYBLE_STATE_CONNECTED != CyBle_GetState()) { apiResult = CYBLE_ERROR_INVALID_STATE; } else if(charIndex >= CYBLE_HRS_CHAR_COUNT) { apiResult = CYBLE_ERROR_INVALID_PARAMETER; } else if((cyBle_hrss.hrmCccdHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE) || (!CYBLE_IS_NOTIFICATION_ENABLED(cyBle_hrss.hrmCccdHandle))) { apiResult = CYBLE_ERROR_NTF_DISABLED; } else { /* Fill all fields of write request structure ... */ ntfReqParam.attrHandle = cyBle_hrss.charHandle[charIndex]; ntfReqParam.value.val = attrValue; ntfReqParam.value.len = attrSize; /* Send notification to client using previously filled structure */ apiResult = CyBle_GattsNotification(connHandle, &ntfReqParam); } return (apiResult); }
/****************************************************************************** * Function Name: CyBle_AnssSendNotification ***************************************************************************//** * * Sends a notification with the characteristic value, as specified by its charIndex, * to the Client device. * On enabling notification successfully for a service characteristic, if the GATT * server has an updated value to be notified to the GATT Client, it sends out a * 'Handle Value Notification' which results in CYBLE_EVT_ANSC_NOTIFICATION event * at the GATT Client's end. * * \param connHandle: The connection handle. * \param charIndex: The index of the service characteristic of type CYBLE_ANS_CHAR_INDEX_T. * The valid values are, * * CYBLE_ANS_UNREAD_ALERT_STATUS * * CYBLE_ANS_NEW_ALERT * \param attrSize: The size of the characteristic value attribute. * \param attrValue: The pointer to the characteristic value data that should be sent * to the Client device. * * \return * Return value is of type CYBLE_API_RESULT_T. * * CYBLE_ERROR_OK - The function completed successfully. * * CYBLE_ERROR_INVALID_PARAMETER - Validation of input parameter is failed. * * CYBLE_ERROR_INVALID_OPERATION - Operation is invalid for this. * characteristic. * * CYBLE_ERROR_INVALID_STATE - Connection with the client is not established. * * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. * * CYBLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. * ******************************************************************************/ CYBLE_API_RESULT_T CyBle_AnssSendNotification(CYBLE_CONN_HANDLE_T connHandle, CYBLE_ANS_CHAR_INDEX_T charIndex, uint8 attrSize, uint8 *attrValue) { CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_INVALID_PARAMETER; if((charIndex == CYBLE_ANS_NEW_ALERT) || (charIndex == CYBLE_ANS_UNREAD_ALERT_STATUS)) { /* Send Notification if it is enabled and connected */ if(CYBLE_STATE_CONNECTED != CyBle_GetState()) { apiResult = CYBLE_ERROR_INVALID_STATE; } else if(!CYBLE_IS_NOTIFICATION_ENABLED(cyBle_anss.charInfo[charIndex].descrHandle[CYBLE_ANS_CCCD])) { apiResult = CYBLE_ERROR_NTF_DISABLED; } else { CYBLE_GATTS_HANDLE_VALUE_NTF_T ntfReqParam; /* Fill all fields of write request structure ... */ ntfReqParam.attrHandle = cyBle_anss.charInfo[charIndex].charHandle; ntfReqParam.value.val = attrValue; ntfReqParam.value.len = attrSize; /* Send notification to client using previously filled structure */ apiResult = CyBle_GattsNotification(connHandle, &ntfReqParam); } } return (apiResult); }
/****************************************************************************** ##Function Name: CyBle_BassSendNotification ******************************************************************************* Summary: This function updates the value of the Battery Level characteristic in the GATT database. If the client has configured a notification on the Battery Level characteristic, the function additionally sends this value using a GATT Notification message. The CYBLE_EVT_BASC_NOTIFICATION event is received by the peer device, on invoking this function. Parameters: connHandle: The BLE peer device connection handle serviceIndex: The index of the service instance. e.g. If two Battery Services are supported in your design, then first service will be identified by serviceIndex of 0 and the second by serviceIndex of 1. charIndex: The index of a service characteristic of type CYBLE_BAS_CHAR_INDEX_T. attrSize: The size of the characteristic value attribute. A battery level characteristic has 1 byte length. *attrValue: The pointer to the characteristic value data that should be sent to the Client device. Return: Return value is of type CYBLE_API_RESULT_T. * CYBLE_ERROR_OK - The request handled successfully * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameter failed * CYBLE_ERROR_INVALID_OPERATION - This operation is not permitted * CYBLE_ERROR_INVALID_STATE - Connection with the client is not established * CYBLE_ERROR_MEMORY_ALLOCATION_FAILED - Memory allocation failed. * CYBLE_ERROR_NTF_DISABLED - Notification is not enabled by the client. ******************************************************************************/ CYBLE_API_RESULT_T CyBle_BassSendNotification(CYBLE_CONN_HANDLE_T connHandle, uint8 serviceIndex, CYBLE_BAS_CHAR_INDEX_T charIndex, uint8 attrSize, uint8 *attrValue) { CYBLE_API_RESULT_T apiResult; /* Store new data in database */ apiResult = CyBle_BassSetCharacteristicValue(serviceIndex, charIndex, attrSize, attrValue); if(CYBLE_ERROR_OK == apiResult) { /* Send Notification if it is enabled and connected */ if(CYBLE_STATE_CONNECTED != CyBle_GetState()) { apiResult = CYBLE_ERROR_INVALID_STATE; } else if((cyBle_bass[serviceIndex].cccdHandle == CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE) || (!CYBLE_IS_NOTIFICATION_ENABLED(cyBle_bass[serviceIndex].cccdHandle))) { apiResult = CYBLE_ERROR_NTF_DISABLED; } else { CYBLE_GATTS_HANDLE_VALUE_NTF_T ntfReqParam; /* Fill all fields of write request structure ... */ ntfReqParam.attrHandle = cyBle_bass[serviceIndex].batteryLevelHandle; ntfReqParam.value.val = attrValue; ntfReqParam.value.len = attrSize; /* Send notification to client using previously filled structure */ apiResult = CyBle_GattsNotification(connHandle, &ntfReqParam); } } return (apiResult); }