/** ****************************************************************************** * @file Mid_temp.h * @brief 温度数据中间层 (Mid) * * @note 解析 CPLD GET_DATA 帧 (0x42, 6400: 83B, 协议 v2.0 §18) 并缓存。 * 温度为单字节整数摄氏度: 0x00..0xFE = 0..254°C, 0xFF = 无效 * (v2.0 §17); 采集换算 (BMC 源格式/CT7428 寄存器) 全部由 CPLD 完成, * 本层不做任何 raw 换算。 * 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 /* 预加热温度数量 */ /* 温度无效哨兵: getter 对 wire 值 0xFF 返回该值 (温度非负, 负值必为无效) */ #define MID_TEMP_INVALID (-127) /* 0x42 GET_DATA (6400, 83B) 载荷内偏移 (v2.0 §18) */ #define MID_TEMP_OFF_PTC_APPLIED 0 /* 24 路 PTC 当前生效百分比 */ #define MID_TEMP_OFF_FRONT_APPLIED 24 /* 4 路进风当前生效百分比 */ #define MID_TEMP_OFF_REAR_APPLIED 28 /* 4 路出风当前生效百分比 */ #define MID_TEMP_OFF_BMC 32 /* 24 路 BMC 温度, 每项 1B */ #define MID_TEMP_OFF_CT 56 /* 27 路 CT7428 温度, 每项 1B */ #define MID_TEMP_PAYLOAD_GET_DATA 83 /* GET_DATA 解析缓存 */ typedef struct { uint8_t ptc_applied[24]; /* 生效 24 路 PTC 占空比 */ uint8_t front_applied[4]; /* 生效 4 路进风占空比 */ uint8_t rear_applied[4]; /* 生效 4 路出风占空比 */ uint8_t bmc[MID_TEMP_BMC_CH]; /* 24 路 BMC温度 (0..254℃, 0xFF=无效) */ uint8_t ct[MID_TEMP_CT_CH]; /* 27 路 CT7428温度 (0..254℃, 0xFF=无效) */ } mid_temp_snapshot_t; /** * @brief 初始化温度缓存 * @param 无 * @return 无 */ void Mid_Temp_Init(void); /** * @brief 解析一帧 0x42 GET_DATA 载荷并刷新缓存 * @param p : 载荷数据指针 (帧内 Type 之后的 83 字节) * @param len : 载荷长度 (须为 83) * @return 1=解析成功并刷新缓存, 0=参数非法 */ uint8_t Mid_Temp_UpdateGetData(const uint8_t *p, uint16_t len); /** * @brief 获取快照缓存指针 (只读, 供日志/调试转储) * @param 无 * @return 指向快照缓存的只读指针 */ const mid_temp_snapshot_t *Mid_Temp_GetSnapshot(void); /** * @brief 判断是否已收到过有效 GET_DATA 帧 * @param 无 * @return 1=已有数据, 0=从未收到 */ uint8_t Mid_Temp_HasData(void); /** * @brief 获取指定 BMC 通道温度 (0~23) * @note PID 过程值来源; 通道无效 (wire 0xFF) 返回 MID_TEMP_INVALID * @param ch : 通道号 (0~23) * @return 温度 (℃); 越界或无效返回 MID_TEMP_INVALID (-127) */ int16_t Mid_Temp_GetBmcTemp(uint8_t ch); /** * @brief 获取指定 CT7428 通道温度 (0~26) * @param ch : 通道号 (0~26) * @return 温度 (℃); 越界或无效返回 MID_TEMP_INVALID (-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 温度 (℃); 越界或无效返回 MID_TEMP_INVALID (-127) */ int16_t Mid_Temp_GetPreheat(uint8_t idx); #endif /* __MID_TEMP_H */