Exemplo n.º 1
0
/*************************************************************************************************************************
* Function Name: UpdateNotificationCCCDAttribute
**************************************************************************************************************************
* Summary: This function updates the notification handle status and reports 
* it to BLE component database so that it can be read by Central device.
*
* Parameters:
*  void
*
* Return:
*  void
*
*************************************************************************************************************************/
void UpdateNotificationCCCDAttribute(void)
{
	/* Update notification attribute only when there is change in temperature CCCD */
    if(UpdateTemperatureNotificationAttribute)
    {
        UpdateTemperatureNotificationAttribute = FALSE; //Clear the flag
        
        /* Write the current temperature notification status to the local variable */
        TemperatureNotificationCCCDValue[0x00] = TemperatureNotificationEnabled;
        TemperatureNotificationCCCDValue[0x01] = ZERO;
        
        /* Update CCCD handle with notification status data */
    	TemperatureNotificationCCCDHandle.attrHandle = CYBLE_BMP180_TEMPERATURE_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;
    	TemperatureNotificationCCCDHandle.value.val = TemperatureNotificationCCCDValue;
    	TemperatureNotificationCCCDHandle.value.len = sizeof(TemperatureNotificationCCCDValue);
    	
    	/* Send the updated handle as part of attribute for notifications */
    	CyBle_GattsWriteAttributeValue(&TemperatureNotificationCCCDHandle, 0x00, &ConnectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
    }
    
    /* Update notification attribute only when there is change in pressure CCCD */
    if(UpdatePressureNotificationAttribute)
    {
        UpdatePressureNotificationAttribute = FALSE; //Clear the flag
        
        /* Write the current pressure notification status to the local variable */
        PressureNotificationCCCDValue[0x00] = PressureNotificationEnabled;
        PressureNotificationCCCDValue[0x01] = ZERO;
        
        /* Update CCCD handle with notification status data */
    	PressureNotificationCCCDHandle.attrHandle = CYBLE_BMP180_PRESSURE_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;
    	PressureNotificationCCCDHandle.value.val = PressureNotificationCCCDValue;
    	PressureNotificationCCCDHandle.value.len = sizeof(PressureNotificationCCCDValue);
    	
    	/* Send the updated handle as part of attribute for notifications */
    	CyBle_GattsWriteAttributeValue(&PressureNotificationCCCDHandle, 0x00, &ConnectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
    }
    
    /* Update notification attribute only when there is change in altitude CCCD */
    if(UpdateAltitudeNotificationAttribute)
    {
        UpdateAltitudeNotificationAttribute = FALSE; //Clear the flag
        
        /* Write the current altitude notification status to the local variable */
        AltitudeNotificationCCCDValue[0x00] = AltitudeNotificationEnabled;
        AltitudeNotificationCCCDValue[0x01] = ZERO;
        
        /* Update CCCD handle with notification status data */
    	AltitudeNotificationCCCDHandle.attrHandle = CYBLE_BMP180_ALTITUDE_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;
    	AltitudeNotificationCCCDHandle.value.val = AltitudeNotificationCCCDValue;
    	AltitudeNotificationCCCDHandle.value.len = sizeof(AltitudeNotificationCCCDValue);
    	
    	/* Send the updated handle as part of attribute for notifications */
    	CyBle_GattsWriteAttributeValue(&AltitudeNotificationCCCDHandle, 0x00, &ConnectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
    }
}
Exemplo n.º 2
0
/*****************************************************************************
* Function Name: _BLE_UpdateCCCD()
******************************************************************************
* Summary:
*   Update the data handle for notification status and report it to BLE 
*	component so that it can be read by Central device.
*
* Parameters:
*   None.
*
* Return:
*   None.
*
* Note:
*   
*****************************************************************************/
void _BLE_UpdateCCCD(void)
{
	// Local variable to store the wanted CCCD value.
	uint8 CCCDvalue[CCC_DATA_LEN];
    
    // Handle value to update the CCCD.
    CYBLE_GATT_HANDLE_VALUE_PAIR_T CCCDhandle;

    // Update sensors notification/indication attribute only when there has 
    // been a write request.
    if(updateSensorsCCCDreq && _BLE_deviceConnected)
	{
		// Reset the flag.
		updateSensorsCCCDreq = FALSE;
	
		// Write the present notification/indication status to the local variable.
		CCCDvalue[0] = sendDataNotifications;
		CCCDvalue[1] = sendDataIndications;
		
		// Update CCCD handle with notification status data.
		CCCDhandle.attrHandle = CYBLE_CAPSENSE_SENSORS_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;
		CCCDhandle.value.val = CCCDvalue;
		CCCDhandle.value.len = CCC_DATA_LEN;
		
		// Report data to BLE component for sending data when read by Central device.
		CyBle_GattsWriteAttributeValue(&CCCDhandle, 0, &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
	}
    
    // Update sensors notification/indication attribute only when there has 
    // been a write request.
    if(updateStatusCCCDreq && _BLE_deviceConnected)
	{
		// Reset the flag.
		updateStatusCCCDreq = FALSE;
	
		// Write the present notification/indication status to the local variable.
		CCCDvalue[0] = sendStatusNotifications;
		CCCDvalue[1] = sendStatusIndications;
		
		// Update CCCD handle with notification status data.
		CCCDhandle.attrHandle = CYBLE_CAPSENSE_STATUS_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;
		CCCDhandle.value.val = CCCDvalue;
		CCCDhandle.value.len = CCC_DATA_LEN;
		
		// Report data to BLE component for sending data when read by Central device.
		CyBle_GattsWriteAttributeValue(&CCCDhandle, 0, &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
	}	
}
Exemplo n.º 3
0
/****************************************************************************** 
##Function Name: CyBle_BcssSetCharacteristicValue
*******************************************************************************

Summary:
 Sets a value for one of three characteristic values of the Weight Scale 
 Service. The characteristic is identified by charIndex.

Parameters:
 charIndex: The index of a Body Composition Service characteristic.
 attrSize: The size of the characteristic value attribute.
 attrValue: The pointer to the characteristic value data that should be 
            stored to the GATT database.

Return:
 Return value is of type CYBLE_API_RESULT_T.
  * CYBLE_ERROR_OK - The characteristic value was written successfully.
  * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed.

******************************************************************************/
CYBLE_API_RESULT_T CyBle_BcssSetCharacteristicValue(CYBLE_BCS_CHAR_INDEX_T charIndex, uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T wssHandleValuePair;

    if(NULL != attrValue)
    {
        if(charIndex == CYBLE_BCS_BODY_COMPOSITION_FEATURE)
        {
            /* Fill the structure */
            wssHandleValuePair.attrHandle = cyBle_bcss.charInfo[CYBLE_BCS_BODY_COMPOSITION_FEATURE].charHandle;
            wssHandleValuePair.value.len = attrSize;
            wssHandleValuePair.value.val = attrValue;
            
            if(CYBLE_GATT_ERR_NONE == 
                CyBle_GattsWriteAttributeValue(&wssHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED))
            {
                /* Indicate success */
                apiResult = CYBLE_ERROR_OK;
            }
        }
    }

    /* Return status */
    return(apiResult);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
/******************************************************************************
##Function Name: CyBle_HtssSetCharacteristicDescriptor
*******************************************************************************

Summary:
 Sets the characteristic descriptor of the specified characteristic.

Parameters:
 charIndex:  The index of the service characteristic.
 descrIndex: The index of the service characteristic descriptor.
 attrSize:   The size of the characteristic descriptor attribute.
 *attrValue: The pointer to the descriptor value data that should 
             be stored in the GATT database. 

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_API_RESULT_T CyBle_HtssSetCharacteristicDescriptor(CYBLE_HTS_CHAR_INDEX_T charIndex,
    CYBLE_HTS_DESCR_INDEX_T descrIndex, uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_OK;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;

    if((charIndex >= CYBLE_HTS_CHAR_COUNT) || (descrIndex >= CYBLE_HTS_DESCR_COUNT))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else
    {
        locHandleValuePair.attrHandle = cyBle_htss.charInfo[charIndex].descrHandle[descrIndex];
        if(locHandleValuePair.attrHandle != CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE)
        {
            locHandleValuePair.value.len = attrSize;
            locHandleValuePair.value.val = attrValue;
            if(CYBLE_GATT_ERR_NONE !=
                CyBle_GattsWriteAttributeValue(&locHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED))
            {
                apiResult = CYBLE_ERROR_INVALID_PARAMETER;
            }
        }
        else
        {
            apiResult = CYBLE_ERROR_INVALID_PARAMETER;
        }
    }
    return (apiResult);
}
Exemplo n.º 6
0
void UpdateRGBled(void)
{
	/* Local variables to calculate the color components from RGB received data*/
	uint8 debug_red;
	uint8 debug_green;
	uint8 debug_blue;
	uint8 intensity_divide_value = RGBledData[INTENSITY_INDEX];
	
	debug_red = (uint8)(((uint16)RGBledData[RED_INDEX] * intensity_divide_value) / 255);
	debug_green = (uint8)(((uint16)RGBledData[GREEN_INDEX] * intensity_divide_value) / 255);
	debug_blue = (uint8)(((uint16)RGBledData[BLUE_INDEX] * intensity_divide_value) / 255);
	
	/* Update the density value of the PrISM module for color control*/
	PrISM_1_WritePulse0(RGB_LED_MAX_VAL - debug_red);
    PrISM_1_WritePulse1(RGB_LED_MAX_VAL - debug_green);
    PrISM_2_WritePulse0(RGB_LED_MAX_VAL - debug_blue);
	
	/* Update RGB control handle with new values */
	rgbHandle.attrHandle = CYBLE_RGB_LED_SERVICE_RGB_LED_CHARACTERISTIC_CHAR_HANDLE;
	rgbHandle.value.val = RGBledData;
	rgbHandle.value.len = RGB_CHAR_DATA_LEN;
	rgbHandle.value.actualLen = RGB_CHAR_DATA_LEN;
	
	/* Send updated RGB control handle as attribute for read by central device */
	CyBle_GattsWriteAttributeValue(&rgbHandle, FALSE, &cyBle_connHandle, FALSE);  
}
Exemplo n.º 7
0
/******************************************************************************
##Function Name: CyBle_GlssSetCharacteristicValue
*******************************************************************************

Summary:
 Sets a characteristic value of the service, which is identified by charIndex.

Parameters:
 charIndex: The index of a service characteristic.
 attrSize: The size of the characteristic value attribute.
 *attrValue: The pointer to the characteristic value data that should be
              stored in the GATT database.

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_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent

******************************************************************************/
CYBLE_API_RESULT_T CyBle_GlssSetCharacteristicValue(CYBLE_GLS_CHAR_INDEX_T charIndex, uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult;
    
    /* Check the parameters */
    if(charIndex >= CYBLE_GLS_CHAR_COUNT) 
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else if(CYBLE_GATT_INVALID_ATTR_HANDLE_VALUE == cyBle_glss.charInfo[charIndex].charHandle)
    {
        apiResult = CYBLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE;
    }
    else
    {
        CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;
        
        /* Store characteristic value into GATT database */
        locHandleValuePair.attrHandle = cyBle_glss.charInfo[charIndex].charHandle;
        locHandleValuePair.value.len = attrSize;
        locHandleValuePair.value.val = attrValue;
        
        if(CYBLE_GATT_ERR_NONE != CyBle_GattsWriteAttributeValue(&locHandleValuePair,
                                    0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED))
        {
            apiResult = CYBLE_ERROR_INVALID_PARAMETER;
        }
        else
        {
            apiResult = CYBLE_ERROR_OK;
        }
    }

    return (apiResult);
}
Exemplo n.º 8
0
/******************************************************************************
##Function Name: CyBle_BassSetCharacteristicValue
*******************************************************************************

Summary:
 Sets a characteristic value of the service in the local database.

Parameters:
 serviceIndex: The index of the service instance.
 charIndex: The index of the 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
              stored to the GATT database.

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_API_RESULT_T CyBle_BassSetCharacteristicValue(uint8 serviceIndex, CYBLE_BAS_CHAR_INDEX_T charIndex,
    uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_OK;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;

    if((serviceIndex >= CYBLE_BASS_SERVICE_COUNT) || (charIndex >= CYBLE_BAS_CHAR_COUNT) ||
       (attrSize != CYBLE_BAS_BATTERY_LEVEL_LEN) || (*attrValue > CYBLE_BAS_MAX_BATTERY_LEVEL_VALUE))
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
    else
    {
        /* Store data in database */
        locHandleValuePair.attrHandle = cyBle_bass[serviceIndex].batteryLevelHandle;
        locHandleValuePair.value.len = attrSize;
        locHandleValuePair.value.val = attrValue;
        if(CYBLE_GATT_ERR_NONE !=
            CyBle_GattsWriteAttributeValue(&locHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED))
        {
            apiResult = CYBLE_ERROR_INVALID_PARAMETER;
        }
    }
    return (apiResult);
}
Exemplo n.º 9
0
/****************************************************************************** 
##Function Name: CyBle_HrssSetCharacteristicValue
*******************************************************************************

Summary:
 Sets local characteristic value of the specified Heart Rate Service 
 characteristic.

Parameters:
 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
                  stored in the GATT database.

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_GATT_DB_INVALID_ATTR_HANDLE - Optional characteristic is absent

******************************************************************************/
CYBLE_API_RESULT_T CyBle_HrssSetCharacteristicValue(CYBLE_HRS_CHAR_INDEX_T charIndex, uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_OK;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;

    if(charIndex >= CYBLE_HRS_CHAR_COUNT)
    {
        apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    }
	else if((charIndex == CYBLE_HRS_BSL) && (!CYBLE_HRS_IS_BSL_SUPPORTED))
    {
        apiResult = CYBLE_ERROR_GATT_DB_INVALID_ATTR_HANDLE;
    }
    else
    {
        /* Store characteristic value into GATT database */
        locHandleValuePair.attrHandle = cyBle_hrss.charHandle[charIndex];
        locHandleValuePair.value.len = attrSize;
        locHandleValuePair.value.val = attrValue;
        
        if(CYBLE_GATT_ERR_NONE != CyBle_GattsWriteAttributeValue(&locHandleValuePair,
                                                0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED))
        {
            apiResult = CYBLE_ERROR_INVALID_PARAMETER;
        }
    }

    return (apiResult);
}
Exemplo n.º 10
0
/****************************************************************************** 
* Function Name: CyBle_IassWriteCmdEventHandler
***************************************************************************//**
* 
*  Handles the Write Without Response Request Event for the Immediate Alert 
*  Service.
* 
*  \param CYBLE_GATTS_WRITE_CMD_REQ_PARAM_T * eventParam: The pointer to a data structure
*                                                    specified by the event.
* 
* \return
*  None
* 
******************************************************************************/
void CyBle_IassWriteCmdEventHandler(CYBLE_GATTS_WRITE_CMD_REQ_PARAM_T *eventParam)
{
    CYBLE_IAS_CHAR_VALUE_T wrCmdParam;
    
    if(NULL != CyBle_IasApplCallback)
    {
        /* Check if attribute handle is handle of Alert Level characteristic of
           Immediate Alert service. */
        if((cyBle_iass.alertLevelCharHandle == eventParam->handleValPair.attrHandle) &&
            (CYBLE_IAS_ALERT_LEVEL_SIZE == eventParam->handleValPair.value.len) &&
                (CYBLE_HIGH_ALERT >= eventParam->handleValPair.value.val[0u]))
        {   
            /* Input parameters validation passed, so save Alert Level */
            if(CYBLE_GATT_ERR_NONE ==
                CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 
                                               0u, 
                                               &eventParam->connHandle,
                                               CYBLE_GATT_DB_PEER_INITIATED))
            {
                wrCmdParam.connHandle = eventParam->connHandle;
                wrCmdParam.charIndex = CYBLE_IAS_ALERT_LEVEL;
                wrCmdParam.value = &eventParam->handleValPair.value;
                
                /* Send callback to user if no error occurred while writing Alert Level */
                CyBle_IasApplCallback((uint32) CYBLE_EVT_IASS_WRITE_CHAR_CMD, (void *) &wrCmdParam);
                cyBle_eventHandlerFlag &= (uint8) (~CYBLE_CALLBACK);
            }
        }
        /* As this handler handles Write Without Response request the error response
          can't be sent for the Client. The erroneous value will be with
          CYBLE_EVT_GATTS_WRITE_CMD_REQ event. User will decide how to handle it. */
    }
}
Exemplo n.º 11
0
/******************************************************************************
##Function Name: CyBle_BlssWriteEventHandler
*******************************************************************************

Summary:
 Handles the Write Request Event.

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

Return:
  CYBLE_GATT_ERR_CODE_T - An API result state if the API succeeded 
                           (CYBLE_GATT_ERR_NONE) or GATT error codes returned
                           by CyBle_GattsWriteAttributeValue();

******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_BlssWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;
    
    if(NULL != CyBle_BlsApplCallback)
    {
	    CYBLE_BLS_CHAR_VALUE_T locCharIndex;
        locCharIndex.connHandle = eventParam->connHandle;
	    locCharIndex.value = NULL;
    
        for (locCharIndex.charIndex = CYBLE_BLS_BPM; locCharIndex.charIndex < CYBLE_BLS_BPF; locCharIndex.charIndex++)
        {
            if(eventParam->handleValPair.attrHandle == cyBle_blss.charInfo[locCharIndex.charIndex].cccdHandle)
            {
                gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair,
                            0u, &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);
            
                if(CYBLE_GATT_ERR_NONE == gattErr)
                {
                    uint32 eventCode;
                    
                    if(locCharIndex.charIndex == CYBLE_BLS_ICP)
                    {
                        if(CYBLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
                        {
                            eventCode = (uint32) CYBLE_EVT_BLSS_NOTIFICATION_ENABLED;
                        }
                        else
                        {
                            eventCode = (uint32) CYBLE_EVT_BLSS_NOTIFICATION_DISABLED;
                        }
                    }
                    else
                    {
                        if(CYBLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
                        {
                            eventCode = (uint32) CYBLE_EVT_BLSS_INDICATION_ENABLED;
                        }
                        else
                        {
                            eventCode = (uint32) CYBLE_EVT_BLSS_INDICATION_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_BlsApplCallback(eventCode, &locCharIndex);
                }
				    
                cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
                break;
			}
        }
    }

    return (gattErr);
}
Exemplo n.º 12
0
/*****************************************************************************
* Function Name: _BLE_UpdateControl()
******************************************************************************
* Summary:
*   Update the values of the 'Control' characteristic.
*
* Parameters:
*   None.
*
* Return:
*   None.
*
* Note:
*   
*****************************************************************************/
void _BLE_UpdateControl(void)
{
    // Local variable to store the wanted control values.
	uint8 ControlValues[NUM_CONTROLS];
    
    // Handle value to update the control values.
    CYBLE_GATT_HANDLE_VALUE_PAIR_T ControlHandle;

    // Update control attribute only when there has been a write request.
    if(updateControlValuesReq && _BLE_deviceConnected)
    {
		// Reset the flag.
		updateControlValuesReq = FALSE;
        
		// Write the present control values to the local variable.
		ControlValues[CONTROL_ACQUIRE_DATA_BYTE_MASK] = _BLE_acquireData;
		ControlValues[CONTROL_SEND_DATA_BYTE_MASK] = _BLE_sendData;
        ControlValues[CONTROL_SEND_DATA_SYNCHRONOUSLY_BYTE_MASK] = _BLE_sendDataSynchronously;
		
		// Update control values handle.
		ControlHandle.attrHandle = CYBLE_CAPSENSE_CONTROL_CHAR_HANDLE;
		ControlHandle.value.val = ControlValues;
		ControlHandle.value.len = NUM_CONTROLS;
		
		// Report data to BLE component.
		CyBle_GattsWriteAttributeValue(&ControlHandle, 0, &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
    }
}
Exemplo n.º 13
0
/******************************************************************************
* Function Name: CyBle_BassWriteEventHandler
***************************************************************************//**
* 
*  Handles the Write Request Event for Battery service.
* 
*  \param void *eventParam: the pointer to the data structure specified by the event.
* 
* \return
*  Return value is of type CYBLE_GATT_ERR_CODE_T.
*   * CYBLE_GATT_ERR_NONE - Write request is handled successfully.
*   * CYBLE_GATT_ERR_REQUEST_NOT_SUPPORTED - Notification isn't supported.
*   * CYBLE_GATT_ERR_UNLIKELY_ERROR - Internal error while writing attribute
*                                      value.
* 
******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_BassWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    uint8 locServIndex = 0u;
    CYBLE_BAS_CHAR_VALUE_T locCharIndex;
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;

    if(NULL != CyBle_BasApplCallback)
    {
        do
        {
            /* Client Characteristic Configuration descriptor write request */
            if(eventParam->handleValPair.attrHandle == cyBle_bass[locServIndex].cccdHandle)
            {
                /* Verify that optional notification property is enabled for Battery Level characteristic */
                if(CYBLE_IS_NOTIFICATION_SUPPORTED(cyBle_bass[locServIndex].batteryLevelHandle))
                {
                    gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 0u, 
                        &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);
                    if(CYBLE_GATT_ERR_NONE == gattErr)
                    {
                        locCharIndex.connHandle = eventParam->connHandle;
                        locCharIndex.serviceIndex = locServIndex;
                        locCharIndex.charIndex = CYBLE_BAS_BATTERY_LEVEL;
                        locCharIndex.value = NULL;
                        
                        if(CYBLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
                        {
                            CyBle_BasApplCallback((uint32)CYBLE_EVT_BASS_NOTIFICATION_ENABLED, &locCharIndex);
                        }
                        else
                        {
                            CyBle_BasApplCallback((uint32)CYBLE_EVT_BASS_NOTIFICATION_DISABLED, &locCharIndex);
                        }
                    #if((CYBLE_GAP_ROLE_PERIPHERAL || CYBLE_GAP_ROLE_CENTRAL) && \
                        (CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES))
                        /* Set flag to store bonding data to flash */
                        if(cyBle_peerBonding == CYBLE_GAP_BONDING)
                        {
                            cyBle_pendingFlashWrite |= CYBLE_PENDING_CCCD_FLASH_WRITE_BIT;
                        }
                    #endif /* (CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES) */
                    }
                }
                else
                {
                    gattErr = CYBLE_GATT_ERR_REQUEST_NOT_SUPPORTED;
                }
                cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
                break;
            }
        locServIndex++;
        }while(locServIndex < CYBLE_BASS_SERVICE_COUNT);
    }
    return (gattErr);
}
Exemplo n.º 14
0
/****************************************************************************** 
##Function Name: CyBle_LlssConnectEventHandler
*******************************************************************************

Summary:
 Handles the Connection Indication event for Link Loss Service. 

Parameters:
 None

Return:
 None

******************************************************************************/
void CyBle_LlssConnectEventHandler(void)
{
    uint8 tmpAlertLevel = CYBLE_NO_ALERT;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T llsHandleValuePair;
    
    llsHandleValuePair.attrHandle = cyBle_llss.alertLevelCharHandle;
    llsHandleValuePair.value.len = CYBLE_LLS_ALERT_LEVEL_SIZE;
    llsHandleValuePair.value.val = &tmpAlertLevel;
    
    /* Input parameters validation passed, so save Alert Level */
    (void) CyBle_GattsWriteAttributeValue(&llsHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED);
}
Exemplo n.º 15
0
/****************************************************************************** 
* Function Name: CyBle_IassDisconnectEventHandler
***************************************************************************//**
* 
*  Handles the Disconnection Indication Event for the Immediate Alert service.
* 
* \return
*  None
* 
******************************************************************************/
void CyBle_IassDisconnectEventHandler(void)
{
    uint8 tmpAlertLevel = CYBLE_NO_ALERT;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T handleVal;
    
    handleVal.attrHandle = cyBle_iass.alertLevelCharHandle;
    handleVal.value.val = &tmpAlertLevel;
    handleVal.value.len = CYBLE_IAS_ALERT_LEVEL_SIZE;
    
    /* Set alert level to "No Alert" per IAS spec */
    (void) CyBle_GattsWriteAttributeValue(&handleVal, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED);
}
Exemplo n.º 16
0
/*******************************************************************************
* Function Name: WriteAttrServChanged()
********************************************************************************
*
* Summary:
*   Sets serviceChangedHandle for enabling or disabling hidden service.
*
* Parameters:
*   None
*
* Return:
*   None
*
*******************************************************************************/
void WriteAttrServChanged(void)
{
    uint32 value;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T    handleValuePair;

    /* Force client to rediscover services in range of bootloader service */
    value = (cyBle_customs[0u].customServiceHandle)<<16u|\
            (cyBle_customs[0u].customServiceInfo[0u].customServiceCharDescriptors[0u]);
    handleValuePair.value.val = (uint8 *)&value;
    handleValuePair.value.len = sizeof(value);

    handleValuePair.attrHandle = cyBle_gatts.serviceChangedHandle;
    CyBle_GattsWriteAttributeValue(&handleValuePair, 0u, NULL,CYBLE_GATT_DB_LOCALLY_INITIATED);
}
Exemplo n.º 17
0
/****************************************************************************** 
##Function Name: CyBle_CtssWriteEventHandler
*******************************************************************************

Summary:
 Handles the Write Request Event for the Current Time Service.

Parameters:
 eventParam: The pointer to the data that came with a write request for the 
             Current Time Service.

Return:
 Return a value of type CYBLE_GATT_ERR_CODE_T:
  * CYBLE_GATT_ERR_NONE - Function terminated successfully.
  * CYBLE_GATT_ERR_INVALID_HANDLE - The Handle of the Current Time Client 
                                     Configuration Characteristic Descriptor
                                     is not valid.
  * CYBLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred.
  * CYBLE_GATT_ERR_REQUEST_NOT_SUPPORTED - The notification property of the
                                            Current Time Client Configuration
                                            Characteristic Descriptor is 
                                            disabled.

******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_CtssWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    CYBLE_CTS_CHAR_VALUE_T wrReqParam;
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;
    uint32 event = (uint32)CYBLE_EVT_CTSS_NOTIFICATION_DISABLED;
    
    if(CyBle_CtsApplCallback != NULL)
    {
        wrReqParam.connHandle = eventParam->connHandle;
        wrReqParam.value = &eventParam->handleValPair.value;

        /* Client Characteristic Configuration descriptor write request */
        if(eventParam->handleValPair.attrHandle == cyBle_ctss.currTimeCccdHandle)
        {
            /* Verify that optional notification property is enabled for Current Time
            * Characteristic.
            */
            if(CYBLE_IS_NOTIFICATION_SUPPORTED(cyBle_ctss.currTimeCharHandle))
            {
                if(CYBLE_IS_NOTIFICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
                {
                    event = (uint32)CYBLE_EVT_CTSS_NOTIFICATION_ENABLED;
                }

                gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 0u, 
                    &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);
                
                if(CYBLE_GATT_ERR_NONE == gattErr)
                {
                    wrReqParam.charIndex = CYBLE_CTS_CURRENT_TIME;
                    wrReqParam.value = NULL;
                    CyBle_CtsApplCallback(event, &wrReqParam);
                }
            #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_GAP_ROLE_PERIPHERAL || CYBLE_GAP_ROLE_CENTRAL) && \
                   * (CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES)
                   */
            }
            else
            {
                gattErr = CYBLE_GATT_ERR_REQUEST_NOT_SUPPORTED;
            }

            /* Clear the callback flag indicating that request was handled */
            cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
        }
Exemplo n.º 18
0
void updateCounter(uint32 data) {
    // Handle value to update the characteristic
    CYBLE_GATT_HANDLE_VALUE_PAIR_T handleValuePair;
    		
    // Update descriptor handle with data
    handleValuePair.attrHandle = COUNTER_CHAR_HANDLE;
    handleValuePair.value.val = (uint8*)&data;
    handleValuePair.value.len = sizeof data;

    // Report data to BLE component for sending data
    // when read by Central device
    CyBle_GattsWriteAttributeValue(
        &handleValuePair, 0,
        &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED
    );
}
Exemplo n.º 19
0
void updateVoltage(uint16_t voltageInMv)
{
    CYBLE_GATTS_HANDLE_VALUE_NTF_T  tempHandle;

 	/* If stack is not busy, then send the notification */
	if(_busyStatus == CYBLE_STACK_STATE_FREE)
    {
        tempHandle.attrHandle = CYBLE_POVDISPLAY_VOLTAGE_CHAR_HANDLE;
        tempHandle.value.val = (uint8_t*)&voltageInMv;
        tempHandle.value.len = 2;
        CyBle_GattsWriteAttributeValue(&tempHandle,0,&cyBle_connHandle,CYBLE_GATT_DB_LOCALLY_INITIATED );
        if (_voltageCCCDValue[0])
        {
		    CyBle_GattsNotification(cyBle_connHandle,&tempHandle);
        }
    }
}
Exemplo n.º 20
0
/****************************************************************************** 
##Function Name: CyBle_LlssWriteEventHandler
*******************************************************************************

Summary:
 Handles the Write Request Event for the Link Loss service.

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

Return:
 CYBLE_GATT_ERR_CODE_T: API result returns one of the following status values:
  * CYBLE_GATT_ERR_NONE - The Alert Level Characteristic was written successfully
  * CYBLE_GATT_ERR_UNLIKELY_ERROR - An Internal Stack error occurred
  * CYBLE_GATT_ERR_INVALID_ATTRIBUTE_LEN - The Data length for the Alert Level
                                            Characteristic handle is invalid
  * CYBLE_GATT_ERR_INVALID_HANDLE - Alert Level Characteristic handle is invalid
  * CYBLE_GATT_ERR_OUT_OF_RANGE - Value is out of allowed range

******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_LlssWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    CYBLE_LLS_CHAR_VALUE_T wrReqParam;
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;

    if(NULL != CyBle_LlsApplCallback)
    {
        if(cyBle_llss.alertLevelCharHandle == eventParam->handleValPair.attrHandle)
        {
            /* Check if attribute handle is handle of Alert Level characteristic of 
               Link Loss service. */
            if ((CYBLE_HIGH_ALERT >= eventParam->handleValPair.value.val[0u]))
            {
                if(CYBLE_LLS_ALERT_LEVEL_SIZE == eventParam->handleValPair.value.len)
                {
                    /* Input parameters validation passed, so save Alert Level */
                    gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 0u, 
                                &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);
                    
                    /* Send callback to user if no error occurred while writing Alert Level */
                    if(CYBLE_GATT_ERR_NONE == gattErr)
                    {
                        wrReqParam.connHandle = eventParam->connHandle;
                        wrReqParam.charIndex = CYBLE_LLS_ALERT_LEVEL;
                        wrReqParam.value = &eventParam->handleValPair.value;
                        
                        CyBle_LlsApplCallback((uint32) CYBLE_EVT_LLSS_WRITE_CHAR_REQ, (void *) &wrReqParam);
                    }
                }
                else
                {
                    gattErr = CYBLE_GATT_ERR_INVALID_ATTRIBUTE_LEN;
                }
            }
            else
            {
                gattErr = CYBLE_GATT_ERR_OUT_OF_RANGE;
            }
            
            /* Indicate that request was handled */
            cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
        }
    }
        
    return(gattErr);
}
Exemplo n.º 21
0
void updateDrawLoopAverage(uint32_t drawTime)
{
    CYBLE_GATTS_HANDLE_VALUE_NTF_T  tempHandle;

 	/* If stack is not busy, then send the notification */
	if(_busyStatus == CYBLE_STACK_STATE_FREE)
	{
        tempHandle.attrHandle = CYBLE_POVDISPLAY_DRAWTIME_CHAR_HANDLE;
        tempHandle.value.val = (uint8_t*)&drawTime;
        tempHandle.value.len = 4;
        CyBle_GattsWriteAttributeValue(&tempHandle,0,&cyBle_connHandle,CYBLE_GATT_DB_LOCALLY_INITIATED );
        if (_drawCCCDValue[0])
        {
		    CyBle_GattsNotification(cyBle_connHandle,&tempHandle);
        }
    }
}
Exemplo n.º 22
0
/*******************************************************************************
* Function Name: WriteAttributeValue
********************************************************************************
*
* Summary:
*  Writes a specified attribute value of certian length to the appropriate
*  attribute handle present in the  GATT DB
*
* Parameters:
*  CYBLE_GATT_DB_ATTR_HANDLE_T  :  GATT DB Attribute Handle Type
*  uint8                        :  length of data
*  uint8*                       :  data buffer
*  uint8                        :  flags
*
* Return:
*  CYBLE_GATT_ERR_CODE_T        : returns the write operation error code
*
*******************************************************************************/
CYBLE_GATT_ERR_CODE_T WriteAttributeValue   (
                                CYBLE_GATT_DB_ATTR_HANDLE_T attributeHandle,
                                uint8 length,
                                uint8* data,
                                uint8 flag
                                            )
{
    CYBLE_GATT_HANDLE_VALUE_PAIR_T handlevaluePair;
    CYBLE_GATT_ERR_CODE_T gattErrCode;

    handlevaluePair.attrHandle = attributeHandle;
    handlevaluePair.value.len = length;
    handlevaluePair.value.val = data;
    gattErrCode = CyBle_GattsWriteAttributeValue( &handlevaluePair, 0,
                                                &cyBle_connHandle, flag);

    return gattErrCode;
}
Exemplo n.º 23
0
/******************************************************************************
##Function Name: CyBle_BcssWriteEventHandler
*******************************************************************************

Summary:
 Handles Write Request Event for Body Composition Service.

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

Return:
 Return value is of type CYBLE_GATT_ERR_CODE_T.
  * CYBLE_GATT_ERR_NONE - Write is successful.
  * CYBLE_GATT_ERR_REQUEST_NOT_SUPPORTED - Request is not supported.
  * CYBLE_GATT_ERR_INVALID_HANDLE - 'handleValuePair.attrHandle' is not valid.
  * CYBLE_GATT_ERR_WRITE_NOT_PERMITTED - Write operation is not permitted on
                                         this attribute.
  * CYBLE_GATT_ERR_INVALID_OFFSET - Offset value is invalid.
  * CYBLE_GATT_ERR_UNLIKELY_ERROR - Some other error occurred.

******************************************************************************/
CYBLE_GATT_ERR_CODE_T CyBle_BcssWriteEventHandler(CYBLE_GATTS_WRITE_REQ_PARAM_T *eventParam)
{
    CYBLE_GATT_ERR_CODE_T gattErr = CYBLE_GATT_ERR_NONE;
    uint32 event = (uint32) CYBLE_EVT_BCSS_INDICATION_DISABLED;
    
    if(NULL != CyBle_BcsApplCallback)
    {
        /* Client Characteristic Configuration descriptor write request */
        if(eventParam->handleValPair.attrHandle ==
            cyBle_bcss.charInfo[CYBLE_BCS_BODY_COMPOSITION_MEASUREMENT].descrHandle[CYBLE_BCS_CCCD])
        {
            if(CYBLE_IS_INDICATION_ENABLED_IN_PTR(eventParam->handleValPair.value.val))
            {
                event = (uint32) CYBLE_EVT_BCSS_INDICATION_ENABLED;
            }

            gattErr = CyBle_GattsWriteAttributeValue(&eventParam->handleValPair, 0u, 
                &eventParam->connHandle, CYBLE_GATT_DB_PEER_INITIATED);

            if(CYBLE_GATT_ERR_NONE == gattErr)
            {
                CYBLE_BCS_CHAR_VALUE_T wrReqParam;
                
                wrReqParam.connHandle = eventParam->connHandle;
                wrReqParam.charIndex = CYBLE_BCS_BODY_COMPOSITION_MEASUREMENT;
                wrReqParam.value = NULL;
                
                CyBle_BcsApplCallback(event, &wrReqParam);
            }
        #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) */
            
            /* Clear the callback flag indicating that request was handled */
            cyBle_eventHandlerFlag &= (uint8)~CYBLE_CALLBACK;
        }
    }

    return(gattErr);
}
Exemplo n.º 24
0
void updateRotationRate(uint32_t rotationRate)
{
    CYBLE_GATTS_HANDLE_VALUE_NTF_T  tempHandle;

    	/* If stack is not busy, then send the notification */
	if(_busyStatus == CYBLE_STACK_STATE_FREE)
	{
		/* Update notification data*/
        tempHandle.attrHandle = CYBLE_POVDISPLAY_ROTATIONSPEED_CHAR_HANDLE;
        tempHandle.value.val = (uint8_t*)&rotationRate;
        tempHandle.value.len = 4;
		/* Send the updated handle as part of attribute for notifications */
        CyBle_GattsWriteAttributeValue(&tempHandle,0,&cyBle_connHandle,CYBLE_GATT_DB_LOCALLY_INITIATED );
        if (_rotationCCCDValue[0])
        {
		    CyBle_GattsNotification(cyBle_connHandle,&tempHandle);
        }
	}

}
Exemplo n.º 25
0
/*****************************************************************************
* Function Name: _BLE_writeStatusFlags()
******************************************************************************
* Summary:
*   Write the actual value of all the status flags into the characteristic.
*
* Parameters:
*   None.
*
* Return:
*   None.
*
* Note:
*   
*****************************************************************************/
void _BLE_writeStatusFlags(void)
{
    uint8 StatusArray[NUM_STATUS];
        
    CYBLE_GATT_HANDLE_VALUE_PAIR_T FlagsHandle;

    // Fill the 'StatusArray' with the current status values.
    StatusArray[STATUS_READY_BYTE_MASK] = Status_Ready;
    StatusArray[STATUS_ACQUIRING_BYTE_MASK] = Status_Acquiring;
    StatusArray[STATUS_NO_MORE_SPACE_BYTE_MASK] = Status_NoMoreSpace;
    StatusArray[STATUS_DATA_ACQUIRED_BYTE_MASK] = Status_DataAcquired;
    StatusArray[STATUS_SENDING_BYTE_MASK] = Status_Sending;
    StatusArray[STATUS_NO_MORE_DATA_BYTE_MASK] = Status_NoMoreData;
    
    // Write the Status values into the characteristic.
    FlagsHandle.attrHandle = CYBLE_CAPSENSE_STATUS_CHAR_HANDLE;
    FlagsHandle.value.val = StatusArray;
    FlagsHandle.value.len = NUM_STATUS;
    CyBle_GattsWriteAttributeValue(&FlagsHandle, 0, &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);
}
Exemplo n.º 26
0
/******************************************************************************
##Function Name: CyBle_WptssSetCharacteristicDescriptor
*******************************************************************************

Summary:
 Sets the characteristic descriptor of the specified characteristic.

Parameters:
 charIndex:       The index of a service characteristic of type
                  CYBLE_WPTS_CHAR_INDEX_T.
 descrIndex:      The index of a service characteristic descriptor of type
                  CYBLE_WPTS_DESCR_INDEX_T.
 attrSize:        The size of the characteristic descriptor attribute.
 *attrValue:      The pointer to the descriptor value data that should
                  be stored to the GATT database.

Return:
 A 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_API_RESULT_T CyBle_WptssSetCharacteristicDescriptor(CYBLE_WPTS_CHAR_INDEX_T charIndex,
    CYBLE_WPTS_DESCR_INDEX_T descrIndex, uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;

    if((charIndex < CYBLE_WPTS_CHAR_COUNT) && (descrIndex < CYBLE_WPTS_DESCR_COUNT) && (attrValue != NULL))
    {
        locHandleValuePair.attrHandle = cyBle_wptss.charInfo[charIndex].descrHandle[descrIndex];
        locHandleValuePair.value.len = attrSize;
        locHandleValuePair.value.val = attrValue;

        /* Read characteristic value from database */
        if(CyBle_GattsWriteAttributeValue(&locHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED) ==
            CYBLE_GATT_ERR_NONE)
        {
            apiResult = CYBLE_ERROR_OK;
        }
    }
    return (apiResult);
}
Exemplo n.º 27
0
void updateCounterCccDescriptor(void) {
    // Handle value to update the CCCD
    CYBLE_GATT_HANDLE_VALUE_PAIR_T  handleValuePair;

    // Update CCCD handle with notification status data
    handleValuePair.attrHandle = COUNTER_CCC_HANDLE;
    handleValuePair.value = counterCccDescriptor.value;
    
    // Send updated RGB control handle as attribute for read
    // by central device
    CyBle_GattsWriteAttributeValue(
        &handleValuePair, 0,
        &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED
    );
    
    // Get notification flag
    enableCounterNotification = counterCccDescriptor.value.val[0] & 1;
    
    // Clear dirty flag
    counterCccDescriptor.dirty = 0;
}
Exemplo n.º 28
0
/******************************************************************************
##Function Name: CyBle_BcssSetCharacteristicDescriptor
*******************************************************************************

Summary:
 Sets the characteristic descriptor of the specified characteristic.

Parameters:
 charIndex: The index of the service characteristic.
 charInstance: The instance of the characteristic specified by "charIndex".
 attrSize: The size of the characteristic descriptor attribute.
 *attrValue: The pointer to the descriptor value data to be stored in the GATT
             database.

Return:
 A 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_API_RESULT_T CyBle_BcssSetCharacteristicDescriptor(CYBLE_BCS_CHAR_INDEX_T charIndex,
    CYBLE_BCS_DESCR_INDEX_T descrIndex, uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;

    if((charIndex == CYBLE_BCS_BODY_COMPOSITION_MEASUREMENT) && (descrIndex == CYBLE_BCS_CCCD) && (NULL != attrValue))
    {
        locHandleValuePair.attrHandle = 
            cyBle_bcss.charInfo[CYBLE_BCS_BODY_COMPOSITION_MEASUREMENT].descrHandle[CYBLE_BCS_CCCD];
        locHandleValuePair.value.len = attrSize;
        locHandleValuePair.value.val = attrValue;

        /* Read characteristic value from database */
        if(CYBLE_GATT_ERR_NONE ==
            CyBle_GattsWriteAttributeValue(&locHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED))
        {
            apiResult = CYBLE_ERROR_OK;
        }
    }
    return (apiResult);
}
Exemplo n.º 29
0
/******************************************************************************
* Function Name: CyBle_AnssSetCharacteristicValue
***************************************************************************//**
* 
*  Sets a characteristic value of Alert Notification Service, which is a value
*  identified by charIndex, to the local database.
* 
*  \param charIndex: The index of the service characteristic of type 
*              CYBLE_ANS_CHAR_INDEX_T. The valid values are,
*              * CYBLE_ANS_SUPPORTED_NEW_ALERT_CAT
*              * CYBLE_ANS_SUPPORTED_UNREAD_ALERT_CAT
*  \param attrSize: The size of the characteristic value attribute.
*  \param attrValue: The pointer to characteristic value data that should be stored
*               in the GATT database.
* 
* \return
*  Return value is of type CYBLE_API_RESULT_T.
*  * CYBLE_ERROR_OK - The request is handled successfully.
*  * CYBLE_ERROR_INVALID_PARAMETER - Validation of the input parameters failed.
*
******************************************************************************/
CYBLE_API_RESULT_T CyBle_AnssSetCharacteristicValue(CYBLE_ANS_CHAR_INDEX_T charIndex,
    uint8 attrSize, uint8 *attrValue)
{
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_INVALID_PARAMETER;
    CYBLE_GATT_HANDLE_VALUE_PAIR_T locHandleValuePair;

    if(charIndex < CYBLE_ANS_CHAR_COUNT)
    {
        locHandleValuePair.attrHandle = cyBle_anss.charInfo[charIndex].charHandle;
        locHandleValuePair.value.len = attrSize;
        locHandleValuePair.value.val = attrValue;
        
        /* Store data in database */
        if(CyBle_GattsWriteAttributeValue(&locHandleValuePair, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED)
                  == CYBLE_GATT_ERR_NONE)
        {
            apiResult = CYBLE_ERROR_OK;
        }
    }

    return (apiResult);
}
Exemplo n.º 30
0
void updateRgbDescriptor(void) {
    // Handle value to update the descriptor
    CYBLE_GATT_HANDLE_VALUE_PAIR_T  handleValuePair;

    // Update descriptor handle with data
    handleValuePair.attrHandle = RGB_CHAR_HANDLE;
    handleValuePair.value = rgbDescriptor.value;
    
    // Send updated RGB control handle as attribute for read
    // by central device
    CyBle_GattsWriteAttributeValue(
        &handleValuePair, 0,
        &connectionHandle, CYBLE_GATT_DB_LOCALLY_INITIATED
    );
    
    // Update the LED color
    LED_Green_Write(!(rgbDescriptor.value.val[0] & 4));
    LED_Red_Write(  !(rgbDescriptor.value.val[0] & 2));
    LED_Blue_Write( !(rgbDescriptor.value.val[0] & 1));
    
    // Clear dirty flag
    rgbDescriptor.dirty = 0;
}