172 lines
5.9 KiB
C#
172 lines
5.9 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.TestMethods.S640Communication
|
|
{
|
|
/// <summary>
|
|
/// Holds information identifying the test bench - serializable configuration.
|
|
/// </summary>
|
|
public class S640EndCfg : ComponentCfgBase, IComponentCfg, IParamsProvider, I640Cfg
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(S640EndCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
|
|
|
///
|
|
/// Serialized parameters
|
|
///
|
|
public int OptoDataTimeout { get; set; }
|
|
public string FileExchangePath { get; set; }
|
|
public int FileExchangeTimeout { get; set; }
|
|
public bool EnterSerialNumbers { get; set; }
|
|
public bool SkipBadMeters { get; set; }
|
|
public bool SimultWithEvacuation { get; set; }
|
|
|
|
/// <summary> Procedure parameters </summary>
|
|
[XmlIgnore]
|
|
public ProcParams ProcParams;
|
|
public override IParamsProvider GetRuntimeProcParamsProvider() { return ProcParams; }
|
|
public override IParamsProvider CreateProcParamsProvider() { return new ProcParams(true); }
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
S640EndCfg()
|
|
{
|
|
ProcParams = CreateProcParamsProvider() as ProcParams;
|
|
}
|
|
|
|
public S640EndCfg(string name, IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
Factory = factory;
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
OptoDataTimeout = 120;
|
|
FileExchangePath = "1";
|
|
FileExchangeTimeout = 420;
|
|
EnterSerialNumbers = false;
|
|
SkipBadMeters = false;
|
|
SimultWithEvacuation = true;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Awaiting optical data timeout [s] (0 = off)",
|
|
"File exchange path",
|
|
"File exchange timeout [s] (0 = off)",
|
|
"Enter serial numbers",
|
|
"Skip bad meters when entering s/n",
|
|
"Simultaneous with evacuation",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
return new List<string> { Strings.yes, Strings.no };
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return OptoDataTimeout.ToString();
|
|
case 1: return FileExchangePath;
|
|
case 2: return FileExchangeTimeout.ToString();
|
|
case 3: return EnterSerialNumbers ? Strings.yes : Strings.no;
|
|
case 4: return SkipBadMeters ? Strings.yes : Strings.no;
|
|
case 5: return SimultWithEvacuation ? Strings.yes : Strings.no;
|
|
default:
|
|
return string.Format("{0}: FileExchangePath = '{1}' FileExchangeTimeout = {2}s", Name, FileExchangePath, FileExchangeTimeout);
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: OptoDataTimeout = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
case 1: FileExchangePath = strValue; return CfgUpdateFlags.RestartRqrd;
|
|
case 2: FileExchangeTimeout = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
case 3: EnterSerialNumbers = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 4: SkipBadMeters = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 5: SimultWithEvacuation = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
default:
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int idummy;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
case 2:
|
|
if (int.TryParse(strValue, out idummy) && idummy >= 0 && idummy <= 2000) return true;
|
|
break;
|
|
case 1:
|
|
return true;
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
if (ParamValues(i).Contains(strValue)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(S640EndCfg prms)
|
|
{
|
|
prms.OptoDataTimeout = this.OptoDataTimeout;
|
|
prms.FileExchangePath = this.FileExchangePath;
|
|
prms.FileExchangeTimeout = this.FileExchangeTimeout;
|
|
prms.EnterSerialNumbers = this.EnterSerialNumbers;
|
|
prms.SkipBadMeters = this.SkipBadMeters;
|
|
prms.SimultWithEvacuation = this.SimultWithEvacuation;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
S640EndCfg pars = new S640EndCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|