Changes for Xylem Nanjing, ver. 3.1.1676
This commit is contained in:
@@ -0,0 +1,364 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Common;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.Rig.TestMethods.S640Communication
|
||||
{
|
||||
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
|
||||
public string ModuleParameter; /// 0
|
||||
public bool MetroEnable; /// 1
|
||||
public double PulseRatePiston; /// 2
|
||||
public double PulseRateLed; /// 3
|
||||
public double OffsetFactor; /// 4
|
||||
public int FactoryCalibration; /// 5
|
||||
public S640Units Units; /// 6
|
||||
public string MeterSize; /// 7
|
||||
public int OffsetTime; /// 8
|
||||
public bool NewReadEnable; /// 9
|
||||
public int NewRead; /// 10
|
||||
public bool TransIntervalEnable; /// 11
|
||||
public int TransInterval; /// 12
|
||||
public bool LatIntervalEnable; /// 13
|
||||
public int LatInterval; /// 14
|
||||
public bool ResetAlarmEnable; /// 15
|
||||
public bool MetrologyTestModeEnable; /// 16
|
||||
public int MetrologyTestModeHours; /// 17
|
||||
public bool OpticalTelegramEnable; /// 18
|
||||
public int OpticalTelegramMinutes; /// 19
|
||||
public bool ChangeRadioEnable; /// 20
|
||||
public bool ChangeMeterIDEnable; /// 21
|
||||
public bool SoftSealEnable; /// 22
|
||||
public bool GoToSleepEnable; /// 23
|
||||
public bool SaveDBEnable; /// 24
|
||||
public EncryptionKeyMode KeyMode; /// 25
|
||||
|
||||
|
||||
public override void InitializeAll()
|
||||
{
|
||||
ModuleParameter = string.Empty;
|
||||
MetroEnable = true;
|
||||
PulseRatePiston = -119.8826;
|
||||
PulseRateLed = 200.0;
|
||||
OffsetFactor = 0.0;
|
||||
FactoryCalibration = 0;
|
||||
Units = S640Units.CubicMeters;
|
||||
MeterSize = "640 DN20";
|
||||
OffsetTime = 5;
|
||||
NewReadEnable = false;
|
||||
NewRead = 0;
|
||||
TransIntervalEnable = false;
|
||||
TransInterval = 3;
|
||||
LatIntervalEnable = false;
|
||||
LatInterval = 1;
|
||||
ResetAlarmEnable = false;
|
||||
MetrologyTestModeEnable = false;
|
||||
MetrologyTestModeHours = 4;
|
||||
OpticalTelegramEnable = true;
|
||||
OpticalTelegramMinutes = 60;
|
||||
ChangeRadioEnable = false;
|
||||
ChangeMeterIDEnable = false;
|
||||
SoftSealEnable = false;
|
||||
GoToSleepEnable = false;
|
||||
SaveDBEnable = false;
|
||||
KeyMode = EncryptionKeyMode.SensusKey;
|
||||
}
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
"Module Parameter",
|
||||
"Metro Enable",
|
||||
"Pulse Rate Piston",
|
||||
"Pulse Rate LED",
|
||||
"Offset Factor",
|
||||
"Factory Calibration",
|
||||
"Units",
|
||||
"Meter Size",
|
||||
"Offset Time",
|
||||
"NewRead Enable",
|
||||
"NewRead",
|
||||
"Trans Interval Enable",
|
||||
"Trans Interval",
|
||||
"Lat Interval Enable",
|
||||
"Lat Interval",
|
||||
"Reset Alarm Enable",
|
||||
"Metrology Test Mode Enable",
|
||||
"Metrology Test Mode Hours",
|
||||
"Optical Telegram Enable",
|
||||
"Optical Telegram Minutes (1..255, 0=off)",
|
||||
"Change Radio Enable",
|
||||
"Change Meter ID Enable",
|
||||
"Soft Seal Enable",
|
||||
"Go To Sleep Enable",
|
||||
"Save DB Enable",
|
||||
"Encryption Key Mode",
|
||||
};
|
||||
public override string ParamName(int i)
|
||||
{
|
||||
return paramNames[i];
|
||||
}
|
||||
public override int ParamsCount() { return paramNames.Length; }
|
||||
|
||||
public override ICollection<string> ParamValues(int ix)
|
||||
{
|
||||
IList<string> values = new List<string>();
|
||||
|
||||
switch (ix)
|
||||
{
|
||||
case 0:
|
||||
case 7:
|
||||
return null;
|
||||
case 1:
|
||||
case 9:
|
||||
case 11:
|
||||
case 13:
|
||||
case 15:
|
||||
case 16:
|
||||
case 18:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
return new string[] { Strings.no, Strings.yes };
|
||||
case 5:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
case 14:
|
||||
case 17:
|
||||
case 19:
|
||||
return null;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return null;
|
||||
case 6:
|
||||
foreach (var enm in Enum.GetValues(typeof(S640Units))) values.Add(enm.ToString());
|
||||
return values;
|
||||
case 25:
|
||||
foreach (var enm in Enum.GetValues(typeof(EncryptionKeyMode))) values.Add(enm.ToString());
|
||||
return values;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: return ModuleParameter;
|
||||
case 1: return MetroEnable ? Strings.yes : Strings.no;
|
||||
case 2: return PulseRatePiston.ToString();
|
||||
case 3: return PulseRateLed.ToString();
|
||||
case 4: return OffsetFactor.ToString();
|
||||
case 5: return FactoryCalibration.ToString();
|
||||
case 6: return Units.ToString();
|
||||
case 7: return MeterSize;
|
||||
case 8: return OffsetTime.ToString();
|
||||
case 9: return NewReadEnable ? Strings.yes : Strings.no;
|
||||
case 10: return NewRead.ToString();
|
||||
case 11: return TransIntervalEnable ? Strings.yes : Strings.no;
|
||||
case 12: return TransInterval.ToString();
|
||||
case 13: return LatIntervalEnable ? Strings.yes : Strings.no;
|
||||
case 14: return LatInterval.ToString();
|
||||
case 15: return ResetAlarmEnable ? Strings.yes : Strings.no;
|
||||
case 16: return MetrologyTestModeEnable ? Strings.yes : Strings.no;
|
||||
case 17: return MetrologyTestModeHours.ToString();
|
||||
case 18: return OpticalTelegramEnable ? Strings.yes : Strings.no;
|
||||
case 19: return OpticalTelegramMinutes.ToString();
|
||||
case 20: return ChangeRadioEnable ? Strings.yes : Strings.no;
|
||||
case 21: return ChangeMeterIDEnable ? Strings.yes : Strings.no;
|
||||
case 22: return SoftSealEnable ? Strings.yes : Strings.no;
|
||||
case 23: return GoToSleepEnable ? Strings.yes : Strings.no;
|
||||
case 24: return SaveDBEnable ? Strings.yes : Strings.no;
|
||||
case 25: return KeyMode.ToString();
|
||||
|
||||
default: return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateParam(int i, string str)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: ModuleParameter = str; return CfgUpdateFlags.None;
|
||||
case 1: MetroEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 2: PulseRatePiston = TBF.Utils.ParseSDouble(str); return CfgUpdateFlags.None;
|
||||
case 3: PulseRateLed = TBF.Utils.ParseSDouble(str); return CfgUpdateFlags.None;
|
||||
case 4: OffsetFactor = TBF.Utils.ParseSDouble(str); return CfgUpdateFlags.None;
|
||||
case 5: FactoryCalibration = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 6: Units = S640Units.CubicMeters; return CfgUpdateFlags.None;
|
||||
case 7: MeterSize = str; return CfgUpdateFlags.None;
|
||||
case 8: OffsetTime = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 9: NewReadEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 10: NewRead = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 11: TransIntervalEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 12: TransInterval = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 13: LatIntervalEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 14: LatInterval = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 15: ResetAlarmEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 16: MetrologyTestModeEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 17: MetrologyTestModeHours = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 18: OpticalTelegramEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 19: OpticalTelegramMinutes = int.Parse(str); return CfgUpdateFlags.None;
|
||||
case 20: ChangeRadioEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 21: ChangeMeterIDEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 22: SoftSealEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 23: GoToSleepEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 24: SaveDBEnable = (str == Strings.yes); return CfgUpdateFlags.None;
|
||||
case 25: KeyMode = EncryptionKeyMode.SensusKey; return CfgUpdateFlags.None;
|
||||
|
||||
default: return CfgUpdateFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateParam(int i, string str, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
int idummy;
|
||||
double ddummy;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
case 7:
|
||||
/// free strings (always OK)
|
||||
return true;
|
||||
case 1:
|
||||
case 9:
|
||||
case 11:
|
||||
case 13:
|
||||
case 15:
|
||||
case 16:
|
||||
case 18:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
/// booleans
|
||||
if (str == Strings.no || str == Strings.yes) return true;
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
/// doubles
|
||||
if (TBF.Utils.TryParseSDouble(str, out ddummy)) return true;
|
||||
break;
|
||||
case 5:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
case 14:
|
||||
case 17:
|
||||
/// integers
|
||||
if (int.TryParse(str, out idummy)) return true;
|
||||
break;
|
||||
case 19:
|
||||
/// integers
|
||||
if (int.TryParse(str, out idummy) && idummy >= 0 && idummy <= 255) return true;
|
||||
break;
|
||||
case 6:
|
||||
case 25:
|
||||
/// enums
|
||||
if (ParamValues(i).Contains(str)) return true;
|
||||
break;
|
||||
default:
|
||||
message = "Invalid index";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = ParamName(i) + " is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
void CopyContentTo(ProcParams prms)
|
||||
{
|
||||
prms.ModuleParameter = this.ModuleParameter;
|
||||
prms.MetroEnable = this.MetroEnable;
|
||||
prms.PulseRatePiston = this.PulseRatePiston;
|
||||
prms.PulseRateLed = this.PulseRateLed;
|
||||
prms.OffsetFactor = this.OffsetFactor;
|
||||
prms.FactoryCalibration = this.FactoryCalibration;
|
||||
prms.Units = this.Units;
|
||||
prms.MeterSize = this.MeterSize;
|
||||
prms.OffsetTime = this.OffsetTime;
|
||||
prms.NewReadEnable = this.NewReadEnable;
|
||||
prms.NewRead = this.NewRead;
|
||||
prms.TransIntervalEnable = this.TransIntervalEnable;
|
||||
prms.TransInterval = this.TransInterval;
|
||||
prms.LatIntervalEnable = this.LatIntervalEnable;
|
||||
prms.LatInterval = this.LatInterval;
|
||||
prms.ResetAlarmEnable = this.ResetAlarmEnable;
|
||||
prms.MetrologyTestModeEnable = this.MetrologyTestModeEnable;
|
||||
prms.MetrologyTestModeHours = this.MetrologyTestModeHours;
|
||||
prms.OpticalTelegramEnable = this.OpticalTelegramEnable;
|
||||
prms.OpticalTelegramMinutes = this.OpticalTelegramMinutes;
|
||||
prms.ChangeRadioEnable = this.ChangeRadioEnable;
|
||||
prms.ChangeMeterIDEnable = this.ChangeMeterIDEnable;
|
||||
prms.SoftSealEnable = this.SoftSealEnable;
|
||||
prms.GoToSleepEnable = this.GoToSleepEnable;
|
||||
prms.SaveDBEnable = this.SaveDBEnable;
|
||||
prms.KeyMode = this.KeyMode;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameterless constructor initializes the parameters
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user