修复了配网时进入休眠导致配网时间变成的问题,同时增加配网时间到了之后停止广播

This commit is contained in:
2026-09-10 12:14:29 +08:00
parent 5875d2a339
commit c141c7e0aa
6 changed files with 73 additions and 27 deletions
+18 -3
View File
@@ -2,10 +2,11 @@
* @file app_pair.c
* @brief 配对会话计时实现
* @author cyWu <1917507415@qq.com>
* @date 2026.08.25
* @version V1.0.0
* @date 2026.09.10
* @version V1.1.0
* @history
* - V1.0.0, 2026.08.25, cyWu, 首次发布,实现配对会话计时与成功/超时判定
* - V1.1.0, 2026.09.10, cyWu, 窗口超时停止绑定广播
******************************************************************************/
#include "app_pair.h"
@@ -26,6 +27,19 @@ typedef struct {
static AppPairCtx_t s_pair;
/**
* @brief 配对超时回调:从任务上下文停绑定广播
* @note app_pair_tick 跑在 usr_timer 硬件时基里,不断开/不停广播,
* 把 BLE 动作丢到 sys_timeout,避免占中断时间。
* @param priv 未使用
* @return 无
*/
static void pair_timeout_stop_adv(void *priv)
{
(void)priv;
usr_stop_bind_adv();
}
/**
* @brief 开始一次配对会话(计时清零)
* @return 无
@@ -59,7 +73,8 @@ AppPairEvt_t app_pair_tick_1ms(uint16_t dt)
if (s_pair.elapsed_ms >= BOARD_PAIR_TIMEOUT_MS) {
s_pair.active = 0;
s_pair.elapsed_ms = 0;
log_info("pair timeout 120s, stay on\n");
log_info("pair timeout 120s, stop bind adv\n");
sys_timeout_add(NULL, pair_timeout_stop_adv, 10);
return APP_PAIR_EVT_FAIL;
}
+6 -5
View File
@@ -1,14 +1,15 @@
/******************************************************************************
* @file app_pair.h
* @brief 配对会话计时:开机配对窗口是否成功/超时,与 BLE 配对本身解耦
* @brief 配对会话计时:开机配对窗口是否成功/超时
* @author cyWu <1917507415@qq.com>
* @date 2026.08.25
* @version V1.0.0
* @date 2026.09.10
* @version V1.1.0
* @history
* - V1.0.0, 2026.08.25, cyWu, 首次发布,实现配对会话计时与成功/超时判定
* - V1.1.0, 2026.09.10, cyWu, 窗口超时停止绑定广播
*
* @note 真正的 BLE 广播/绑定逻辑在 usr_le_code;本模块负责进入配对后
* 60s 内 usr_get_pair_flag() 是否变 1”这件事,纯状态,不碰灯/按键
* @note 真正的 BLE 广播/绑定逻辑在 usr_le_code;本模块负责进入配对后
* 120s 内 usr_get_pair_flag() 是否变 1,超时则停绑定广播
******************************************************************************/
#ifndef __APP_PAIR_H__
+15 -8
View File
@@ -2,8 +2,8 @@
* @file usr_jb_main.c
* @brief CBC2 业务组合根:只做“先后调用谁、谁通知谁”,不含具体业务算法
* @author cyWu <1917507415@qq.com>
* @date 2026.08.27
* @version V2.2.0
* @date 2026.09.10
* @version V2.3.0
* @history
* - V1.0.0, 2026.08.21, cyWu, 首次发布
* - V1.1.0, 2026.08.24, cyWu, 收口未接线模块;DP2 仅第 1 字节点动 1s
@@ -21,6 +21,9 @@
* - V2.2.0, 2026.08.27, cyWu, app_led_init() 提前到 app_boot_wait_key() 之前,
* 开机 3s/5s/拒绝开机低电闪直接用灯效事件表,
* 不用再各自摸裸 GPIO 手搓一份闪烁定时
* - V2.3.0, 2026.09.10, cyWu, 配网期间禁睡:priority=0 时低功耗会把 20ms
* 节拍拉长,绑定广播和 AUTHSETUP 握手变慢,
* 实测配网可拖到数分钟
*
* @note 协议生成文件 jb_product.c 不要填业务。APP 下行写 gDevData。
* usr_timer_loop 由 BLE 回调,勿再注册第二份。
@@ -84,7 +87,7 @@ const uint8_t g_usr_le_pcode[USR_LE_PCODE_LEN] = {
*/
typedef enum {
USR_TICK_IDLE = 0, /**< 可休眠 */
USR_TICK_BLOCK_SLEEP /**< 禁止休眠(按键按住/玩法中/关机等待/电机运转,含换向死区)*/
USR_TICK_BLOCK_SLEEP /**< 禁止休眠(按键按住/玩法中/关机等待/电机运转/配网,含换向死区)*/
} UsrTickMode_t;
/** 调度器状态,替代原来 2 个散落的 static */
@@ -155,15 +158,17 @@ static void usr_poweroff_finalize_hook(void)
/**
* @brief 按当前业务状态判断能不能休眠
* @note 换向死区(bsp_motor_is_busy 已把它算进"忙")、点动、玩法、按键按住、
* 关机等待,统一都是"不能睡",节拍周期都一样用 USR_TIMER_IDLE_MS
* 不再区分要不要 1ms
* 关机等待、配网窗口,统一都是"不能睡",节拍周期都一样用 USR_TIMER_IDLE_MS
* 配网只跟 120s 配对窗口(app_pair_is_active):窗口内禁睡,保证广播
* 节拍不被低功耗拉长;成功或超时后恢复可休眠。
* @return 本次应使用的档位
*/
static UsrTickMode_t usr_timer_pick_mode(void)
{
if (bsp_key_is_pressed() || app_power_poweroff_pending()
|| app_mode_get_active() || bsp_motor_is_busy()
|| app_function_is_hand_busy()) {
|| app_function_is_hand_busy()
|| app_pair_is_active()) {
return USR_TICK_BLOCK_SLEEP;
}
return USR_TICK_IDLE;
@@ -292,8 +297,10 @@ void usr_jb_init(void)
user_key_lock_if_held();
app_function_power_on_silent();
usr_timer_rearm(USR_TICK_IDLE);
log_info("timer idle %ums, sleep ok\n", (unsigned)USR_TIMER_IDLE_MS);
/* 开机若已进配对,第一拍就禁睡,不要先挂可休眠档再等 20ms 才切 */
usr_timer_rearm(usr_timer_pick_mode());
log_info("timer %ums, mode=%d\n", (unsigned)USR_TIMER_IDLE_MS,
(int)s_sched.mode);
}
/**
+19 -6
View File
@@ -2,11 +2,12 @@
* @file usr_le_adv.c
* @brief BLE 广播 / 配对 / OTA 广播切换
* @author cyWu <1917507415@qq.com>
* @date 2026.08.19
* @version V1.1.0
* @date 2026.09.10
* @version V1.2.0
* @history
* - V1.0.0, 2026.08.03, cyWu, 首次发布
* - V1.1.0, 2026.08.19, cyWu, 对齐模组注释与助手;保留 SOC 上电绑广播策略
* - V1.2.0, 2026.09.10, cyWu, 配对窗口超时停止绑定广播
******************************************************************************/
#include "system/includes.h"
@@ -138,16 +139,28 @@ void usr_goto_pair_mode(void)
usr_ble_adv_init();
}
/**
* @brief 停止绑定广播:清配网标志、关掉广播;未完成的连接一并断开
* @note 只关广播,500ms 协议定时器还在,避免把 usr_timer_loop 停掉。
* usr_adv_flag 清 0 后周期刷新不会再 enable,广播不会自己开回来。
* @return 无
*/
void usr_stop_bind_adv(void)
{
printf("usr_stop_bind_adv\n");
ble_multi_trans_disconnect();
usr_var.usr_goto_pair = 0;
usr_var.usr_adv_flag = 0;
ble_trans_module_enable(0);
}
/**
* @brief 断开 BLE 并停止广播(复位/重启前)
*/
void usr_ble_disconnect_and_stop_adv(void)
{
printf("usr_ble_disconnect_and_stop_adv\n");
ble_multi_trans_disconnect();
usr_var.usr_goto_pair = 0;
usr_var.usr_adv_flag = 0;
ble_trans_module_enable(0);
usr_stop_bind_adv();
}
/**
+11 -2
View File
@@ -2,12 +2,13 @@
* @file usr_le_api.h
* @brief usr_le_code 对外应用 API(配网 / 配对 / OTA
* @author cyWu <1917507415@qq.com>
* @date 2026.08.03
* @version V1.0.2
* @date 2026.09.10
* @version V1.0.3
* @history
* - V1.0.0, 2026.08.03, cyWu, 首次发布
* - V1.0.1, 2026.08.19, cyWu, 收敛公开 API,移除 BLE 栈钩子声明
* - V1.0.2, 2026.08.25, cyWu, 改为源码编译,去掉静态库
* - V1.0.3, 2026.09.10, cyWu, 增加配对窗口超时停绑定广播
*
* @note usr_ble_adv_init / usr_le_data_recieve 为 BLE/RCSP 协议栈链接钩子,
* 由 usr_le_code 内部实现并导出符号,不作为应用层公开接口。
@@ -47,6 +48,14 @@ void usr_clear_pair_info(void);
*/
uint8_t usr_get_pair_flag(void);
/**
* @brief 停止绑定广播(配对窗口超时)
* @note 清 usr_goto_pair,关掉广播;若绑定未完成则断开连接。
* 已配网的回连广播不走本接口。
* @return 无
*/
void usr_stop_bind_adv(void);
/**
* @brief 启动应用侧 OTA 流程
* @note 置位 usr_goto_updata,并创建 1s 周期定时器驱动断连与 OTA 广播切换