/**@brief Function for handling the Write event.
 *
 * @param[in]   p_agsensor       AgSensor Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_write(ble_agsensor_t * p_agsensor, ble_gatts_evt_write_t * p_ble_evt)
{
    
    if(p_ble_evt->handle == p_agsensor->configuration_handles.cccd_handle)
    {
        if(p_agsensor->evt_handler != NULL)
        {
            ble_agsensor_evt_t evt;
            evt.evt_type = BLE_AGSENSOR_CONFIGURATION_EVT_CCCD_WRITE;
            bds_uint16_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.cccd_value);
            p_agsensor->evt_handler(p_agsensor, &evt);
        	configIndicationEnable = true;
        	opcode_inRead = BLE_AGSENSOR_CONFIGURATION_OPCODE_DATETIME;
        	// As indication enable, Set the time to send as it should be default opcode to read
            ble_agsensor_process_request(0, NULL, opcode_inRead, false, false, false);
        }
    } 
    if(p_ble_evt->handle == p_agsensor->configuration_handles.value_handle)
    {
        if(p_agsensor->evt_handler != NULL)
        {
            ble_agsensor_evt_t evt;
            evt.evt_type = BLE_AGSENSOR_CONFIGURATION_EVT_WRITE;
            configuration_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.configuration, p_agsensor);
            p_agsensor->evt_handler(p_agsensor, &evt);
        }
    }
    if(p_ble_evt->handle == p_agsensor->data_handles.cccd_handle)
    {
        if(p_agsensor->evt_handler != NULL)
        {
            ble_agsensor_evt_t evt;
            evt.evt_type = BLE_AGSENSOR_DATA_EVT_CCCD_WRITE;
            bds_uint16_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.cccd_value);
            p_agsensor->evt_handler(p_agsensor, &evt);
        }
    } 
    if(p_ble_evt->handle == p_agsensor->data_handles.value_handle)
    {
        if(p_agsensor->evt_handler != NULL)
        {
            ble_agsensor_evt_t evt;
            evt.evt_type = BLE_AGSENSOR_DATA_EVT_WRITE;
            data_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.data);
            p_agsensor->evt_handler(p_agsensor, &evt);
        }
    }
}
/**@brief Function for handling the Write event.
 *
 * @param[in]   p_dfu__nordic_       DFU (Nordic) Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_write(ble_dfu__nordic__t * p_dfu__nordic_, ble_gatts_evt_write_t * p_ble_evt)
{
    
    if(p_ble_evt->handle == p_dfu__nordic_->dfu_packet_handles.value_handle)
    {
        if(p_dfu__nordic_->evt_handler != NULL)
        {
            ble_dfu__nordic__evt_t evt;
            evt.evt_type = BLE_DFU__NORDIC__DFU_PACKET_EVT_WRITE;
            dfu_packet_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.dfu_packet);
            p_dfu__nordic_->evt_handler(p_dfu__nordic_, &evt);
        }
    }
    if(p_ble_evt->handle == p_dfu__nordic_->dfu_control_point_handles.cccd_handle)
    {
        if(p_dfu__nordic_->evt_handler != NULL)
        {
            ble_dfu__nordic__evt_t evt;
            evt.evt_type = BLE_DFU__NORDIC__DFU_CONTROL_POINT_EVT_CCCD_WRITE;
            bds_uint16_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.cccd_value);
            p_dfu__nordic_->evt_handler(p_dfu__nordic_, &evt);
        }
    } 
    if(p_ble_evt->handle == p_dfu__nordic_->dfu_control_point_handles.value_handle)
    {
        if(p_dfu__nordic_->evt_handler != NULL)
        {
            ble_dfu__nordic__evt_t evt;
            evt.evt_type = BLE_DFU__NORDIC__DFU_CONTROL_POINT_EVT_WRITE;
            dfu_control_point_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.dfu_control_point);
            p_dfu__nordic_->evt_handler(p_dfu__nordic_, &evt);
        }
    }
}
/**@brief Function for handling the Write event.
 *
 * @param[in]   p_display_service       Display Service Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_write(ble_display_service_t * p_display_service, ble_gatts_evt_write_t * p_ble_evt)
{
    
	if (p_ble_evt->handle == p_display_service->record_number_handles.value_handle)
	{
		if (p_display_service->evt_handler != NULL)
		{
			ble_display_service_evt_t evt;
			evt.evt_type = BLE_DISPLAY_SERVICE_RECORD_NUMBER_EVT_WRITE;
			record_number_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.record_number);
			p_display_service->evt_handler(p_display_service, &evt);
		}
	}
	if (p_ble_evt->handle == p_display_service->record_handles.cccd_handle)
	{
		if (p_display_service->evt_handler != NULL)
		{
			ble_display_service_evt_t evt;
			evt.evt_type = BLE_DISPLAY_SERVICE_RECORD_EVT_CCCD_WRITE;
			bds_uint16_decode(p_ble_evt->len, p_ble_evt->data, &evt.params.cccd_value);
			p_display_service->evt_handler(p_display_service, &evt);
		}
	} 
}