157 lines
4.5 KiB
C#
157 lines
4.5 KiB
C#
///
|
|
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO.Ports;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.RegisterReaders.PoseidonCmdStartStop
|
|
{
|
|
/// PoseidonCSSCfg => Poseidon Cmd Start Stop Cfg
|
|
public class PoseidonCfg : ComponentCfgBase, IComponentCfg, IParamsProvider
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(PoseidonCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
public string ComponentName { get; }
|
|
|
|
///
|
|
/// Serialized parameters
|
|
///
|
|
public int ComPortNr;
|
|
public string CliFileName;
|
|
public int MeterType;
|
|
|
|
|
|
/// <summary> Procedure parameters </summary>
|
|
[XmlIgnore]
|
|
public PoseidonProcParams ProcParams;
|
|
public override IParamsProvider GetRuntimeProcParamsProvider() { return ProcParams; }
|
|
public override IParamsProvider CreateProcParamsProvider() { return new PoseidonProcParams(true); }
|
|
|
|
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Serial port number", /// 0
|
|
"CLI program name", /// 1
|
|
"Meter Type", /// 2
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
return new string[] { "3","4","5","6","7","8","9","10","11","12"};
|
|
case 1:
|
|
return new string[] { "HatCLI.exe"};
|
|
case 2:
|
|
return new string[] { "74" };
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
|
|
|
|
|
public void InitializeAll()
|
|
{
|
|
ComPortNr = 3;
|
|
CliFileName = "HatCLI.exe";
|
|
MeterType = 74;
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int idummy;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (int.TryParse(strValue, out idummy) && idummy > 0) return true;
|
|
break;
|
|
case 1:
|
|
if (ParamValues(i).Contains(strValue)) return true; //is in list
|
|
if(System.Text.RegularExpressions.Regex.IsMatch(strValue, @"^[a-zA-Z0-9_-]+\.exe$")) return true; //validate exe file name
|
|
break;
|
|
case 2:
|
|
if (int.TryParse(strValue, out idummy) && idummy > 0) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string str)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 1: CliFileName = str; return CfgUpdateFlags.RestartRqrd;
|
|
case 2: MeterType = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
PoseidonCfg pars = new PoseidonCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
PoseidonCfg()
|
|
{
|
|
ProcParams = CreateProcParamsProvider() as PoseidonProcParams;
|
|
}
|
|
|
|
public PoseidonCfg(string name, IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
Factory = factory;
|
|
ParentName = "";
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return ComPortNr.ToString();
|
|
case 1: return CliFileName;
|
|
case 2: return MeterType.ToString();
|
|
default:
|
|
return string.Format("{0}: Com{1}, CliName =`{2}`, MeterType = {3}",
|
|
Name, ComPortNr, CliFileName, MeterType);
|
|
}
|
|
}
|
|
|
|
void CopyContentTo(PoseidonCfg prms)
|
|
{
|
|
prms.ComPortNr = this.ComPortNr;
|
|
prms.CliFileName = this.CliFileName;
|
|
prms.MeterType = this.MeterType;
|
|
prms.ProcParams = this.ProcParams;
|
|
}
|
|
}
|
|
}
|