137 lines
4.2 KiB
C#
137 lines
4.2 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.ControlBoard.Uni
|
|
{
|
|
/// <summary>
|
|
/// Holds backup and security options - serializable configuration.
|
|
/// </summary>
|
|
public class CBoardCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(CBoardCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl() { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
|
|
|
///
|
|
/// Serialized parameters
|
|
///
|
|
public int ComPortNr;
|
|
public int VirtValvesRangeLo;
|
|
public int VirtValvesRangeHi;
|
|
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
CBoardCfg() { }
|
|
|
|
public CBoardCfg(string name, IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
Factory = factory;
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
ComPortNr = 1;
|
|
VirtValvesRangeLo = 90;
|
|
VirtValvesRangeHi = 99;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Serial port number",
|
|
"Virtual valves range LO [bit#]",
|
|
"Virtual valves range HI [bit#]",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public IList<string> ParamValues(int i)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
if (i == -1)
|
|
{
|
|
return string.Format("{0}: COM{1}, VirtValvesRngLO={2}, VirtValvesRngeHI={3}", Name, ComPortNr, VirtValvesRangeLo, VirtValvesRangeHi);
|
|
}
|
|
|
|
switch (i)
|
|
{
|
|
case 0: return ComPortNr.ToString();
|
|
case 1: return VirtValvesRangeLo.ToString();
|
|
case 2: return VirtValvesRangeHi.ToString();
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: ComPortNr = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
case 1: VirtValvesRangeLo = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
case 2: VirtValvesRangeHi = int.Parse(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int dummy;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
/// Real number between 800 and 1200 kg/m3 expected
|
|
if (int.TryParse(strValue, out dummy) && (dummy >= 1) && (dummy <= 1000)) return true;
|
|
break;
|
|
case 1:
|
|
case 2:
|
|
/// Real number above 0 expected
|
|
if (int.TryParse(strValue, out dummy) && (dummy >= 0) && dummy <= 127) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(CBoardCfg prms)
|
|
{
|
|
prms.ComPortNr = this.ComPortNr;
|
|
prms.VirtValvesRangeLo = this.VirtValvesRangeLo;
|
|
prms.VirtValvesRangeHi = this.VirtValvesRangeHi;
|
|
}
|
|
|
|
public Config.Entities.IParamsProvider Clone()
|
|
{
|
|
var pars = new CBoardCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|