199 lines
6.3 KiB
C#
199 lines
6.3 KiB
C#
///
|
|
/// Copyright (c) 2015-2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|
{
|
|
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 float CalibTargetQ2; /// Target error at Q2 after Q2 correction in [%]
|
|
public int FactorLimitLo; /// Lower limit for the calibration factor
|
|
public int FactorLimitHi; /// Upper limit for the calibration factor
|
|
public Counting Counting; /// Initial iPerl counting (Artbitrary, Positive or Negative)
|
|
public int WMType_ID; /// Required for Oracle DB: ID_WZTyp in table VT_PRUEFPUNKT_SOLL_SD
|
|
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
MeterType = MeterType.AutoDetect;
|
|
CalibTarget = 0;
|
|
CalibTargetQ2 = 0;
|
|
FactorLimitLo = 1000;
|
|
FactorLimitHi = 8000;
|
|
Counting = Counting.Arbitrary;
|
|
WMType_ID = 2; /// Value for iPerl DN15
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"iPerl type",
|
|
"Calib. target [%]",
|
|
"Calib. target at Q2 [%]",
|
|
"Calib. factor Lo",
|
|
"Calib. factor Hi",
|
|
"Counting",
|
|
"WM type ID",
|
|
};
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override ICollection<string> ParamValues(int i)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
IList<string> retVal = new List<string>();
|
|
for (MeterType mt = 0; mt < MeterType.Count; mt++) retVal.Add(mt.ToString());
|
|
return retVal;
|
|
}
|
|
else if (i == 5)
|
|
{
|
|
IList<string> retVal = new List<string>();
|
|
for (Counting c = 0; c < Counting.Count; c++) retVal.Add(c.ToString());
|
|
return retVal;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return MeterType.ToString();
|
|
case 1: return CalibTarget.ToString();
|
|
case 2: return CalibTargetQ2.ToString();
|
|
case 3: return FactorLimitLo.ToString();
|
|
case 4: return FactorLimitHi.ToString();
|
|
case 5: return Counting.ToString();
|
|
case 6: return WMType_ID.ToString();
|
|
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.None; }
|
|
}
|
|
break;
|
|
case 1: CalibTarget = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None;
|
|
case 2: CalibTargetQ2 = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None;
|
|
case 3: FactorLimitLo = int.Parse(strValue); return CfgUpdateFlags.None;
|
|
case 4: FactorLimitHi = int.Parse(strValue); return CfgUpdateFlags.None;
|
|
case 5:
|
|
for (Counting c = 0; c < Counting.Count; c++)
|
|
{
|
|
if (c.ToString().Equals(strValue)) { Counting = c; return CfgUpdateFlags.None; }
|
|
}
|
|
break;
|
|
case 6: WMType_ID = int.Parse(strValue); return CfgUpdateFlags.None;
|
|
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:
|
|
case 2:
|
|
if (Utils.TryParseSFloat(strValue, out fDummy) && fDummy >= -10.0f && fDummy <= 10.0f) return true;
|
|
break;
|
|
case 3:
|
|
case 4:
|
|
if (int.TryParse(strValue, out iDummy) && iDummy >= 1000 && iDummy <= 8000) return true;
|
|
break;
|
|
case 5:
|
|
for (Counting c = 0; c < Counting.Count; c++) if (c.ToString().Equals(strValue)) return true;
|
|
break;
|
|
case 6: /// WMType_ID
|
|
if (int.TryParse(strValue, out iDummy)) return true;
|
|
break;
|
|
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.CalibTargetQ2 = this.CalibTargetQ2;
|
|
prms.FactorLimitLo = this.FactorLimitLo;
|
|
prms.FactorLimitHi = this.FactorLimitHi;
|
|
prms.Counting = this.Counting;
|
|
prms.WMType_ID = this.WMType_ID;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ProcParams pars = new ProcParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override void UpdateFromDbEntity(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;
|
|
}
|
|
}
|
|
}
|