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

0
user/Compute/ATypeFlowRate.c Executable file → Normal file
View File

0
user/Compute/ATypeFlowRate.h Executable file → Normal file
View File

64
user/Compute/AccCompute.c Executable file → Normal file
View File

@@ -7,9 +7,6 @@ u16 totalPulse;
u8 MemoryPointer;
u16 flowAccCumulationRemaining, samplingIntervalForTotal;
//#define REC_PULSE_REMAINING
//#define PULSE_COUNTER
/******************************************************************************/
void ReleaseTotalToDisArray(void)
{
@@ -158,36 +155,36 @@ u16 FRAMWriteTotal(void)
// write to first bank and second bank and update EPROMPointer
// input: voltAcc, voltAcc0, EPROMPointer
// output: EPROMPointer
u16 blockAddr, I;
unsigned int blockAddr, I;
u8 temp[7], WriteCounter=0;
FRAMWriteRepeat:
MemoryPointer++;
WriteCounter++;
if (MemoryPointer > REC_ACC_DEPTH) MemoryPointer = 0;
if (WriteCounter > REC_ACC_DEPTH) return 1;
if (MemoryPointer > REC_DEPTH) MemoryPointer = 0;
if (WriteCounter > REC_DEPTH) return 1;
blockAddr = REC_ACC_BASE + MemoryPointer * REC_ACC_WIDTH;
blockAddr = REC_BASE + MemoryPointer * REC_WIDTH;
WriteMultiByteToFRAM(blockAddr,Total,7);
ReadMultiByteFromFRAM(blockAddr,temp,7);
for(I=0; I < (u16)ACC_BLOCK_WIDTH; I++)
for(I=0; I < (u16)BLOCK_WIDTH; I++)
{
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
}
blockAddr += ACC_BLOCK2_START;
blockAddr += BLOCK2_START;
WriteMultiByteToFRAM(blockAddr,Total,7);
ReadMultiByteFromFRAM(blockAddr,temp,7);
for(I=0; I<ACC_BLOCK_WIDTH; I++)
for(I=0; I<BLOCK_WIDTH; I++)
{
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
}
// blockAddr = REC_PULSE_REMAINING + MemoryPointer * PULSE_REMAINING_WIDTH;
// tempDev.DWord[0] = lastRemaining;
// tempDev.Byte[PULSE_REMAINING_CRC] = CRC8(tempDev.Byte, PULSE_REMAINING_CRC);
// WriteMultiByteToFRAM(blockAddr,tempDev.Byte,PULSE_REMAINING_WIDTH);
blockAddr = REC_PULSE_REMAINING + MemoryPointer * PULSE_REMAINING_WIDTH;
tempDev.DWord[0] = lastRemaining;
tempDev.Byte[PULSE_REMAINING_CRC] = CRC8(tempDev.Byte, PULSE_REMAINING_CRC);
WriteMultiByteToFRAM(blockAddr,tempDev.Byte,PULSE_REMAINING_WIDTH);
//tempDev.DWord[0] = pulseCounter;
//tempDev.Byte[PULSE_COUNTER_CRC] = CRC8(tempDev.Byte, PULSE_COUNTER_CRC);
@@ -203,9 +200,9 @@ u16 FRAMCheckSaveTotalFlow(u8 Pointer)
u8 block1[7], block2[7];
u16 blockAddr, I;
blockAddr = REC_ACC_BASE + Pointer * REC_ACC_WIDTH;
blockAddr = REC_BASE + Pointer * REC_WIDTH;
ReadMultiByteFromFRAM(blockAddr, block1, 7);
blockAddr += ACC_BLOCK2_START;
blockAddr += BLOCK2_START;
ReadMultiByteFromFRAM(blockAddr, block2, 7);
if(block1[CRC_CHK] != CRC8(block1, 6)) return false;
@@ -229,14 +226,15 @@ u16 RetrieveLastAccumulationFromFRAM(void)
{
u32 voltPartA, tempPartA;
u16 voltPartB, tempPartB;
u8 I, max_g;
u8 good_ind[REC_ACC_DEPTH+1];
unsigned char I, max_g;
unsigned char good_ind[REC_DEPTH+1];
// if(ReadFRAMDeviceID()) return 0;
if(ReadFRAMDeviceID()) return 0;
//find EPROMPointer with good data
max_g = 0;
for(I = 0; I <= REC_ACC_DEPTH; I++) {
for(I = 0; I <= REC_DEPTH; I++)
{
if(FRAMCheckSaveTotalFlow(I)) { good_ind[max_g] = I; max_g++; }
}
if(max_g == 0) return 0;
@@ -245,8 +243,11 @@ u16 RetrieveLastAccumulationFromFRAM(void)
voltPartA = 0;
voltPartB = 0;
MemoryPointer = 0;
for(I = 0; I < max_g; I++) {
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)good_ind[I]* REC_ACC_WIDTH, Total, 7);
for(I = 0; I < max_g; I++)
{
ReadMultiByteFromFRAM(REC_BASE + (u16)good_ind[I]* REC_WIDTH, Total, 7);
//tempPartA = make32(Total[0],Total[1],Total[2],Total[3]);
//tempPartB = make16(Total[4],Total[5]);
tempL.Byte[3] = Total[0];
tempL.Byte[2] = Total[1];
tempL.Byte[1] = Total[2];
@@ -268,12 +269,12 @@ u16 RetrieveLastAccumulationFromFRAM(void)
MemoryPointer = good_ind[I];
}
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)MemoryPointer* REC_ACC_WIDTH, Total, 7);
ReadMultiByteFromFRAM(REC_BASE + (u16)MemoryPointer* REC_WIDTH, Total, 7);
ReleaseTotalToDisArray();
// ReadMultiByteFromFRAM(REC_PULSE_REMAINING+ MemoryPointer * PULSE_REMAINING_WIDTH, tempDev.Byte, PULSE_REMAINING_WIDTH);
// if(tempDev.Byte[PULSE_REMAINING_CRC] != CRC8(tempDev.Byte, PULSE_REMAINING_CRC)) lastRemaining = 0;
// else lastRemaining = tempDev.DWord[0];
ReadMultiByteFromFRAM(REC_PULSE_REMAINING+ MemoryPointer * PULSE_REMAINING_WIDTH, tempDev.Byte, PULSE_REMAINING_WIDTH);
if(tempDev.Byte[PULSE_REMAINING_CRC] != CRC8(tempDev.Byte, PULSE_REMAINING_CRC)) lastRemaining = 0;
else lastRemaining = tempDev.DWord[0];
//ReadMultiByteFromFRAM(PULSE_COUNTER, tempDev.Byte, PULSE_COUNTER_WIDTH);
//if(tempDev.Byte[PULSE_COUNTER_CRC] != CRC8(tempDev.Byte, PULSE_COUNTER_CRC)) pulseCounter = 0;
@@ -462,12 +463,11 @@ void ComputeFlowRateToTotal(void)
#ifndef ENABLE_ACCPULSE
#pragma message("[undefined] ENABLE_ACCPULSE")
#elif(ENABLE_ACCPULSE)
// lastRemaining += (u32)tempInt;
// totalPulse = (u16)(lastRemaining / unitPerPulse);
// lastRemaining -= (u32)totalPulse * (u32)unitPerPulse;
// if(totalPulse > MaxPulseOutput[samplingIntervalForTotal]) totalPulse = MaxPulseOutput[samplingIntervalForTotal];
lastRemaining += (u32)tempInt;
totalPulse = (u16)(lastRemaining / unitPerPulse);
lastRemaining -= (u32)totalPulse * (u32)unitPerPulse;
if(totalPulse > MaxPulseOutput[samplingIntervalForTotal]) totalPulse = MaxPulseOutput[samplingIntervalForTotal];
#endif
//------------------------------------------------------------------------------
#ifndef REC_ACC_PER
#pragma message("[undefined] REC_ACC_PER")
@@ -501,7 +501,7 @@ void SetupACCArray(void)
#ifndef REC_ACC_PER
#pragma message("[undefined] REC_ACC_PER")
#elif(REC_ACC_PER)
for(I=0; I <= REC_ACC_DEPTH; I++) FRAMWriteTotal();
for(I=0; I <= REC_DEPTH; I++) FRAMWriteTotal();
#endif
}

22
user/Compute/AccCompute.h Executable file → Normal file
View File

@@ -54,19 +54,19 @@
// ACC Data save
// For FRAM(< 0x0800)
// For EEPROM(< 0x0200)
//#define REC_BASE 0x0100 // the start EEPROM address of acc data
//#define REC_WIDTH 14
//#define BLOCK_WIDTH 7 // 0x100(256) + 14*4 = 0x138(312)
//#define BLOCK2_START 0x140 // 0x180(256) + 14*4 = 0x1B8
//#define REC_DEPTH 4
#define REC_BASE 0x0100 // the start EEPROM address of acc data
#define REC_WIDTH 14
#define BLOCK_WIDTH 7 // 0x100(256) + 14*4 = 0x138(312)
#define BLOCK2_START 0x140 // 0x180(256) + 14*4 = 0x1B8
#define REC_DEPTH 4
//#define REC_PULSE_REMAINING 0x01D0 // 0x1D0(256) + 20 = 0x1E4
//#define PULSE_REMAINING_WIDTH 5
//#define PULSE_REMAINING_CRC (PULSE_REMAINING_WIDTH-1)
#define REC_PULSE_REMAINING 0x01D0 // 0x1D0(256) + 20 = 0x1E4
#define PULSE_REMAINING_WIDTH 5
#define PULSE_REMAINING_CRC (PULSE_REMAINING_WIDTH-1)
//#define PULSE_COUNTER 0x01F0 // 0x1D0(256) + 20 = 0x1E4
//#define PULSE_COUNTER_WIDTH 5
//#define PULSE_COUNTER_CRC (PULSE_COUNTER_WIDTH-1)
#define PULSE_COUNTER 0x01F0 // 0x1D0(256) + 20 = 0x1E4
#define PULSE_COUNTER_WIDTH 5
#define PULSE_COUNTER_CRC (PULSE_COUNTER_WIDTH-1)
//------------------------------------------------------------------------------
//#define REC_BASE_WIDTH ()

0
user/Compute/AdjustOffset.c Executable file → Normal file
View File

0
user/Compute/AdjustOffset.h Executable file → Normal file
View File

0
user/Compute/CheckSystemVoltage.c Executable file → Normal file
View File

0
user/Compute/CheckSystemVoltage.h Executable file → Normal file
View File

15
user/Compute/Correct.c Executable file → Normal file
View File

@@ -3,7 +3,7 @@
u32 dcoefNode[DCOEF_MAX];
u16 dcoef, dcoefVal[DCOEF_MAX];
float GCFParaA, GCFParaB, GCFParaC;
u16 GCFCoefB;
u16 MeterFactor,GCFCoefB;
s32 GCFCoefA, GCFCoefC;
float GCFParaA, GCFParaB, GCFParaC;
//u16 dcoefNum;
@@ -17,14 +17,14 @@ void StoreDevCoefNodeAndValue(unsigned char I)
tempDev.Word[1] = tempL.Word[0];
tempDev.Word[0] = dcoefVal[I];
WriteMultiByteToMemory(DCOEF_BASE+I*DCOEF_WIDTH, tempDev.Byte, DCOEF_WIDTH);
WriteParameterToEEPROM(DCOEF_BASE+I*DCOEF_WIDTH, DCOEF_WIDTH);
}
//******************************************************************************
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߽ڵ<DFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
bool ReadDevCoefNodeAndValue(unsigned char I)
{
ReadMultiByteFromMemory(DCOEF_BASE + I * DCOEF_WIDTH, tempDev.Byte, DCOEF_WIDTH);
ReadMultiByteFromEEPROM(DCOEF_BASE + I * DCOEF_WIDTH, tempDev.Byte, DCOEF_WIDTH, PARA_EEPROM);
if(tempDev.Byte[DCOEF_CRC] == CRC8(tempDev.Byte, DCOEF_CRC))
{
tempDev.Byte[DCOEF_CRC] = 0;
@@ -64,8 +64,7 @@ void DefaultDevCoef(void)
dcoefNum = 5;
tempL.Byte[0] = dcoefNum;
// WriteShortParameterToEEPROM(DCOEF_NUM, DCOEF_NUM_WIDTH);
WriteShortParameterToEEPROM(DCOEF_NUM);
WriteShortParameterToEEPROM(DCOEF_NUM, DCOEF_NUM_WIDTH);
for (I = 0; I < dcoefNum; I++)
{
@@ -80,11 +79,11 @@ void DefaultDevCoef(void)
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
void RetriveDevCoef(void)
{
u32 I;
unsigned char I;
// u32 flowRateMax;
ReadShortParameterFromMemory(DCOEF_NUM, PARA_EEPROM);
// if(tempL.Byte[1] != CRC8(tempL.Byte, 1)) goto RetResetDevCoef;
ReadMultiByteFromEEPROM(DCOEF_NUM, tempL.Byte, DCOEF_NUM_WIDTH, PARA_EEPROM);
if(tempL.Byte[1] != CRC8(tempL.Byte, 1)) goto RetResetDevCoef;
dcoefNum = tempL.Byte[0];
if((dcoefNum > DCOEF_MAX)||(dcoefNum < 3)) goto RetResetDevCoef;

2
user/Compute/Correct.h Executable file → Normal file
View File

@@ -12,7 +12,7 @@
//******************************************************************************
extern u32 dcoefNode[];
extern u16 dcoef, dcoefVal[];
extern u16 GCFCoefB;
extern u16 MeterFactor, GCFCoefB;
extern s32 GCFCoefA, GCFCoefC;
//extern u16 dcoefNum ;

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

0
user/Compute/FlowRateCompute.h Executable file → Normal file
View File

50
user/Compute/GasAnalysis.c Executable file → Normal file
View File

@@ -1,5 +1,6 @@
#include "../main/SystemInclude.h"
static s16 GasAnalysisCNT;
u16 ATypeNode[CURVE_DATA_MAX], ATypeVal[CURVE_DATA_MAX], curveATypeNum;
bool isCurrentGas;
@@ -7,8 +8,8 @@ bool isCurrentGas;
/******************************************************************************/
void GasAnalysisParameterInit(void)
{
airFactor = (u16)ReadShortParameterFromMemory(AIR_FACTOR, AIR_FACTOR_DEFAULT);
factorVth = (u16)ReadShortParameterFromMemory(FACTOR_VTH, 1000);
VHHParameterAir = (u16)ReadParameterFromMemory(VHH_AIR_PARA, VHH_AIR_PARA_WIDTH, RH_PARA_DEFAULT);
VHHParameterScale = (u16)ReadParameterFromMemory(VHH_PARA_SCALE, VHH_PARA_SCALE_WIDTH, 1000);
//------------------------------------------------------------------------------
#ifndef ENABLE_GAS_RECOGNITION_TABLE
@@ -21,37 +22,37 @@ void GasAnalysisParameterInit(void)
#ifndef ENABLE_DENSITY_DETECT
#pragma message("[undefined] ENABLE_DENSITY_DETECT")
#elif(ENABLE_DENSITY_DETECT)
// densityFSParameter = (u16)ReadParameterFromMemory(DENSITY_FS_PARA, DENSITY_FS_PARA_WIDTH, DENSITY_FS_PARA_DEFAULT);
densityFSParameter = (u16)ReadParameterFromMemory(DENSITY_FS_PARA, DENSITY_FS_PARA_WIDTH, DENSITY_FS_PARA_DEFAULT);
#endif
}
/******************************************************************************/
u16 ComputeZeroVHH(void)
unsigned int ComputeZeroVHH(void)
{
tmpSLA = (u32)voltageDetected[RRRES];
tmpSLA -= (u32)RRRoom;
tmpSLA = (unsigned long int)voltageDetected[RRRES];
tmpSLA -= (unsigned long int)NRHRoom;
tmpSLB = (u32)VHHHigh;
tmpSLB -= (u32)VHHLow;
tmpSLB = (unsigned long int)VHHHigh;
tmpSLB -= (unsigned long int)VHHLow;
tmpSLA *= tmpSLB;
tmpSLB = (u32)RRHigh;
tmpSLB -= (u32)RRLow;
tmpSLB = (unsigned long int)NRHHigh;
tmpSLB -= (unsigned long int)NRHLow;
tmpSLA /= tmpSLB;
tmpSLA += (u32)VHHRoom;
tmpSLA += (unsigned long int)VHHRoom;
return (u16)tmpSLA;
return (unsigned int)tmpSLA;
}
/******************************************************************************/
bool GasAnasisOneTime(void)
{
s16 valueTemp;
signed int valueTemp;
valueTemp = (s16)(voltageDetected[VHPA] - airFactor);
if(abs(valueTemp) < factorVth) return 1;
else return 0;
valueTemp = (signed int)(voltageDetected[VHPA] - VHHParameterAir);
if(abs(valueTemp) < VHHParameterScale) return 1;
else return 0;
}
/******************************************************************************/
@@ -67,7 +68,7 @@ void GasAnasisCompute(void)//
#elif(ENABLE_GAS_RECOGNITION_TABLE)
voltageDetected[VHPA] = FindVHHInCalibCurve(voltageDetected[RGIDX]);
#else
voltageDetected[VHPA] = (u16)GetFlowRate(voltageDetected[REG_INDEX], ATYPE_VH);
voltageDetected[VHPA] = (unsigned int)GetFlowRate(voltageDetected[REG_INDEX], ATYPE_VH);
#endif
voltageDetected[VHPA] = WordSubFunction(voltageDetected[DVHHX], voltageDetected[VHPA]);
@@ -99,9 +100,9 @@ void GasAnasisCompute(void)//
/******************************************************************************/
void ReadVHHCurveFromMemory(void)
{
u16 I;
unsigned int I;
curveATypeNum = ReadShortParameterFromMemory(ATYPECURVE_NUM, ATYPECURVE_NUM_DEFAULT);
curveATypeNum = (unsigned int)ReadParameterFromMemory(ATYPECURVE_NUM, ATYPECURVE_NUM_WIDTH, ATYPECURVE_NUM_DEFAULT);
for(I=0; I<curveATypeNum; I++)
{
ReadMultiByteFromEEPROM(ATYPECURVE_DATA_BASE + I * ATYPECURVE_DATA_WIDTH, tempDev.Byte, ATYPECURVE_DATA_WIDTH, PARA_EEPROM);
@@ -120,9 +121,9 @@ void ReadVHHCurveFromMemory(void)
}
/******************************************************************************/
u16 FindVHHInCalibCurve(u16 calibIndex)
unsigned int FindVHHInCalibCurve(unsigned int calibIndex)
{
u16 I;
unsigned int I;
if((curveATypeNum < 3) || (curveATypeNum > CURVE_DATA_MAX))
{
@@ -135,7 +136,7 @@ u16 FindVHHInCalibCurve(u16 calibIndex)
//----------------------------------------------------------------------------
for(I = 0; I < curveATypeNum - 1; I++)
{
if(ATypeNode[I] > 32767) continue;
if(ATypeNode[I] > 32767) continue;
if(ATypeNode[I] > calibIndex) break;
}
@@ -144,9 +145,8 @@ u16 FindVHHInCalibCurve(u16 calibIndex)
//----------------------------------------------------------------------------
Secondary.NodeX = calibIndex;
if(ATypeNode[I] > 32767) Secondary.NodeH = 0;
else Secondary.NodeH = ATypeNode[I];
if(ATypeNode[I] > 32767) Secondary.NodeH = 0;
else Secondary.NodeH = ATypeNode[I];
if(ATypeNode[I-1] > 32767) Secondary.NodeL = 0;
else Secondary.NodeL = ATypeNode[I-1];

6
user/Compute/GasAnalysis.h Executable file → Normal file
View File

@@ -14,12 +14,12 @@
extern u16 ATypeNode[CURVE_DATA_MAX], ATypeVal[CURVE_DATA_MAX], curveATypeNum;
//******************************************************************************
void GasAnalysisParameterInit(void);
u16 ComputeZeroVHH(void);
u32 GetVHHFactor(u16 flowIndex);
unsigned int ComputeZeroVHH(void);
unsigned long int GetVHHFactor(unsigned int flowIndex);
void GasAnasisCompute(void);
bool GasAnasisOneTime(void);
void ReadVHHCurveFromMemory(void);
u16 FindVHHInCalibCurve(u16 calibIndex);
unsigned int FindVHHInCalibCurve(unsigned int calibIndex);
//------------------------------------------------------------------------------
#ifndef ENABLE_DENSITY_DETECT

0
user/Compute/PipeFlowRate.c Executable file → Normal file
View File

0
user/Compute/PipeFlowRate.h Executable file → Normal file
View File

35
user/Compute/SavingData.c Executable file → Normal file
View File

@@ -1,17 +1,18 @@
#include "../main/SystemInclude.h"
/******************************************************************************
recordTime must be define
*******************************************************************************/
//******************************************************************************
// for save data
u16 historyPeriodSet;
static u16 lastState;
u16 saveTimeCounter;
/******************************************************************************/
void SaveParameterInit(void)
{
// history record period
recordTime = (u16)ReadShortParameterFromMemory(RECORD_TIME, RECORD_TIME_DEFAULT);
// ReadMultiByteFromEEPROM(HISTORY_PERIOD, tempL.Byte, HISTORY_PERIOD_WIDTH, PARA_EEPROM);
// if(tempL.Byte[HISTORY_PERIOD_CRC] != CRC8(tempL.Byte, HISTORY_PERIOD_CRC)) historyPeriod = HISTORY_PERIOD_DEFAULT;
// else historyPeriod = tempL.Word[0];
historyPeriod = (u16)ReadParameterFromMemory(HISTORY_PERIOD, HISTORY_PERIOD_WIDTH, HISTORY_PERIOD_DEFAULT);
}
/******************************************************************************/
@@ -98,6 +99,12 @@ u16 AlarmWrite(void)
#pragma message("[undefined] REC_ALARM_DATA")
#elif(REC_ALARM_DATA)
#ifndef ENABLE_EXT_RTC
#pragma message("[undefined] ENABLE_EXT_RTC")
#elif(ENABLE_EXT_RTC)
ExtRTCTimeRead();
#endif
// The Zero record: Factory initial state
ReadMultiByteFromEEPROM(ALARM_POINTER, tempL.Byte, ALARM_POINTER_WIDTH, DATA_EEPROM);
if(tempL.Byte[ALARM_POINTER_CRC] != CRC8(tempL.Byte, ALARM_POINTER_CRC)) tempL.Word[0] = 1;
@@ -119,7 +126,7 @@ u16 AlarmWrite(void)
void SetHistoryRecordTime(void)
{
/*
u16 wrt_base, pointer;
unsigned int wrt_base, pointer;
ReadMultiByteFromEEPROM(HISTORY_POINTER_H, temp, 2, DATA_EEPROM);
pointer = make16(temp[0], temp[1]);
@@ -181,6 +188,12 @@ u16 HistoryRecordWrite(void)
#pragma message("[undefined] REC_HISTORY_DATA")
#elif(REC_HISTORY_DATA)
#ifndef ENABLE_EXT_RTC
#pragma message("[undefined] ENABLE_EXT_RTC")
#elif(ENABLE_EXT_RTC)
ExtRTCTimeRead();
#endif
ReadMultiByteFromEEPROM(HISTORY_POINTER, tempL.Byte, HISTORY_POINTER_WIDTH, DATA_EEPROM);
if(tempL.Byte[HISTORY_POINTER_CRC] != CRC8(tempL.Byte, HISTORY_POINTER_CRC)) tempL.Word[0] = 1;
else if(tempL.Word[0] >= HISTORY_DEPTH) tempL.Word[0] = 1;
@@ -254,8 +267,14 @@ u16 DateAccWrite(void)
#ifndef REC_DATE_DATA
#pragma message("[undefined] REC_DATE_DATA")
#elif(REC_DATE_DATA)
u16 wrt_base;
unsigned int wrt_base;
unsigned char buffer[DATE_WIDTH];
#ifndef ENABLE_EXT_RTC
#pragma message("[undefined] ENABLE_EXT_RTC")
#elif(ENABLE_EXT_RTC)
ExtRTCTimeRead();
#endif
ReadMultiByteFromEEPROM(DATE_POINTER, tempL.Byte, DATE_POINTER_WIDTH, DATA_EEPROM);
if(tempL.Byte[DATE_POINTER_CRC] != CRC8(tempL.Byte, DATE_POINTER_CRC)) tempL.Word[0] = 1;
@@ -371,7 +390,7 @@ void ClearDateRecord(void)
/******************************************************************************/
void DataStorageManagement(void)
{
systemProcessing.Bit.SaveHandle = 0;
systemProcess.Bit.SaveHandle = 0;
if(alarmState != lastState)
{

0
user/Compute/SavingData.h Executable file → Normal file
View File

48
user/Compute/StaticTemperature.c Executable file → Normal file
View File

@@ -1,9 +1,53 @@
#include "../main/SystemInclude.h"
// for flowrate compute
u16 staticHighTemperature, staticLowTemperature, RHHighTa, RHLowTa;
s32 RHCalibDeltaVaule, TACalibDeltaVaule, RHTemperature;
static u16 zeroCalibType;
//******************************************************************************
void StaticTemperatureInit(void)
{
zeroCalibType = 0;
staticLowTemperature = (u16)ReadParameterFromMemory(STATIC_LOW_TA, STATIC_LOW_TA_WIDTH, STATIC_LOW_TA_DEFAULT);
if((isReadParameterOK) && (staticLowTemperature < ENABLE_WRITE_TA_LOW)) zeroCalibType |= 'L';
staticHighTemperature = (u16)ReadParameterFromMemory(STATIC_HIGH_TA, STATIC_HIGH_TA_WIDTH, STATIC_HIGH_TA_DEFAULT);
if((isReadParameterOK) && (staticHighTemperature > ENABLE_WRITE_TA_HIGH)) zeroCalibType |= 'H'<<8;
}
//******************************************************************************
void StaticLowTemperatureWrite(void)
{
tempL.Word[0] = voltageDetected[TPCB];
staticLowTemperature = WriteShortParameterToEEPROM(STATIC_LOW_TA, STATIC_LOW_TA_WIDTH);
zeroCalibType &= 0xff00;
zeroCalibType |= 'L';
currentMode.Bit.LowCalibEnd = 1;
if(zeroCalibType == (('H'<<8)+'L'))
{
tempL.Word[0] = 0;
tempL.Word[0] = WriteShortParameterToEEPROM(SYS_COMMAND, SYS_COMMAND_WIDTH);
EnterUserMode();
}
}
//******************************************************************************
void StaticHighTemperatureWrite(void)
{
tempL.Word[0] = voltageDetected[TPCB];
staticHighTemperature = WriteShortParameterToEEPROM(STATIC_HIGH_TA, STATIC_HIGH_TA_WIDTH);
zeroCalibType &= 0x00ff;
zeroCalibType |= 'H'<<8;
currentMode.Bit.HighCalibEnd = 1;
if(zeroCalibType == (('H'<<8)+'L'))
{
tempL.Word[0] = 0;
tempL.Word[0] = WriteShortParameterToEEPROM(SYS_COMMAND, SYS_COMMAND_WIDTH);
EnterUserMode();
}
}
//******************************************************************************
u16 ComputeRHTemperature(u16 RHRes)
{
@@ -30,10 +74,10 @@ void StaticTGasCompute(void)
#pragma message("[undefined] ENABLE_RR_CALIBRATION")
#elif(ENABLE_RR_CALIBRATION)
// ͨ<><CDA8><EFBFBD>ߵ<EFBFBD><DFB5>±궨<C2B1><EAB6A8><EFBFBD><EFBFBD>RR<52><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RHCalibDeltaVaule = (u32)RRHigh-(u32)RRLow;
RHCalibDeltaVaule = (u32)NRHHigh-(u32)NRHLow;
TACalibDeltaVaule = (u32)staticHighTemperature-(u32)staticLowTemperature;
tmpSLA = (u32)voltageDetected[RRRES]-(u32)RRLow;
tmpSLA = (u32)voltageDetected[RRRES]-(u32)NRHLow;
tmpSLA *= TACalibDeltaVaule;
tmpSLA /= RHCalibDeltaVaule;
tmpSLA += (u32)staticLowTemperature;

3
user/Compute/StaticTemperature.h Executable file → Normal file
View File

@@ -21,9 +21,12 @@
#define RES_FACTOR_MAX 35
// for flowrate compute
extern u16 staticHighTemperature, staticLowTemperature, RHHighTa, RHLowTa;
extern s32 RHCalibDeltaVaule, TACalibDeltaVaule, RHTemperature;
//******************************************************************************
void StaticTemperatureInit(void);
void StaticLowTemperatureWrite(void);
void StaticHighTemperatureWrite(void);
void StaticTGasCompute(void);
u16 ComputeRHTemperature(u16 RHRes);

13
user/Compute/TemperatureCorrect.c Executable file → Normal file
View File

@@ -1,14 +1,15 @@
#include "../main/SystemInclude.h"
//==============================================================================
/*
resFactor,temperatureFactor must be define in internal modbus
*/
u16 calibTANode[CURVE_DATA_MAX];
u16 calibTAVal[CURVE_DATA_MAX], curveTANum;
u16 resFactor,temperatureFactor;
/******************************************************************************/
void TemperatureCorrectInit(void)
{
//------------------------------------------------------------------------------
temperatureFactor = (u16)ReadParameterFromMemory(TEMP_FACTOR, TEMP_FACTOR_WIDTH, TEMP_FACTOR_DEFAULT);
resFactor = (u16)ReadParameterFromMemory(RES_FACTOR, RES_FACTOR_WIDTH, RES_FACTOR_DEFAULT);
}
/******************************************************************************/
@@ -139,7 +140,7 @@ void DefaultTACuvre(void)
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
void RetriveTACurve(void)
{
ReadMultiByteFromMemory(TACURVE_NUM, tempL.Byte, TACURVE_NUM_WIDTH);
ReadMultiByteFromEEPROM(TACURVE_NUM, tempL.Byte, TACURVE_NUM_WIDTH, PARA_EEPROM);
if(tempL.Byte[1] != CRC8(tempL.Byte, 1)) goto RetResetCurve;
curveTANum = tempL.Byte[0];
@@ -241,13 +242,13 @@ void WriteCurveByCom(void)
tempDev.DWord[1] = 0;
if(calibType == INTCMD_1ST_TABLE)
{
WriteMultiByteToMemory(TACURVE_DATA_BASE+I*TACURVE_DATA_WIDTH, &tempDev.Byte[0], TACURVE_DATA_WIDTH);
WriteParameterToEEPROM(TACURVE_DATA_BASE+I*TACURVE_DATA_WIDTH, TACURVE_DATA_WIDTH);
calibTANode[I] = tempDev.Word[1];
calibTAVal[I] = tempDev.Word[0];
}
else if(calibType == INTCMD_2ND_TABLE)
{
WriteMultiByteToMemory(ATYPECURVE_DATA_BASE+I*ATYPECURVE_DATA_WIDTH, &tempDev.Byte[0], ATYPECURVE_DATA_WIDTH);
WriteParameterToEEPROM(ATYPECURVE_DATA_BASE+I*ATYPECURVE_DATA_WIDTH, ATYPECURVE_DATA_WIDTH);
ATypeNode[I] = tempDev.Word[1];
ATypeVal[I] = tempDev.Word[0];
}

2
user/Compute/TemperatureCorrect.h Executable file → Normal file
View File

@@ -25,5 +25,5 @@ u16 GetTACurveValue(u16 calibIndex);
void ReadCurveByCom(void);
void WriteCurveByCom(void);
void TemperatureCorrection(void);
#endif

24
user/Compute/UnitConverter.c Executable file → Normal file
View File

@@ -308,19 +308,16 @@ void ConvertAllFlowRateAndSave(u16 NewFlowUnit)
// max flowRate
maxFlowRate = ConvertFlowrate(maxFlowRate, flowComUnit, originalFlowUnit);
tempDev.DWord[0] = maxFlowRate;
maxFlowRate = WriteLongParameterToMemory(OUT_MAX_FLOW);
tempL.DWord = maxFlowRate;
maxFlowRateH = tempL.Word[1];
maxFlowRateL = tempL.Word[0];
maxFlowRate = WriteParameterToEEPROM(MAX_FLOW, MAX_FLOW_WIDTH);
// tempL.DWord = maxFlowRate;
// maxFlowRateH = tempL.Word[1];
// maxFlowRateL = tempL.Word[0];
// min flowRate
minFlowRate = ConvertFlowrate(minFlowRate, flowComUnit, originalFlowUnit);
tempDev.DWord[0] = minFlowRate;
minFlowRate = WriteLongParameterToMemory(OUT_MIN_FLOW);
tempL.DWord = minFlowRate;
minFlowRateH = tempL.Word[1];
minFlowRateL = tempL.Word[0];
minFlowRate = WriteParameterToEEPROM(MIN_FLOW, MIN_FLOW_WIDTH);
// alarmUpperFlowRate = ConvertFlowrate(alarmUpperFlowRate, flowComUnit, originalFlowUnit);
// tempDev.DWord[0] = alarmUpperFlowRate;
// alarmUpperFlowRate = WriteShortParameterToEEPROM(HIGH_FLOW_ALARM, HIGH_FLOW_ALARM_WIDTH);
@@ -381,7 +378,7 @@ void ConvertAllFlowRateAndSave(u16 NewFlowUnit)
SendToTotalArray();
ReleaseToIntAndDecimalBufForUart();
for(I=0; I <= REC_ACC_DEPTH; I++) FRAMWriteTotal();
for(I=0; I <= REC_DEPTH; I++) FRAMWriteTotal();
lastRemaining = 0;
flowAccCumulationRemaining = 0;
@@ -389,7 +386,7 @@ void ConvertAllFlowRateAndSave(u16 NewFlowUnit)
//===========================================================================
tempL.Word[0] = NewFlowUnit;
flowUnit = WriteShortParameterToMemory(FLOW_UNIT);
flowUnit = WriteShortParameterToEEPROM(WORK_UNIT, WORK_UNIT_WIDTH);
}
//******************************************************************************
@@ -418,6 +415,7 @@ u16 ReturnStartUnitBit(u16 stdBit)
// FRUnitForHour[] ={28800, 14400, 7200, 3600, 1800, 900}
// FRUnitForMinute[] ={480, 240, 120, 60, 30, 15}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0xFFFFFFF/(1000/15):65000000
u16 ConvertTimeBaseAndUnit(u16 unit, u16 timeBaseIndex)
{
switch(unit)
@@ -445,10 +443,10 @@ void UnitConverterInit(void)
//if(tempL.Byte[CALIB_DIAMETER_CRC] != CRC8(tempL.Byte, CALIB_DIAMETER_CRC)) flowUnit = CALIB_DIAMETER_DEFAULT;
//else flowUnit = tempL.Word[0];
flowUnit = (u16)ReadShortParameterFromMemory(FLOW_UNIT, FLOW_UNIT_DEFAULT);
flowUnit = (u16)ReadParameterFromMemory(WORK_UNIT, WORK_UNIT_WIDTH, WORK_UNIT_DEFAULT);
if(JudgeflowUnit(flowUnit))
{
flowUnit = FLOW_UNIT_DEFAULT;
flowUnit = WORK_UNIT_DEFAULT;
JudgeflowUnit(flowUnit);
}
}

0
user/Compute/UnitConverter.h Executable file → Normal file
View File

0
user/Compute/UnitConverterDefine.h Executable file → Normal file
View File

0
user/Compute/VHHCompute.c Executable file → Normal file
View File

0
user/Compute/VHHCompute.h Executable file → Normal file
View File