Mid_temp.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. ******************************************************************************
  3. * @file Mid_temp.h
  4. * @brief 温度数据中间层 (Mid)
  5. *
  6. * @note 解析 CPLD GET_DATA 帧 (0x42, 6400: 83B, 协议 v2.0 §18) 并缓存。
  7. * 温度为单字节整数摄氏度: 0x00..0xFE = 0..254°C, 0xFF = 无效
  8. * (v2.0 §17); 采集换算 (BMC 源格式/CT7428 寄存器) 全部由 CPLD 完成,
  9. * 本层不做任何 raw 换算。
  10. * PID 过程值取 bmc 24 路; 预加热达标判定/风扇分区取预加热 4 路
  11. * (暂定 = ct 前 4 路, 表驱动, 便于日后核对通道对应关系)。
  12. ******************************************************************************
  13. */
  14. #ifndef __MID_TEMP_H
  15. #define __MID_TEMP_H
  16. #include <stdint.h>
  17. /* 通道数量 */
  18. #define MID_TEMP_BMC_CH 24 /* BMC 温度通道数 (与 24 路 PTC 对应) */
  19. #define MID_TEMP_CT_CH 27 /* CT7428 温度通道数 (3 芯片 x 9 寄存器) */
  20. #define MID_TEMP_PREHEAT_NUM 4 /* 预加热温度数量 */
  21. /* 温度无效哨兵: getter 对 wire 值 0xFF 返回该值 (温度非负, 负值必为无效) */
  22. #define MID_TEMP_INVALID (-127)
  23. /* 0x42 GET_DATA (6400, 83B) 载荷内偏移 (v2.0 §18) */
  24. #define MID_TEMP_OFF_PTC_APPLIED 0 /* 24 路 PTC 当前生效百分比 */
  25. #define MID_TEMP_OFF_FRONT_APPLIED 24 /* 4 路进风当前生效百分比 */
  26. #define MID_TEMP_OFF_REAR_APPLIED 28 /* 4 路出风当前生效百分比 */
  27. #define MID_TEMP_OFF_BMC 32 /* 24 路 BMC 温度, 每项 1B */
  28. #define MID_TEMP_OFF_CT 56 /* 27 路 CT7428 温度, 每项 1B */
  29. #define MID_TEMP_PAYLOAD_GET_DATA 83
  30. /* GET_DATA 解析缓存 */
  31. typedef struct
  32. {
  33. uint8_t ptc_applied[24]; /* 生效 24 路 PTC 占空比 */
  34. uint8_t front_applied[4]; /* 生效 4 路进风占空比 */
  35. uint8_t rear_applied[4]; /* 生效 4 路出风占空比 */
  36. uint8_t bmc[MID_TEMP_BMC_CH]; /* 24 路 BMC温度 (0..254℃, 0xFF=无效) */
  37. uint8_t ct[MID_TEMP_CT_CH]; /* 27 路 CT7428温度 (0..254℃, 0xFF=无效) */
  38. } mid_temp_snapshot_t;
  39. /**
  40. * @brief 初始化温度缓存
  41. * @param 无
  42. * @return 无
  43. */
  44. void Mid_Temp_Init(void);
  45. /**
  46. * @brief 解析一帧 0x42 GET_DATA 载荷并刷新缓存
  47. * @param p : 载荷数据指针 (帧内 Type 之后的 83 字节)
  48. * @param len : 载荷长度 (须为 83)
  49. * @return 1=解析成功并刷新缓存, 0=参数非法
  50. */
  51. uint8_t Mid_Temp_UpdateGetData(const uint8_t *p, uint16_t len);
  52. /**
  53. * @brief 获取快照缓存指针 (只读, 供日志/调试转储)
  54. * @param 无
  55. * @return 指向快照缓存的只读指针
  56. */
  57. const mid_temp_snapshot_t *Mid_Temp_GetSnapshot(void);
  58. /**
  59. * @brief 判断是否已收到过有效 GET_DATA 帧
  60. * @param 无
  61. * @return 1=已有数据, 0=从未收到
  62. */
  63. uint8_t Mid_Temp_HasData(void);
  64. /**
  65. * @brief 获取指定 BMC 通道温度 (0~23)
  66. * @note PID 过程值来源; 通道无效 (wire 0xFF) 返回 MID_TEMP_INVALID
  67. * @param ch : 通道号 (0~23)
  68. * @return 温度 (℃); 越界或无效返回 MID_TEMP_INVALID (-127)
  69. */
  70. int16_t Mid_Temp_GetBmcTemp(uint8_t ch);
  71. /**
  72. * @brief 获取指定 CT7428 通道温度 (0~26)
  73. * @param ch : 通道号 (0~26)
  74. * @return 温度 (℃); 越界或无效返回 MID_TEMP_INVALID (-127)
  75. */
  76. int16_t Mid_Temp_GetCtTemp(uint8_t ch);
  77. /**
  78. * @brief 获取预加热传感器温度
  79. * @note 暂定 idx0~3 → CT7428 通道 0~3 (表驱动, 便于日后按实测修正)
  80. * @param idx : 序号 (0~MID_TEMP_PREHEAT_NUM-1)
  81. * @return 温度 (℃); 越界或无效返回 MID_TEMP_INVALID (-127)
  82. */
  83. int16_t Mid_Temp_GetPreheat(uint8_t idx);
  84. #endif /* __MID_TEMP_H */