关闭1分钟没重连就切慢广播的功能,修复1分钟之后重连不上网关的问题

This commit is contained in:
2026-09-07 19:49:18 +08:00
parent 9b15f3f9e3
commit 767b9e4343
2 changed files with 31 additions and 7 deletions
+19 -7
View File
@@ -2,9 +2,10 @@
* @file usr_le_adv.c * @file usr_le_adv.c
* @brief BLE 广播 / 配对 / OTA 广播切换 * @brief BLE 广播 / 配对 / OTA 广播切换
* @author cyWu <1917507415@qq.com> * @author cyWu <1917507415@qq.com>
* @date 2026.09.03 * @date 2026.09.07
* @version V1.3.0温湿度窗拆到 app_th_adv * @version V1.4.0慢广播改由 BOARD_BLE_SLOW_ADV_ENABLE / SEC 控制
* @history * @history
* - V1.4.0, 2026.09.07, cyWu, 常供电默认不切慢广播,秒数可配
* - V1.0.0, 2026.08.03, cyWu, 首次发布 * - V1.0.0, 2026.08.03, cyWu, 首次发布
* - V1.1.0, 2026.08.19, cyWu, 对齐模组注释与助手;保留 SOC 上电绑广播策略 * - V1.1.0, 2026.08.19, cyWu, 对齐模组注释与助手;保留 SOC 上电绑广播策略
* - V1.2.0, 2026.09.03, cyWu, 已绑定未连接温湿度窗(随后拆出) * - V1.2.0, 2026.09.03, cyWu, 已绑定未连接温湿度窗(随后拆出)
@@ -20,6 +21,7 @@
#include "usr_le_product.h" #include "usr_le_product.h"
#include "usr_le_api.h" #include "usr_le_api.h"
#include "app_th_adv.h" #include "app_th_adv.h"
#include "board_pin.h"
#define LOG_TAG_CONST APP #define LOG_TAG_CONST APP
#define LOG_TAG "[LE_ADV]" #define LOG_TAG "[LE_ADV]"
@@ -54,6 +56,10 @@ extern u8 muti_adv_data_len;
/** 广播数据最大长度(BLE 4.x 31 字节) */ /** 广播数据最大长度(BLE 4.x 31 字节) */
#define USR_ADV_DATA_MAX 31 #define USR_ADV_DATA_MAX 31
#define USR_LE_ADV_TICK_MS 500u /* 与 sys_timer_add(usr_ble_adv_updata) 一致 */
#if BOARD_BLE_SLOW_ADV_ENABLE
#define USR_LE_SLOW_ADV_TICKS ((BOARD_BLE_SLOW_ADV_SEC * 1000u) / USR_LE_ADV_TICK_MS)
#endif
/* 定义在 usr_le_recieve.c,库内共用,不对外导出 */ /* 定义在 usr_le_recieve.c,库内共用,不对外导出 */
extern bleproto_authsetup_req_t usr_auth_data; extern bleproto_authsetup_req_t usr_auth_data;
@@ -213,7 +219,7 @@ void usr_ble_adv_init(void)
usr_ble_adv_updata(); usr_ble_adv_updata();
if (le_timer_handle == 0) if (le_timer_handle == 0)
{ {
le_timer_handle = sys_timer_add(NULL, usr_ble_adv_updata, 500); le_timer_handle = sys_timer_add(NULL, usr_ble_adv_updata, USR_LE_ADV_TICK_MS);
} }
} }
@@ -268,7 +274,9 @@ void usr_ble_adv_set_raw(const uint8_t *data, uint8_t len)
*/ */
void usr_ble_adv_updata(void) void usr_ble_adv_updata(void)
{ {
#if BOARD_BLE_SLOW_ADV_ENABLE
static u16 usr_goto_slow_adv = 0; static u16 usr_goto_slow_adv = 0;
#endif
/* 产品温湿度窗:须先于广播刷新,进/出窗当拍立即生效 */ /* 产品温湿度窗:须先于广播刷新,进/出窗当拍立即生效 */
app_th_adv_tick(); app_th_adv_tick();
@@ -283,10 +291,11 @@ void usr_ble_adv_updata(void)
ble_trans_module_enable(1); ble_trans_module_enable(1);
} }
#if BOARD_BLE_SLOW_ADV_ENABLE
if (!usr_ble_is_connected()) if (!usr_ble_is_connected())
{ {
/* 未连接:回连快广播(80)持续约 60s500ms×120)后切慢广播 /* 未连接:回连快广播(80)持续 BOARD_BLE_SLOW_ADV_SEC 后切慢广播(800
* 温湿度窗内暂停计数(窗内强制快广播,窗长 1s */ * 温湿度窗内暂停计数(窗内强制快广播) */
if (usr_get_adv_interval() == 80) if (usr_get_adv_interval() == 80)
{ {
if ((usr_var.usr_goto_pair == 0) && usr_auth_data.paired_flag) if ((usr_var.usr_goto_pair == 0) && usr_auth_data.paired_flag)
@@ -294,13 +303,15 @@ void usr_ble_adv_updata(void)
if ((usr_var.usr_ota_succ_flag == 0) && (app_th_adv_is_active() == 0)) if ((usr_var.usr_ota_succ_flag == 0) && (app_th_adv_is_active() == 0))
{ {
usr_goto_slow_adv++; usr_goto_slow_adv++;
printf("usr_goto_slow_adv = %d\n", usr_goto_slow_adv);
} }
if (usr_goto_slow_adv >= 120) if ((USR_LE_SLOW_ADV_TICKS > 0) &&
(usr_goto_slow_adv >= USR_LE_SLOW_ADV_TICKS))
{ {
usr_goto_slow_adv = 0; usr_goto_slow_adv = 0;
usr_set_adv_interval(80 * 10); usr_set_adv_interval(80 * 10);
usr_var.usr_adv_flag = 1; usr_var.usr_adv_flag = 1;
printf("ble switch slow adv, after %us\n",
(unsigned)BOARD_BLE_SLOW_ADV_SEC);
} }
} }
} }
@@ -313,6 +324,7 @@ void usr_ble_adv_updata(void)
{ {
usr_goto_slow_adv = 0; usr_goto_slow_adv = 0;
} }
#endif
if (usr_get_ota_status() == 0) if (usr_get_ota_status() == 0)
{ {
+12
View File
@@ -35,6 +35,18 @@
#define BOARD_RUNREC_ENABLE 1 /* 31 天运行记录;P2 开 */ #define BOARD_RUNREC_ENABLE 1 /* 31 天运行记录;P2 开 */
#define BOARD_NVM_ENABLE 1 /* VM 持久化;P1 开 */ #define BOARD_NVM_ENABLE 1 /* VM 持久化;P1 开 */
/*============================================================================*/
/* BLE 广播 */
/*============================================================================*/
/**
* 未连接回连快广播(间隔 80)超时后是否切慢广播(间隔 800)。
* 本机常供电,默认 0:一直快广播,方便网关回连。
* 1=使能;超时秒数见 BOARD_BLE_SLOW_ADV_SECusr_ble_adv_updata 每 500ms 计一次)。
*/
#define BOARD_BLE_SLOW_ADV_ENABLE 0
#define BOARD_BLE_SLOW_ADV_SEC 60 /**< 使能为 1 时:快广播持续秒数后再切慢广播 */
/*============================================================================*/ /*============================================================================*/
/* GPIO */ /* GPIO */
/*============================================================================*/ /*============================================================================*/