Compare commits
7 Commits
ed475e870f
...
141b538bf5
| Author | SHA1 | Date | |
|---|---|---|---|
| 141b538bf5 | |||
| 23b14f0142 | |||
| c870b07b02 | |||
| 86199b822e | |||
| 754a529211 | |||
| 2bc443584c | |||
| f63092fe87 |
8
Makefile
8
Makefile
@ -245,8 +245,7 @@ INCLUDES := \
|
||||
-Iinclude_lib/media/aispeech/enc/include \
|
||||
-Icpu/br28/audio_hearing \
|
||||
-Iinclude_lib/media/cvp \
|
||||
-Iapps/earphone/xtell_Sensor \
|
||||
-Iapps/earphone/remote_control/ \
|
||||
-Iapps/earphone/xtell_remote_control \
|
||||
-I$(SYS_INC_DIR) \
|
||||
|
||||
|
||||
@ -611,13 +610,12 @@ c_SRC_FILES := \
|
||||
cpu/br28/uart_dev.c \
|
||||
cpu/br28/umidigi_chargestore.c \
|
||||
apps/common/colorful_lights/colorful_lights.c \
|
||||
apps/earphone/xtell_Sensor/xtell_app_main.c \
|
||||
apps/earphone/xtell_Sensor/xtell_handler.c \
|
||||
|
||||
|
||||
|
||||
# 定义需要自动搜索 .c 文件的目录列表
|
||||
C_SRC_DIRS := \
|
||||
apps/earphone/remote_control \
|
||||
apps/earphone/xtell_remote_control \
|
||||
|
||||
# 使用 shell 的 find 命令递归查找所有 .c 文件
|
||||
# foreach 遍历 C_SRC_DIRS 中的每一个目录
|
||||
|
||||
@ -1663,7 +1663,8 @@ void send_version_to_sibling(void)
|
||||
data[2] = ver >> 8;
|
||||
tws_api_send_data_to_sibling(data, sizeof(data), TWS_FUNC_ID_SEQ_RAND_SYNC);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -1689,4 +1690,5 @@ void send_data_to_ble_client(const u8* data, u16 length)
|
||||
} else {
|
||||
// printf("Insufficient buffer space to send data: Length %d\n", length);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -60,7 +60,8 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
//搜索匹配信息
|
||||
const client_match_cfg_t *match_dev_cfg[CLIENT_MATCH_CONN_MAX];
|
||||
// const client_match_cfg_t *match_dev_cfg[CLIENT_MATCH_CONN_MAX]; //xtell
|
||||
client_match_cfg_t *match_dev_cfg[CLIENT_MATCH_CONN_MAX];
|
||||
//加密保定配置 0 or 1
|
||||
u8 security_en;
|
||||
//搜索服务的个数
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
* notifications.
|
||||
*/
|
||||
// *****************************************************************************
|
||||
|
||||
#if 0
|
||||
#include "system/app_core.h"
|
||||
#include "system/includes.h"
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
#if (TCFG_BLE_DEMO_SELECT == DEF_BLE_DEMO_WIRELESS_MIC_CLIENT)
|
||||
|
||||
#define SUPPORT_TEST_BOX_BLE_MASTER_TEST_EN 1
|
||||
#define SUPPORT_TEST_BOX_BLE_MASTER_TEST_EN 0
|
||||
#define SHOW_RX_DATA_RATE 1
|
||||
#define SHOW_TX_DATA_RATE 1
|
||||
|
||||
@ -189,8 +189,8 @@ static void default_report_data_deal(att_data_report_t *report_data, target_uuid
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const u8 test_remoter_name1[] = "AC637N_MX(BLE)";//
|
||||
static const u8 test_remoter_name1[] = "CM-22222";
|
||||
// static const u8 test_remoter_name1[] = "AC637N_MX(BLE)";//
|
||||
/* static const u8 test_remoter_name2[] = "AC630N_HID567(BLE)";// */
|
||||
static u16 default_client_write_handle;
|
||||
static u16 test_client_timer = 0;
|
||||
@ -275,7 +275,7 @@ static const client_conn_cfg_t client_conn_config_default = {
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
static client_conn_cfg_t *client_config = NULL; //(void *) &client_conn_config_default ;
|
||||
static client_conn_cfg_t *client_config = (void *) &client_conn_config_default ;
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -729,7 +729,7 @@ static bool resolve_adv_report(u8 *adv_address, u8 data_length, u8 *data, s8 rss
|
||||
log_info_hexdump(adv_address, 6);
|
||||
adv_data_pt[lenght - 1] = tmp32;
|
||||
//-------
|
||||
#if 1 //无线麦产线通过识别特殊字符串进行近距离连接测试
|
||||
#if 0 //无线麦产线通过识别特殊字符串进行近距离连接测试
|
||||
if (0 == memcmp(adv_data_pt, SPECIFIC_STRING, strlen(SPECIFIC_STRING))) {
|
||||
flag_specific_adv_name = 1;
|
||||
flag_need_judge_rssi = 1;
|
||||
@ -1483,12 +1483,12 @@ void bt_ble_init(void)
|
||||
put_buf(match_name, config_name_len);
|
||||
printf("%s", match_name);
|
||||
#endif
|
||||
if (0 == memcmp(match_name, SPECIFIC_STRING, strlen(SPECIFIC_STRING))) {
|
||||
match_name = &match_name[strlen(SPECIFIC_STRING)];
|
||||
printf("specific scan%s", match_name);
|
||||
flag_specific_sacn = 1;
|
||||
// if (0 == memcmp(match_name, SPECIFIC_STRING, strlen(SPECIFIC_STRING))) {
|
||||
// match_name = &match_name[strlen(SPECIFIC_STRING)];
|
||||
// printf("specific scan%s", match_name);
|
||||
// flag_specific_sacn = 1;
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
set_ble_work_state(BLE_ST_INIT_OK);
|
||||
conn_pair_vm_do(&conn_pair_info, 0);
|
||||
@ -1557,10 +1557,25 @@ void client_send_conn_param_update(void)
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
//lmx
|
||||
void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
|
||||
{
|
||||
#if (MUTIl_CHARGING_BOX_EN)
|
||||
u8 *mac_addr = get_chargebox_adv_addr();
|
||||
if (mac_addr) {
|
||||
swapX(mac_addr, mac_addr_buf, 6);
|
||||
}
|
||||
|
||||
/* printf("mac_addr:"); */
|
||||
/* printf_buf(mac_addr_buf, 6); */
|
||||
|
||||
#else
|
||||
swapX(bt_get_mac_addr(), mac_addr_buf, 6);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@ -32,8 +32,8 @@
|
||||
// IIC配置 //
|
||||
//*********************************************************************************//
|
||||
/*软件IIC设置*/ //xtell
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTB_04 //软件IIC CLK脚选择 XTELL
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTB_05 //软件IIC DAT脚选择
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTA_05//IO_PORTB_04 //软件IIC CLK脚选择 XTELL
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTA_06//IO_PORTB_05 //软件IIC DAT脚选择
|
||||
#define TCFG_SW_I2C0_DELAY_CNT 0 //IIC延时参数,影响通讯时钟频率
|
||||
|
||||
/*硬件IIC端口选择 -- 具体看手册,这里写的不准 -- lmx
|
||||
@ -44,7 +44,6 @@
|
||||
'D': IO_PORTA_05 IO_PORTA_06
|
||||
|
||||
具体要选择哪个iic口,去board_jl701n_demo.c中设置:hw_iic_cfg
|
||||
|
||||
*/
|
||||
#define TCFG_HW_I2C0_PORTS 'B'
|
||||
#define TCFG_HW_I2C0_CLK 100000
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
//#define CONFIG_DEBUG_LITE_ENABLE //轻量级打印开关, 默认关闭
|
||||
#endif
|
||||
|
||||
|
||||
#define BLE_WIRELESS_CLIENT_EN 1 //开启则作为主设备,lmx
|
||||
//*********************************************************************************//
|
||||
// AI配置 //
|
||||
//*********************************************************************************//
|
||||
@ -23,12 +23,16 @@
|
||||
#ifdef CONFIG_APP_BT_ENABLE
|
||||
#define TRANS_DATA_EN 0
|
||||
#define RCSP_BTMATE_EN 0
|
||||
#define RCSP_ADV_EN 1
|
||||
#if BLE_WIRELESS_CLIENT_EN == 0
|
||||
#define RCSP_ADV_EN 1 // lmx,打开这个,则作为ble从设备
|
||||
#else
|
||||
#define RCSP_ADV_EN 0
|
||||
#endif
|
||||
#define AI_APP_PROTOCOL 0
|
||||
#define LL_SYNC_EN 0
|
||||
#define TUYA_DEMO_EN 0
|
||||
#else
|
||||
#define TRANS_DATA_EN 1
|
||||
#define TRANS_DATA_EN 0
|
||||
#define RCSP_BTMATE_EN 0
|
||||
#define RCSP_ADV_EN 0
|
||||
#define AI_APP_PROTOCOL 0
|
||||
|
||||
@ -204,31 +204,31 @@ int app_protocol_sys_event_handler(struct sys_event *event);
|
||||
#define EARPHONE_STATE_SNIFF(a)
|
||||
#define EARPHONE_STATE_ROLE_SWITCH(a)
|
||||
|
||||
#else
|
||||
int adv_earphone_state_init();
|
||||
int adv_earphone_state_set_page_scan_enable();
|
||||
int adv_earphone_state_get_connect_mac_addr();
|
||||
int adv_earphone_state_cancel_page_scan();
|
||||
int adv_earphone_state_enter_soft_poweroff();
|
||||
int adv_earphone_state_tws_init(int paired);
|
||||
int adv_earphone_state_tws_connected(int first_pair, u8 *comm_addr);
|
||||
int adv_sys_event_handler_specific(struct sys_event *event);
|
||||
int adv_earphone_state_sniff(u8 state);
|
||||
int adv_earphone_state_role_switch(u8 role);
|
||||
// #else
|
||||
// int adv_earphone_state_init();
|
||||
// int adv_earphone_state_set_page_scan_enable();
|
||||
// int adv_earphone_state_get_connect_mac_addr();
|
||||
// int adv_earphone_state_cancel_page_scan();
|
||||
// int adv_earphone_state_enter_soft_poweroff();
|
||||
// int adv_earphone_state_tws_init(int paired);
|
||||
// int adv_earphone_state_tws_connected(int first_pair, u8 *comm_addr);
|
||||
// int adv_sys_event_handler_specific(struct sys_event *event);
|
||||
// int adv_earphone_state_sniff(u8 state);
|
||||
// int adv_earphone_state_role_switch(u8 role);
|
||||
|
||||
#define EARPHONE_STATE_INIT() adv_earphone_state_init()
|
||||
#define EARPHONE_STATE_SET_PAGE_SCAN_ENABLE() adv_earphone_state_set_page_scan_enable()
|
||||
#define EARPHONE_STATE_GET_CONNECT_MAC_ADDR() adv_earphone_state_get_connect_mac_addr()
|
||||
#define EARPHONE_STATE_CANCEL_PAGE_SCAN() adv_earphone_state_cancel_page_scan()
|
||||
#define EARPHONE_STATE_ENTER_SOFT_POWEROFF() adv_earphone_state_enter_soft_poweroff()
|
||||
#define EARPHONE_STATE_TWS_INIT(a) adv_earphone_state_tws_init(a)
|
||||
#define EARPHONE_STATE_TWS_CONNECTED(a, b) adv_earphone_state_tws_connected(a,b)
|
||||
#define SYS_EVENT_HANDLER_SPECIFIC(a) adv_sys_event_handler_specific(a)
|
||||
#define SYS_EVENT_REMAP(a) 0
|
||||
#define EARPHONE_STATE_SNIFF(a) adv_earphone_state_sniff(a)
|
||||
#define EARPHONE_STATE_ROLE_SWITCH(a) adv_earphone_state_role_switch(a)
|
||||
// #define EARPHONE_STATE_INIT() adv_earphone_state_init()
|
||||
// #define EARPHONE_STATE_SET_PAGE_SCAN_ENABLE() adv_earphone_state_set_page_scan_enable()
|
||||
// #define EARPHONE_STATE_GET_CONNECT_MAC_ADDR() adv_earphone_state_get_connect_mac_addr()
|
||||
// #define EARPHONE_STATE_CANCEL_PAGE_SCAN() adv_earphone_state_cancel_page_scan()
|
||||
// #define EARPHONE_STATE_ENTER_SOFT_POWEROFF() adv_earphone_state_enter_soft_poweroff()
|
||||
// #define EARPHONE_STATE_TWS_INIT(a) adv_earphone_state_tws_init(a)
|
||||
// #define EARPHONE_STATE_TWS_CONNECTED(a, b) adv_earphone_state_tws_connected(a,b)
|
||||
// #define SYS_EVENT_HANDLER_SPECIFIC(a) adv_sys_event_handler_specific(a)
|
||||
// #define SYS_EVENT_REMAP(a) 0
|
||||
// #define EARPHONE_STATE_SNIFF(a) adv_earphone_state_sniff(a)
|
||||
// #define EARPHONE_STATE_ROLE_SWITCH(a) adv_earphone_state_role_switch(a)
|
||||
|
||||
#endif
|
||||
// #endif
|
||||
|
||||
|
||||
#else
|
||||
@ -246,6 +246,7 @@ int adv_earphone_state_role_switch(u8 role);
|
||||
#define EARPHONE_STATE_ROLE_SWITCH(a)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@ -231,6 +231,7 @@ const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
|
||||
const uint64_t config_btctler_le_features = LE_ENCRYPTION;
|
||||
|
||||
#else
|
||||
|
||||
const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
|
||||
const uint64_t config_btctler_le_features = 0;
|
||||
#endif
|
||||
|
||||
@ -1,113 +0,0 @@
|
||||
#include "system/includes.h"
|
||||
#include "system/syscfg_id.h"
|
||||
#include "nvs.h"
|
||||
|
||||
// 2. 定义一个唯一的配置项ID (必须在1-49之间)
|
||||
#define CFG_FACTORY_INFO_ID 10
|
||||
|
||||
/**
|
||||
* @brief 将出厂信息写入Flash
|
||||
*
|
||||
* @param info 指向要写入的出厂信息结构体的指针
|
||||
* @return 实际写入的长度, <0: 失败
|
||||
*/
|
||||
int nvs_write_factory_info(const factory_info_t *info)
|
||||
{
|
||||
if (!info) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("--> Writing factory info to flash...\n");
|
||||
int ret = syscfg_write(CFG_FACTORY_INFO_ID, (void*)info, sizeof(factory_info_t));
|
||||
if (ret != sizeof(factory_info_t)) {
|
||||
printf("!!! syscfg_write factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write factory info success.\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取出厂信息
|
||||
*
|
||||
* @param info 指向用于存储读取数据的出厂信息结构体的指针
|
||||
* @return 实际读取的长度, <0: 失败 (例如尚未写入过)
|
||||
*/
|
||||
int nvs_read_factory_info(factory_info_t *info)
|
||||
{
|
||||
if (!info) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("--> Reading factory info from flash...\n");
|
||||
int ret = syscfg_read(CFG_FACTORY_INFO_ID, (void*)info, sizeof(factory_info_t));
|
||||
if (ret != sizeof(factory_info_t)) {
|
||||
printf("!!! syscfg_read factory info failed, ret = %d. Maybe not set yet.\n", ret);
|
||||
// 如果读取失败,清空结构体以避免使用脏数据
|
||||
memset(info, 0, sizeof(factory_info_t));
|
||||
} else {
|
||||
printf("--> syscfg_read factory info success.\n");
|
||||
// 可以在这里打印读取到的信息以供调试
|
||||
printf(" Product ID: %s\n", info->product_id);
|
||||
printf(" Serial No: %s\n", info->serial_number);
|
||||
printf(" HW Version: 0x%x\n", info->hw_version);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_factory_info(void)
|
||||
{
|
||||
printf("--> Clearing factory info from flash...\n");
|
||||
// 写入长度为0的数据即可实现删除效果
|
||||
int ret = syscfg_write(CFG_FACTORY_INFO_ID, NULL, 0);
|
||||
if (ret != 0) {
|
||||
printf("!!! syscfg_write clear factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write clear factory info success.\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// 可以在这里添加一个测试函数
|
||||
void nvs_test_factory_info(void)
|
||||
{
|
||||
factory_info_t write_info = {
|
||||
.product_id = "RC_V2",
|
||||
.serial_number = "SN202511260002",
|
||||
.hw_version = 0x0102, // v1.1
|
||||
.cal_data = 1234,
|
||||
.manufacture_date = 1764080400, // 2025-11-26
|
||||
};
|
||||
factory_info_t read_info;
|
||||
|
||||
printf("\n\n--- NVS WRITE TEST ---\n");
|
||||
nvs_write_factory_info(&write_info);
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ TEST ---\n");
|
||||
nvs_read_factory_info(&read_info);
|
||||
|
||||
// ASSERT(memcmp(&write_info, &read_info, sizeof(factory_info_t)) == 0, "NVS Read/Write Check Failed!");
|
||||
|
||||
// printf("\n--- NVS CLEAR TEST ---\n");
|
||||
// nvs_clear_factory_info();
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ AFTER CLEAR TEST ---\n");
|
||||
int ret = nvs_read_factory_info(&read_info);
|
||||
if(ret < 0){
|
||||
printf("--- nvs read error ---\n");
|
||||
}
|
||||
|
||||
printf("\n\n--- NVS TEST COMPLETE ---\n\n");
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
#ifndef __NVS_H__
|
||||
#define __NVS_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
// 定义出厂信息数据结构
|
||||
typedef struct {
|
||||
char product_id[16]; // 产品ID
|
||||
char serial_number[32]; // 序列号
|
||||
u16 hw_version; // 硬件版本
|
||||
u16 cal_data; // 某个校准数据
|
||||
u32 manufacture_date; // 生产日期 (Unix时间戳)
|
||||
} factory_info_t;
|
||||
|
||||
/**
|
||||
* @brief 将出厂信息写入Flash
|
||||
*
|
||||
* @param info 指向要写入的出厂信息结构体的指针
|
||||
* @return 实际写入的长度, <0: 失败
|
||||
*/
|
||||
int nvs_write_factory_info(const factory_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取出厂信息
|
||||
*
|
||||
* @param info 指向用于存储读取数据的出厂信息结构体的指针
|
||||
* @return 实际读取的长度, <0: 失败 (例如尚未写入过)
|
||||
*/
|
||||
int nvs_read_factory_info(factory_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_factory_info(void);
|
||||
|
||||
/**
|
||||
* @brief 用于测试NVS读写功能的函数
|
||||
*
|
||||
*/
|
||||
void nvs_test_factory_info(void);
|
||||
|
||||
#endif // __NVS_H__
|
||||
@ -203,8 +203,8 @@ void cfg_file_parse(u8 idx)
|
||||
} else if (ret >= LOCAL_NAME_LEN) {
|
||||
memset(bt_cfg.edr_name, 0x00, LOCAL_NAME_LEN);
|
||||
// memcpy(bt_cfg.edr_name, tmp, LOCAL_NAME_LEN);
|
||||
extern char xt_ble_new_name[9];
|
||||
memcpy(bt_cfg.edr_name, xt_ble_new_name, LOCAL_NAME_LEN);
|
||||
// extern char xt_ble_new_name[9];
|
||||
// memcpy(bt_cfg.edr_name, xt_ble_new_name, LOCAL_NAME_LEN);
|
||||
bt_cfg.edr_name[LOCAL_NAME_LEN - 1] = 0;
|
||||
} else {
|
||||
memset(bt_cfg.edr_name, 0x00, LOCAL_NAME_LEN);
|
||||
|
||||
@ -1,173 +0,0 @@
|
||||
#include "system/includes.h"
|
||||
/*#include "btcontroller_config.h"*/
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "asm/pwm_led.h"
|
||||
#include "tone_player.h"
|
||||
#include "gpio.h"
|
||||
#include "app_main.h"
|
||||
#include "asm/charge.h"
|
||||
#include "update.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "app_charge.h"
|
||||
#include "bt_profile_cfg.h"
|
||||
#include "dev_manager/dev_manager.h"
|
||||
#include "update_loader_download.h"
|
||||
#include "avctp_user.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
#define LOG_TAG_CONST APP
|
||||
#define LOG_TAG "[APP]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//变量
|
||||
extern APP_VAR app_var;
|
||||
u16 close_BL_number=0;
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//函数定义
|
||||
extern void timer_2ms_handler();
|
||||
extern void app_var_init(void);
|
||||
void app_earphone_play_voice_file(const char *name);
|
||||
void clr_wdt(void);
|
||||
extern void check_power_on_key(void);
|
||||
extern int cpu_reset_by_soft();
|
||||
extern int audio_dec_init();
|
||||
extern int audio_enc_init();
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*充电拔出,CPU软件复位, 不检测按键,直接开机*/
|
||||
static void app_poweron_check(int update)
|
||||
{
|
||||
if (!update && cpu_reset_by_soft()) {
|
||||
app_var.play_poweron_tone = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
void create_process(u16* pid,char* name, void *priv, void (*func)(void *priv), u32 msec){
|
||||
xlog("1 name=%s, pid =%d\n",name,*pid);
|
||||
if (*pid != 0) return;
|
||||
*pid = sys_timer_add(priv, func, msec);
|
||||
xlog("2 name=%s, pid =%d\n",name,*pid);
|
||||
}
|
||||
void close_process(u16* pid,char* name){
|
||||
xlog("name=%s,pid =%d\n",name,*pid);
|
||||
if (*pid == 0) return;
|
||||
sys_timer_del(*pid);
|
||||
*pid = 0;
|
||||
}
|
||||
|
||||
|
||||
void close_BL(){
|
||||
/**开机默认关闭 经典蓝牙 */
|
||||
// close_BL_flag++;
|
||||
xlog("xtell Classic Bluetooth off\n");
|
||||
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL); //断开此时经典蓝牙的连接,经典蓝牙还是可以被发现
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); //关闭蓝牙可发现,已连接时不能操作
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); //关闭蓝牙可连接,
|
||||
// sys_timer_del(close_BL_number); //删除定时器任务
|
||||
close_process(&close_BL_number,__func__);
|
||||
}
|
||||
|
||||
void xtell_set_ble_name(char* name){
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern u32 timer_get_ms(void);
|
||||
void xtell_app_main()
|
||||
{
|
||||
int update = 0;
|
||||
u32 addr = 0, size = 0;
|
||||
struct intent it;
|
||||
|
||||
xlog("==============xtell_app_main start================\n");
|
||||
log_info("app_main\n");
|
||||
app_var.start_time = timer_get_ms();
|
||||
|
||||
|
||||
|
||||
if (!UPDATE_SUPPORT_DEV_IS_NULL()) {
|
||||
update = update_result_deal();
|
||||
}
|
||||
|
||||
app_var_init();
|
||||
|
||||
if (get_charge_online_flag()) {
|
||||
#if(TCFG_SYS_LVD_EN == 1)
|
||||
vbat_check_init();
|
||||
#endif
|
||||
xlog("==============idle================\n");
|
||||
init_intent(&it);
|
||||
it.name = "idle";
|
||||
it.action = ACTION_IDLE_MAIN;
|
||||
start_app(&it);
|
||||
} else {
|
||||
xlog("==============handler start================\n");
|
||||
check_power_on_voltage();
|
||||
app_poweron_check(update);
|
||||
init_intent(&it);
|
||||
it.name = "handler";
|
||||
it.action = ACTION_EARPHONE_MAIN;
|
||||
start_app(&it);
|
||||
xlog("==============handler end================\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
//开机必须延时关闭经典蓝牙,不然底层代码会再次把蓝牙 打开
|
||||
// create_process(&close_BL_number, "close_BL",NULL, close_BL, 3000);
|
||||
|
||||
|
||||
|
||||
|
||||
u8 mac_data[6];
|
||||
extern void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf);
|
||||
rcsp_adv_fill_mac_addr(mac_data); //读取MAC地址
|
||||
xlog("xtell BT mac data:%x:%x:%x:%x:%x:%x",mac_data[0],mac_data[1],mac_data[2],mac_data[3],mac_data[4],mac_data[5]);
|
||||
|
||||
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
|
||||
delay_2ms(50);
|
||||
|
||||
|
||||
|
||||
xlog("==============xtell_app_end================\n");
|
||||
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief 处理Type A卡片事件。
|
||||
* @brief 处理Type A卡片事件。uid:8位数组
|
||||
* @details
|
||||
* 该函数执行ISO/IEC 14443 Type A卡片的完整激活流程,包括:
|
||||
* 1. 初始化读卡器以支持Type A协议。
|
||||
@ -34,7 +34,7 @@
|
||||
* 5. 操作结束后关闭RF场。
|
||||
* @return 无。
|
||||
*/
|
||||
void TYPE_A_EVENT(void)
|
||||
void TYPE_A_EVENT(char* uid)
|
||||
{
|
||||
unsigned char result;
|
||||
int i;
|
||||
@ -75,6 +75,7 @@ void TYPE_A_EVENT(void)
|
||||
xlog("-> UID = ");
|
||||
for (i = 0; i < PICC_A.UID_Length; i++)
|
||||
{
|
||||
uid[i] = PICC_A.UID[i];
|
||||
xlog("%02X", PICC_A.UID[i]);
|
||||
}
|
||||
xlog("\r\n");
|
||||
@ -168,7 +169,7 @@ void TYPE_B_EVENT(void)
|
||||
* 6. 操作结束后关闭RF场。
|
||||
* @return 无。
|
||||
*/
|
||||
void TYPE_V_EVENT(void)
|
||||
void TYPE_V_EVENT(char* uid)
|
||||
{
|
||||
unsigned char result, i;
|
||||
xlog("TYPE_V_EVENT begin\n");
|
||||
@ -188,6 +189,7 @@ void TYPE_V_EVENT(void)
|
||||
xlog("UID=");
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
uid[i] = PICC_V.UID[i];
|
||||
xlog("%02X", PICC_V.UID[i]);
|
||||
}
|
||||
xlog("\r\n");
|
||||
@ -298,6 +300,6 @@ void rfid_task_fuc(void)
|
||||
|
||||
// TYPE_A_EVENT();
|
||||
// TYPE_B_EVENT();
|
||||
TYPE_V_EVENT();
|
||||
// TYPE_V_EVENT();
|
||||
// TYPE_F_EVENT();
|
||||
}
|
||||
@ -45,7 +45,7 @@
|
||||
#include "default_event_handler.h"
|
||||
#include "debug.h"
|
||||
#include "system/event.h"
|
||||
#include "../remote_control/nvs.h"
|
||||
#include "../nvs/nvs.h"
|
||||
#if (JL_EARPHONE_APP_EN)
|
||||
#include "rcsp_adv_bluetooth.h"
|
||||
#endif
|
||||
@ -102,6 +102,7 @@ extern void create_process(u16* pid, const char* name, void *priv, void (*func)(
|
||||
extern void close_process(u16* pid,char* name);
|
||||
extern void start_collect_fuc(void);
|
||||
extern void BLE_send_fuc(void);
|
||||
extern void xtell_ble_central_test_start(void);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* 模式状态机, 通过start_app()控制状态切换
|
||||
@ -301,7 +302,8 @@ static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
ble_bqb_test_thread_init();
|
||||
} else {
|
||||
#if !TCFG_WIRELESS_MIC_ENABLE
|
||||
bt_ble_init();
|
||||
bt_ble_init(); // lmx,初始化完,初始化ble,决定ble是作为主设备还是从设备
|
||||
// xtell_ble_central_test_start(); //xtell
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -335,7 +337,7 @@ static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
bt_newname =1;
|
||||
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||
send_data_to_ble_client(&temp,5);
|
||||
// send_data_to_ble_client(&temp,5);
|
||||
}
|
||||
earphone_change_pwr_mode(PWR_DCDC15, 3000);
|
||||
sys_auto_shut_down_disable();
|
||||
@ -368,7 +370,7 @@ static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
bt_newname=0;
|
||||
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||
send_data_to_ble_client(&temp,5);
|
||||
// send_data_to_ble_client(&temp,5);
|
||||
}
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
/*关机不播断开提示音*/
|
||||
268
apps/earphone/xtell_remote_control/ble_handler/ble_test.c
Normal file
268
apps/earphone/xtell_remote_control/ble_handler/ble_test.c
Normal file
@ -0,0 +1,268 @@
|
||||
|
||||
#include "system/app_core.h"
|
||||
#include "system/includes.h"
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "btstack/bluetooth.h"
|
||||
#include "le_common.h"
|
||||
#include "ble_user.h"
|
||||
|
||||
#if 0 //ENABLE_THIS_TEST
|
||||
|
||||
#define LOG_TAG_CONST EARPHONE
|
||||
#define LOG_TAG "[BLE_TEST]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
// =================== 配置区 START ===================
|
||||
|
||||
// 1. 设置要连接的目标从机设备蓝牙名称
|
||||
#define TARGET_BLE_NAME "CM-22222"
|
||||
|
||||
// 2. 设置要搜索的 Service UUID 和 Characteristic UUID
|
||||
// Service UUID: 0x180D
|
||||
#define TARGET_SERVICE_UUID16 0x180D
|
||||
// Characteristic UUID: 0x2A37 (Notify)
|
||||
#define TARGET_CHARACTERISTIC_UUID16 0x2A37
|
||||
#define TARGET_CHARACTERISTIC_OPT_TYPE ATT_PROPERTY_NOTIFY
|
||||
|
||||
// =================== 配置区 END =====================
|
||||
|
||||
// ATT RAM buffer
|
||||
#define ATT_LOCAL_MTU_SIZE (517)
|
||||
#define ATT_SEND_CBUF_SIZE (256)
|
||||
#define ATT_RAM_BUFSIZE (ATT_CTRL_BLOCK_SIZE + ATT_LOCAL_MTU_SIZE + ATT_SEND_CBUF_SIZE)
|
||||
static u8 att_ram_buffer[ATT_RAM_BUFSIZE] __attribute__((aligned(4)));
|
||||
|
||||
// Profile 搜索 buffer
|
||||
#define SEARCH_PROFILE_BUFSIZE (512)
|
||||
static u8 search_ram_buffer[SEARCH_PROFILE_BUFSIZE] __attribute__((aligned(4)));
|
||||
|
||||
// BLE 工作状态
|
||||
static u8 ble_work_state = 0;
|
||||
static hci_con_handle_t con_handle;
|
||||
|
||||
// 搜索到的目标特征值句柄
|
||||
static u16 target_write_handle = 0;
|
||||
static u16 target_notify_handle = 0;
|
||||
|
||||
// 函数前向声明
|
||||
static int ble_central_test_scan_enable(u32 en);
|
||||
static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
|
||||
// 设置 BLE 工作状态
|
||||
static void set_ble_work_state(u8 state) {
|
||||
if (state != ble_work_state) {
|
||||
log_info("ble_work_state: %d -> %d\n", ble_work_state, state);
|
||||
ble_work_state = state;
|
||||
}
|
||||
}
|
||||
|
||||
// 解析广播数据,寻找目标设备
|
||||
static bool resolve_adv_report(u8 *adv_address, u8 data_length, u8 *data) {
|
||||
u8 i, length, ad_type;
|
||||
u8 *adv_data_ptr = data;
|
||||
|
||||
for (i = 0; i < data_length;) {
|
||||
if (*adv_data_ptr == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
length = *adv_data_ptr++;
|
||||
ad_type = *adv_data_ptr++;
|
||||
i += (length + 1);
|
||||
|
||||
if (ad_type == HCI_EIR_DATATYPE_COMPLETE_LOCAL_NAME || ad_type == HCI_EIR_DATATYPE_SHORTENED_LOCAL_NAME) {
|
||||
if (length > 1 && (0 == memcmp(adv_data_ptr, TARGET_BLE_NAME, strlen(TARGET_BLE_NAME)))) {
|
||||
log_info("Found target device: %s", TARGET_BLE_NAME);
|
||||
log_info_hexdump(adv_address, 6);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
adv_data_ptr += (length - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建连接
|
||||
static void central_test_create_connection(u8 *addr, u8 addr_type) {
|
||||
if (ble_work_state >= BLE_ST_CREATE_CONN) {
|
||||
return;
|
||||
}
|
||||
log_info("Stopping scan...");
|
||||
ble_central_test_scan_enable(0);
|
||||
|
||||
struct create_conn_param_t conn_param = {0};
|
||||
conn_param.conn_interval = 24;
|
||||
conn_param.conn_latency = 0;
|
||||
conn_param.supervision_timeout = 600;
|
||||
conn_param.peer_address_type = addr_type;
|
||||
memcpy(conn_param.peer_address, addr, 6);
|
||||
|
||||
set_ble_work_state(BLE_ST_CREATE_CONN);
|
||||
ble_op_create_connection(&conn_param);
|
||||
}
|
||||
|
||||
// 开始搜索 Profile
|
||||
static void central_test_search_profile() {
|
||||
target_write_handle = 0;
|
||||
target_notify_handle = 0;
|
||||
user_client_init(con_handle, search_ram_buffer, SEARCH_PROFILE_BUFSIZE);
|
||||
ble_op_search_profile_all();
|
||||
}
|
||||
|
||||
// 搜索 Profile 结果回调
|
||||
void user_client_report_search_result(search_result_t *result_info) {
|
||||
if (result_info == (void *)-1) {
|
||||
log_info("Search profile complete.");
|
||||
set_ble_work_state(BLE_ST_SEARCH_COMPLETE);
|
||||
// 如果找到了 NOTIFY 特征,使能它
|
||||
if (target_notify_handle) {
|
||||
log_info("Enabling notification for handle 0x%04x", target_notify_handle);
|
||||
u16 val = 0x0001;
|
||||
ble_op_att_send_data(target_notify_handle + 1, &val, 2, ATT_OP_WRITE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result_info->services.uuid16 == TARGET_SERVICE_UUID16 &&
|
||||
result_info->characteristic.uuid16 == TARGET_CHARACTERISTIC_UUID16) {
|
||||
log_info("Found target characteristic UUID 0x%04x", TARGET_CHARACTERISTIC_UUID16);
|
||||
if ((result_info->characteristic.properties & ATT_PROPERTY_WRITE_WITHOUT_RESPONSE) ||
|
||||
(result_info->characteristic.properties & ATT_PROPERTY_WRITE)) {
|
||||
target_write_handle = result_info->characteristic.value_handle;
|
||||
log_info("Found write handle: 0x%04x", target_write_handle);
|
||||
}
|
||||
if (result_info->characteristic.properties & ATT_PROPERTY_NOTIFY) {
|
||||
target_notify_handle = result_info->characteristic.value_handle;
|
||||
log_info("Found notify handle: 0x%04x", target_notify_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接收到数据回调
|
||||
void user_client_report_data_callback(att_data_report_t *report_data) {
|
||||
log_info("RX data, handle=0x%04x, len=%d:", report_data->value_handle, report_data->blob_length);
|
||||
log_info_hexdump(report_data->blob, report_data->blob_length);
|
||||
}
|
||||
|
||||
// BLE 事件回调处理
|
||||
static void cbk_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case HCI_EVENT_LE_META:
|
||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE:
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||
if (hci_subevent_le_connection_complete_get_status(packet)) {
|
||||
log_error("Connection failed, status: 0x%x", hci_subevent_le_connection_complete_get_status(packet));
|
||||
set_ble_work_state(BLE_ST_CONNECT_FAIL);
|
||||
ble_central_test_scan_enable(1); // 重新开始扫描
|
||||
} else {
|
||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
log_info("Connection established, handle: 0x%04x", con_handle);
|
||||
ble_op_att_send_init(con_handle, att_ram_buffer, ATT_RAM_BUFSIZE, ATT_LOCAL_MTU_SIZE);
|
||||
set_ble_work_state(BLE_ST_CONNECT);
|
||||
central_test_search_profile();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
log_info("Disconnected, reason: 0x%x", hci_event_disconnection_complete_get_reason(packet));
|
||||
con_handle = 0;
|
||||
ble_op_att_send_init(0, NULL, 0, 0);
|
||||
set_ble_work_state(BLE_ST_DISCONN);
|
||||
ble_central_test_scan_enable(1); // 断开后重新扫描
|
||||
break;
|
||||
|
||||
case GAP_EVENT_ADVERTISING_REPORT:
|
||||
if (ble_work_state != BLE_ST_SCAN) {
|
||||
break;
|
||||
}
|
||||
adv_report_t *report = (void *)&packet[2];
|
||||
if (resolve_adv_report(report->address, report->length, report->data)) {
|
||||
central_test_create_connection(report->address, report->address_type);
|
||||
}
|
||||
break;
|
||||
|
||||
case ATT_EVENT_MTU_EXCHANGE_COMPLETE:
|
||||
log_info("MTU exchange complete, MTU = %d", att_event_mtu_exchange_complete_get_MTU(packet));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 启动或停止扫描
|
||||
static int ble_central_test_scan_enable(u32 en) {
|
||||
if (en) {
|
||||
if (ble_work_state >= BLE_ST_SCAN) {
|
||||
return 0; // 已经在扫描或连接中
|
||||
}
|
||||
log_info("Starting scan...");
|
||||
set_ble_work_state(BLE_ST_SCAN);
|
||||
ble_op_set_scan_param(SCAN_ACTIVE, 48, 48);
|
||||
ble_op_scan_enable2(1, 0);
|
||||
} else {
|
||||
if (ble_work_state < BLE_ST_SCAN) {
|
||||
return 0; // 已经停止
|
||||
}
|
||||
log_info("Stopping scan...");
|
||||
set_ble_work_state(BLE_ST_IDLE);
|
||||
ble_op_scan_enable2(0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 发送数据接口
|
||||
int xtell_ble_central_test_send_data(u8 *data, u16 len) {
|
||||
if (!con_handle || ble_work_state != BLE_ST_SEARCH_COMPLETE) {
|
||||
log_error("Not connected or profile search not complete.");
|
||||
return -1;
|
||||
}
|
||||
if (!target_write_handle) {
|
||||
log_error("No writable characteristic found.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = ble_op_att_send_data(target_write_handle, data, len, ATT_OP_WRITE_WITHOUT_RESPOND);
|
||||
if (ret == 0) {
|
||||
log_info("TX data, len=%d:", len);
|
||||
log_info_hexdump(data, len);
|
||||
} else {
|
||||
log_error("Failed to send data, ret=%d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 注册 BLE central 模式需要的回调
|
||||
static void ble_central_test_register_handlers(void) {
|
||||
log_info("Registering BLE central test handlers...");
|
||||
// 注意:le_device_db_init() 和 ble_stack_gatt_role() 可能已被RCSP的profile_init调用
|
||||
// 这里我们只覆盖 packet handlers
|
||||
gatt_client_init(); // 确保 gatt client 被初始化
|
||||
gatt_client_register_packet_handler(cbk_packet_handler);
|
||||
hci_event_callback_set(cbk_packet_handler);
|
||||
le_l2cap_register_packet_handler(cbk_packet_handler);
|
||||
ble_vendor_set_default_att_mtu(ATT_LOCAL_MTU_SIZE);
|
||||
}
|
||||
|
||||
// 测试总开关和初始化
|
||||
void xtell_ble_central_test_start(void) {
|
||||
if (ble_work_state != 0) {
|
||||
log_info("Test is already running.");
|
||||
return;
|
||||
}
|
||||
log_info("======== Xtell BLE Central Test Start ========");
|
||||
set_ble_work_state(BLE_ST_INIT_OK);
|
||||
ble_module_enable(1); // 使能 BLE 模块
|
||||
ble_central_test_register_handlers(); // 注册我们的回调
|
||||
ble_central_test_scan_enable(1); // 开始扫描
|
||||
}
|
||||
|
||||
#endif
|
||||
1673
apps/earphone/xtell_remote_control/ble_handler/client_handler.c
Normal file
1673
apps/earphone/xtell_remote_control/ble_handler/client_handler.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
147
apps/earphone/xtell_remote_control/nvs/nvs.c
Normal file
147
apps/earphone/xtell_remote_control/nvs/nvs.c
Normal file
@ -0,0 +1,147 @@
|
||||
#include "system/includes.h"
|
||||
#include "system/syscfg_id.h"
|
||||
#include "nvs.h"
|
||||
|
||||
// 2. 定义唯一的配置项ID
|
||||
|
||||
#define CFG_RC_MAC_ADDR_ID 11 // 配置项id
|
||||
|
||||
/**
|
||||
* @brief 将主板MAC地址写入Flash
|
||||
*/
|
||||
int nvs_write_main_board_mac(const u8 *mac_addr)
|
||||
{
|
||||
if (!mac_addr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc_nvs_data_t nvs_data;
|
||||
memcpy(nvs_data.main_board_mac, mac_addr, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
|
||||
printf("--> Writing main board MAC to flash...\n");
|
||||
int ret = syscfg_write(CFG_RC_MAC_ADDR_ID, &nvs_data, sizeof(rc_nvs_data_t));
|
||||
if (ret != sizeof(rc_nvs_data_t)) {
|
||||
printf("!!! syscfg_write main board MAC failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write main board MAC success.\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取主板MAC地址
|
||||
*/
|
||||
int nvs_read_main_board_mac(u8 *mac_addr)
|
||||
{
|
||||
if (!mac_addr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc_nvs_data_t nvs_data;
|
||||
printf("--> Reading main board MAC from flash...\n");
|
||||
int ret = syscfg_read(CFG_RC_MAC_ADDR_ID, &nvs_data, sizeof(rc_nvs_data_t));
|
||||
|
||||
if (ret != sizeof(rc_nvs_data_t)) {
|
||||
printf("!!! syscfg_read main board MAC failed, ret = %d. Maybe not set yet.\n", ret);
|
||||
memset(mac_addr, 0, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
} else {
|
||||
printf("--> syscfg_read main board MAC success.\n");
|
||||
memcpy(mac_addr, nvs_data.main_board_mac, MAIN_BOARD_MAC_ADDR_LENGTH);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_info(void)
|
||||
{
|
||||
rc_nvs_data_t nvs_data;
|
||||
for(int i = 0 ; i < MAIN_BOARD_MAC_ADDR_LENGTH; i++){
|
||||
nvs_data.main_board_mac[i] = 0;
|
||||
}
|
||||
printf("--> Clearing factory info from flash...\n");
|
||||
// 写入长度为0的数据即可实现删除效果
|
||||
int ret = syscfg_write(CFG_RC_MAC_ADDR_ID, &nvs_data, sizeof(rc_nvs_data_t));
|
||||
if (ret != 0) {
|
||||
printf("!!! syscfg_write clear factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write clear factory info success.\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// =================================================================================
|
||||
// 以下为旧的通用出厂信息API,已废弃
|
||||
// =================================================================================
|
||||
#define CFG_FACTORY_INFO_ID 10 // 旧的、通用的出厂信息ID (已废弃)
|
||||
int nvs_write_factory_info(const factory_info_t *info)
|
||||
{
|
||||
printf("WARNING: nvs_write_factory_info is deprecated.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nvs_read_factory_info(factory_info_t *info)
|
||||
{
|
||||
printf("WARNING: nvs_read_factory_info is deprecated.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空Flash中的出厂信息
|
||||
*
|
||||
* @return 0: 成功, <0: 失败
|
||||
*/
|
||||
int nvs_clear_factory_info(void)
|
||||
{
|
||||
printf("--> Clearing factory info from flash...\n");
|
||||
// 写入长度为0的数据即可实现删除效果
|
||||
int ret = syscfg_write(CFG_FACTORY_INFO_ID, NULL, 0);
|
||||
if (ret != 0) {
|
||||
printf("!!! syscfg_write clear factory info failed, ret = %d\n", ret);
|
||||
} else {
|
||||
printf("--> syscfg_write clear factory info success.\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// 可以在这里添加一个测试函数
|
||||
void nvs_test_factory_info(void)
|
||||
{
|
||||
factory_info_t write_info = {
|
||||
.product_id = "RC_V2",
|
||||
.serial_number = "SN202511260002",
|
||||
.hw_version = 0x0102, // v1.1
|
||||
.cal_data = 1234,
|
||||
.manufacture_date = 1764080400, // 2025-11-26
|
||||
};
|
||||
factory_info_t read_info;
|
||||
|
||||
printf("\n\n--- NVS WRITE TEST ---\n");
|
||||
nvs_write_factory_info(&write_info);
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ TEST ---\n");
|
||||
nvs_read_factory_info(&read_info);
|
||||
|
||||
// ASSERT(memcmp(&write_info, &read_info, sizeof(factory_info_t)) == 0, "NVS Read/Write Check Failed!");
|
||||
|
||||
// printf("\n--- NVS CLEAR TEST ---\n");
|
||||
// nvs_clear_factory_info();
|
||||
|
||||
os_time_dly(10);
|
||||
|
||||
printf("\n--- NVS READ AFTER CLEAR TEST ---\n");
|
||||
int ret = nvs_read_factory_info(&read_info);
|
||||
if(ret < 0){
|
||||
printf("--- nvs read error ---\n");
|
||||
}
|
||||
|
||||
printf("\n\n--- NVS TEST COMPLETE ---\n\n");
|
||||
}
|
||||
58
apps/earphone/xtell_remote_control/nvs/nvs.h
Normal file
58
apps/earphone/xtell_remote_control/nvs/nvs.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef __NVS_H__
|
||||
#define __NVS_H__
|
||||
|
||||
#include "typedef.h"
|
||||
#include "../task_func.h"
|
||||
|
||||
#define MAIN_BOARD_MAC_ADDR_LENGTH UID_LENGTH
|
||||
|
||||
/**
|
||||
* @brief 定义用于存储遥控器配对信息的数据结构
|
||||
*/
|
||||
typedef struct {
|
||||
u8 main_board_mac[MAIN_BOARD_MAC_ADDR_LENGTH]; // 配对的主板MAC地址
|
||||
// u8 reserved[2]; // 可选的保留字节,用于对齐或未来扩展
|
||||
} rc_nvs_data_t;
|
||||
|
||||
/**
|
||||
* @brief 将主板MAC地址写入Flash
|
||||
*
|
||||
* @param mac_addr 指向要写入的MAC地址数组的指针
|
||||
* @return 实际写入的长度, <0: 失败
|
||||
*/
|
||||
int nvs_write_main_board_mac(const u8 *mac_addr);
|
||||
|
||||
/**
|
||||
* @brief 从Flash读取主板MAC地址
|
||||
*
|
||||
* @param mac_addr 指向用于存储读取数据的MAC地址数组的指针
|
||||
* @return 实际读取的长度, <0: 失败 (例如尚未写入过)
|
||||
*/
|
||||
int nvs_read_main_board_mac(u8 *mac_addr);
|
||||
|
||||
int nvs_clear_info(void);
|
||||
// =================================================================================
|
||||
// 以下为旧的通用出厂信息API,已废弃,不建议在新代码中使用
|
||||
// =================================================================================
|
||||
|
||||
typedef struct {
|
||||
char product_id[16];
|
||||
char serial_number[32];
|
||||
u16 hw_version;
|
||||
u16 cal_data;
|
||||
u32 manufacture_date;
|
||||
} factory_info_t;
|
||||
|
||||
__attribute__((deprecated("Use nvs_write_main_board_mac instead")))
|
||||
int nvs_write_factory_info(const factory_info_t *info);
|
||||
|
||||
__attribute__((deprecated("Use nvs_read_main_board_mac instead")))
|
||||
int nvs_read_factory_info(factory_info_t *info);
|
||||
|
||||
__attribute__((deprecated("This function is no longer needed")))
|
||||
int nvs_clear_factory_info(void);
|
||||
|
||||
__attribute__((deprecated("This function is no longer needed")))
|
||||
void nvs_test_factory_info(void);
|
||||
|
||||
#endif // __NVS_H__
|
||||
292
apps/earphone/xtell_remote_control/task_func.c
Normal file
292
apps/earphone/xtell_remote_control/task_func.c
Normal file
@ -0,0 +1,292 @@
|
||||
#include "task_func.h"
|
||||
#include "./nvs/nvs.h"
|
||||
#include "timer.h"
|
||||
#include "system/includes.h"
|
||||
#include "user_cfg.h"
|
||||
#include "earphone.h" // 宏定义 EARPHONE_STATE_...
|
||||
#include "ble_user.h"
|
||||
#include "le_client_demo.h"
|
||||
#include "le_common.h"
|
||||
#include "./ble_handler/client_handler.h"
|
||||
// =================================================================================
|
||||
// 宏定义与日志
|
||||
// =================================================================================
|
||||
|
||||
#define RC_LOG_ENABLE 1
|
||||
#if RC_LOG_ENABLE
|
||||
#define rc_log(format, ...) printf("[RC_APP] " format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define rc_log(format, ...)
|
||||
#endif
|
||||
|
||||
// =================================================================================
|
||||
// 外部函数声明
|
||||
// =================================================================================
|
||||
extern void TYPE_V_EVENT(char* uid);
|
||||
extern void TYPE_A_EVENT(char* uid);
|
||||
// =================================================================================
|
||||
// 静态函数声明
|
||||
// =================================================================================
|
||||
|
||||
static RFID_Device_Type_t get_rfid_device_type(const u8* uid);
|
||||
|
||||
// BLE 状态转换的辅助函数
|
||||
static void rc_ble_state_set_connecting(void);
|
||||
static void rc_ble_state_set_connected(void);
|
||||
static void rc_ble_state_set_disconnected(void);
|
||||
|
||||
// =================================================================================
|
||||
// 全局变量
|
||||
// =================================================================================
|
||||
|
||||
static RC_Context_t g_rc_context; // 全局上下文实例
|
||||
static u16 g_rfid_timer_id = 0; // RFID 定时器ID
|
||||
static u16 g_ble_timer_id = 0; // BLE 定时器ID
|
||||
static u8 current_board_mac[MAIN_BOARD_MAC_ADDR_LENGTH] = {0}; //当前连接主板的名称 -- mac
|
||||
|
||||
|
||||
|
||||
// =================================================================================
|
||||
// 核心回调函数 (Core Callback Handlers)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief RFID回调处理函数 (由定时器周期性调用)
|
||||
*/
|
||||
void rc_rfid_callback_handler(void *priv)
|
||||
{
|
||||
u8 uid[UID_LENGTH] = {0};
|
||||
|
||||
//读id卡
|
||||
// TYPE_V_EVENT((char *)uid);
|
||||
TYPE_A_EVENT((char *)uid);
|
||||
|
||||
//是否有rfid卡靠近
|
||||
u8 is_new_data = 0;
|
||||
for (int i = 0; i < UID_LENGTH; i++) {
|
||||
if (uid[i] != 0x00) {
|
||||
is_new_data = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_new_data) {
|
||||
return; //没有rfid卡靠近,返回
|
||||
}
|
||||
|
||||
|
||||
rc_log("New RFID card detected.\n");
|
||||
|
||||
RFID_Device_Type_t device_type = get_rfid_device_type(uid);
|
||||
|
||||
switch (device_type) {
|
||||
case RFID_DEVICE_TYPE_MAIN_BOARD: //船主板上的rfid卡
|
||||
if(strncmp(uid, current_board_mac, UID_LENGTH) == 0){
|
||||
// 扫到的rfid卡的uid和当前连接的主板mac相同
|
||||
return;
|
||||
}
|
||||
//扫到新的主板
|
||||
rc_log("Device is Main Board. Storing MAC...\n");
|
||||
// 将新的MAC地址写入Flash
|
||||
nvs_write_main_board_mac(uid);
|
||||
|
||||
// memset(current_board_mac, uid, sizeof(current_board_mac));
|
||||
|
||||
// TODO:发送指令,让主板断开经典蓝牙连接
|
||||
// TODO: 切断BLE
|
||||
|
||||
// g_ble_connect_new_device(current_board_mac); //连接新主板
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case RFID_DEVICE_TYPE_REMOTE_CONTROL: //扫的是遥控器
|
||||
rc_log("Device is another Remote Control.\n");
|
||||
if(g_rc_context.team != TEAM_YES){
|
||||
nvs_clear_info(); //清楚nfc数据
|
||||
return; //非组队状态
|
||||
}
|
||||
if (g_ble_get_state() == BLE_ST_NOTIFY_IDICATE) {
|
||||
rc_log("Sending teaming request to main board...\n");
|
||||
//TODO:
|
||||
//向主板发送新的遥控器rfid uid
|
||||
} else {
|
||||
rc_log("Not connected to main board, ignoring teaming request.\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
rc_log("Unknown RFID device type.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BLE回调处理函数 (由定时器周期性调用)s
|
||||
*/
|
||||
void rc_ble_callback_handler(void *priv)
|
||||
{
|
||||
u8 read_uid[UID_LENGTH] = {0};
|
||||
nvs_read_main_board_mac(read_uid); //读nvs
|
||||
|
||||
//读到的是当前连接的主板uid
|
||||
if((strncmp(read_uid, current_board_mac, UID_LENGTH) == 0) && g_ble_get_state()){
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
// bool is_connected = ble_hid_is_connected();
|
||||
|
||||
// // 状态机转换
|
||||
// if (is_connected && g_rc_context.state != RC_STATE_CONNECTED) {
|
||||
// rc_ble_state_set_connected();
|
||||
// } else if (!is_connected && g_rc_context.state != RC_STATE_DISCONNECTED) {
|
||||
// rc_ble_state_set_disconnected();
|
||||
// }
|
||||
|
||||
// // 状态机行为
|
||||
// switch (g_rc_context.state) {
|
||||
// case RC_STATE_DISCONNECTED:
|
||||
// {
|
||||
// u8 target_mac[MAC_ADDR_LENGTH] = {0};
|
||||
// // 检查Flash中是否有已配对的MAC
|
||||
// if (nvs_read_main_board_mac(target_mac) > 0) {
|
||||
// rc_log("Found paired MAC. Start scanning...\n");
|
||||
// // 启动扫描和连接。SDK的HID实现会自动连接到已配对的设备。
|
||||
// EARPHONE_STATE_SET_PAGE_SCAN_ENABLE();
|
||||
// } else {
|
||||
// rc_log("No paired MAC found. Waiting for RFID pairing...\n");
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case RC_STATE_CONNECTING:
|
||||
// // 在这个状态下,我们只是等待 is_connected 变为 true
|
||||
// rc_log("Waiting for connection result...\n");
|
||||
// break;
|
||||
|
||||
// case RC_STATE_CONNECTED:
|
||||
// // 已连接,目前无需周期性操作
|
||||
// // rc_log("BLE is connected.\n");
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 根据UID前缀判断设备类型
|
||||
*/
|
||||
static RFID_Device_Type_t get_rfid_device_type(const u8* uid)
|
||||
{
|
||||
if (uid == NULL) {
|
||||
return RFID_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
// 根据 RC_app_main.h 中定义的UID前缀进行判断
|
||||
if (uid[0] == UID_PREFIX_MAIN_BOARD) {
|
||||
return RFID_DEVICE_TYPE_MAIN_BOARD;
|
||||
} else if (uid[0] == UID_PREFIX_REMOTE_CONTROL) {
|
||||
return RFID_DEVICE_TYPE_REMOTE_CONTROL;
|
||||
}
|
||||
|
||||
return RFID_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
// =================================================================================
|
||||
// 辅助函数 (Helper Functions)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief 进入 CONNECTING 状态的逻辑
|
||||
*/
|
||||
static void rc_ble_state_set_connecting(void)
|
||||
{
|
||||
rc_log("State transition to -> CONNECTING\n");
|
||||
g_rc_context.state = RC_STATE_CONNECTING;
|
||||
// 可以在这里控制LED灯效,例如黄灯呼吸闪烁
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 进入 CONNECTED 状态的逻辑
|
||||
*/
|
||||
static void rc_ble_state_set_connected(void)
|
||||
{
|
||||
rc_log("State transition to -> CONNECTED\n");
|
||||
g_rc_context.state = RC_STATE_CONNECTED;
|
||||
// 停止扫描以省电
|
||||
EARPHONE_STATE_CANCEL_PAGE_SCAN();
|
||||
|
||||
// 发送指令,要求主板连接遥控器的经典蓝牙
|
||||
u8 classic_conn_req_payload[] = {0x01, 0x02, 0x03};
|
||||
rc_log("Sending request for classic BT connection.\n");
|
||||
ble_hid_data_send(0xFE, classic_conn_req_payload, sizeof(classic_conn_req_payload));
|
||||
|
||||
// 在这里控制LED灯效,例如蓝灯呼吸闪烁三次后熄灭
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 进入 DISCONNECTED 状态的逻辑
|
||||
*/
|
||||
static void rc_ble_state_set_disconnected(void)
|
||||
{
|
||||
rc_log("State transition to -> DISCONNECTED\n");
|
||||
g_rc_context.state = RC_STATE_DISCONNECTED;
|
||||
// 在这里控制LED灯效,例如黄灯呼吸闪烁
|
||||
}
|
||||
|
||||
// 初始化函数 (Initialization Function)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用主初始化函数
|
||||
*/
|
||||
void rc_app_main_init(void)
|
||||
{
|
||||
rc_log("Initializing Remote Control App...\n");
|
||||
|
||||
// 1. 初始化全局上下文
|
||||
memset(&g_rc_context, 0, sizeof(RC_Context_t));
|
||||
g_rc_context.state = RC_STATE_DISCONNECTED; // 初始状态为未连接
|
||||
g_rc_context.team = TEAM_NO;
|
||||
FM176XX_HardInit();
|
||||
|
||||
// 2. 检查并启动RFID处理定时器
|
||||
if (g_rfid_timer_id == 0) {
|
||||
g_rfid_timer_id = sys_timer_add(NULL, rc_rfid_callback_handler, RC_RFID_CALLBACK_INTERVAL_MS);
|
||||
rc_log("RFID handler timer started (ID: %d).\n", g_rfid_timer_id);
|
||||
}
|
||||
|
||||
// 3. 检查并启动BLE处理定时器
|
||||
if (g_ble_timer_id == 0) {
|
||||
g_ble_timer_id = sys_timer_add(NULL, rc_ble_callback_handler, RC_BLE_CALLBACK_INTERVAL_MS);
|
||||
rc_log("BLE handler timer started (ID: %d).\n", g_ble_timer_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//test
|
||||
#define TEST_FUNCTION 1
|
||||
void test_task(void){
|
||||
|
||||
|
||||
#if TEST_FUNCTION == 1
|
||||
FM176XX_HardInit();
|
||||
while(1){
|
||||
u8 uid[UID_LENGTH] = {0};
|
||||
//读id卡
|
||||
TYPE_V_EVENT((char *)uid);
|
||||
// TYPE_A_EVENT((char *)uid);
|
||||
|
||||
os_time_dly(100);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void test_func_main(void){
|
||||
#if TEST_FUNCTION == 1
|
||||
os_task_create(test_task, NULL, 1, 1024, 128, "rfid_test");
|
||||
#endif
|
||||
}
|
||||
101
apps/earphone/xtell_remote_control/task_func.h
Normal file
101
apps/earphone/xtell_remote_control/task_func.h
Normal file
@ -0,0 +1,101 @@
|
||||
#ifndef __RC_APP_MAIN_H__
|
||||
#define __RC_APP_MAIN_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
// =================================================================================
|
||||
// 常量定义 (Constants)
|
||||
// =================================================================================
|
||||
|
||||
// 假设UID的前1个字节用于区分设备类型
|
||||
#define UID_PREFIX_MAIN_BOARD 0xA1 // 主板UID前缀
|
||||
#define UID_PREFIX_REMOTE_CONTROL 0xA2 // 遥控器UID前缀
|
||||
|
||||
#define UID_LENGTH 8 // RFID UID 的标准长度
|
||||
|
||||
// 定时器调用间隔 (ms)
|
||||
#define RC_RFID_CALLBACK_INTERVAL_MS 500 // RFID轮询间隔,500ms
|
||||
#define RC_BLE_CALLBACK_INTERVAL_MS 1000 // BLE状态机处理间隔, 1s
|
||||
|
||||
// =================================================================================
|
||||
// 枚举与结构体定义 (Enums & Structs)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器核心状态机
|
||||
*/
|
||||
typedef enum {
|
||||
RC_STATE_IDLE, // 空闲状态,等待初始化
|
||||
RC_STATE_DISCONNECTED, // 未连接主板 (正在扫描或等待)
|
||||
RC_STATE_CONNECTING, // 正在连接主板
|
||||
RC_STATE_CONNECTED, // 已连接主板
|
||||
} RC_State_t;
|
||||
|
||||
/**
|
||||
* @brief 当前是否处于组队状态
|
||||
*/
|
||||
typedef enum {
|
||||
TEAM_NO, //未组队
|
||||
TEAM_YES,
|
||||
} RC_State_t;
|
||||
|
||||
/**
|
||||
* @brief RFID读取到的设备类型
|
||||
*/
|
||||
typedef enum {
|
||||
RFID_DEVICE_TYPE_UNKNOWN, // 未知设备
|
||||
RFID_DEVICE_TYPE_MAIN_BOARD, // 船体主板
|
||||
RFID_DEVICE_TYPE_REMOTE_CONTROL // 其他遥控器
|
||||
} RFID_Device_Type_t;
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用全局上下文
|
||||
*/
|
||||
typedef struct {
|
||||
RC_State_t state; // 当前状态机状态
|
||||
RC_State_t team; //当前是否组队
|
||||
u8 paired_mac_addr[UID_LENGTH]; // 已配对主板的MAC地址(包含前缀)
|
||||
// ... 可在此处添加更多运行时需要管理的数据
|
||||
} RC_Context_t;
|
||||
|
||||
|
||||
// =================================================================================
|
||||
// 公共函数声明 (Public Function Prototypes)
|
||||
// =================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用主初始化函数
|
||||
* @details
|
||||
* - 初始化全局上下文
|
||||
* - 设置并启动RFID和BLE处理定时器
|
||||
*/
|
||||
void rc_app_main_init(void);
|
||||
|
||||
/**
|
||||
* @brief RFID回调处理函数 (由定时器周期性调用)
|
||||
* @details
|
||||
* - 调用RFID读取函数
|
||||
* - 分析UID并执行相应逻辑 (配对/组队)
|
||||
*/
|
||||
void rc_rfid_callback_handler(void *priv);
|
||||
|
||||
/**
|
||||
* @brief BLE回调处理函数 (由定时器周期性调用)
|
||||
* @details
|
||||
* - 维护与主板的BLE连接状态
|
||||
* - 处理断线重连等
|
||||
*/
|
||||
void rc_ble_callback_handler(void *priv);
|
||||
|
||||
/**
|
||||
* @brief BLE连接状态回调 (由蓝牙协议栈调用)
|
||||
* @param status 0: 成功, 其他: 失败
|
||||
* @param addr 连接或断开的设备地址
|
||||
* @details
|
||||
* - 在BLE连接成功后,请求主板连接经典蓝牙
|
||||
* - 更新连接状态
|
||||
*/
|
||||
// void rc_ble_connection_status_callback(u8 status, u8 *addr); // No longer needed
|
||||
|
||||
|
||||
#endif // __RC_APP_MAIN_H__
|
||||
@ -7,4 +7,6 @@
|
||||
|
||||
#define ACC_RANGE 16 //g,加速度满量程:2、4、8、16
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
124
apps/earphone/xtell_remote_control/xtell_app_main.c
Normal file
124
apps/earphone/xtell_remote_control/xtell_app_main.c
Normal file
@ -0,0 +1,124 @@
|
||||
#include "system/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "app_main.h"
|
||||
#include "update.h"
|
||||
#include "update_loader_download.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "app_charge.h"
|
||||
#include "bt_profile_cfg.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
#define LOG_TAG_CONST APP
|
||||
#define LOG_TAG "[APP]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
// 外部函数/变量声明
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
extern APP_VAR app_var;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
// 系统主函数 app_main
|
||||
//-------------------------------------------------------------------------------------------------//
|
||||
|
||||
/**
|
||||
* @brief 创建一个周期性执行的系统定时器任务
|
||||
*/
|
||||
void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec){
|
||||
xlog("1 name=%s, pid =%d\n",name,*pid);
|
||||
if (*pid != 0) return;
|
||||
*pid = sys_timer_add(priv, func, msec);
|
||||
xlog("2 name=%s, pid =%d\n",name,*pid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭一个系统定时器任务
|
||||
*/
|
||||
void close_process(u16* pid, const char* name){
|
||||
xlog("name=%s,pid =%d\n",name,*pid);
|
||||
if (*pid == 0) return;
|
||||
sys_timer_del(*pid);
|
||||
*pid = 0;
|
||||
}
|
||||
|
||||
|
||||
/*充电拔出,CPU软件复位, 不检测按键,直接开机*/
|
||||
static void app_poweron_check(int update)
|
||||
{
|
||||
extern int cpu_reset_by_soft();
|
||||
if (!update && cpu_reset_by_soft()) {
|
||||
app_var.play_poweron_tone = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 应用层主入口
|
||||
*/
|
||||
void xtell_app_main()
|
||||
{
|
||||
int update = 0;
|
||||
struct intent it;
|
||||
|
||||
xlog("==============xtell_app_main start================\n");
|
||||
log_info("app_main\n");
|
||||
extern u32 timer_get_ms(void);
|
||||
app_var.start_time = timer_get_ms();
|
||||
|
||||
// 检查是否有固件升级
|
||||
if (!UPDATE_SUPPORT_DEV_IS_NULL()) {
|
||||
update = update_result_deal();
|
||||
}
|
||||
|
||||
// 初始化应用层变量
|
||||
extern void app_var_init(void);
|
||||
app_var_init();
|
||||
|
||||
// 根据充电状态决定进入 idle 模式还是 handler 模式
|
||||
if (get_charge_online_flag()) {
|
||||
#if(TCFG_SYS_LVD_EN == 1)
|
||||
vbat_check_init();
|
||||
#endif
|
||||
xlog("==============idle================\n");
|
||||
init_intent(&it);
|
||||
it.name = "idle";
|
||||
it.action = ACTION_IDLE_MAIN;
|
||||
start_app(&it);
|
||||
} else {
|
||||
xlog("==============handler start================\n");
|
||||
check_power_on_voltage();
|
||||
app_poweron_check(update);
|
||||
init_intent(&it);
|
||||
it.name = "handler";
|
||||
it.action = ACTION_EARPHONE_MAIN;
|
||||
start_app(&it);
|
||||
xlog("==============handler end================\n");
|
||||
}
|
||||
|
||||
xlog("==============xtell_app_end================\n");
|
||||
|
||||
extern void test_func_main(void);
|
||||
test_func_main();
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -61,4 +61,4 @@ copy /b text.bin + data.bin + mov_slot.bin + data_code.bin + aec.bin + aac.bin +
|
||||
|
||||
del !bankfiles! common.bin text.bin data.bin bank.bin
|
||||
copy eq_cfg_hw_less.bin eq_cfg_hw.bin
|
||||
call download/earphone/download_app_ota.bat
|
||||
call download/earphone/download.bat
|
||||
|
||||
@ -10,7 +10,7 @@ copy ..\..\ota.bin .
|
||||
copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key AC69.key -format all -key 646-AC690X-7603.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -format all
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ copy ..\..\ota.bin .
|
||||
copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key 646-AC690X-7603.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ copy ..\..\anc_coeff.bin .
|
||||
copy ..\..\anc_gains.bin .
|
||||
|
||||
:: -format all -key AC690X-8029.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress -key AC690X-8029.key
|
||||
..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin ..\..\eq_cfg_hw.bin -uboot_compress
|
||||
|
||||
@REM..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br34 -boot 0x20000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin ..\..\cfg_tool.bin -res tone.cfg kws_command.bin p11_code.bin -uboot_compress
|
||||
|
||||
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user