This commit is contained in:
2026-03-20 21:19:04 +08:00
parent 90c3d919df
commit 9d3b4b836f
247 changed files with 22127 additions and 30305 deletions

109
user/Compute/FlowRateCompute.c Executable file → Normal file
View File

@@ -15,19 +15,29 @@ u32 maxAlarmFlowRate;
u16 leakDetectLowCounter, leakDetectHighCounter, leakDetectCounter;
#endif
/******************************************************************************/
u32 GetFlowRate(u16 flowIndex, u16 curveType)
{
u16 indexL, dataCompFac;
u8 temp[12];
switch(curveType)
{
case CURVE_1ST:
// if(flowIndex > 32767) return 0;
// else if(flowIndex < zeroSuppression) return 0;
// else if(flowIndex >= CALIB_MAX_INDEX) flowIndex = CALIB_MAX_INDEX;
// dataCompFac = DATA_COMP_FAC;
// indexL = CALI_DATA_ADDR;
if(flowIndex > 32767) return 0;
else if(flowIndex < zeroSuppression) return 0;
else if(flowIndex >= CALIB_MAX_INDEX) flowIndex = CALIB_MAX_INDEX;
// else if(flowIndex < zeroSuppression) return 0;
else if(flowIndex >= CALIB_MAX_INDEX) flowIndex = CALIB_MAX_INDEX; //MAX_INDEX
dataCompFac = CALIB_COMP_FAC;
indexL = CALI_DATA_ADDR;
//indexL = (CORRECT_DATA_ADDR&0xFFFF);
indexL = 0 ;//<2F><>CORRECT_DATA[0]<5D><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ڴ<EFBFBD>0<EFBFBD><30>ַ<EFBFBD><D6B7>ʼȡ
break;
//------------------------------------------------------------------------
@@ -35,8 +45,7 @@ u32 GetFlowRate(u16 flowIndex, u16 curveType)
#pragma message("[undefined] ENABLE_2ND_CURVE")
#elif(ENABLE_2ND_CURVE)
case CURVE_2ND:
dataCompFac = CALIB_COMP_FAC2;
indexL = CALI_DATA2_ADDR;
break;
#endif
@@ -47,19 +56,20 @@ u32 GetFlowRate(u16 flowIndex, u16 curveType)
case CURVE_3RD:
if(flowIndex > 32767) return 0;
else if(flowIndex < zeroSuppression) return 0;
else if(flowIndex >= CALIB_MAX_INDEX3) flowIndex = CALIB_MAX_INDEX;
dataCompFac = CALIB_COMP_FAC3;
else if(flowIndex >= MAX_INDEX3) flowIndex = CALIB_MAX_INDEX;
dataCompFac = DATA_COMP_FAC3;
indexL = CALI_DATA3_ADDR;
break;
#endif
#endif
default: return 0;
}
//240000-3*4 2*4096*6=48828-6*4
if(flowIndex > (CALIB_MAX_INDEX - dataCompFac*4)) {
indexL += (CALIB_MAX_INDEX / dataCompFac - 1)*3;
ReadCalbrationDataFromMemory(indexL, &tempDev.Byte[0], 3);
if(flowIndex > (CALIB_MAX_INDEX - dataCompFac*4))//240000-3*4 2*4096*6=48828-6*4
{
indexL += (CALIB_MAX_INDEX / dataCompFac - 1)*3;
//ReadMultiByteFromEEPROM(indexL, &tempDev.Byte[0], 3, PARA_EEPROM);
ReadDataFromFlash(indexL, &tempDev.Byte[0], 3);
tempDev.Byte[3] = 0;
return tempDev.DWord[0];
@@ -72,29 +82,34 @@ u32 GetFlowRate(u16 flowIndex, u16 curveType)
index0 = flowIndex / dataCompFac;
indexL += index0*3;
ReadCalbrationDataFromMemory(indexL-3, temp, 12);
//ReadMultiByteFromEEPROM(indexL-3, temp, 12, PARA_EEPROM);
ReadDataFromFlash(indexL-3, temp, 12);
tmpLA = 0;
tmpLB = 0xffffffff;
for(K=0, J=0; K<4; K++) {
for(K=0, J=0; K<4; K++)
{
tempL.Byte[0] = temp[J++];
tempL.Byte[1] = temp[J++];
tempL.Byte[2] = temp[J++];
tempL.Byte[3] = 0;
tempFR[K] = tempL.DWord;
if(tempL.DWord > tmpLA) {
if(tempL.DWord > tmpLA)
{
tmpLA = tempL.DWord;
IndexA = K;
}
if(tempL.DWord < tmpLB) {
if(tempL.DWord < tmpLB)
{
tmpLB = tempL.DWord;
IndexB = K;
}
}
for(K=0, J=0; K<4; K++) {
for(K=0, J=0; K<4; K++)
{
if(K == IndexA) continue;
if(K == IndexB) continue;
temp[J] = K;
@@ -114,12 +129,14 @@ u32 GetFlowRate(u16 flowIndex, u16 curveType)
indexD += dataCompFac;
tmpSLB -= tmpSLA;
if(indexD > IndexA) {
if(indexD > IndexA)
{
tmpSLB *= (u32)(indexD-IndexA);
tmpSLB /= (u32)IndexB;
tmpSLA += tmpSLB;
}
else {
else
{
tmpSLB *= (u32)(IndexA-indexD);
tmpSLB /= (u32)IndexB;
tmpSLA -= tmpSLB;
@@ -311,13 +328,13 @@ void FlowRateLeakDetect(void)
return;
}
// if((leakDetectTime == 0) || (sampleState.EnableRoughTest))
// {
// leakDetectCounter = 0;
// leakDetectHighCounter = 0;
// leakDetectLowCounter = 0;
// return;
// }
if((leakDetectTime == 0) || (sampleState.EnableRoughTest))
{
leakDetectCounter = 0;
leakDetectHighCounter = 0;
leakDetectLowCounter = 0;
return;
}
//---------------------------------------------------------------------------
if(flowRate < minLeakFlowRate)
@@ -361,3 +378,39 @@ void FlowRateLeakDetect(void)
}
#endif
//******************************************************************************
#ifndef ENABLE_USER_UART
#pragma message("[undefined] ENABLE_USER_UART")
#elif(ENABLE_FLOW_GAIN)
u16 JudgeFlowRateGain(u16 flowGain)
{
switch(flowGain)
{
case 1: return 0;
//--------------------------------------------------------------------------
#ifndef FLOW_GAIN_MAX
#pragma message("[undefined] FLOW_GAIN_MAX")
#elif(FLOW_GAIN_MAX >= 10)
case 10: return 0;
#endif
//--------------------------------------------------------------------------
#ifndef FLOW_GAIN_MAX
#pragma message("[undefined] FLOW_GAIN_MAX")
#elif(FLOW_GAIN_MAX >= 100)
case 100: return 0;
#endif
//--------------------------------------------------------------------------
#ifndef FLOW_GAIN_MAX
#pragma message("[undefined] FLOW_GAIN_MAX")
#elif(FLOW_GAIN_MAX >= 1000)
case 1000: return 0;
#endif
default: return 1;
}
}
#endif