Files
microchip-application-bmd38…/le_gap.c
T
2024-01-03 14:40:04 +08:00

67 lines
1.9 KiB
C

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_log.h"
#include "app_error.h"
#ifdef __cplusplus
}
#endif
void le_gap_init(const char *device_name, uint16_t usAppearance)
{
ret_code_t err_code;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
if (device_name != NULL)
{
// Set GAP device name
err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)device_name, strlen(device_name));
APP_ERROR_CHECK(err_code);
}
// Set GAP Appearance value
err_code = sd_ble_gap_appearance_set(usAppearance);
APP_ERROR_CHECK(err_code);
// Set GAP Peripheral Preferred Connection Parameters.
ble_gap_conn_params_t gap_conn_params;
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = MSEC_TO_UNITS(8, UNIT_1_25_MS); /**< Minimum connection interval (7.5 ms) */
gap_conn_params.max_conn_interval = MSEC_TO_UNITS(20, UNIT_1_25_MS); /**< Maximum connection interval (20 ms). */
gap_conn_params.slave_latency = 8; /**< Slave latency. */
gap_conn_params.conn_sup_timeout = MSEC_TO_UNITS(10000, UNIT_10_MS); /**< Connection supervisory timeout (10s). */
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);
}
void le_gap_disconnect(uint16_t conn_handle, void *p_context)
{
UNUSED_PARAMETER(p_context);
ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_SUCCESS)
{
NRF_LOG_WARNING("Failed to disconnect connection. Connection handle: %d Error: %d", conn_handle, err_code);
}
else
{
NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle);
}
}