|
@@ -1,14 +1,26 @@
|
|
|
#include "gas_sensor.h"
|
|
|
#include "math_tools.h"
|
|
|
+#include "log_save.h"
|
|
|
|
|
|
uint16_t GasSensor_OffSet = 0;
|
|
|
|
|
|
#define ZeroOffSetData 100
|
|
|
+TrueOrFalse_Flag_Struct_t IsGasSensorConnectedFlag = FALSE;
|
|
|
|
|
|
//指拨零点值初始化
|
|
|
void GasSensorOffSet_Init(uint16_t* OffSet, uint16_t AdcData)
|
|
|
{
|
|
|
- *OffSet = AdcData + ZeroOffSetData;
|
|
|
+ //根据开始时刻采集值判断是否连接转把
|
|
|
+ if(AdcData < 300)
|
|
|
+ {
|
|
|
+ IsGasSensorConnectedFlag = FALSE;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IsGasSensorConnectedFlag = TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ *OffSet = AdcData + ZeroOffSetData;
|
|
|
}
|
|
|
|
|
|
//指拨零点值更新
|
|
@@ -16,7 +28,7 @@ void GasSensorOffSetData_Update(uint16_t* PresentData, uint16_t AdcData, MC_Erro
|
|
|
{
|
|
|
static uint16_t Array[50];
|
|
|
static TrueOrFalse_Flag_Struct_t IsArrayFullFalg = FALSE;
|
|
|
- uint8_t i = 0;
|
|
|
+ static uint8_t i = 0;
|
|
|
uint16_t TempData;
|
|
|
static uint32_t ErrorDelayTimeCnt = 0;
|
|
|
|
|
@@ -37,18 +49,31 @@ void GasSensorOffSetData_Update(uint16_t* PresentData, uint16_t AdcData, MC_Erro
|
|
|
if(TempData < *PresentData)
|
|
|
{
|
|
|
//更新零点值
|
|
|
- *PresentData = TempData;
|
|
|
+ if(TempData > 300)//避免线缆松脱导致零点变为异常值
|
|
|
+ {
|
|
|
+ *PresentData = TempData;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//判断零点是否超出范围
|
|
|
- if(*PresentData <= 1500)
|
|
|
+ if(p_MC_ErrorCode->ERROR_Bit.Fault_GasSensor == 0)
|
|
|
{
|
|
|
- ErrorDelayTimeCnt = HAL_GetTick();
|
|
|
- p_MC_ErrorCode->ERROR_Bit.Fault_GasSensor = 0;
|
|
|
- }
|
|
|
- if((HAL_GetTick() - ErrorDelayTimeCnt) > 10000)
|
|
|
- {
|
|
|
- p_MC_ErrorCode->ERROR_Bit.Fault_GasSensor = 1;
|
|
|
+ if(*PresentData <= 1500)
|
|
|
+ {
|
|
|
+ ErrorDelayTimeCnt = HAL_GetTick();
|
|
|
+ }
|
|
|
+ if((HAL_GetTick() - ErrorDelayTimeCnt) > 10000)
|
|
|
+ {
|
|
|
+ p_MC_ErrorCode->ERROR_Bit.Fault_GasSensor = 1;
|
|
|
+ //记录故障日志
|
|
|
+ MC_ErrorLogSaveInfo.NotesInfo1 = 1;
|
|
|
+ MC_ErrorLogSaveInfo.NotesInfo2 = *PresentData;
|
|
|
+ ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
|
|
|
+ IsErrorLogSaveInfoUpdateFlag = TRUE;
|
|
|
+ //存储故障次数
|
|
|
+ MC_RunLog2.GasSensor_FaultCnt++;
|
|
|
+ RunLogSaveIndex = 2;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|