Files
ESP32_COMM/main/monitor/health_monitor.h
T
小龙虾 6f4be9189c feat(relay): OTA可用版本,添加OTA中继阶段健康检查和APP存活验证功能
- 新增health_check_before_ota_relay函数,用于OTA中继转发阶段的健康检查,
  跳过WiFi相关检查,只检查温度等本地状态
- 添加APP存活验证阶段,OTA完成后等待GD32 APP启动并通过ping确认存活
- 实现更精确的响应帧类型匹配和轮询机制,提高协议可靠性
- 添加多个阶段的响应匹配器(is_handshake_echo_ack、is_challenge_payload_ack等)
- 优化poll_until_expected_ack_shape函数,处理残留ACK和超时情况
- 将调试日志级别从INFO降级为DBG,减少日志输出
- 修复handshake阶段重试机制,添加最大重试次数限制
- 优化Flash擦除期间的WATI状态处理,使用短超时避免长阻塞
- 添加完整的会话数据清理,防止状态污染
- 增加详细的注释说明各阶段的处理逻辑
2026-05-30 20:04:04 +08:00

90 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* health_monitor.h - 系统健康监控头文件
*/
#pragma once
#include <stdint.h>
#include "app_config.h"
// T9.3: 健康状态等级
typedef enum {
SYS_NORMAL = 0, // 正常
SYS_WARNING = 1, // 警告
SYS_CRITICAL = 2, // 危险
SYS_SAFE_SHUTDOWN = 3 // 安全关机
} health_state_t;
typedef enum {
HEALTH_MON_OK = 0,
HEALTH_MON_WARNING = 1,
HEALTH_MON_CRITICAL = 2,
HEALTH_MON_SHUTDOWN = 3
} health_status_t;
// 外部共享状态(互斥锁保护)
extern health_state_t g_health_state;
// WiFi RSSI 阈值(来自 app_config.h)
#define WIFI_RSSI_NORMAL WIFI_RSSI_WARNING
#define WIFI_RSSI_WEAK WIFI_RSSI_CRITICAL
/**
* @brief 初始化健康监控模块,创建内部互斥锁与基础状态。
*/
void health_monitor_init(void);
/**
* @brief 健康监控任务入口,负责启动温度定时检测并周期性巡检系统状态。
* @param pvParameters FreeRTOS 任务参数,未使用。
*/
void health_monitor_task(void *pvParameters);
/**
* @brief 在 OTA 传输开始前执行健康检查,返回当前是否允许传输。
* @return 健康检查结果,决定是否允许 OTA。
*/
health_status_t health_check_before_ota(void);
/**
* @brief 在 OTA 中继转发阶段执行健康检查,跳过 WiFi 相关检查。
*
* SPI 中继阶段固件已存储在 ESP32 Flash 中,不依赖 WiFi 连接,
* 因此跳过 WiFi 连接状态和 RSSI 检查,只检查温度等本地状态。
* @return 健康检查结果,决定是否允许 OTA。
*/
health_status_t health_check_before_ota_relay(void);
/**
* @brief 记录一条健康相关事件日志,便于故障追踪与状态回溯。
* @param event 事件名称字符串。
* @param value 事件关联的数值。
*/
void health_log_event(const char *event, int value);
/**
* @brief 获取当前系统健康状态。
* @return 当前健康状态枚举值。
*/
health_state_t health_get_current(void);
/**
* @brief 根据最新 WiFi RSSI 更新健康状态,并返回对应健康检查结果。
* @param rssi 当前 WiFi 信号强度(dBm)。
* @return 健康检查结果。
*/
health_status_t health_update_from_wifi_rssi(int8_t rssi);
/**
* @brief 获取最近一次采样到的芯片温度(摄氏度)。
* @return 最近一次温度采样值(摄氏度)。
*/
float health_get_last_temperature(void);
/**
* @brief 获取最近一次健康监控采样得到的 WiFi RSSI。
* @param out_rssi 输出 RSSI。
* @param out_age_ms 输出样本距今时长(毫秒)。
* @return true 有有效样本,false 当前无有效样本。
*/
bool health_get_last_wifi_rssi(int8_t *out_rssi, uint32_t *out_age_ms);