remove ble_conn_params dependency
This commit is contained in:
		@@ -1,323 +0,0 @@
 | 
			
		||||
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "ble_conn_params.h"
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
#include "ble_hci.h"
 | 
			
		||||
#include "app_timer.h"
 | 
			
		||||
#include "ble_srv_common.h"
 | 
			
		||||
#include "app_util.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static ble_conn_params_init_t m_conn_params_config;     /**< Configuration as specified by the application. */
 | 
			
		||||
static ble_gap_conn_params_t  m_preferred_conn_params;  /**< Connection parameters preferred by the application. */
 | 
			
		||||
static uint8_t                m_update_count;           /**< Number of Connection Parameter Update messages that has currently been sent. */
 | 
			
		||||
static uint16_t               m_conn_handle;            /**< Current connection handle. */
 | 
			
		||||
static ble_gap_conn_params_t  m_current_conn_params;    /**< Connection parameters received in the most recent Connect event. */
 | 
			
		||||
APP_TIMER_DEF(m_conn_params_timer_id);                  /**< Connection parameters timer. */
 | 
			
		||||
 | 
			
		||||
static bool m_change_param = false;
 | 
			
		||||
 | 
			
		||||
static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params)
 | 
			
		||||
{
 | 
			
		||||
    // Check if interval is within the acceptable range.
 | 
			
		||||
    // NOTE: Using max_conn_interval in the received event data because this contains
 | 
			
		||||
    //       the client's connection interval.
 | 
			
		||||
    if (
 | 
			
		||||
        (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval)
 | 
			
		||||
        && 
 | 
			
		||||
        (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval)
 | 
			
		||||
       )
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void update_timeout_handler(void * p_context)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_PARAMETER(p_context);
 | 
			
		||||
 | 
			
		||||
    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
 | 
			
		||||
    {
 | 
			
		||||
        // Check if we have reached the maximum number of attempts
 | 
			
		||||
        m_update_count++;
 | 
			
		||||
        if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
 | 
			
		||||
        {
 | 
			
		||||
            uint32_t err_code;
 | 
			
		||||
 | 
			
		||||
            // Parameters are not ok, send connection parameters update request.
 | 
			
		||||
            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
 | 
			
		||||
            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
 | 
			
		||||
            {
 | 
			
		||||
                m_conn_params_config.error_handler(err_code);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            m_update_count = 0;
 | 
			
		||||
 | 
			
		||||
            // Negotiation failed, disconnect automatically if this has been configured
 | 
			
		||||
            if (m_conn_params_config.disconnect_on_fail)
 | 
			
		||||
            {
 | 
			
		||||
                uint32_t err_code;
 | 
			
		||||
 | 
			
		||||
                err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
 | 
			
		||||
                if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
 | 
			
		||||
                {
 | 
			
		||||
                    m_conn_params_config.error_handler(err_code);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Notify the application that the procedure has failed
 | 
			
		||||
            if (m_conn_params_config.evt_handler != NULL)
 | 
			
		||||
            {
 | 
			
		||||
                ble_conn_params_evt_t evt;
 | 
			
		||||
 | 
			
		||||
                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
 | 
			
		||||
                m_conn_params_config.evt_handler(&evt);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t err_code;
 | 
			
		||||
 | 
			
		||||
    m_conn_params_config = *p_init;
 | 
			
		||||
    m_change_param = false;
 | 
			
		||||
    if (p_init->p_conn_params != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        m_preferred_conn_params = *p_init->p_conn_params;
 | 
			
		||||
 | 
			
		||||
        // Set the connection params in stack
 | 
			
		||||
        err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
 | 
			
		||||
        if (err_code != NRF_SUCCESS)
 | 
			
		||||
        {
 | 
			
		||||
            return err_code;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // Fetch the connection params from stack
 | 
			
		||||
        err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
 | 
			
		||||
        if (err_code != NRF_SUCCESS)
 | 
			
		||||
        {
 | 
			
		||||
            return err_code;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m_conn_handle  = BLE_CONN_HANDLE_INVALID;
 | 
			
		||||
    m_update_count = 0;
 | 
			
		||||
 | 
			
		||||
    return app_timer_create(&m_conn_params_timer_id,
 | 
			
		||||
                            APP_TIMER_MODE_SINGLE_SHOT,
 | 
			
		||||
                            update_timeout_handler);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t ble_conn_params_stop(void)
 | 
			
		||||
{
 | 
			
		||||
    return app_timer_stop(m_conn_params_timer_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void conn_params_negotiation(void)
 | 
			
		||||
{
 | 
			
		||||
    // Start negotiation if the received connection parameters are not acceptable
 | 
			
		||||
    if (!is_conn_params_ok(&m_current_conn_params))
 | 
			
		||||
    {
 | 
			
		||||
        uint32_t err_code;
 | 
			
		||||
        uint32_t timeout_ticks;
 | 
			
		||||
 | 
			
		||||
        if (m_change_param)
 | 
			
		||||
        {
 | 
			
		||||
            // Notify the application that the procedure has failed
 | 
			
		||||
            if (m_conn_params_config.evt_handler != NULL)
 | 
			
		||||
            {
 | 
			
		||||
                ble_conn_params_evt_t evt;
 | 
			
		||||
 | 
			
		||||
                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
 | 
			
		||||
                m_conn_params_config.evt_handler(&evt);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if (m_update_count == 0)
 | 
			
		||||
            {
 | 
			
		||||
                // First connection parameter update
 | 
			
		||||
                timeout_ticks = m_conn_params_config.first_conn_params_update_delay;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                timeout_ticks = m_conn_params_config.next_conn_params_update_delay;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
 | 
			
		||||
            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
 | 
			
		||||
            {
 | 
			
		||||
                m_conn_params_config.error_handler(err_code);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // Notify the application that the procedure has succeded
 | 
			
		||||
        if (m_conn_params_config.evt_handler != NULL)
 | 
			
		||||
        {
 | 
			
		||||
            ble_conn_params_evt_t evt;
 | 
			
		||||
 | 
			
		||||
            evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
 | 
			
		||||
            m_conn_params_config.evt_handler(&evt);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    m_change_param = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void on_connect(ble_evt_t * p_ble_evt)
 | 
			
		||||
{
 | 
			
		||||
    // Save connection parameters
 | 
			
		||||
    m_conn_handle         = p_ble_evt->evt.gap_evt.conn_handle;
 | 
			
		||||
    m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params;
 | 
			
		||||
    m_update_count        = 0;  // Connection parameter negotiation should re-start every connection
 | 
			
		||||
 | 
			
		||||
    // Check if we shall handle negotiation on connect
 | 
			
		||||
    if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID)
 | 
			
		||||
    {
 | 
			
		||||
        conn_params_negotiation();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void on_disconnect(ble_evt_t * p_ble_evt)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t err_code;
 | 
			
		||||
 | 
			
		||||
    m_conn_handle = BLE_CONN_HANDLE_INVALID;
 | 
			
		||||
 | 
			
		||||
    // Stop timer if running
 | 
			
		||||
    m_update_count = 0; // Connection parameters updates should happen during every connection
 | 
			
		||||
 | 
			
		||||
    err_code = app_timer_stop(m_conn_params_timer_id);
 | 
			
		||||
    if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
 | 
			
		||||
    {
 | 
			
		||||
        m_conn_params_config.error_handler(err_code);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void on_write(ble_evt_t * p_ble_evt)
 | 
			
		||||
{
 | 
			
		||||
    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
 | 
			
		||||
 | 
			
		||||
    // Check if this the correct CCCD
 | 
			
		||||
    if (
 | 
			
		||||
        (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle)
 | 
			
		||||
        &&
 | 
			
		||||
        (p_evt_write->len == 2)
 | 
			
		||||
       )
 | 
			
		||||
    {
 | 
			
		||||
        // Check if this is a 'start notification'
 | 
			
		||||
        if (ble_srv_is_notification_enabled(p_evt_write->data))
 | 
			
		||||
        {
 | 
			
		||||
            // Do connection parameter negotiation if necessary
 | 
			
		||||
            conn_params_negotiation();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            uint32_t err_code;
 | 
			
		||||
 | 
			
		||||
            // Stop timer if running
 | 
			
		||||
            err_code = app_timer_stop(m_conn_params_timer_id);
 | 
			
		||||
            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
 | 
			
		||||
            {
 | 
			
		||||
                m_conn_params_config.error_handler(err_code);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void on_conn_params_update(ble_evt_t * p_ble_evt)
 | 
			
		||||
{
 | 
			
		||||
    // Copy the parameters
 | 
			
		||||
    m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params;
 | 
			
		||||
 | 
			
		||||
    conn_params_negotiation();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt)
 | 
			
		||||
{
 | 
			
		||||
    switch (p_ble_evt->header.evt_id)
 | 
			
		||||
    {
 | 
			
		||||
        case BLE_GAP_EVT_CONNECTED:
 | 
			
		||||
            on_connect(p_ble_evt);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case BLE_GAP_EVT_DISCONNECTED:
 | 
			
		||||
            on_disconnect(p_ble_evt);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case BLE_GATTS_EVT_WRITE:
 | 
			
		||||
            on_write(p_ble_evt);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case BLE_GAP_EVT_CONN_PARAM_UPDATE:
 | 
			
		||||
            on_conn_params_update(p_ble_evt);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            // No implementation needed.
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t err_code;
 | 
			
		||||
 | 
			
		||||
    m_preferred_conn_params = *new_params;
 | 
			
		||||
    // Set the connection params in stack
 | 
			
		||||
    err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
 | 
			
		||||
    if (err_code == NRF_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
        if (!is_conn_params_ok(&m_current_conn_params))
 | 
			
		||||
        {
 | 
			
		||||
            m_change_param = true;
 | 
			
		||||
            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
 | 
			
		||||
            m_update_count = 1;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            // Notify the application that the procedure has succeded
 | 
			
		||||
            if (m_conn_params_config.evt_handler != NULL)
 | 
			
		||||
            {
 | 
			
		||||
                ble_conn_params_evt_t evt;
 | 
			
		||||
 | 
			
		||||
                evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
 | 
			
		||||
                m_conn_params_config.evt_handler(&evt);
 | 
			
		||||
            }
 | 
			
		||||
            err_code = NRF_SUCCESS;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return err_code;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,111 +0,0 @@
 | 
			
		||||
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup ble_sdk_lib
 | 
			
		||||
 * @brief Module for initiating and executing a connection parameters negotiation procedure.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef BLE_CONN_PARAMS_H__
 | 
			
		||||
#define BLE_CONN_PARAMS_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "ble.h"
 | 
			
		||||
#include "ble_srv_common.h"
 | 
			
		||||
 | 
			
		||||
/**@brief Connection Parameters Module event type. */
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
    BLE_CONN_PARAMS_EVT_FAILED   ,                                  /**< Negotiation procedure failed. */
 | 
			
		||||
    BLE_CONN_PARAMS_EVT_SUCCEEDED                                   /**< Negotiation procedure succeeded. */
 | 
			
		||||
} ble_conn_params_evt_type_t;
 | 
			
		||||
 | 
			
		||||
/**@brief Connection Parameters Module event. */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    ble_conn_params_evt_type_t evt_type;                            /**< Type of event. */
 | 
			
		||||
} ble_conn_params_evt_t;
 | 
			
		||||
 | 
			
		||||
/**@brief Connection Parameters Module event handler type. */
 | 
			
		||||
typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt);
 | 
			
		||||
 | 
			
		||||
/**@brief Connection Parameters Module init structure. This contains all options and data needed for
 | 
			
		||||
 *        initialization of the connection parameters negotiation module. */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    ble_gap_conn_params_t *       p_conn_params;                    /**< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host. */
 | 
			
		||||
    uint32_t                      first_conn_params_update_delay;   /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks). */
 | 
			
		||||
    uint32_t                      next_conn_params_update_delay;    /**< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0. */
 | 
			
		||||
    uint8_t                       max_conn_params_update_count;     /**< Number of attempts before giving up the negotiation. */
 | 
			
		||||
    uint16_t                      start_on_notify_cccd_handle;      /**< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event. */
 | 
			
		||||
    bool                          disconnect_on_fail;               /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */
 | 
			
		||||
    ble_conn_params_evt_handler_t evt_handler;                      /**< Event handler to be called for handling events in the Connection Parameters. */
 | 
			
		||||
    ble_srv_error_handler_t       error_handler;                    /**< Function to be called in case of an error. */
 | 
			
		||||
} ble_conn_params_init_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for initializing the Connection Parameters module.
 | 
			
		||||
 *
 | 
			
		||||
 * @note If the negotiation procedure should be triggered when notification/indication of 
 | 
			
		||||
 *       any characteristic is enabled by the peer, then this function must be called after
 | 
			
		||||
 *       having initialized the services.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_init  This contains information needed to initialize this module.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      NRF_SUCCESS on successful initialization, otherwise an error code.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for stopping the Connection Parameters module.
 | 
			
		||||
 *
 | 
			
		||||
 * @details This function is intended to be used by the application to clean up the connection
 | 
			
		||||
 *          parameters update module. This will stop the connection parameters update timer if
 | 
			
		||||
 *          running, thereby preventing any impending connection parameters update procedure. This
 | 
			
		||||
 *          function must be called by the application when it needs to clean itself up (for
 | 
			
		||||
 *          example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry
 | 
			
		||||
 *          event can be avoided.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      NRF_SUCCESS on successful initialization, otherwise an error code.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t ble_conn_params_stop(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for changing the current connection parameters to a new set.
 | 
			
		||||
 *
 | 
			
		||||
 *  @details Use this function to change the connection parameters to a new set of parameter 
 | 
			
		||||
 *       (ie different from the ones given at init of the module).
 | 
			
		||||
 *       This function is usefull for scenario where most of the time the application
 | 
			
		||||
 *       needs a relatively big connection interval, and just sometimes, for a temporary
 | 
			
		||||
 *       period requires shorter connection interval, for example to transfer a higher
 | 
			
		||||
 *       amount of data.
 | 
			
		||||
 *       If the given parameters does not match the current connection's parameters
 | 
			
		||||
 *       this function initiates a new negotiation.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   new_params  This contains the new connections parameters to setup.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      NRF_SUCCESS on successful initialization, otherwise an error code.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for handling the Application's BLE Stack events.
 | 
			
		||||
 *
 | 
			
		||||
 * @details Handles all events from the BLE stack that are of interest to this module.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_ble_evt  The event received from the BLE stack.
 | 
			
		||||
 */
 | 
			
		||||
void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt);
 | 
			
		||||
 | 
			
		||||
#endif // BLE_CONN_PARAMS_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
@@ -28,7 +28,6 @@
 | 
			
		||||
#include "ble_dfu.h"
 | 
			
		||||
#include "ble_dis.h"
 | 
			
		||||
#include "app_timer.h"
 | 
			
		||||
#include "ble_conn_params.h"
 | 
			
		||||
#include "hci_mem_pool.h"
 | 
			
		||||
#include "bootloader.h"
 | 
			
		||||
#include "dfu_ble_svc_internal.h"
 | 
			
		||||
@@ -63,10 +62,6 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 };
 | 
			
		||||
 | 
			
		||||
#define APP_TIMER_PRESCALER                  0                                                       /**< Value of the RTC1 PRESCALER register. */
 | 
			
		||||
 | 
			
		||||
#define FIRST_CONN_PARAMS_UPDATE_DELAY       APP_TIMER_TICKS(100)               /**< Time from the Connected event to first time sd_ble_gap_conn_param_update is called (100 milliseconds). */
 | 
			
		||||
#define NEXT_CONN_PARAMS_UPDATE_DELAY        APP_TIMER_TICKS(500)               /**< Time between each call to sd_ble_gap_conn_param_update after the first call (500 milliseconds). */
 | 
			
		||||
#define MAX_CONN_PARAMS_UPDATE_COUNT         3                                                       /**< Number of attempts before giving up the connection parameter negotiation. */
 | 
			
		||||
 | 
			
		||||
#define APP_ADV_INTERVAL                     MSEC_TO_UNITS(25, UNIT_0_625_MS)                        /**< The advertising interval (25 ms.). */
 | 
			
		||||
#define APP_ADV_TIMEOUT_IN_SECONDS           BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED                   /**< The advertising timeout in units of seconds. This is set to @ref BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED so that the advertisement is done as long as there there is a call to @ref dfu_transport_close function.*/
 | 
			
		||||
#define APP_DIRECTED_ADV_TIMEOUT             50                                                       /**< number of direct advertisement (each lasting 1.28seconds). */
 | 
			
		||||
@@ -536,40 +531,6 @@ static void on_dfu_pkt_write(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief     Function for handling a Connection Parameters error.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] nrf_error Error code.
 | 
			
		||||
 */
 | 
			
		||||
static void conn_params_error_handler(uint32_t nrf_error)
 | 
			
		||||
{
 | 
			
		||||
    APP_ERROR_HANDLER(nrf_error);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for initializing the Connection Parameters module.
 | 
			
		||||
 */
 | 
			
		||||
static void conn_params_init(void)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t               err_code;
 | 
			
		||||
    ble_conn_params_init_t cp_init;
 | 
			
		||||
 | 
			
		||||
    memset(&cp_init, 0, sizeof(cp_init));
 | 
			
		||||
 | 
			
		||||
    cp_init.p_conn_params                  = NULL;
 | 
			
		||||
    cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
 | 
			
		||||
    cp_init.next_conn_params_update_delay  = NEXT_CONN_PARAMS_UPDATE_DELAY;
 | 
			
		||||
    cp_init.max_conn_params_update_count   = MAX_CONN_PARAMS_UPDATE_COUNT;
 | 
			
		||||
    cp_init.start_on_notify_cccd_handle    = BLE_GATT_HANDLE_INVALID;
 | 
			
		||||
    cp_init.disconnect_on_fail             = false;
 | 
			
		||||
    cp_init.evt_handler                    = NULL;
 | 
			
		||||
    cp_init.error_handler                  = conn_params_error_handler;
 | 
			
		||||
 | 
			
		||||
    err_code = ble_conn_params_init(&cp_init);
 | 
			
		||||
    APP_ERROR_CHECK(err_code);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief     Function for the Device Firmware Update Service event handler.
 | 
			
		||||
 *
 | 
			
		||||
 * @details   This function will be called for all Device Firmware Update Service events which
 | 
			
		||||
@@ -982,7 +943,6 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
 | 
			
		||||
 */
 | 
			
		||||
/*static*/ void ble_evt_dispatch(ble_evt_t * p_ble_evt)
 | 
			
		||||
{
 | 
			
		||||
    ble_conn_params_on_ble_evt(p_ble_evt);
 | 
			
		||||
    ble_dfu_on_ble_evt(&m_dfu, p_ble_evt);
 | 
			
		||||
    on_ble_evt(p_ble_evt);
 | 
			
		||||
}
 | 
			
		||||
@@ -1130,7 +1090,6 @@ uint32_t dfu_transport_ble_update_start(void)
 | 
			
		||||
 | 
			
		||||
    gap_params_init();
 | 
			
		||||
    services_init();
 | 
			
		||||
    conn_params_init();
 | 
			
		||||
    sec_params_init();
 | 
			
		||||
 | 
			
		||||
    sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, 0, 4); // maximum power
 | 
			
		||||
@@ -1158,8 +1117,5 @@ uint32_t dfu_transport_ble_close()
 | 
			
		||||
        advertising_stop();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err_code = ble_conn_params_stop();
 | 
			
		||||
    APP_ERROR_CHECK(err_code);
 | 
			
		||||
 | 
			
		||||
    return NRF_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user