📄 ftankcalculate.c
字号:
#include "ftankcalculate.h"
TankCoefficient tankcoeffs[MAX_COEFFS_NUM];
Boolean ftankcal_Init(CHAR* tankCfgFile, CHAR* volumeCfgFile)
{
TankCoefficient* pTank;
if(fvol_init(volumeCfgFile) == False)
return False;
// Todo :获取罐参数,设置为常量
pTank = &tankcoeffs[0];
pTank->TankID = 1;
pTank->Initialized = False;
// ...
return True;
}
Boolean ftankcal_MatchTag(FTag* tag, INT16 tagTypeID, CalTag* ctag, Boolean isConstant)
{
if(tag->TypeID == tagTypeID)
{
ctag->Valid = gcol_ValidStatus(tag);
ctag->value = tag->Value;
ctag->Constant = isConstant;
return True;
}
else
return False;
}
TankCoefficient* ftankcal_getConfficient(INT32 tankID)
{
REGINT i;
for(i=0; i<MAX_COEFFS_NUM; i++)
{
if(tankcoeffs[i].TankID == tankID)
return &tankcoeffs[i];
}
return NULL;
}
Boolean ftankcal_Volume(TankCoefficient* tankcnf, FTagGroup* grp)
{
if(tankcnf->dProductVolume.Valid == True)
return True;
else
{
INT32 volume;
tankcnf->dProductVolume.value = 0;
// liquid temperature, liquidupside temp
ftankcal_Temp(tankcnf, grp);
// product density
ftankcal_Density(tankcnf);
volume = fvol_getVolume(tankcnf->n32TankIndex, tankcnf);
if(volume >= 0)
{
tankcnf->dProductVolume.Valid = True;
tankcnf->dProductVolume.value = volume;
}
return tankcnf->dProductVolume.Valid;
}
}
Boolean ftankcal_Temp(TankCoefficient* tankcnf, FTagGroup* group)
{
TempPoints temps;
REGINT i,start;
FTag* curTag;
DOUBLE liquid,upside;
INT32 validtempcount,countupside,countliquid;
if(tankcnf->volParams.dLiquidTemp.Valid == True && tankcnf->volParams.dLiquidUpsideTemp.Valid == True)
return True;
else
{
tankcnf->volParams.dLiquidTemp.value = 0;
tankcnf->volParams.dLiquidUpsideTemp.value = 0;
tankcnf->volParams.dLiquidTemp.Valid = False;
tankcnf->volParams.dLiquidUpsideTemp.Valid = False;
upside = 0; liquid = 0;
countupside = 0;
countliquid = 0;
// get temperature tags
temps.Num = 0;
for(i=0; i<group->TagNum; i++)
{
if( ftankcal_MatchTag(group->Tag[i], FTANK_TAG_TEMP, &temps.Temperature[temps.Num], False) )
temps.Num = temps.Num + 1;
}
// get tag index of liquid temperature
if(tankcnf->volParams.n32LiquidLevel.Valid == False ||
(INT32)tankcnf->n32TankHeight.value == 0)
{
start = 0;
}
else
{
start = temps.Num * (1.0 - tankcnf->volParams.n32LiquidLevel.value / tankcnf->n32TankHeight.value);
start = start - 1;
if(start < 0 || start >temps.Num)
start = 0;
}
// calculate liquid tempearture & upside temperature
for(i=0; i<temps.Num; i++)
{
if(temps.Temperature[i].Valid == True)
{
if(i<start)
{
upside += temps.Temperature[i].value;
countupside ++;
}
else
{
liquid += temps.Temperature[i].value;
countliquid ++;
}
validtempcount ++;
}
}
if(validtempcount < MIN_TANK_TEMPNUM)
{
return False;
}
else
{
tankcnf->volParams.dLiquidUpsideTemp.Valid = True;
tankcnf->volParams.dLiquidTemp.Valid = True;
if(countupside > 0)
tankcnf->volParams.dLiquidUpsideTemp.value = upside / countupside;
if(countliquid > 0)
tankcnf->volParams.dLiquidTemp.value = liquid / countliquid;
if(countupside == 0)
tankcnf->volParams.dLiquidUpsideTemp.value = tankcnf->volParams.dLiquidTemp.value;
if(countliquid == 0)
tankcnf->volParams.dLiquidTemp.value = tankcnf->volParams.dLiquidUpsideTemp.value;
}
return True;
}
}
Boolean ftankcal_Density(TankCoefficient* tankcnf, FTagGroup* grp)
{
if(tankcnf->dStandardDensity.Valid == True)
return True;
else
{
ftankcal_Temp(tankcnf, grp);
// todo: ...
return False;
}
}
Boolean ftankcal_Weight(TankCoefficient* tankcnf, FTagGroup* grp)
{
if(tankcnf->dProductWeight.Valid == True)
return True;
else
{
ftankcal_Volume(tankcnf, grp);
ftankcal_Density(tankcnf, grp);
// todo: ...
return False;
}
}
VOID ftankcal_CalTag(FTag* tag, TankCoefficient* tankcnf, FTagGroup* grp)
{
DOUBLE value;
Boolean succeed = False;
if(tag->Mode == TAG_GATHER_CALCULATE)
{
tag->Status = TAG_STATUS_CAL_ERROR;
tag->Value = 0;
switch(tag->TypeID)
{
case FTANK_TAG_VOLUME:
succeed = ftankcal_Volume(tankcnf, grp);
value = tankcnf->dProductVolume.value;
break;
case FTANK_TAG_DENSITY:
succeed = ftankcal_Density(tankcnf, grp);
value = tankcnf->volParams.dProductDensity.value;
break;
case FTANK_TAG_WEIGHT:
succeed = ftankcal_Weight(tankcnf, grp);
value = tankcnf->dProductWeight.value;
break;
default:
break;
}
if(succeed == True)
{ tag->Status = TAG_STATUS_CAL_OK;
tag->Value = value;
}
}
}
VOID ftankcal_ResetCalTag(CalTag* ctag)
{
if(ctag->Constant == True)
return;
ctag->Err = 0;
ctag->Valid = False;
ctag->value = 0;
}
VOID ftankcal_ResetCoefficients(TankCoefficient* tankcnf)
{
ftankcal_ResetCalTag( &tankcnf->AFC );
ftankcal_ResetCalTag( &tankcnf->dProductVolume );
ftankcal_ResetCalTag( &tankcnf->dProductWeight );
ftankcal_ResetCalTag( &tankcnf->dWeightplus );
ftankcal_ResetCalTag( &tankcnf->dStandardDensity );
ftankcal_ResetCalTag( &tankcnf->volParams.dProductDensity );
ftankcal_ResetCalTag( &tankcnf->volParams.dAmbientTemp );
ftankcal_ResetCalTag( &tankcnf->volParams.dLiquidTemp );
ftankcal_ResetCalTag( &tankcnf->volParams.dLiquidUpsideTemp );
ftankcal_ResetCalTag( &tankcnf->volParams.dPressure );
ftankcal_ResetCalTag( &tankcnf->volParams.n32LiquidLevel );
ftankcal_ResetCalTag( &tankcnf->volParams.n32WaterLevel );
}
VOID ftankcal_GetTagValues(INT32 TagMODE, FTagGroup* group, TankCoefficient* tankcnf, Boolean isConstant)
{
REGINT i;
FTag* curTag;
for(i=0; i<group->TagNum; i++)
{
curTag = group->Tag[i];
if(curTag->Mode == TagMODE)
{
if( ftankcal_MatchTag(curTag, FTANK_TAG_LIQUIDLEVEL, &tankcnf->volParams.n32LiquidLevel, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_ETEMP, &tankcnf->volParams.dAmbientTemp, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_PRESSURE, &tankcnf->volParams.dPressure, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_WATERLEVEL, &tankcnf->volParams.n32WaterLevel, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_DENSITY, &tankcnf->volParams.dProductDensity, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_VOLUME, &tankcnf->volParams.dProductDensity, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_STDDENSITY, &tankcnf->volParams.dProductDensity, isConstant) == True)
continue;
else if( ftankcal_MatchTag(curTag, FTANK_TAG_WEIGHT, &tankcnf->volParams.dProductDensity, isConstant) == True)
continue;
}
}
}
VOID ftankcal_SetGatherdValues(FTagGroup* group, TankCoefficient* tankcnf)
{
return ftankcal_GetTagValues(TAG_GATHER_EQUIP, group, tankcnf, False);
}
VOID ftankcal_SetConstant(FTagGroup* group, TankCoefficient* tankcnf)
{
// 获取采集点中的常量数据,设置为常量
if(tankcnf->Initialized == True)
return;
else
{
ftankcal_GetTagValues(TAG_GATHER_CONSTANT, group, tankcnf, True);
tankcnf->Initialized = True;
}
}
VOID ftankcal_SetOutTags(FTagGroup* group)
{
REGINT i;
FOutputTag* outTag;
for(i=0; i<group->OutTagNum; i++)
{
outTag = group->OutTag[i];
outTag->Status = TAG_STATUS_NOTDEFINE;
switch(outTag->RelationType)
{
case OUTTAG_RELATION_EQUAL:
outTag->wValue = outTag->RelatedTag[0]->wValue;
outTag->Value = outTag->RelatedTag[0]->Value;
outTag->Status = outTag->RelatedTag[0]->Status;
break;
default:
break;
}
}
}
VOID ftankcal_CalTank(FTagGroup* group)
{
REGINT i;
TankCoefficient* tankcnf = ftankcal_getConfficient(group->GroupID);
if(tankcnf != NULL)
{
// set constant varibles
ftankcal_SetConstant(group, tankcnf);
// reset calculated coefficients
ftankcal_ResetCoefficients(tankcnf);
// init gathered tag values
ftankcal_SetGatherdValues(group, tankcnf);
// foreach tag call calculate
for(i=0; i<group->TagNum; i++)
{
ftankcal_CalTag(group->Tag[i], tankcnf, group);
}
}
ftankcal_SetOutTags(group);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -