184 lines
5.1 KiB
C#
184 lines
5.1 KiB
C#
///
|
|
/// Copyright (c) 2015-2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.TestMethods.GenesisCommunication.GenesisHead
|
|
{
|
|
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public MeterType MeterType;
|
|
public float CalibTarget; /// Target error after calibration in [%]
|
|
public int FactorLimitLo; /// Lower limit for the calibration factor
|
|
public int FactorLimitHi; /// Upper limit for the calibration factor
|
|
#if ORACLE_DB
|
|
public int WMType_ID; /// Required for Oracle DB: ID_WZTyp in table VT_PRUEFPUNKT_SOLL_SD
|
|
public int WMType_Rev; /// Required for Oracle DB: Rev_WZTyp in table VT_PRUEFPUNKT_SOLL_SD
|
|
#endif
|
|
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
MeterType = MeterType.AutoDetect;
|
|
CalibTarget = 0;
|
|
FactorLimitLo = 1000;
|
|
FactorLimitHi = 8000;
|
|
#if ORACLE_DB
|
|
WMType_ID = 2; /// Value for iPerl DN15
|
|
WMType_Rev = 1; /// Value for iPerl DN15
|
|
#endif
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"iPerl type",
|
|
"Calib. target [%]",
|
|
"Calib. factor Lo",
|
|
"Calib. factor Hi",
|
|
#if ORACLE_DB
|
|
"WMType ID",
|
|
"WMType Rev.",
|
|
#endif
|
|
};
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return MeterType.ToString();
|
|
case 1: return CalibTarget.ToString();
|
|
case 2: return FactorLimitLo.ToString();
|
|
case 3: return FactorLimitHi.ToString();
|
|
#if ORACLE_DB
|
|
case 4: return WMType_ID.ToString();
|
|
case 5: return WMType_Rev.ToString();
|
|
#endif
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
for (MeterType mt = 0; mt < MeterType.Count; mt++)
|
|
{
|
|
if (mt.ToString().Equals(strValue)) { MeterType = mt; return CfgUpdateFlags.AnyChange; }
|
|
}
|
|
break;
|
|
case 1: CalibTarget = Utils.ParseSFloat(strValue); return CfgUpdateFlags.AnyChange;
|
|
case 2: FactorLimitLo = int.Parse(strValue); return CfgUpdateFlags.AnyChange;
|
|
case 3: FactorLimitHi = int.Parse(strValue); return CfgUpdateFlags.AnyChange;
|
|
#if ORACLE_DB
|
|
case 4: WMType_ID = int.Parse(strValue); return;
|
|
case 5: WMType_Rev = int.Parse(strValue); return;
|
|
#endif
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
return CfgUpdateFlags.None;
|
|
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
int iDummy;
|
|
float fDummy;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
for (MeterType mt = 0; mt < MeterType.Count; mt++) if (mt.ToString().Equals(strValue)) return true;
|
|
break;
|
|
case 1:
|
|
if (Utils.TryParseSFloat(strValue, out fDummy) && fDummy >= -10.0f && fDummy <= 10.0f) return true;
|
|
break;
|
|
case 2:
|
|
case 3:
|
|
if (int.TryParse(strValue, out iDummy) && iDummy >= 1000 && iDummy <= 8000) return true;
|
|
break;
|
|
|
|
#if ORACLE_DB
|
|
case 4: /// WMType_ID
|
|
case 5: /// WMType_Rev
|
|
if (int.TryParse(strValue, out iDummy)) return true;
|
|
break;
|
|
#endif
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(ProcParams prms)
|
|
{
|
|
prms.MeterType = this.MeterType;
|
|
prms.CalibTarget = this.CalibTarget;
|
|
prms.FactorLimitLo = this.FactorLimitLo;
|
|
prms.FactorLimitHi = this.FactorLimitHi;
|
|
#if ORACLE_DB
|
|
prms.WMType_ID = this.WMType_ID;
|
|
prms.WMType_Rev = this.WMType_Rev;
|
|
#endif
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ProcParams pars = new ProcParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public void UpdateProcedureParams(ComponentProcedure dbEntity)
|
|
{
|
|
if (dbEntity == null) return;
|
|
try
|
|
{
|
|
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
|
|
|
|
procedureParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
procedure = dbEntity.Procedure;
|
|
|
|
if (tmp != null) tmp.CopyContentTo(this);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
public ProcParams()
|
|
{
|
|
}
|
|
|
|
public ProcParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
|
|
{
|
|
this.procedureParamsEntity = procParamsEntity;
|
|
this.componentName = componentName;
|
|
this.procedure = procedure;
|
|
}
|
|
}
|
|
}
|