116 lines
3.6 KiB
C
116 lines
3.6 KiB
C
#include "app_config.h"
|
|
#include "interface.h"
|
|
#include "app_frm_monitor.h"
|
|
#include "app_frm_signal.h"
|
|
#include "app_frm_timer.h"
|
|
#include "app_param_manage.h"
|
|
|
|
#include "app_temp.h"
|
|
|
|
|
|
// 声明 temp_data 变量
|
|
TempSystem temp_data;
|
|
|
|
// 温度输出处理函数
|
|
static void tempOutput(void *signal_id)
|
|
{
|
|
(void)signal_id;
|
|
|
|
// 根据当前状态,控制风扇
|
|
switch (temp_data.state)
|
|
{
|
|
case TEMP_NORMAL:
|
|
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
|
// un_inf_can_kgf_output1.bit_data.KGF03 = setFanOff();
|
|
// un_inf_can_kgf_output1.bit_data.KGF14 = setFanOff();//整车风扇
|
|
// un_inf_can_kgf_output2.bit_data.KGF03 = setFanOff();
|
|
break;
|
|
case TEMP_WARNING:
|
|
case TEMP_CRITICAL:
|
|
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();
|
|
// un_inf_can_kgf_output1.bit_data.KGF03 = setFanOn();
|
|
// un_inf_can_kgf_output1.bit_data.KGF14 = setFanOn();
|
|
// un_inf_can_kgf_output2.bit_data.KGF03 = setFanOn();
|
|
break;
|
|
}
|
|
|
|
// // 设置风扇速度
|
|
// temp_data.fan_speed = 0;
|
|
// un_inf_can_kgf_output1.bit_data.pwm_01 = temp_data.fan_speed;
|
|
|
|
publishMessage(&un_inf_can_kgf_output1, 1);
|
|
}
|
|
|
|
// 温度状态处理函数
|
|
static void tempProcess(void *signal_id)
|
|
{
|
|
(void)signal_id;
|
|
|
|
// 获取当前最高温度
|
|
int16_t max_temp = temp_data.current_temp[0];
|
|
for (uint8_t i = 1; i < 8; i++)
|
|
{
|
|
if (temp_data.current_temp[i] > max_temp)
|
|
{
|
|
max_temp = temp_data.current_temp[i];
|
|
}
|
|
}
|
|
// 根据最高温度设置状态
|
|
if (max_temp > 80) // 假设80度为危险温度
|
|
{
|
|
temp_data.state = TEMP_CRITICAL;
|
|
temp_data.fan_speed = 255; // 全速运转
|
|
}
|
|
else if (max_temp > 60) // 假设60度为警告温度
|
|
{
|
|
temp_data.state = TEMP_WARNING;
|
|
temp_data.fan_speed = 128; // 半速运转
|
|
}
|
|
else
|
|
{
|
|
temp_data.state = TEMP_NORMAL;
|
|
temp_data.fan_speed = 0; // 停止运转
|
|
}
|
|
|
|
tempOutput(NULL);
|
|
}
|
|
|
|
// 处理输入信号的函数
|
|
static void tempInput(void *signal_id)
|
|
{
|
|
// TempSystem old_data = temp_data;
|
|
|
|
// 填充数据
|
|
if (signal_id == &un_temp_module_input)
|
|
{
|
|
temp_data.current_temp[0] = (int16_t)un_temp_module_input.bit_data.channel_1;
|
|
temp_data.current_temp[1] = (int16_t)un_temp_module_input.bit_data.channel_2;
|
|
temp_data.current_temp[2] = (int16_t)un_temp_module_input.bit_data.channel_3;
|
|
temp_data.current_temp[3] = (int16_t)un_temp_module_input.bit_data.channel_4;
|
|
temp_data.current_temp[4] = (int16_t)un_temp_module_input.bit_data.channel_5;
|
|
temp_data.current_temp[5] = (int16_t)un_temp_module_input.bit_data.channel_6;
|
|
temp_data.current_temp[6] = (int16_t)un_temp_module_input.bit_data.channel_7;
|
|
temp_data.current_temp[7] = (int16_t)un_temp_module_input.bit_data.channel_8;
|
|
}
|
|
}
|
|
|
|
|
|
// APP模块的初始化
|
|
void tempAppInit(void)
|
|
{
|
|
// 初始化
|
|
memset(&temp_data, 0, sizeof(TempSystem));
|
|
temp_data.state = TEMP_NORMAL;
|
|
temp_data.mode = TEMP_MODE_AUTO;
|
|
temp_data.target_temp = 25; // 默认目标温度25度
|
|
|
|
// 订阅输入信号,处理温度逻辑
|
|
subscribe(&un_temp_module_input, tempInput);
|
|
|
|
// 启动定时器,每秒检查一次温度
|
|
subscribe(&temp_data.timer, tempProcess);
|
|
timerStart(&temp_data.timer, 1000, 1); //1s
|
|
|
|
printf("app_temp: initial OK \n");
|
|
}
|