/** ****************************************************************************** * @file Mid_temp.h * @brief 温度数据中间层 (Mid) * * @note 解析 CPLD 快照帧 (0x82 SNAPSHOT_DATA, 199B) 并缓存全部遥测字段。 * 温度源: * - bmc_raw (24 路) : 值即摄氏温度, 不换算 * - ct_raw (27 路) : CT7428, 按 (raw>>7)&0x1FF 换算 * PID 过程值取 bmc 24 路; 预加热达标判定/风扇分区取预加热 4 路 * (暂定 = ct 前 4 路, 表驱动, 便于日后核对通道对应关系)。 ****************************************************************************** */ #ifndef __MID_TEMP_H #define __MID_TEMP_H #include /* 通道数量 */ #define MID_TEMP_BMC_CH 24 /* BMC 温度通道数 (与 24 路 PTC 对应) */ #define MID_TEMP_CT_CH 27 /* CT7428 温度通道数 (3 芯片 x 9 寄存器) */ #define MID_TEMP_PREHEAT_NUM 4 /* 预加热温度数量 */ /* 0x82 载荷内偏移 (来源: CPLD_通讯协议.md 4.4) */ #define MID_TEMP_OFF_MODE 0 #define MID_TEMP_OFF_FAULT_FLAGS 1 #define MID_TEMP_OFF_WD_ACTIVE 3 #define MID_TEMP_OFF_WD_REMAIN 4 #define MID_TEMP_OFF_MANUAL_MODE 5 #define MID_TEMP_OFF_BMC_VALID 6 #define MID_TEMP_OFF_BMC_STALE 7 #define MID_TEMP_OFF_CT_VALID 8 #define MID_TEMP_OFF_CT_STALE 9 #define MID_TEMP_OFF_HARD_PROTECT 10 #define MID_TEMP_OFF_BMC_EPOCH 11 #define MID_TEMP_OFF_CT_EPOCH 13 #define MID_TEMP_OFF_CTRL_EPOCH 15 #define MID_TEMP_OFF_BMC_AGE 17 #define MID_TEMP_OFF_CT_AGE 19 #define MID_TEMP_OFF_BMC_RAW 21 /* u16 x 24 */ #define MID_TEMP_OFF_BMC_VALID_MASK 69 /* 24 bits */ #define MID_TEMP_OFF_CT_RAW 72 /* u16 x 27 */ #define MID_TEMP_OFF_CT_VALID_MASK 126 /* 32 bits */ #define MID_TEMP_OFF_PTC_REQUESTED 130 /* u8 x 24 */ #define MID_TEMP_OFF_PTC_APPLIED 154 /* u8 x 24 */ #define MID_TEMP_OFF_FRONT_REQUESTED 178 /* u8 x 4 */ #define MID_TEMP_OFF_FRONT_APPLIED 182 /* u8 x 4 */ #define MID_TEMP_OFF_REAR_REQUESTED 186 /* u8 x 4 */ #define MID_TEMP_OFF_REAR_APPLIED 190 /* u8 x 4 */ #define MID_TEMP_PAYLOAD_SNAPSHOT 199 /* 快照解析缓存 */ typedef struct { uint8_t mode; /* 运行模式 (0=安全, 1=手动, 2=自动闭环) */ uint16_t fault_flags; /* 系统综合故障掩码 */ uint8_t watchdog_active; /* 看门狗激活标志 */ uint8_t watchdog_remaining; /* 看门狗剩余秒数 (初始 30) */ uint8_t manual_mode; /* 手动设定模式标志 */ uint8_t bmc_valid; /* BMC 链路有效标志 */ uint8_t bmc_stale; /* BMC 数据过时标志 */ uint8_t ct_valid; /* CT7428 链路有效标志 */ uint8_t ct_stale; /* CT7428 数据过时标志 */ uint8_t hard_protect; /* 硬件超温保护跳闸标志 */ uint16_t bmc_epoch; /* BMC 采样周期序号 */ uint16_t ct_epoch; /* CT7428 采样周期序号 */ uint16_t control_epoch; /* 主控制环路周期序号 */ uint16_t bmc_age; /* BMC 距上次刷新秒数 */ uint16_t ct_age; /* CT7428 距上次刷新秒数 */ int16_t bmc[MID_TEMP_BMC_CH]; /* 24 路 BMC 温度 (℃, 值即原始读数) */ uint8_t bmc_valid_mask[3]; /* 24 bits: 各 BMC 通道有效掩码 */ int16_t ct[MID_TEMP_CT_CH]; /* 27 路 CT7428 温度 (℃, 已换算) */ uint8_t ct_valid_mask[4]; /* 32 bits: 各 CT 通道有效掩码 */ uint8_t ptc_requested[24]; /* 期望设定 24 路 PTC 占空比 */ uint8_t ptc_applied[24]; /* 生效 24 路 PTC 占空比 */ uint8_t front_requested[4]; /* 期望设定 4 路进风占空比 */ uint8_t front_applied[4]; /* 生效 4 路进风占空比 */ uint8_t rear_requested[4]; /* 期望设定 4 路出风占空比 */ uint8_t rear_applied[4]; /* 生效 4 路出风占空比 */ } mid_temp_snapshot_t; /** * @brief 初始化温度缓存 * @param 无 * @return 无 */ void Mid_Temp_Init(void); /** * @brief 解析一帧 0x82 SNAPSHOT_DATA 载荷并刷新缓存 * @param p : 载荷数据指针 (帧内 Type 之后的 199 字节) * @param len : 载荷长度 (须为 199) * @return 1=解析成功并刷新缓存, 0=参数非法 */ uint8_t Mid_Temp_UpdateSnapshot(const uint8_t *p, uint16_t len); /** * @brief 获取快照缓存指针 (只读, 供日志/调试转储) * @param 无 * @return 指向快照缓存的只读指针 */ const mid_temp_snapshot_t *Mid_Temp_GetSnapshot(void); /** * @brief 获取指定 BMC 通道温度 (0~23) * @note PID 过程值来源; 通道无效或无数据返回 -127 * @param ch : 通道号 (0~23) * @return 温度 (℃); 越界或无效返回 -127 */ int16_t Mid_Temp_GetBmcTemp(uint8_t ch); /** * @brief 获取指定 CT7428 通道温度 (0~26) * @param ch : 通道号 (0~26) * @return 温度 (℃); 越界或无效返回 -127 */ int16_t Mid_Temp_GetCtTemp(uint8_t ch); /** * @brief 获取预加热传感器温度 * @note 暂定 idx0~3 → CT7428 通道 0~3 (表驱动, 便于日后按实测修正) * @param idx : 序号 (0~MID_TEMP_PREHEAT_NUM-1) * @return 温度 (℃); 越界或无效返回 -127 */ int16_t Mid_Temp_GetPreheat(uint8_t idx); #endif /* __MID_TEMP_H */