223 lines
7.9 KiB
C#
223 lines
7.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; } /// 0
|
|
public string FileExchangePath { get; set; } /// 1
|
|
public int FileExchangeTimeout { get; set; } /// 2
|
|
public SerialNumbers SerialNumbers { get; set; } /// 3
|
|
public SerialNumbers AssignedNumbers { get; set; } /// 4
|
|
public bool SkipBadMeters { get; set; } /// 5
|
|
public bool SimultWithEvacuation { get; set; } /// 6
|
|
public bool EndSessionWhenCompleted { get; set; } /// 7
|
|
|
|
/// <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 = "C:\\eRegister Programming\\DataTransfer";
|
|
FileExchangeTimeout = 420;
|
|
SerialNumbers = SerialNumbers.None;
|
|
AssignedNumbers = SerialNumbers.None;
|
|
SkipBadMeters = false;
|
|
SimultWithEvacuation = true;
|
|
EndSessionWhenCompleted = false;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Awaiting optical data timeout [s] (0 = off)",
|
|
"File exchange path",
|
|
"File exchange timeout [s] (0 = off)",
|
|
"Housing numbers mode",
|
|
"Assigned S/N-s mode",
|
|
"Skip bad meters when entering s/n",
|
|
"Simultaneous with evacuation",
|
|
"End session when completed OK",
|
|
};
|
|
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:
|
|
return new List<string> { SerialNumbers.None.ToString(),
|
|
SerialNumbers.DisplayReadonly.ToString(),
|
|
SerialNumbers.EnterManually.ToString(),
|
|
SerialNumbers.FromProductionTracing.ToString() };
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
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 SerialNumbers.ToString();
|
|
case 4: return AssignedNumbers.ToString();
|
|
case 5: return SkipBadMeters ? Strings.yes : Strings.no;
|
|
case 6: return SimultWithEvacuation ? Strings.yes : Strings.no;
|
|
case 7: return EndSessionWhenCompleted ? 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:
|
|
for (SerialNumbers sn = 0; sn < SerialNumbers.Count; sn++)
|
|
if (sn.ToString() == strValue)
|
|
{
|
|
SerialNumbers = sn;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
break;
|
|
case 4:
|
|
for (SerialNumbers sn = 0; sn < SerialNumbers.Count; sn++)
|
|
if (sn.ToString() == strValue)
|
|
{
|
|
AssignedNumbers = sn;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
break;
|
|
case 5:
|
|
SkipBadMeters = (strValue == Strings.yes);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
case 6:
|
|
SimultWithEvacuation = (strValue == Strings.yes);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
case 7:
|
|
EndSessionWhenCompleted = (strValue == Strings.yes);
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
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:
|
|
case 6:
|
|
case 7:
|
|
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.SerialNumbers = this.SerialNumbers;
|
|
prms.AssignedNumbers = this.AssignedNumbers;
|
|
prms.SkipBadMeters = this.SkipBadMeters;
|
|
prms.SimultWithEvacuation = this.SimultWithEvacuation;
|
|
prms.EndSessionWhenCompleted = this.EndSessionWhenCompleted;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
S640EndCfg pars = new S640EndCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|