修改温度模块的KGF通道以及取消打印
This commit is contained in:
File diff suppressed because it is too large
Load Diff
858
app/app_power.c
858
app/app_power.c
@@ -1,429 +1,429 @@
|
|||||||
#include "app_config.h"
|
#include "app_config.h"
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "app_frm_monitor.h"
|
#include "app_frm_monitor.h"
|
||||||
#include "app_frm_signal.h"
|
#include "app_frm_signal.h"
|
||||||
#include "app_frm_timer.h"
|
#include "app_frm_timer.h"
|
||||||
#include "app_param_manage.h"
|
#include "app_param_manage.h"
|
||||||
|
|
||||||
#include "app_power.h"
|
#include "app_power.h"
|
||||||
|
|
||||||
|
|
||||||
// 定义按钮状态枚举
|
// 定义按钮状态枚举
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BUTTON_STATE_INITIAL,
|
BUTTON_STATE_INITIAL,
|
||||||
BUTTON_STATE_SHORT_PRESS,
|
BUTTON_STATE_SHORT_PRESS,
|
||||||
BUTTON_STATE_SHORT_PRESS_DETECTED,
|
BUTTON_STATE_SHORT_PRESS_DETECTED,
|
||||||
BUTTON_STATE_WAIT_FOR_LONG_PRESS,
|
BUTTON_STATE_WAIT_FOR_LONG_PRESS,
|
||||||
BUTTON_STATE_LONG_PRESS,
|
BUTTON_STATE_LONG_PRESS,
|
||||||
BUTTON_STATE_LONG_PRESS_WAIT
|
BUTTON_STATE_LONG_PRESS_WAIT
|
||||||
} ButtonState;
|
} ButtonState;
|
||||||
|
|
||||||
// 定义按钮结构体
|
// 定义按钮结构体
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ButtonState state;
|
ButtonState state;
|
||||||
uint32_t press_start_time;
|
uint32_t press_start_time;
|
||||||
uint32_t release_start_time;
|
uint32_t release_start_time;
|
||||||
uint8_t is_power_on;
|
uint8_t is_power_on;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
uint8_t old_is_power_on;
|
uint8_t old_is_power_on;
|
||||||
Timer timer1;
|
Timer timer1;
|
||||||
|
|
||||||
} PowerButton;
|
} PowerButton;
|
||||||
|
|
||||||
// 全局变量
|
// 全局变量
|
||||||
PowerSystem power_data;
|
PowerSystem power_data;
|
||||||
static PowerButton power_button = {BUTTON_STATE_INITIAL, 0, 0, 0, {0},0};
|
static PowerButton power_button = {BUTTON_STATE_INITIAL, 0, 0, 0, {0},0};
|
||||||
|
|
||||||
// 电源按钮处理函数
|
// 电源按钮处理函数
|
||||||
static void handlePowerButton(void)
|
static void handlePowerButton(void)
|
||||||
{
|
{
|
||||||
switch (power_button.state)
|
switch (power_button.state)
|
||||||
{
|
{
|
||||||
case BUTTON_STATE_INITIAL:
|
case BUTTON_STATE_INITIAL:
|
||||||
if (power_data.remote_power_switch == app_close())
|
if (power_data.remote_power_switch == app_close())
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_SHORT_PRESS_DETECTED;
|
power_button.state = BUTTON_STATE_SHORT_PRESS_DETECTED;
|
||||||
timerStart(&power_button.timer, 500, 0); // 启动短按定时器,500ms
|
timerStart(&power_button.timer, 500, 0); // 启动短按定时器,500ms
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUTTON_STATE_SHORT_PRESS_DETECTED:
|
case BUTTON_STATE_SHORT_PRESS_DETECTED:
|
||||||
if (power_data.remote_power_switch == app_open())
|
if (power_data.remote_power_switch == app_open())
|
||||||
{
|
{
|
||||||
if (power_button.timer.active) // 定时器未到期,短按完成,启动等待长按定时器
|
if (power_button.timer.active) // 定时器未到期,短按完成,启动等待长按定时器
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_WAIT_FOR_LONG_PRESS;
|
power_button.state = BUTTON_STATE_WAIT_FOR_LONG_PRESS;
|
||||||
timerStart(&power_button.timer, 500, 0); // 启动等待长按定时器,500ms
|
timerStart(&power_button.timer, 500, 0); // 启动等待长按定时器,500ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!power_button.timer.active)// 短按定时器到期,按键仍被按下,视为无效,重置为初始状态
|
else if (!power_button.timer.active)// 短按定时器到期,按键仍被按下,视为无效,重置为初始状态
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_INITIAL;
|
power_button.state = BUTTON_STATE_INITIAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUTTON_STATE_WAIT_FOR_LONG_PRESS:
|
case BUTTON_STATE_WAIT_FOR_LONG_PRESS:
|
||||||
if (power_data.remote_power_switch == app_close())// 检测是否在等待时间内进行长按
|
if (power_data.remote_power_switch == app_close())// 检测是否在等待时间内进行长按
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_LONG_PRESS;
|
power_button.state = BUTTON_STATE_LONG_PRESS;
|
||||||
timerStart(&power_button.timer, 1000, 0); // 启动长按定时器,1000ms
|
timerStart(&power_button.timer, 1000, 0); // 启动长按定时器,1000ms
|
||||||
}
|
}
|
||||||
else if (!power_button.timer.active) // 等待长按超时,重置为初始状态
|
else if (!power_button.timer.active) // 等待长按超时,重置为初始状态
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_INITIAL;
|
power_button.state = BUTTON_STATE_INITIAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUTTON_STATE_LONG_PRESS:
|
case BUTTON_STATE_LONG_PRESS:
|
||||||
|
|
||||||
if (!power_button.timer.active)// 长按完成,切换电源状态 20250423 修改不需要判断松开按键就打开控制器
|
if (!power_button.timer.active)// 长按完成,切换电源状态 20250423 修改不需要判断松开按键就打开控制器
|
||||||
{
|
{
|
||||||
power_button.is_power_on = !power_button.is_power_on;
|
power_button.is_power_on = !power_button.is_power_on;
|
||||||
printf("PowerButton: is_power_on = %d\n", power_button.is_power_on);
|
printf("PowerButton: is_power_on = %d\n", power_button.is_power_on);
|
||||||
power_button.state = BUTTON_STATE_LONG_PRESS_WAIT;
|
power_button.state = BUTTON_STATE_LONG_PRESS_WAIT;
|
||||||
}
|
}
|
||||||
else if(power_data.remote_power_switch == app_open())
|
else if(power_data.remote_power_switch == app_open())
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_INITIAL;
|
power_button.state = BUTTON_STATE_INITIAL;
|
||||||
printf("Long press for short duration");
|
printf("Long press for short duration");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUTTON_STATE_LONG_PRESS_WAIT:
|
case BUTTON_STATE_LONG_PRESS_WAIT:
|
||||||
if (power_data.remote_power_switch == app_open())// 检测按键释放
|
if (power_data.remote_power_switch == app_open())// 检测按键释放
|
||||||
{
|
{
|
||||||
power_button.state = BUTTON_STATE_INITIAL;
|
power_button.state = BUTTON_STATE_INITIAL;
|
||||||
printf("Release the button");
|
printf("Release the button");
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
power_button.state = BUTTON_STATE_INITIAL;
|
power_button.state = BUTTON_STATE_INITIAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 输出处理函数
|
// 输出处理函数
|
||||||
static void powerOutput(void *signal_id)
|
static void powerOutput(void *signal_id)
|
||||||
{
|
{
|
||||||
(void)signal_id;
|
(void)signal_id;
|
||||||
|
|
||||||
// 根据当前状态,控制各个设备的电源
|
// 根据当前状态,控制各个设备的电源
|
||||||
switch (power_data.current_state)
|
switch (power_data.current_state)
|
||||||
{
|
{
|
||||||
case POWER_PRE_CHARGE:
|
case POWER_PRE_CHARGE:
|
||||||
publishMessage(&power_data.pre_charge_finish, 1);//发布预充完成信号,100ms发送一次,直到预充完成
|
publishMessage(&power_data.pre_charge_finish, 1);//发布预充完成信号,100ms发送一次,直到预充完成
|
||||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOn(); // 预充继电器
|
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOn(); // 预充继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_NEUTRAL:
|
case POWER_NEUTRAL:
|
||||||
publishMessage(&power_data.pre_charge_finish, 1);//20250316增加,发送空挡信号,保证电机控制器高压上电后,发送空挡信号
|
publishMessage(&power_data.pre_charge_finish, 1);//20250316增加,发送空挡信号,保证电机控制器高压上电后,发送空挡信号
|
||||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 高压继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 高压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case POWER_STANDBY:
|
case POWER_STANDBY:
|
||||||
// 初始状态,只开启基本设备
|
// 初始状态,只开启基本设备
|
||||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOff(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOff(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOff(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOff(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_WORKING:
|
case POWER_WORKING:
|
||||||
// 工作状态,除预充继电器外所有设备开启
|
// 工作状态,除预充继电器外所有设备开启
|
||||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 高压继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 高压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_EMERGENCY:
|
case POWER_EMERGENCY:
|
||||||
// 急停状态,断开高压
|
// 急停状态,断开高压
|
||||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_SLEEP:
|
case POWER_SLEEP:
|
||||||
// 休眠状态,关闭所有设备
|
// 休眠状态,关闭所有设备
|
||||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOff(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF10 = setPowerOff(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOff(); // 低压继电器
|
un_inf_can_kgf_output2.bit_data.KGF11 = setPowerOff(); // 低压继电器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 网络交换机
|
||||||
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
un_inf_can_kgf_output2.bit_data.KGF04 = setPowerOn(); // E3
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
publishMessage(&power_data, 1);
|
publishMessage(&power_data, 1);
|
||||||
publishMessage(&un_inf_can_kgf_output1, 1);
|
publishMessage(&un_inf_can_kgf_output1, 1);
|
||||||
publishMessage(&un_inf_can_kgf_output2, 1);
|
publishMessage(&un_inf_can_kgf_output2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wakeupProcess(void *signal_id)
|
static void wakeupProcess(void *signal_id)
|
||||||
{
|
{
|
||||||
(void)signal_id;
|
(void)signal_id;
|
||||||
|
|
||||||
un_gather_output.bit_data.sleep_duration = (uint16_t)getParam("sleepTm");
|
un_gather_output.bit_data.sleep_duration = (uint16_t)getParam("sleepTm");
|
||||||
un_gather_output.bit_data.wakeup_interval = (uint16_t)getParam("wakeTm");
|
un_gather_output.bit_data.wakeup_interval = (uint16_t)getParam("wakeTm");
|
||||||
|
|
||||||
if(un_gather_output.bit_data.sleep_duration < 5)//最小值限定
|
if(un_gather_output.bit_data.sleep_duration < 5)//最小值限定
|
||||||
{
|
{
|
||||||
un_gather_output.bit_data.sleep_duration = 5;
|
un_gather_output.bit_data.sleep_duration = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(un_gather_output.bit_data.wakeup_interval < 5)//最小值限定
|
if(un_gather_output.bit_data.wakeup_interval < 5)//最小值限定
|
||||||
{
|
{
|
||||||
un_gather_output.bit_data.wakeup_interval = 5;
|
un_gather_output.bit_data.wakeup_interval = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
un_gather_output.bit_data.vehicle_mode = power_data.current_state;
|
un_gather_output.bit_data.vehicle_mode = power_data.current_state;
|
||||||
|
|
||||||
publishMessage(&un_gather_output, 1);
|
publishMessage(&un_gather_output, 1);
|
||||||
timerStart(&power_data.timer1, 500, 1); //周期调用
|
timerStart(&power_data.timer1, 500, 1); //周期调用
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 定时器处理函数
|
// 定时器处理函数
|
||||||
static void powerTimerProcess(void *signal_id)
|
static void powerTimerProcess(void *signal_id)
|
||||||
{
|
{
|
||||||
(void)signal_id;
|
(void)signal_id;
|
||||||
|
|
||||||
// 调用电源按钮处理函数
|
// 调用电源按钮处理函数
|
||||||
handlePowerButton();
|
handlePowerButton();
|
||||||
// 电源按钮状态有变化,保存到参数
|
// 电源按钮状态有变化,保存到参数
|
||||||
if (power_button.is_power_on != power_button.old_is_power_on)
|
if (power_button.is_power_on != power_button.old_is_power_on)
|
||||||
{
|
{
|
||||||
setParam("pwr_btn", (float)power_button.is_power_on);
|
setParam("pwr_btn", (float)power_button.is_power_on);
|
||||||
power_button.old_is_power_on = power_button.is_power_on;
|
power_button.old_is_power_on = power_button.is_power_on;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 状态转换逻辑
|
// 状态转换逻辑
|
||||||
switch (power_data.current_state)
|
switch (power_data.current_state)
|
||||||
{
|
{
|
||||||
case POWER_PRE_CHARGE:
|
case POWER_PRE_CHARGE:
|
||||||
if (!power_data.timer_pre_charge.active) // 预充时间到
|
if (!power_data.timer_pre_charge.active) // 预充时间到
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_NEUTRAL; // 工作
|
power_data.current_state = POWER_NEUTRAL; // 工作
|
||||||
power_data.pre_charge_finish = 1; // 预充完成
|
power_data.pre_charge_finish = 1; // 预充完成
|
||||||
printf("Power: Transitioning from PRE_CHARGE to POWER_NEUTRAL state\n");
|
printf("Power: Transitioning from PRE_CHARGE to POWER_NEUTRAL state\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case POWER_NEUTRAL://20250316增加,发送空挡信号
|
case POWER_NEUTRAL://20250316增加,发送空挡信号
|
||||||
if (power_data.neutral_cnt >= 5) // 运行5次
|
if (power_data.neutral_cnt >= 5) // 运行5次
|
||||||
{
|
{
|
||||||
power_data.neutral_cnt = 0;
|
power_data.neutral_cnt = 0;
|
||||||
power_data.current_state = POWER_WORKING; // 工作
|
power_data.current_state = POWER_WORKING; // 工作
|
||||||
power_data.pre_charge_finish = 1; // 预充完成
|
power_data.pre_charge_finish = 1; // 预充完成
|
||||||
printf("Power: Transitioning from POWER_NEUTRAL to WORKING state\n");
|
printf("Power: Transitioning from POWER_NEUTRAL to WORKING state\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
power_data.neutral_cnt ++;
|
power_data.neutral_cnt ++;
|
||||||
power_data.current_state = POWER_NEUTRAL; // 空挡
|
power_data.current_state = POWER_NEUTRAL; // 空挡
|
||||||
power_data.pre_charge_finish = 1; // 预充完成
|
power_data.pre_charge_finish = 1; // 预充完成
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_STANDBY:
|
case POWER_STANDBY:
|
||||||
if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_SLEEP; // 休眠
|
power_data.current_state = POWER_SLEEP; // 休眠
|
||||||
printf("Power: Transitioning from STANDBY to SLEEP state\n");
|
printf("Power: Transitioning from STANDBY to SLEEP state\n");
|
||||||
}
|
}
|
||||||
else if (power_button.is_power_on == app_close() && power_data.emergency_stop == app_close()) // 遥控器电源开关闭合且急停开关闭合
|
else if (power_button.is_power_on == app_close() && power_data.emergency_stop == app_close()) // 遥控器电源开关闭合且急停开关闭合
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_EMERGENCY; // 急停
|
power_data.current_state = POWER_EMERGENCY; // 急停
|
||||||
printf("Power: Transitioning from STANDBY to EMERGENCY state\n");
|
printf("Power: Transitioning from STANDBY to EMERGENCY state\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_WORKING:
|
case POWER_WORKING:
|
||||||
if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_SLEEP; // 休眠
|
power_data.current_state = POWER_SLEEP; // 休眠
|
||||||
printf("Power: Transitioning from STANDBY to SLEEP state\n");
|
printf("Power: Transitioning from STANDBY to SLEEP state\n");
|
||||||
}
|
}
|
||||||
else if (power_data.emergency_stop == app_close()) // 急停开关闭合
|
else if (power_data.emergency_stop == app_close()) // 急停开关闭合
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_EMERGENCY; // 急停
|
power_data.current_state = POWER_EMERGENCY; // 急停
|
||||||
printf("Power: Transitioning from WORKING to EMERGENCY state\n");
|
printf("Power: Transitioning from WORKING to EMERGENCY state\n");
|
||||||
|
|
||||||
printf("emergency_stop_switch: %d, remote_emergency_stop: %d\n", power_data.emergency_stop_switch, power_data.remote_emergency_stop); //打印状态
|
printf("emergency_stop_switch: %d, remote_emergency_stop: %d\n", power_data.emergency_stop_switch, power_data.remote_emergency_stop); //打印状态
|
||||||
printf("remote_stop: %d\n", un_remote_control_input.bit_data.switch_b);
|
printf("remote_stop: %d\n", un_remote_control_input.bit_data.switch_b);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case POWER_EMERGENCY:
|
case POWER_EMERGENCY:
|
||||||
if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_SLEEP; // 休眠
|
power_data.current_state = POWER_SLEEP; // 休眠
|
||||||
printf("Power: Transitioning from EMERGENCY to SLEEP state\n");
|
printf("Power: Transitioning from EMERGENCY to SLEEP state\n");
|
||||||
}
|
}
|
||||||
else if (power_button.is_power_on == app_open()) // 遥控器电源开关断开
|
else if (power_button.is_power_on == app_open()) // 遥控器电源开关断开
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_STANDBY; // 待机
|
power_data.current_state = POWER_STANDBY; // 待机
|
||||||
printf("Power: Transitioning from EMERGENCY to STANDBY state\n");
|
printf("Power: Transitioning from EMERGENCY to STANDBY state\n");
|
||||||
}
|
}
|
||||||
else if (power_data.emergency_stop == app_open()) // 急停断开
|
else if (power_data.emergency_stop == app_open()) // 急停断开
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_PRE_CHARGE; // 预充
|
power_data.current_state = POWER_PRE_CHARGE; // 预充
|
||||||
timerStart(&power_data.timer_pre_charge, (uint32_t)(getParam("prCTime") * 1000), 1); // 启动预充定时器
|
timerStart(&power_data.timer_pre_charge, (uint32_t)(getParam("prCTime") * 1000), 1); // 启动预充定时器
|
||||||
printf("Power: Transitioning from EMERGENCY to PRE_CHARGE state\n");
|
printf("Power: Transitioning from EMERGENCY to PRE_CHARGE state\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case POWER_SLEEP:
|
case POWER_SLEEP:
|
||||||
if (power_data.high_voltage_switch == app_close()) // 高压开关闭合
|
if (power_data.high_voltage_switch == app_close()) // 高压开关闭合
|
||||||
{
|
{
|
||||||
power_data.current_state = POWER_STANDBY; // 待机
|
power_data.current_state = POWER_STANDBY; // 待机
|
||||||
printf("Power: Transitioning from SLEEP to STANDBY state\n");
|
printf("Power: Transitioning from SLEEP to STANDBY state\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
power_data.current_state = POWER_STANDBY; // 待机
|
power_data.current_state = POWER_STANDBY; // 待机
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
powerOutput(NULL); // 输出
|
powerOutput(NULL); // 输出
|
||||||
|
|
||||||
// 电源状态有变化,记录到参数
|
// 电源状态有变化,记录到参数
|
||||||
if (power_data.old_state != power_data.current_state)
|
if (power_data.old_state != power_data.current_state)
|
||||||
{
|
{
|
||||||
power_data.old_state = power_data.current_state;
|
power_data.old_state = power_data.current_state;
|
||||||
setParam("pwr_sta", (float)power_data.current_state);
|
setParam("pwr_sta", (float)power_data.current_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
timerStart(&power_data.timer, 100, 1); //周期调用
|
timerStart(&power_data.timer, 100, 1); //周期调用
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 处理所有输入信号的函数
|
// 处理所有输入信号的函数
|
||||||
static void powerInput(void *signal_id)
|
static void powerInput(void *signal_id)
|
||||||
{
|
{
|
||||||
//不能直接赋值,用memcpy
|
//不能直接赋值,用memcpy
|
||||||
PowerSystem old_data;
|
PowerSystem old_data;
|
||||||
memcpy(&old_data, &power_data, sizeof(PowerSystem));
|
memcpy(&old_data, &power_data, sizeof(PowerSystem));
|
||||||
|
|
||||||
// 填充数据
|
// 填充数据
|
||||||
if (signal_id == &un_sw_sample)
|
if (signal_id == &un_sw_sample)
|
||||||
{
|
{
|
||||||
power_data.emergency_stop_switch = (uint8_t)un_sw_sample.bit_data.emergency_stop_switch;//急停开关
|
power_data.emergency_stop_switch = (uint8_t)un_sw_sample.bit_data.emergency_stop_switch;//急停开关
|
||||||
power_data.high_voltage_switch = (uint8_t)un_sw_sample.bit_data.High_voltage_switch;//高压开关
|
power_data.high_voltage_switch = (uint8_t)un_sw_sample.bit_data.High_voltage_switch;//高压开关
|
||||||
}
|
}
|
||||||
else if ( (signal_id == &un_remote_control_input) && (1 == un_remote_control_input.bit_data.enable) )// 遥控器断线,不更新数据
|
else if ( (signal_id == &un_remote_control_input) && (1 == un_remote_control_input.bit_data.enable) )// 遥控器断线,不更新数据
|
||||||
{
|
{
|
||||||
power_data.remote_power_switch = (uint8_t)un_remote_control_input.bit_data.switch_d; // 遥控器电源开关
|
power_data.remote_power_switch = (uint8_t)un_remote_control_input.bit_data.switch_d; // 遥控器电源开关
|
||||||
power_data.remote_emergency_stop = ((uint8_t)un_remote_control_input.bit_data.switch_b == 1) ? 0 : 1;// 遥控器急停开关
|
power_data.remote_emergency_stop = ((uint8_t)un_remote_control_input.bit_data.switch_b == 1) ? 0 : 1;// 遥控器急停开关
|
||||||
}
|
}
|
||||||
// 急停开关
|
// 急停开关
|
||||||
power_data.emergency_stop = (uint8_t)( (power_data.emergency_stop_switch == app_close()) || (power_data.remote_emergency_stop == app_close()) );
|
power_data.emergency_stop = (uint8_t)( (power_data.emergency_stop_switch == app_close()) || (power_data.remote_emergency_stop == app_close()) );
|
||||||
|
|
||||||
// 急停开关有变化,记录到参数
|
// 急停开关有变化,记录到参数
|
||||||
if (power_data.old_emergency_stop != power_data.emergency_stop)
|
if (power_data.old_emergency_stop != power_data.emergency_stop)
|
||||||
{
|
{
|
||||||
power_data.old_emergency_stop = power_data.emergency_stop;
|
power_data.old_emergency_stop = power_data.emergency_stop;
|
||||||
setParam("stop_sw", (float)power_data.emergency_stop);
|
setParam("stop_sw", (float)power_data.emergency_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 高压开关状态有变化,记录到参数
|
// 高压开关状态有变化,记录到参数
|
||||||
if (power_data.old_high_voltage_switch != power_data.high_voltage_switch)
|
if (power_data.old_high_voltage_switch != power_data.high_voltage_switch)
|
||||||
{
|
{
|
||||||
power_data.old_high_voltage_switch = power_data.high_voltage_switch;
|
power_data.old_high_voltage_switch = power_data.high_voltage_switch;
|
||||||
setParam("high_sw", (float)power_data.high_voltage_switch);
|
setParam("high_sw", (float)power_data.high_voltage_switch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// APP模块的初始化
|
// APP模块的初始化
|
||||||
void powerAppInit(void)
|
void powerAppInit(void)
|
||||||
{
|
{
|
||||||
// 初始化变量
|
// 初始化变量
|
||||||
memset(&power_data, 0, sizeof(PowerSystem));
|
memset(&power_data, 0, sizeof(PowerSystem));
|
||||||
power_data.current_state = POWER_STANDBY;
|
power_data.current_state = POWER_STANDBY;
|
||||||
// 初始化时恢复电源状态
|
// 初始化时恢复电源状态
|
||||||
power_data.current_state = (PowerState)getParam("pwr_sta");
|
power_data.current_state = (PowerState)getParam("pwr_sta");
|
||||||
power_data.old_state = power_data.current_state;
|
power_data.old_state = power_data.current_state;
|
||||||
// 恢复电源按钮状态
|
// 恢复电源按钮状态
|
||||||
power_button.is_power_on = (uint8_t)getParam("pwr_btn");
|
power_button.is_power_on = (uint8_t)getParam("pwr_btn");
|
||||||
power_button.old_is_power_on = power_button.is_power_on;
|
power_button.old_is_power_on = power_button.is_power_on;
|
||||||
//恢复高压开关状态
|
//恢复高压开关状态
|
||||||
power_data.high_voltage_switch = (uint8_t)getParam("high_sw");
|
power_data.high_voltage_switch = (uint8_t)getParam("high_sw");
|
||||||
power_data.old_high_voltage_switch = power_data.high_voltage_switch;
|
power_data.old_high_voltage_switch = power_data.high_voltage_switch;
|
||||||
//恢复急停开关状态
|
//恢复急停开关状态
|
||||||
power_data.emergency_stop = (uint8_t)getParam("stop_sw");
|
power_data.emergency_stop = (uint8_t)getParam("stop_sw");
|
||||||
power_data.old_emergency_stop = power_data.emergency_stop;
|
power_data.old_emergency_stop = power_data.emergency_stop;
|
||||||
|
|
||||||
// 订阅输入信号
|
// 订阅输入信号
|
||||||
subscribe(&un_sw_sample, powerInput); // 急停开关、高压开关
|
subscribe(&un_sw_sample, powerInput); // 急停开关、高压开关
|
||||||
subscribe(&un_remote_control_input, powerInput); // 遥控器电源开关
|
subscribe(&un_remote_control_input, powerInput); // 遥控器电源开关
|
||||||
// 定时器
|
// 定时器
|
||||||
timerInit(&power_data.timer);
|
timerInit(&power_data.timer);
|
||||||
subscribe(&power_data.timer, powerTimerProcess);
|
subscribe(&power_data.timer, powerTimerProcess);
|
||||||
timerStart(&power_data.timer, 500, 1); // 周期调用
|
timerStart(&power_data.timer, 500, 1); // 周期调用
|
||||||
//定时器唤醒
|
//定时器唤醒
|
||||||
timerInit(&power_data.timer1);
|
timerInit(&power_data.timer1);
|
||||||
subscribe(&power_data.timer1, wakeupProcess);
|
subscribe(&power_data.timer1, wakeupProcess);
|
||||||
timerStart(&power_data.timer1, 500, 1); // 周期调用
|
timerStart(&power_data.timer1, 500, 1); // 周期调用
|
||||||
//预充定时器
|
//预充定时器
|
||||||
timerInit(&power_data.timer_pre_charge);
|
timerInit(&power_data.timer_pre_charge);
|
||||||
subscribe(&power_data.timer_pre_charge, powerTimerProcess);
|
subscribe(&power_data.timer_pre_charge, powerTimerProcess);
|
||||||
|
|
||||||
printf("app_power: initial OK\n");
|
printf("app_power: initial OK\n");
|
||||||
}
|
}
|
||||||
|
|||||||
570
app/app_temp.c
570
app/app_temp.c
@@ -1,285 +1,285 @@
|
|||||||
#include "app_config.h"
|
#include "app_config.h"
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "app_frm_monitor.h"
|
#include "app_frm_monitor.h"
|
||||||
#include "app_frm_signal.h"
|
#include "app_frm_signal.h"
|
||||||
#include "app_frm_timer.h"
|
#include "app_frm_timer.h"
|
||||||
#include "app_param_manage.h"
|
#include "app_param_manage.h"
|
||||||
|
|
||||||
#include "app_temp.h"
|
#include "app_temp.h"
|
||||||
|
|
||||||
|
|
||||||
// 声明 temp_data 变量
|
// 声明 temp_data 变量
|
||||||
TempSystem temp_data;
|
TempSystem temp_data;
|
||||||
|
|
||||||
|
|
||||||
static void handleTemperatureAlarm(int16_t current_temp, float alarm_temp,
|
static void handleTemperatureAlarm(int16_t current_temp, float alarm_temp,
|
||||||
float critical_temp, float threshold_temp,
|
float critical_temp, float threshold_temp,
|
||||||
TempState *state)
|
TempState *state)
|
||||||
{
|
{
|
||||||
switch (*state)
|
switch (*state)
|
||||||
{
|
{
|
||||||
case TEMP_NORMAL:
|
case TEMP_NORMAL:
|
||||||
// 从正常状态进入警告状态的条件
|
// 从正常状态进入警告状态的条件
|
||||||
if (current_temp > (alarm_temp + threshold_temp))
|
if (current_temp > (alarm_temp + threshold_temp))
|
||||||
{
|
{
|
||||||
*state = TEMP_WARNING;
|
*state = TEMP_WARNING;
|
||||||
printf("Temperature Warning: Activated! Current temp: %d°C\n", current_temp);
|
printf("Temperature Warning: Activated! Current temp: %d°C\n", current_temp);
|
||||||
}
|
}
|
||||||
// 从正常状态直接进入严重状态的条件
|
// 从正常状态直接进入严重状态的条件
|
||||||
else if (current_temp > (critical_temp + threshold_temp))
|
else if (current_temp > (critical_temp + threshold_temp))
|
||||||
{
|
{
|
||||||
*state = TEMP_CRITICAL;
|
*state = TEMP_CRITICAL;
|
||||||
printf("Temperature Critical: Activated! Current temp: %d°C\n", current_temp);
|
printf("Temperature Critical: Activated! Current temp: %d°C\n", current_temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*state = TEMP_NORMAL;
|
*state = TEMP_NORMAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TEMP_WARNING:
|
case TEMP_WARNING:
|
||||||
// 从警告状态返回正常状态的条件
|
// 从警告状态返回正常状态的条件
|
||||||
if (current_temp < (alarm_temp - threshold_temp))
|
if (current_temp < (alarm_temp - threshold_temp))
|
||||||
{
|
{
|
||||||
*state = TEMP_NORMAL;
|
*state = TEMP_NORMAL;
|
||||||
printf("Temperature Warning: Deactivated! Current temp: %d°C\n", current_temp);
|
printf("Temperature Warning: Deactivated! Current temp: %d°C\n", current_temp);
|
||||||
}
|
}
|
||||||
// 从警告状态进入严重状态的条件
|
// 从警告状态进入严重状态的条件
|
||||||
else if (current_temp > (critical_temp + threshold_temp))
|
else if (current_temp > (critical_temp + threshold_temp))
|
||||||
{
|
{
|
||||||
*state = TEMP_CRITICAL;
|
*state = TEMP_CRITICAL;
|
||||||
printf("Temperature Critical: Activated! Current temp: %d°C\n", current_temp);
|
printf("Temperature Critical: Activated! Current temp: %d°C\n", current_temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*state = TEMP_WARNING;
|
*state = TEMP_WARNING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TEMP_CRITICAL:
|
case TEMP_CRITICAL:
|
||||||
// 从严重状态返回警告状态的条件
|
// 从严重状态返回警告状态的条件
|
||||||
if (current_temp < (critical_temp - threshold_temp))
|
if (current_temp < (critical_temp - threshold_temp))
|
||||||
{
|
{
|
||||||
*state = TEMP_WARNING;
|
*state = TEMP_WARNING;
|
||||||
printf("Temperature Critical: Deactivated! Current temp: %d°C\n", current_temp);
|
printf("Temperature Critical: Deactivated! Current temp: %d°C\n", current_temp);
|
||||||
}
|
}
|
||||||
// 从严重状态直接返回正常状态的条件
|
// 从严重状态直接返回正常状态的条件
|
||||||
else if (current_temp < (alarm_temp - threshold_temp))
|
else if (current_temp < (alarm_temp - threshold_temp))
|
||||||
{
|
{
|
||||||
*state = TEMP_NORMAL;
|
*state = TEMP_NORMAL;
|
||||||
printf("Temperature Warning: Deactivated! Current temp: %d°C\n", current_temp);
|
printf("Temperature Warning: Deactivated! Current temp: %d°C\n", current_temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*state = TEMP_CRITICAL;
|
*state = TEMP_CRITICAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
*state = TEMP_NORMAL;
|
*state = TEMP_NORMAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 温度输出处理函数
|
// 温度输出处理函数
|
||||||
static void tempOutput(void *signal_id)
|
static void tempOutput(void *signal_id)
|
||||||
{
|
{
|
||||||
(void)signal_id;
|
(void)signal_id;
|
||||||
|
|
||||||
// 电机1风扇 左前
|
// 电机1风扇 左前
|
||||||
switch (temp_data.state[0])
|
switch (temp_data.state[0])
|
||||||
{
|
{
|
||||||
case TEMP_NORMAL:
|
case TEMP_NORMAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||||
break;
|
break;
|
||||||
case TEMP_WARNING:
|
case TEMP_WARNING:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_01 = 5;
|
un_inf_can_kgf_output1.bit_data.pwm_01 = 5;
|
||||||
break;
|
break;
|
||||||
case TEMP_CRITICAL:
|
case TEMP_CRITICAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 电机2风扇 右前
|
// 电机2风扇 右前
|
||||||
switch (temp_data.state[1])
|
switch (temp_data.state[1])
|
||||||
{
|
{
|
||||||
case TEMP_NORMAL:
|
case TEMP_NORMAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOff();//电机控制器风扇
|
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOff();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_02 = 0;
|
un_inf_can_kgf_output1.bit_data.pwm_02 = 0;
|
||||||
break;
|
break;
|
||||||
case TEMP_WARNING:
|
case TEMP_WARNING:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_02 = 5;
|
un_inf_can_kgf_output1.bit_data.pwm_02 = 5;
|
||||||
break;
|
break;
|
||||||
case TEMP_CRITICAL:
|
case TEMP_CRITICAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_02 = 0;
|
un_inf_can_kgf_output1.bit_data.pwm_02 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 电机3风扇 左后
|
// 电机3风扇 左后
|
||||||
switch (temp_data.state[2])
|
switch (temp_data.state[2])
|
||||||
{
|
{
|
||||||
case TEMP_NORMAL:
|
case TEMP_NORMAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setFanOff();//电机控制器风扇
|
un_inf_can_kgf_output2.bit_data.KGF07 = setFanOff();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_07 = 0;
|
un_inf_can_kgf_output2.bit_data.pwm_07 = 0;
|
||||||
break;
|
break;
|
||||||
case TEMP_WARNING:
|
case TEMP_WARNING:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output2.bit_data.KGF07 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_07 = 5;
|
un_inf_can_kgf_output2.bit_data.pwm_07 = 5;
|
||||||
break;
|
break;
|
||||||
case TEMP_CRITICAL:
|
case TEMP_CRITICAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF07 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output2.bit_data.KGF07 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_07 = 0;
|
un_inf_can_kgf_output2.bit_data.pwm_07 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 电机4风扇 右后
|
// 电机4风扇 右后
|
||||||
switch (temp_data.state[3])
|
switch (temp_data.state[3])
|
||||||
{
|
{
|
||||||
case TEMP_NORMAL:
|
case TEMP_NORMAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setFanOff();//电机控制器风扇
|
un_inf_can_kgf_output2.bit_data.KGF08 = setFanOff();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_08 = 0;
|
un_inf_can_kgf_output2.bit_data.pwm_08 = 0;
|
||||||
break;
|
break;
|
||||||
case TEMP_WARNING:
|
case TEMP_WARNING:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output2.bit_data.KGF08 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_08 = 5;
|
un_inf_can_kgf_output2.bit_data.pwm_08 = 5;
|
||||||
break;
|
break;
|
||||||
case TEMP_CRITICAL:
|
case TEMP_CRITICAL:
|
||||||
un_inf_can_kgf_output1.bit_data.KGF08 = setFanOn();//电机控制器风扇
|
un_inf_can_kgf_output2.bit_data.KGF08 = setFanOn();//电机控制器风扇
|
||||||
un_inf_can_kgf_output1.bit_data.pwm_08 = 0;
|
un_inf_can_kgf_output2.bit_data.pwm_08 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 电机3风扇
|
// // 电机3风扇
|
||||||
// switch (temp_data.state[2])
|
// switch (temp_data.state[2])
|
||||||
// {
|
// {
|
||||||
// case TEMP_NORMAL:
|
// case TEMP_NORMAL:
|
||||||
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
||||||
// un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
// un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||||
// break;
|
// break;
|
||||||
// case TEMP_WARNING:
|
// case TEMP_WARNING:
|
||||||
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||||
// un_inf_can_kgf_output1.bit_data.pwm_01 = 5;
|
// un_inf_can_kgf_output1.bit_data.pwm_01 = 5;
|
||||||
// break;
|
// break;
|
||||||
// case TEMP_CRITICAL:
|
// case TEMP_CRITICAL:
|
||||||
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||||
// un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
// un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
publishMessage(&un_inf_can_kgf_output1, 1);
|
publishMessage(&un_inf_can_kgf_output1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 温度状态处理函数
|
// 温度状态处理函数
|
||||||
static void tempProcess(void *signal_id)
|
static void tempProcess(void *signal_id)
|
||||||
{
|
{
|
||||||
(void)signal_id;
|
(void)signal_id;
|
||||||
int16_t max_temp[4] = {0,0};
|
int16_t max_temp[4] = {0,0};
|
||||||
|
|
||||||
max_temp[0] = temp_data.current_temp[0];
|
max_temp[0] = temp_data.current_temp[0];
|
||||||
max_temp[1] = temp_data.current_temp[1];
|
max_temp[1] = temp_data.current_temp[1];
|
||||||
|
|
||||||
// printf("motor1 temp: %d, motor2 temp: %d\n", max_temp[0], max_temp[1]);
|
// printf("motor1 temp: %d, motor2 temp: %d\n", max_temp[0], max_temp[1]);
|
||||||
handleTemperatureAlarm(max_temp[0], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[0]);
|
handleTemperatureAlarm(max_temp[0], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[0]);
|
||||||
|
|
||||||
handleTemperatureAlarm(max_temp[1], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[1]);
|
handleTemperatureAlarm(max_temp[1], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[1]);
|
||||||
|
|
||||||
handleTemperatureAlarm(max_temp[2], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[2]);
|
handleTemperatureAlarm(max_temp[2], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[2]);
|
||||||
|
|
||||||
handleTemperatureAlarm(max_temp[3], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[3]);
|
handleTemperatureAlarm(max_temp[3], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[3]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if (max_temp[0] >= 60) // 假设60度为危险温度
|
// if (max_temp[0] >= 60) // 假设60度为危险温度
|
||||||
// {
|
// {
|
||||||
// temp_data.state[0] = TEMP_CRITICAL;
|
// temp_data.state[0] = TEMP_CRITICAL;
|
||||||
// }
|
// }
|
||||||
// else if (max_temp[0] >= 40) // 假设40度为警告温度
|
// else if (max_temp[0] >= 40) // 假设40度为警告温度
|
||||||
// {
|
// {
|
||||||
// temp_data.state[0] = TEMP_WARNING;
|
// temp_data.state[0] = TEMP_WARNING;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// temp_data.state[0] = TEMP_NORMAL;
|
// temp_data.state[0] = TEMP_NORMAL;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// max_temp[1] = temp_data.current_temp[1];
|
// max_temp[1] = temp_data.current_temp[1];
|
||||||
// if (max_temp[1] >= 60) // 假设60度为危险温度
|
// if (max_temp[1] >= 60) // 假设60度为危险温度
|
||||||
// {
|
// {
|
||||||
// temp_data.state[1] = TEMP_CRITICAL;
|
// temp_data.state[1] = TEMP_CRITICAL;
|
||||||
// }
|
// }
|
||||||
// else if (max_temp[1] >= 40) // 假设40度为警告温度
|
// else if (max_temp[1] >= 40) // 假设40度为警告温度
|
||||||
// {
|
// {
|
||||||
// temp_data.state[1] = TEMP_WARNING;
|
// temp_data.state[1] = TEMP_WARNING;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// temp_data.state[1] = TEMP_NORMAL;
|
// temp_data.state[1] = TEMP_NORMAL;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//// printf("motor1 temp: %d, motor2 temp: %d\n", max_temp[0], max_temp[1]);
|
//// printf("motor1 temp: %d, motor2 temp: %d\n", max_temp[0], max_temp[1]);
|
||||||
//// printf("motor1 state: %d, motor2 state: %d\n", temp_data.state[0], temp_data.state[1]);
|
//// printf("motor1 state: %d, motor2 state: %d\n", temp_data.state[0], temp_data.state[1]);
|
||||||
|
|
||||||
tempOutput(NULL);
|
tempOutput(NULL);
|
||||||
|
|
||||||
timerStart(&temp_data.timer, 1000, 1); //1s
|
timerStart(&temp_data.timer, 1000, 1); //1s
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理输入信号的函数
|
// 处理输入信号的函数
|
||||||
static void tempInput(void *signal_id)
|
static void tempInput(void *signal_id)
|
||||||
{
|
{
|
||||||
(void)signal_id;
|
(void)signal_id;
|
||||||
// 填充数据
|
// 填充数据
|
||||||
if (signal_id == &un_motor_temp1)
|
if (signal_id == &un_motor_temp1)
|
||||||
{
|
{
|
||||||
temp_data.current_temp[0] = ( (int16_t)(un_motor_temp1.bit_data.controller_temp) - 40);//40偏移量
|
temp_data.current_temp[0] = ( (int16_t)(un_motor_temp1.bit_data.controller_temp) - 40);//40偏移量
|
||||||
}
|
}
|
||||||
else if(signal_id == &un_motor_temp2)
|
else if(signal_id == &un_motor_temp2)
|
||||||
{
|
{
|
||||||
temp_data.current_temp[1] = ( (int16_t)(un_motor_temp2.bit_data.controller_temp) - 40);
|
temp_data.current_temp[1] = ( (int16_t)(un_motor_temp2.bit_data.controller_temp) - 40);
|
||||||
}
|
}
|
||||||
else if(signal_id == &un_motor_temp3)
|
else if(signal_id == &un_motor_temp3)
|
||||||
{
|
{
|
||||||
temp_data.current_temp[2] = ( (int16_t)(un_motor_temp3.bit_data.controller_temp) - 40);
|
temp_data.current_temp[2] = ( (int16_t)(un_motor_temp3.bit_data.controller_temp) - 40);
|
||||||
}
|
}
|
||||||
else if(signal_id == &un_motor_temp4)
|
else if(signal_id == &un_motor_temp4)
|
||||||
{
|
{
|
||||||
temp_data.current_temp[3] = ( (int16_t)(un_motor_temp4.bit_data.controller_temp) - 40);
|
temp_data.current_temp[3] = ( (int16_t)(un_motor_temp4.bit_data.controller_temp) - 40);
|
||||||
}
|
}
|
||||||
else{}
|
else{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// APP模块的初始化
|
// APP模块的初始化
|
||||||
void tempAppInit(void)
|
void tempAppInit(void)
|
||||||
{
|
{
|
||||||
// 初始化
|
// 初始化
|
||||||
timerInit(&temp_data.timer);
|
timerInit(&temp_data.timer);
|
||||||
|
|
||||||
memset(&temp_data, 0, sizeof(TempSystem));
|
memset(&temp_data, 0, sizeof(TempSystem));
|
||||||
temp_data.state[0] = TEMP_NORMAL;
|
temp_data.state[0] = TEMP_NORMAL;
|
||||||
temp_data.state[1] = TEMP_NORMAL;
|
temp_data.state[1] = TEMP_NORMAL;
|
||||||
temp_data.mode = TEMP_MODE_AUTO;
|
temp_data.mode = TEMP_MODE_AUTO;
|
||||||
temp_data.target_temp = 25; // 默认目标温度25度
|
temp_data.target_temp = 25; // 默认目标温度25度
|
||||||
|
|
||||||
// 订阅输入信号,处理温度逻辑
|
// 订阅输入信号,处理温度逻辑
|
||||||
subscribe(&un_motor_temp1, tempInput);
|
subscribe(&un_motor_temp1, tempInput);
|
||||||
subscribe(&un_motor_temp2, tempInput);
|
subscribe(&un_motor_temp2, tempInput);
|
||||||
subscribe(&un_motor_temp3, tempInput);
|
subscribe(&un_motor_temp3, tempInput);
|
||||||
subscribe(&un_motor_temp4, tempInput);
|
subscribe(&un_motor_temp4, tempInput);
|
||||||
|
|
||||||
// 启动定时器,每秒检查一次温度
|
// 启动定时器,每秒检查一次温度
|
||||||
subscribe(&temp_data.timer, tempProcess);
|
subscribe(&temp_data.timer, tempProcess);
|
||||||
timerStart(&temp_data.timer, 1000, 1); //1s
|
timerStart(&temp_data.timer, 1000, 1); //1s
|
||||||
|
|
||||||
printf("app_temp: initial OK \n");
|
printf("app_temp: initial OK \n");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
283
main.c
283
main.c
@@ -1,142 +1,141 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "regs_base.h"
|
#include "regs_base.h"
|
||||||
#include "irq_num.h"
|
#include "irq_num.h"
|
||||||
|
|
||||||
#include "clock_cfg.h"
|
#include "clock_cfg.h"
|
||||||
#include "reset_cfg.h"
|
#include "reset_cfg.h"
|
||||||
#include "pinmux_cfg.h"
|
#include "pinmux_cfg.h"
|
||||||
#include "eth_cfg.h"
|
#include "eth_cfg.h"
|
||||||
#include "lwip/err.h"
|
#include "lwip/err.h"
|
||||||
#include "lwip/inet.h"
|
#include "lwip/inet.h"
|
||||||
#include "lwip/tcp.h"
|
#include "lwip/tcp.h"
|
||||||
#include "lwip/timeouts.h"
|
#include "lwip/timeouts.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
#include "flexcan_cfg.h"
|
#include "flexcan_cfg.h"
|
||||||
|
|
||||||
#include "interface_config.h"
|
#include "interface_config.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
|
|
||||||
//app包含
|
//app包含
|
||||||
#include "app/app_config.h"
|
#include "app/app_config.h"
|
||||||
#include "app/app_param_manage.h"
|
#include "app/app_param_manage.h"
|
||||||
#include "app/app_power.h"
|
#include "app/app_power.h"
|
||||||
#include "app/app_brake.h"
|
#include "app/app_brake.h"
|
||||||
#include "app/app_differential_drive.h"
|
#include "app/app_differential_drive.h"
|
||||||
#include <app/app_test.h>
|
#include <app/app_test.h>
|
||||||
#include <app/app_temp.h>
|
#include <app/app_temp.h>
|
||||||
#include <app/app_light.h>
|
#include <app/app_light.h>
|
||||||
#include "app/app_request.h"
|
#include "app/app_request.h"
|
||||||
#include "app/app_ultrasonic.h"
|
#include "app/app_ultrasonic.h"
|
||||||
|
|
||||||
void testAppInit(void);
|
void testAppInit(void);
|
||||||
|
|
||||||
#define IP_ADDR0 10
|
#define IP_ADDR0 10
|
||||||
#define IP_ADDR1 18
|
#define IP_ADDR1 18
|
||||||
#define IP_ADDR2 252
|
#define IP_ADDR2 252
|
||||||
#define IP_ADDR3 34
|
#define IP_ADDR3 34
|
||||||
|
|
||||||
|
|
||||||
extern int btm_init(void);
|
extern int btm_init(void);
|
||||||
extern struct tcp_pcb *netdemo_connect_server(char *ip, int port);
|
extern struct tcp_pcb *netdemo_connect_server(char *ip, int port);
|
||||||
extern bool netdemo_tcp_connected(void);
|
extern bool netdemo_tcp_connected(void);
|
||||||
extern bool netdemo_tcp_send_done(void);
|
extern bool netdemo_tcp_send_done(void);
|
||||||
extern void netdemo_clear_tcp_send_done(void);
|
extern void netdemo_clear_tcp_send_done(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t mainCnt = 0;
|
uint8_t mainCnt = 0;
|
||||||
uint8_t mainCntarr[8] = {0x56,0x88,0x98,0x79,0x23};
|
uint8_t mainCntarr[8] = {0x56,0x88,0x98,0x79,0x23};
|
||||||
|
|
||||||
|
|
||||||
uint8_t test_app[26] = {0};
|
uint8_t test_app[26] = {0};
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
initFramework();
|
initFramework();
|
||||||
|
|
||||||
uint8_t BOOT_Arr[2] = {0x01,0x02};//上电发送app帧给上位机用
|
uint8_t BOOT_Arr[2] = {0x01,0x02};//上电发送app帧给上位机用
|
||||||
|
|
||||||
// 释放MCU各模块reset信号
|
// 释放MCU各模块reset信号
|
||||||
board_reset_init();
|
board_reset_init();
|
||||||
|
|
||||||
// 配置时钟
|
// 配置时钟
|
||||||
int ret = sdrv_ckgen_init(&g_clock_config);
|
int ret = sdrv_ckgen_init(&g_clock_config);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
// VIC初始化
|
// VIC初始化
|
||||||
irq_initialize(VIC1_BASE, IRQ_MAX_INTR_NUM);
|
irq_initialize(VIC1_BASE, IRQ_MAX_INTR_NUM);
|
||||||
|
|
||||||
// 配置pinmux
|
// 配置pinmux
|
||||||
sdrv_pinctrl_init(NUM_OF_CONFIGURED_PINS, g_pin_init_config);
|
sdrv_pinctrl_init(NUM_OF_CONFIGURED_PINS, g_pin_init_config);
|
||||||
|
|
||||||
// Timer初始化,用于提供LWIP sys_now接口获取当前时间
|
// Timer初始化,用于提供LWIP sys_now接口获取当前时间
|
||||||
btm_init();
|
btm_init();
|
||||||
|
|
||||||
// 使能打印
|
// 使能打印
|
||||||
board_debug_console_init();
|
board_debug_console_init();
|
||||||
|
|
||||||
printf("debug_console_init initial OK %d\n",getCurrentTime());
|
printf("debug_console_init initial OK %d\n",getCurrentTime());
|
||||||
//初始化所有can
|
//初始化所有can
|
||||||
initialization_All_Flexcan();
|
initialization_All_Flexcan();
|
||||||
|
|
||||||
printf("initialization_All_Flexcan initial OK %d\n",getCurrentTime());
|
printf("initialization_All_Flexcan initial OK %d\n",getCurrentTime());
|
||||||
// ETH初始化
|
// ETH初始化
|
||||||
board_eth_init();
|
board_eth_init();
|
||||||
|
|
||||||
initSpi();//初始化SPI
|
initSpi();//初始化SPI
|
||||||
|
|
||||||
//以太网端口初始化
|
//以太网端口初始化
|
||||||
UDP_Echo_Init(UDPCB_1, udp_Callback_1, COMMUNICATION_PORT);
|
UDP_Echo_Init(UDPCB_1, udp_Callback_1, COMMUNICATION_PORT);
|
||||||
UDP_Echo_Init(UDPCB_2, udp_Callback_2, UPPER_PORT);
|
UDP_Echo_Init(UDPCB_2, udp_Callback_2, UPPER_PORT);
|
||||||
UDP_Echo_Init(UDPCB_3, udp_Callback_3, PARAM_PORT);
|
UDP_Echo_Init(UDPCB_3, udp_Callback_3, PARAM_PORT);
|
||||||
UDP_Echo_Init(UDPCB_4, udp_Callback_4, DOWNLOAR_PORT);
|
UDP_Echo_Init(UDPCB_4, udp_Callback_4, DOWNLOAR_PORT);
|
||||||
UDP_Echo_Init(UDPCB_5, udp_Callback_5, WDT_PORT);
|
UDP_Echo_Init(UDPCB_5, udp_Callback_5, WDT_PORT);
|
||||||
|
|
||||||
printf("board_eth_init initial OK %d\n",getCurrentTime());
|
printf("board_eth_init initial OK %d\n",getCurrentTime());
|
||||||
//读取重启标志
|
//读取重启标志
|
||||||
g_systemDataRecord.canBootloaderUpgrade = rdbyte_24c02(0x00);
|
g_systemDataRecord.canBootloaderUpgrade = rdbyte_24c02(0x00);
|
||||||
printf("rdbyte_24c02 OK %d\n",getCurrentTime());
|
printf("rdbyte_24c02 OK %d\n",getCurrentTime());
|
||||||
|
|
||||||
ethernet_parameter.download_ip[0] = rdbyte_24c02(BOOT_DES_IP);//读取下载的IP
|
ethernet_parameter.download_ip[0] = rdbyte_24c02(BOOT_DES_IP);//读取下载的IP
|
||||||
ethernet_parameter.download_ip[1] = rdbyte_24c02(BOOT_DES_IP+1);//读取下载的IP
|
ethernet_parameter.download_ip[1] = rdbyte_24c02(BOOT_DES_IP+1);//读取下载的IP
|
||||||
ethernet_parameter.download_ip[2] = rdbyte_24c02(BOOT_DES_IP+2);//读取下载的IP
|
ethernet_parameter.download_ip[2] = rdbyte_24c02(BOOT_DES_IP+2);//读取下载的IP
|
||||||
ethernet_parameter.download_ip[3] = rdbyte_24c02(BOOT_DES_IP+3);//读取下载的IP
|
ethernet_parameter.download_ip[3] = rdbyte_24c02(BOOT_DES_IP+3);//读取下载的IP
|
||||||
|
|
||||||
//发送重启后的第一帧给上位机
|
//发送重启后的第一帧给上位机
|
||||||
CAN_Send_Msg(&can_handle_6,OTA_CANTxID, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, BOOT_Arr,2, TX_MB_INDEX);//app 帧
|
CAN_Send_Msg(&can_handle_6,OTA_CANTxID, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, BOOT_Arr,2, TX_MB_INDEX);//app 帧
|
||||||
|
|
||||||
printf("CAN_Send_Msg can_handle_6 OK %d\n",getCurrentTime());
|
printf("CAN_Send_Msg can_handle_6 OK %d\n",getCurrentTime());
|
||||||
|
|
||||||
|
|
||||||
//打印版本号
|
//打印版本号
|
||||||
printf("version: V1.72 \n");
|
printf("version: V1.72 \n");
|
||||||
// 初始化框架 放在最前面,解决电机can发送信号累积不处理的问题。
|
// 初始化框架 放在最前面,解决电机can发送信号累积不处理的问题。
|
||||||
|
|
||||||
testAppInit();
|
testAppInit();
|
||||||
paramAppInit();
|
paramAppInit();
|
||||||
diffAppInit();
|
diffAppInit();
|
||||||
brakeAppInit();
|
brakeAppInit();
|
||||||
powerAppInit(); //电源管理
|
powerAppInit(); //电源管理
|
||||||
tempAppInit(); //温度
|
tempAppInit(); //温度
|
||||||
lightAppInit(); //灯光
|
lightAppInit(); //灯光
|
||||||
ethernetInterfaceInit(); //以太网先初始化
|
ethernetInterfaceInit(); //以太网先初始化
|
||||||
requestAppInit();
|
requestAppInit();
|
||||||
canInterfaceInit();
|
canInterfaceInit();
|
||||||
bootInterfaceInit();
|
bootInterfaceInit();
|
||||||
// ultrasonicAppInit();
|
// ultrasonicAppInit();
|
||||||
|
|
||||||
printf("All init OK ------ %d\n",getCurrentTime());
|
printf("All init OK ------ %d\n",getCurrentTime());
|
||||||
|
|
||||||
sdrv_gpio_set_pin_output_level(GPIO_B9, 1); //测量时间
|
for (;;)
|
||||||
for (;;)
|
{
|
||||||
{
|
// 处理信号
|
||||||
// 处理信号
|
processMessages();
|
||||||
processMessages();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user