/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file fault_probe.c
* @author Motor Control SDK Team, Yuwell Software XiangenWang
* @brief Voice Recognition Module Initialization Section,
including peripheral initialization and message node insertion, etc.
* @version 1.0
* @changelog version 1.0 初始版本 2025.11.13
- 新增:新建第一个版本的软件,待完善解析命令后的程序执行部分
******************************************************************************
* @attention
*
*
© Copyright (c) 2025 Yuwell Software Danyang.Jiangsu.China.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Yuwell Software nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for Yuwell Software.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY Yuwell Software AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL Yuwell Software OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* USER CODE END Header */
#include "fault_probe.h"
FaultInfo fault_info;
void fault_array_init(void)
{
MsgQueueItem msg_item;
// 初始化报警器所在GPIO
FL_GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.pin = BEEP_GPIO_PIN;
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = FL_ENABLE;
GPIO_InitStruct.remapPin = FL_DISABLE;
GPIO_InitStruct.analogSwitch = FL_DISABLE;
FL_GPIO_Init(BEEP_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.pin = BEEP_LIGHT_GPIO_PIN;
FL_GPIO_Init(BEEP_LIGHT_GPIO_PORT, &GPIO_InitStruct);
// 获取当前队列中的边界消息 更新故障数组
peek_queue_node_by_type(&global_queue, MSG_TYPE_AD_BOUNDARY_SEND, &msg_item);
fault_info.elec_low_boundary = msg_item.data.adc_boundary.elec_low_boundary;
fault_info.elec_high_boundary = msg_item.data.adc_boundary.elec_high_boundary;
fault_info.ntc_low_boundary = msg_item.data.adc_boundary.ntc_low_boundary;
fault_info.ntc_high_boundary = msg_item.data.adc_boundary.ntc_high_boundary;
fault_info.press_low_boundary = msg_item.data.adc_boundary.press_low_boundary;
fault_info.press_high_boundary = msg_item.data.adc_boundary.press_high_boundary;
fault_info.net220v_low_boundary = msg_item.data.adc_boundary.net220v_low_boundary;
fault_info.net220v_high_boundary = msg_item.data.adc_boundary.net220v_high_boundary;
// 初始化故障为未发生状态
fault_info.e1_press_low_state = NO_HAPPEN;
fault_info.e2_press_high_state = NO_HAPPEN;
fault_info.e3_elec_low_state = NO_HAPPEN;
fault_info.e4_elec_high_state = NO_HAPPEN;
fault_info.e5_ntc_high_state = NO_HAPPEN;
fault_info.ll_flow_low_state = NO_HAPPEN;
fault_info.e7_net220v_low_state = NO_HAPPEN;
fault_info.O2_900_low_state = NO_HAPPEN;
fault_info.O2_835_low_state = NO_HAPPEN;
BEEP_LIGHT_ON;
}
void fault_process_task(void)
{
static uint32_t e1_press_low_count = 0;
static uint32_t e2_press_high_count = 0;
static uint32_t e3_elec_low_count = 0;
static uint32_t e4_elec_high_count = 0;
static uint32_t e5_ntc_high_count = 0;
static uint32_t ll_flow_low_count = 0;
static uint32_t e7_220v_low_count = 0;
static uint32_t o2_835_low_count = 0;
// 依次判定故障
MsgQueueItem o2_sensor_item;
MsgQueueItem adc_sample_item;
MsgQueueItem currentTime_item;
MsgQueueItem stm_item;
// 判定当前状态机是否为调试模式或校准模式 若是不判定故障立即返回 否则执行
if(peek_queue_node_by_type(&global_queue, MSG_TYPE_OXG_STM, &stm_item))
{
switch(stm_item.data.state_machine.oxg_stm)
{
case STM_CARLIB:
case STM_DEBUG: // 插入短路块时不进行检查
return;
case STM_ERROR_NONE_STOP:
// O90 O8335 E7
if(xOxygenEventGroupCheckBit(&global_event, EVENT_O2_900_LOW)) // 浓度低于90事件发生不报警
{
BEEP_OFF;
}
if(xOxygenEventGroupCheckAnyBits(&global_event, EVENT_O2_835_LOW | EVENT_E7_220V_LOW))
{
if(xOxygenEventGroupCheckBit(&global_event, EVENT_BEEP_MUTE))
{
BEEP_OFF; // 发生静音事件则关闭报警
}else{
BEEP_ON;
}
}
break;
case STM_ERROR_SHOUNTDOWN: // 报警器响起
if(xOxygenEventGroupCheckBit(&global_event, EVENT_BEEP_MUTE))
{
BEEP_OFF; // 发生静音事件则关闭报警
}else{
BEEP_ON;
}
break;
default: // 默认情况下进行故障检查
break;
}
}
// 获取当前的氧浓度数据并判定是否发生了故障
if(peek_queue_node_by_type(&global_queue, MSG_TYPE_OXYGEN_SENSOR, &o2_sensor_item))
{
fault_info.O2_900_low_state = (o2_sensor_item.data.oxygen.concentration < O2_90_PERCENT_BOUNDARY) ? YES_HAPPEND:NO_HAPPEN;
fault_info.O2_835_low_state = (o2_sensor_item.data.oxygen.concentration < O2_83P5_PERCENT_BOUNDARY) ? YES_HAPPEND:NO_HAPPEN;
fault_info.ll_flow_low_state = (o2_sensor_item.data.oxygen.flow_rate < LL_FLOW_BOUNDARY) ? YES_HAPPEND:NO_HAPPEN;
}else{
return;
}
// 获取当前的ADC数据并判定是否发生了故障
if(peek_queue_node_by_type(&global_queue, MSG_TYPE_AD_SAMPLING, &adc_sample_item))
{
fault_info.e1_press_low_state = (adc_sample_item.data.adc_data.real_press < fault_info.press_low_boundary) ? YES_HAPPEND:NO_HAPPEN;
fault_info.e2_press_high_state = (adc_sample_item.data.adc_data.real_press > fault_info.press_high_boundary) ? YES_HAPPEND:NO_HAPPEN;
fault_info.e3_elec_low_state = (adc_sample_item.data.adc_data.real_elec < fault_info.elec_low_boundary) ? YES_HAPPEND:NO_HAPPEN;
fault_info.e4_elec_high_state = (adc_sample_item.data.adc_data.real_elec > fault_info.elec_high_boundary) ? YES_HAPPEND:NO_HAPPEN;
fault_info.e5_ntc_high_state = (adc_sample_item.data.adc_data.real_ntc > fault_info.ntc_high_boundary) ? YES_HAPPEND:NO_HAPPEN;
fault_info.e7_net220v_low_state = (adc_sample_item.data.adc_data.real_220V < fault_info.net220v_low_boundary) ? YES_HAPPEND:NO_HAPPEN;
}else{
return;
}
// 多种故障类型判定
if(peek_queue_node_by_type(&global_queue, MSG_TYPE_CURRENT_TIME, ¤tTime_item))
{
// E1故障判定 开机4min后,连续8秒仍旧气压低则判定发生E1事件
if((currentTime_item.data.hour_meter.minute >= 4)||(currentTime_item.data.hour_meter.hour >= 1))
{
if(fault_info.e1_press_low_state == YES_HAPPEND)
{
if(e1_press_low_count >= 80) // 连续八秒发生气压过低事件
{
vOxygenEventGroupSetBits(&global_event, EVENT_E1_PRESS_LOW); // 标记此时发生了E1事件
}else{
e1_press_low_count++;
}
}else{
e1_press_low_count = 0;
// vOxygenEventGroupClearBits(&global_event, EVENT_E1_PRESS_LOW); // 清空E1事件
}
}
// E2故障判定 开机25秒后,连续0.5秒仍旧发生高压事件则发生E2事件
if((currentTime_item.data.hour_meter.second > 25)||(currentTime_item.data.hour_meter.minute >= 1)||(currentTime_item.data.hour_meter.hour >= 1))
{
if(fault_info.e2_press_high_state == YES_HAPPEND)
{
if(e2_press_high_count >= 5)
{
vOxygenEventGroupSetBits(&global_event, EVENT_E2_PRESS_HIGH); // 标记此时发生了E2事件
}else{
e2_press_high_count++;
}
}else{
e2_press_high_count = 0;
// vOxygenEventGroupClearBits(&global_event, EVENT_E2_PRESS_HIGH); // 清空E2事件
}
}
// E3故障判定 开机后连续8s电流低则发生E3事件
if(fault_info.e3_elec_low_state == YES_HAPPEND)
{
if(e3_elec_low_count >= 80)
{
vOxygenEventGroupSetBits(&global_event, EVENT_E3_ELEC_LOW); // 标记此时发生了E3事件
}else{
e3_elec_low_count++;
}
}else{
e3_elec_low_count = 0;
vOxygenEventGroupClearBits(&global_event, EVENT_E3_ELEC_LOW);
}
// E4故障判定 开机后持续检测若连续8s电流过高则报警
if(fault_info.e4_elec_high_state == YES_HAPPEND)
{
if(e4_elec_high_count >= 80)
{
vOxygenEventGroupSetBits(&global_event, EVENT_E4_ELEC_HIGH); // 标记此时发生了E4事件
}else{
e4_elec_high_count++;
}
}else{
e4_elec_high_count = 0;
// vOxygenEventGroupClearBits(&global_event, EVENT_E4_ELEC_HIGH);
}
// E5故障判定 开机后2min 连续4s温度高
if((currentTime_item.data.hour_meter.minute >= 2)||(currentTime_item.data.hour_meter.hour >= 1))
{
if(fault_info.e5_ntc_high_state == YES_HAPPEND)
{
if(e5_ntc_high_count >= 40)
{
vOxygenEventGroupSetBits(&global_event, EVENT_E5_NTC_HIGH); // 标记此时发生了E5事件
}else{
e5_ntc_high_count++;
}
}else{
e5_ntc_high_count = 0;
// vOxygenEventGroupClearBits(&global_event, EVENT_E5_NTC_HIGH);
}
}
// LL判定
if(fault_info.ll_flow_low_state == YES_HAPPEND)
{
if(ll_flow_low_count >= 320)
{
vOxygenEventGroupSetBits(&global_event, EVENT_LL_FLOW_LOW); // 标记此时发生了LL事件
}else{
ll_flow_low_count++;
}
}else{
ll_flow_low_count = 0;
// vOxygenEventGroupClearBits(&global_event, EVENT_LL_FLOW_LOW);
}
// E7判定
if((currentTime_item.data.hour_meter.minute >= 5)||(currentTime_item.data.hour_meter.hour >= 1))
{
if(fault_info.e7_net220v_low_state == YES_HAPPEND)
{
if(e7_220v_low_count >= 80)
{
vOxygenEventGroupSetBits(&global_event, EVENT_E7_220V_LOW); // 标记此时发生了E7事件
}else{
e7_220v_low_count++;
}
}else{
e7_220v_low_count = 0;
vOxygenEventGroupClearBits(&global_event, EVENT_E7_220V_LOW);
}
}
// O2浓度低判定
if(((currentTime_item.data.hour_meter.minute >= 2)&&(currentTime_item.data.hour_meter.hour == 0)) &&
((currentTime_item.data.hour_meter.minute <= 5)&&(currentTime_item.data.hour_meter.hour == 0)))
{
if(fault_info.O2_900_low_state == YES_HAPPEND)
{
// 开机2-5min若出现浓度低于90% 亮灯不停机 不报警
vOxygenEventGroupSetBits(&global_event, EVENT_O2_900_LOW); // 标记此时发生了浓度低于90%事件
}
}else{
// 开机5min后不管浓度低于90的事情
vOxygenEventGroupClearBits(&global_event, EVENT_O2_900_LOW);
}
if((currentTime_item.data.hour_meter.minute >= 5)||(currentTime_item.data.hour_meter.hour >= 1))
{
if(fault_info.O2_835_low_state == YES_HAPPEND)
{
if(o2_835_low_count >= 600)
{
vOxygenEventGroupSetBits(&global_event, EVENT_O2_835_LOW); // 标记此时发生了浓度低于83.5%事件
}else{
o2_835_low_count++;
}
}else{
o2_835_low_count = 0;
vOxygenEventGroupClearBits(&global_event, EVENT_O2_835_LOW);
}
}
}
}
/************************ (C) COPYRIGHT FMSH *****END OF FILE****/