This commit is contained in:
lmx
2025-12-17 16:23:51 +08:00
parent 0087d2922a
commit d029d273f8
9 changed files with 170 additions and 30 deletions

View File

@ -44,7 +44,7 @@
#define SUPPORT_TEST_BOX_BLE_MASTER_TEST_EN 0 // 是否支持测试盒BLE主设备测试 #define SUPPORT_TEST_BOX_BLE_MASTER_TEST_EN 0 // 是否支持测试盒BLE主设备测试
#define SHOW_RX_DATA_RATE 1 // 是否显示接收数据速率 #define SHOW_RX_DATA_RATE 1 // 是否显示接收数据速率
#define SHOW_TX_DATA_RATE 1 // 是否显示发送数据速率 #define SHOW_TX_DATA_RATE 1 // 是否显示发送数据速率
#define XTELL_DEBUG 0 #define XTELL_DEBUG 1
// 日志打印宏 // 日志打印宏
#if XTELL_DEBUG == 1 #if XTELL_DEBUG == 1
@ -500,6 +500,25 @@ void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf)
#endif #endif
} }
/**
* @brief 发送数据给server
*
* @param data
* @param length
*/
void g_send_data_to_ble_server(const u8* data, u16 length){
// 检查数据长度是否有效
if (length == 0 || length > 512) {
printf("Error: Data length %d is out of range (1-512)\n", length);
return;
}
int ret = client_operation_send(default_client_write_handle, data, length, ATT_OP_WRITE_WITHOUT_RESPOND);
if(ret == 0){
printf("success: send data to server\n");
return;
}
printf("error: send data to server\n");
}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
static u8 new_device_name[MAIN_BOARD_MAC_ADDR_LENGTH] = {0}; static u8 new_device_name[MAIN_BOARD_MAC_ADDR_LENGTH] = {0};
@ -1022,7 +1041,7 @@ opt_end:
} }
/** /**
* @brief 协议栈上报搜索结果的回调 * @brief 协议栈上报搜索结果的回调,内部调用
* @param result_info 搜索结果,为-1时表示搜索完成 * @param result_info 搜索结果,为-1时表示搜索完成
*/ */
void user_client_report_search_result(search_result_t *result_info) void user_client_report_search_result(search_result_t *result_info)
@ -1641,13 +1660,16 @@ static void default_event_callback(le_client_event_e event, u8 *packet, int size
log_info("CLI_EVENT_SEARCH_PROFILE_COMPLETE\n"); log_info("CLI_EVENT_SEARCH_PROFILE_COMPLETE\n");
if ((!test_client_timer) && default_client_write_handle) { if ((!test_client_timer) && default_client_write_handle) {
log_info("test timer_add\n"); log_info("test timer_add\n");
test_client_timer = sys_hi_timer_add(0, default_test_write, 500); // test_client_timer = sys_hi_timer_add(0, default_test_write, 500); //xtell
extern void test_func_main(void);
test_func_main();
} }
break; break;
case CLI_EVENT_CONNECTED: case CLI_EVENT_CONNECTED:
connect_state = 1; connect_state = 1;
log_info("<<<<<<<<<< BLE Connection Successful! >>>>>>>>>>\n"); log_info("<<<<<<<<<< BLE Connection Successful! >>>>>>>>>>\n");
break; break;
case CLI_EVENT_DISCONNECT: case CLI_EVENT_DISCONNECT:
@ -1665,7 +1687,7 @@ static void default_event_callback(le_client_event_e event, u8 *packet, int size
} }
#endif #endif
/////////////////////////////////////////////////////////////////////////////////

View File

@ -49,4 +49,12 @@ extern void g_ble_connect_new_device(char* name);
* @return //0:连接断开; 1连接成功 * @return //0:连接断开; 1连接成功
*/ */
extern u8 g_ble_get_state(void); extern u8 g_ble_get_state(void);
/**
* @brief 发送数据给server
*
* @param data
* @param length
*/
void g_send_data_to_ble_server(const u8* data, u16 length);
#endif #endif

View File

@ -8,9 +8,9 @@
#include "le_client_demo.h" #include "le_client_demo.h"
#include "le_common.h" #include "le_common.h"
#include "./ble_handler/client_handler.h" #include "./ble_handler/client_handler.h"
// ================================================================================= // ==================================================================================================================================================================
// 宏定义与日志 // 宏定义与日志
// ================================================================================= // ==================================================================================================================================================================
#define RC_LOG_ENABLE 1 #define RC_LOG_ENABLE 1
#if RC_LOG_ENABLE #if RC_LOG_ENABLE
@ -19,14 +19,14 @@
#define rc_log(format, ...) #define rc_log(format, ...)
#endif #endif
// ================================================================================= // ==================================================================================================================================================================
// 外部函数声明 // 外部函数声明
// ================================================================================= // ==================================================================================================================================================================
extern void TYPE_V_EVENT(char* uid); extern void TYPE_V_EVENT(char* uid);
extern void TYPE_A_EVENT(char* uid); extern void TYPE_A_EVENT(char* uid);
// ================================================================================= // ==================================================================================================================================================================
// 静态函数声明 // 静态函数声明
// ================================================================================= // ==================================================================================================================================================================
static RFID_Device_Type_t get_rfid_device_type(const u8* uid); static RFID_Device_Type_t get_rfid_device_type(const u8* uid);
@ -35,9 +35,12 @@ static void rc_ble_state_set_connecting(void);
static void rc_ble_state_set_connected(void); static void rc_ble_state_set_connected(void);
static void rc_ble_state_set_disconnected(void); static void rc_ble_state_set_disconnected(void);
// ================================================================================= //进程名称
static char control_key_task_name[] = "control_key";
// ==================================================================================================================================================================
// 全局变量 // 全局变量
// ================================================================================= // ==================================================================================================================================================================
static RC_Context_t g_rc_context; // 全局上下文实例 static RC_Context_t g_rc_context; // 全局上下文实例
static u16 g_rfid_timer_id = 0; // RFID 定时器ID static u16 g_rfid_timer_id = 0; // RFID 定时器ID
@ -46,9 +49,9 @@ static u8 current_board_mac[MAIN_BOARD_MAC_ADDR_LENGTH] = {0}; //当前连接
// ================================================================================= // ==================================================================================================================================================================
// 核心回调函数 (Core Callback Handlers) // rfid功能相关
// ================================================================================= // ==================================================================================================================================================================
/** /**
* @brief RFID回调处理函数 (由定时器周期性调用) * @brief RFID回调处理函数 (由定时器周期性调用)
@ -121,6 +124,11 @@ void rc_rfid_callback_handler(void *priv)
} }
} }
// ==================================================================================================================================================================
// ble功能相关
// ==================================================================================================================================================================
/** /**
* @brief BLE回调处理函数 (由定时器周期性调用)s * @brief BLE回调处理函数 (由定时器周期性调用)s
*/ */
@ -195,9 +203,95 @@ static RFID_Device_Type_t get_rfid_device_type(const u8* uid)
return RFID_DEVICE_TYPE_UNKNOWN; return RFID_DEVICE_TYPE_UNKNOWN;
} }
// =================================================================================
// 辅助函数 (Helper Functions) // ==================================================================================================================================================================
// ================================================================================= // 遥感按键相关
// ==================================================================================================================================================================
/**
* @brief 遥感按键初始化
*
*/
void control_key_init(void){
//Yout
adc_add_sample_ch(AD_CH_PG5);
gpio_set_die(IO_PORTG_05, 0);
gpio_set_direction(IO_PORTG_05, 1);
gpio_set_pull_down(IO_PORTG_05, 0);
gpio_set_pull_up(IO_PORTG_05, 0);
//Xout
adc_add_sample_ch(AD_CH_PG7);
gpio_set_die(IO_PORTG_07, 0);
gpio_set_direction(IO_PORTG_07, 1);
gpio_set_pull_down(IO_PORTG_07, 0);
gpio_set_pull_up(IO_PORTG_07, 0);
//key 1默认为高按下为低
gpio_set_die(IO_PORTG_06, 1);
gpio_set_direction(IO_PORTG_06, 1);
gpio_set_pull_down(IO_PORTG_06, 0);
gpio_set_pull_up(IO_PORTG_06, 1);
}
/**
* @brief 获取遥感按键值
*
* @param Xout_adc x轴遥感adc
* @param Yout_adc y轴遥感adc
* @param key1_state 按键1值
* @param key2_state 按键2值
*/
void control_key_get_value(u16* Xout_adc, u16* Yout_adc, u8* key1_state, u8* key2_state){
*Xout_adc = (u16)adc_get_value(AD_CH_PG5);
*Yout_adc = (u16)adc_get_value(AD_CH_PG7);
*key1_state = gpio_read(IO_PORTG_06);
rc_log("adc_get_value: Xout = %d, Yout = %d, key1_state = %d, key2_state = %d\n", *Xout_adc , *Yout_adc, *key1_state, 1);
}
/**
* @brief 按键的处理任务
*
*/
void contol_key_task(void){
static u16 vbat_value = 0; //当前剩余电量
static u16 Xout_adc = 0;
static u16 Yout_adc = 0;
static u8 key1_state = 1;
u8 ble_data_buff[13] = {0xBE, 0xBB, 0x0A, 0x01, //0-3
0x00, 0x00, 0x00, 0x00, //4-7 遥感值:上下、左右
0x00, 0x00, //8、9 两个按键
0x00, 0x00, //10、11 vbat adc值
0x0C}; //12 校验和
control_key_init(); //遥感按键初始化
while(1){
extern u16 get_vbat_level(void);
vbat_value = get_vbat_level(); //当前电量
control_key_get_value(&Xout_adc, &Yout_adc, &key1_state, NULL); //遥感值
ble_data_buff[4] = (u8)(Yout_adc & 0xFF);
ble_data_buff[5] = (u8)((Yout_adc >> 8) & 0xFF);
ble_data_buff[6] = (u8)(Xout_adc & 0xFF);
ble_data_buff[7] = (u8)((Xout_adc >> 8) & 0xFF);
ble_data_buff[8] = key1_state;
ble_data_buff[9] = 0x01;
ble_data_buff[10] = (u8)(vbat_value & 0xFF);
ble_data_buff[11] = (u8)((vbat_value >> 8) & 0xFF);
g_send_data_to_ble_server(ble_data_buff, sizeof(ble_data_buff));
os_time_dly(5);
}
}
// ==================================================================================================================================================================
// 辅助函数
// ==================================================================================================================================================================
/** /**
* @brief 进入 CONNECTING 状态的逻辑 * @brief 进入 CONNECTING 状态的逻辑
@ -237,8 +331,9 @@ static void rc_ble_state_set_disconnected(void)
// 在这里控制LED灯效例如黄灯呼吸闪烁 // 在这里控制LED灯效例如黄灯呼吸闪烁
} }
// 初始化函数 (Initialization Function) // ==================================================================================================================================================================
// ================================================================================= // 初始化函数
// ==================================================================================================================================================================
/** /**
* @brief 遥控器应用主初始化函数 * @brief 遥控器应用主初始化函数
@ -255,13 +350,13 @@ void rc_app_main_init(void)
// 2. 检查并启动RFID处理定时器 // 2. 检查并启动RFID处理定时器
if (g_rfid_timer_id == 0) { if (g_rfid_timer_id == 0) {
g_rfid_timer_id = sys_timer_add(NULL, rc_rfid_callback_handler, RC_RFID_CALLBACK_INTERVAL_MS); // 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); rc_log("RFID handler timer started (ID: %d).\n", g_rfid_timer_id);
} }
// 3. 检查并启动BLE处理定时器 // 3. 检查并启动BLE处理定时器
if (g_ble_timer_id == 0) { if (g_ble_timer_id == 0) {
g_ble_timer_id = sys_timer_add(NULL, rc_ble_callback_handler, RC_BLE_CALLBACK_INTERVAL_MS); // 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); rc_log("BLE handler timer started (ID: %d).\n", g_ble_timer_id);
} }
} }
@ -288,5 +383,7 @@ void test_task(void){
void test_func_main(void){ void test_func_main(void){
#if TEST_FUNCTION == 1 #if TEST_FUNCTION == 1
// os_task_create(test_task, NULL, 1, 1024, 128, "rfid_test"); // os_task_create(test_task, NULL, 1, 1024, 128, "rfid_test");
os_task_create(contol_key_task, NULL, 1, 2048, 128, control_key_task_name);
#endif #endif
} }

View File

@ -130,5 +130,5 @@ void xtell_app_main()
delay_2ms(50); delay_2ms(50);
extern void test_func_main(void); extern void test_func_main(void);
test_func_main(); // test_func_main();
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5177,6 +5177,7 @@ objs/apps/earphone/xtell_remote_control/ble_handler/ble_test.c.o
objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_get_client_operation_table,pl -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_get_client_operation_table,pl
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_profile_init,pl -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_profile_init,pl
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,printf,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,le_device_db_init,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,le_device_db_init,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_stack_gatt_role,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_stack_gatt_role,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,gatt_client_init,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,gatt_client_init,l
@ -5195,19 +5196,20 @@ objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,rcsp_adv_fill_mac_addr,pl -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,rcsp_adv_fill_mac_addr,pl
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,swapX,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,swapX,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,bt_get_mac_addr,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,bt_get_mac_addr,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,g_send_data_to_ble_server,pl
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,g_ble_connect_new_device,pl -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,g_ble_connect_new_device,pl
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,g_ble_get_state,pl -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,g_ble_get_state,pl
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,usr_timer_add,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,put_buf,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,sys_timeout_del,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,test_func_main,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,syscfg_read,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,syscfg_read,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,syscfg_write,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,syscfg_write,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,little_endian_read_16,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,little_endian_read_16,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,printf,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,put_buf,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,memcmp,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,memcmp,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,user_client_init,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,user_client_init,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,user_client_set_search_complete,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,user_client_set_search_complete,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,sys_timer_add,l -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,sys_timer_add,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,ble_vendor_get_peer_rssi,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,puts,l
-r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,client_user_target,pl -r=objs/apps/earphone/xtell_remote_control/ble_handler/client_handler.c.o,client_user_target,pl
objs/apps/earphone/xtell_remote_control/ble_handler/example/example.c.o objs/apps/earphone/xtell_remote_control/ble_handler/example/example.c.o
objs/apps/earphone/xtell_remote_control/nvs/nvs.c.o objs/apps/earphone/xtell_remote_control/nvs/nvs.c.o
@ -5366,13 +5368,25 @@ objs/apps/earphone/xtell_remote_control/task_func.c.o
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,g_ble_get_state,l -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,g_ble_get_state,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,rc_ble_callback_handler,pl -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,rc_ble_callback_handler,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,nvs_read_main_board_mac,l -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,nvs_read_main_board_mac,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,control_key_init,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,adc_add_sample_ch,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,gpio_set_die,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,gpio_set_direction,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,gpio_set_pull_down,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,gpio_set_pull_up,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,control_key_get_value,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,adc_get_value,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,gpio_read,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,contol_key_task,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,get_vbat_level,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,g_send_data_to_ble_server,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,os_time_dly,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,rc_app_main_init,pl -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,rc_app_main_init,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,FM176XX_HardInit,l -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,FM176XX_HardInit,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,sys_timer_add,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,test_task,pl -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,test_task,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,TYPE_V_EVENT,l -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,TYPE_V_EVENT,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,os_time_dly,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,test_func_main,pl -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,test_func_main,pl
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,os_task_create,l
-r=objs/apps/earphone/xtell_remote_control/task_func.c.o,puts,l -r=objs/apps/earphone/xtell_remote_control/task_func.c.o,puts,l
objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,create_process,pl -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,create_process,pl
@ -5392,7 +5406,6 @@ objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,rcsp_adv_fill_mac_addr,l -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,rcsp_adv_fill_mac_addr,l
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,user_send_cmd_prepare,l -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,user_send_cmd_prepare,l
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,delay_2ms,l -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,delay_2ms,l
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,test_func_main,l
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,cpu_reset_by_soft,l -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,cpu_reset_by_soft,l
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,app_var,l -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,app_var,l
-r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,config_update_mode,l -r=objs/apps/earphone/xtell_remote_control/xtell_app_main.c.o,config_update_mode,l