cun
This commit is contained in:
@ -31,7 +31,7 @@
|
||||
#include "le_client_demo.h"
|
||||
#include "le_common.h"
|
||||
#include "ble_user.h"
|
||||
|
||||
#include "../nvs/nvs.h"
|
||||
#if (BLE_WIRELESS_CLIENT_EN == 1) // 作为主设备主动去连接其他蓝牙
|
||||
|
||||
/*
|
||||
@ -196,6 +196,7 @@ static void client_timer_start(void);
|
||||
* 全局/静态变量定义
|
||||
**************************************************************************************************
|
||||
*/
|
||||
static u8 connect_state = 0; //0:连接断开; 1:连接成功
|
||||
|
||||
// --- 缓冲区 ---
|
||||
static u8 att_ram_buffer[ATT_RAM_BUFSIZE] __attribute__((aligned(4))); // ATT协议栈RAM缓冲区
|
||||
@ -246,9 +247,9 @@ static const target_uuid_t default_search_uuid_table[] = {
|
||||
};
|
||||
|
||||
// 默认匹配的设备名称
|
||||
static const u8 test_remoter_name1[] = "CM-22222";
|
||||
static u8 test_remoter_name1[] = "CM-22222";
|
||||
// 默认匹配规则
|
||||
static const client_match_cfg_t match_dev01 = {
|
||||
static client_match_cfg_t match_dev01 = {
|
||||
.create_conn_mode = BIT(CLI_CREAT_BY_NAME), // 通过名称匹配
|
||||
.compare_data_len = sizeof(test_remoter_name1) - 1, // 名称长度
|
||||
.compare_data = test_remoter_name1, // 名称数据
|
||||
@ -256,7 +257,7 @@ static const client_match_cfg_t match_dev01 = {
|
||||
};
|
||||
|
||||
// 默认客户端连接配置
|
||||
static const client_conn_cfg_t client_conn_config_default = {
|
||||
static client_conn_cfg_t client_conn_config_default = {
|
||||
.match_dev_cfg[0] = &match_dev01,
|
||||
.match_dev_cfg[1] = NULL,
|
||||
.match_dev_cfg[2] = NULL,
|
||||
@ -300,7 +301,7 @@ static const char *const phy_result[] = { // PHY速率类型字符串
|
||||
};
|
||||
|
||||
// --- 接口操作结构体 ---
|
||||
const struct ble_client_operation_t client_operation = {
|
||||
static const struct ble_client_operation_t client_operation = {
|
||||
.scan_enable = bt_ble_scan_enable,
|
||||
.disconnect = ble_disconnect,
|
||||
.get_buffer_vaild = get_buffer_vaild_len,
|
||||
@ -323,6 +324,7 @@ const struct ble_client_operation_t client_operation = {
|
||||
**************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取客户端操作接口表
|
||||
* @return 指向ble_client_operation_t结构体的指针
|
||||
@ -380,7 +382,7 @@ void bt_ble_init(void)
|
||||
set_ble_work_state(BLE_ST_INIT_OK);
|
||||
conn_pair_vm_do(&conn_pair_info, 0); // 读取VM中的配对信息
|
||||
|
||||
#if !WIRELESS_PAIR_BONDING
|
||||
#if !WIRELESS_PAIR_BONDING
|
||||
device_bonding_init();
|
||||
#endif
|
||||
|
||||
@ -497,6 +499,46 @@ void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static u8 new_device_name[MAIN_BOARD_MAC_ADDR_LENGTH] = {0};
|
||||
|
||||
static client_match_cfg_t new_match_dev = {
|
||||
.create_conn_mode = BIT(CLI_CREAT_BY_NAME), // 通过名称匹配
|
||||
.compare_data_len = MAIN_BOARD_MAC_ADDR_LENGTH, // 名称长度,不包含"\0"
|
||||
.compare_data = new_device_name, // 名称数据
|
||||
.bonding_flag = 0, // 不进行绑定
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief 连接新的设备
|
||||
*
|
||||
* @param name 设备的名称
|
||||
*/
|
||||
void g_ble_connect_new_device(char* name){
|
||||
memcpy(new_device_name, name, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
client_config->match_dev_cfg[0] = &new_match_dev;
|
||||
|
||||
// client_operation.init_config(NULL, client_config); //新配置
|
||||
|
||||
// client_operation.disconnect(NULL); //断开成功后会自动使用新配置进行扫描
|
||||
|
||||
client_init_config(NULL, client_config);//新配置
|
||||
ble_disconnect(NULL); //断开成功后会自动使用新配置进行扫描
|
||||
connect_state = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取当前ble连接状态
|
||||
*
|
||||
* @return //0:连接断开; 1:连接成功
|
||||
*/
|
||||
u8 g_ble_get_state(void){
|
||||
return connect_state;
|
||||
}
|
||||
|
||||
/*
|
||||
**************************************************************************************************
|
||||
* 内部静态函数实现
|
||||
@ -1603,9 +1645,12 @@ static void default_event_callback(le_client_event_e event, u8 *packet, int size
|
||||
break;
|
||||
|
||||
case CLI_EVENT_CONNECTED:
|
||||
connect_state = 1;
|
||||
log_info("<<<<<<<<<< BLE Connection Successful! >>>>>>>>>>\n");
|
||||
break;
|
||||
|
||||
case CLI_EVENT_DISCONNECT:
|
||||
connect_state = 0;
|
||||
if (test_client_timer) {
|
||||
sys_timeout_del(test_client_timer);
|
||||
test_client_timer = 0;
|
||||
@ -1619,4 +1664,9 @@ static void default_event_callback(le_client_event_e event, u8 *packet, int size
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_WIRELESS_MIC_CLIENT) */
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
#ifndef __CLIENT_HANDLER_H__
|
||||
#define __CLIENT_HANDLER_H__
|
||||
|
||||
#include "app_config.h"
|
||||
#include "ble_user.h"
|
||||
/**
|
||||
* @brief BLE客户端退出
|
||||
*/
|
||||
extern void bt_ble_exit(void);
|
||||
|
||||
/**
|
||||
* @brief 应用层调用的断开连接接口
|
||||
*/
|
||||
extern void ble_app_disconnect(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief BLE模块使能/禁止 (兼容旧接口)
|
||||
* @param enable 1:使能, 0:禁止
|
||||
*/
|
||||
extern void bt_ble_adv_enable(u8 enable);
|
||||
|
||||
/**
|
||||
* @brief BLE模块使能/禁止
|
||||
* @param en 1:使能, 0:禁止
|
||||
*/
|
||||
extern void ble_module_enable(u8 en);
|
||||
|
||||
/**
|
||||
* @brief 客户端发起连接参数更新请求
|
||||
*/
|
||||
extern void client_send_conn_param_update(void);
|
||||
|
||||
/**
|
||||
* @brief 清除绑定信息
|
||||
*/
|
||||
extern void clear_bonding_info(void);
|
||||
|
||||
/**
|
||||
* @brief 连接新的设备
|
||||
*
|
||||
* @param name 设备的名称
|
||||
*/
|
||||
extern void g_ble_connect_new_device(char* name);
|
||||
|
||||
/**
|
||||
* @brief 获取当前ble连接状态
|
||||
*
|
||||
* @return //0:连接断开; 1:连接成功
|
||||
*/
|
||||
extern u8 g_ble_get_state(void);
|
||||
#endif
|
||||
Reference in New Issue
Block a user