169 lines
4.6 KiB
C#
169 lines
4.6 KiB
C#
///
|
|
/// Copyright (c) 2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
using System.Collections.Generic;
|
|
|
|
namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
|
{
|
|
public class iPerlCommunicationParams : TestParamsBase, IParamsProvider, ITestParams
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(iPerlCommunicationParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public string Activity; /// Communication activity
|
|
public bool SimultWithPrevious;
|
|
public bool SimultWithNext;
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
Activity = "Read Configuration";
|
|
SimultWithPrevious = false;
|
|
SimultWithNext = false;
|
|
}
|
|
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
Strings.Activity,
|
|
Strings.Simultaneous_with_previous_step,
|
|
Strings.Simultaneous_with_next_step,
|
|
};
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override IList<string> ParamValues(int i)
|
|
{
|
|
IList<string> retVal = new List<string>();
|
|
|
|
if (i == 0)
|
|
{
|
|
retVal.Add("Read configuration");
|
|
retVal.Add("Set Test mode A0");
|
|
retVal.Add("Set Test mode A4");
|
|
retVal.Add("Read calibration");
|
|
retVal.Add("Normalize calibration factor");
|
|
retVal.Add("Reset Q2 correction");
|
|
retVal.Add("Write calibration factor");
|
|
retVal.Add("Write Q2 correction");
|
|
retVal.Add("Write Q2 correction Alt");
|
|
retVal.Add("Write Q2 correction Greece");
|
|
retVal.Add("Q2 corrected from Q2adj");
|
|
retVal.Add("Set Active mode");
|
|
retVal.Add("---");
|
|
retVal.Add("Reset 2Hz correction");
|
|
retVal.Add("Write 2Hz correction");
|
|
retVal.Add("Read configuration if enabled");
|
|
retVal.Add("Set Test mode 80");
|
|
}
|
|
else
|
|
{
|
|
retVal.Add(Strings.yes);
|
|
retVal.Add(Strings.no);
|
|
}
|
|
|
|
return retVal;
|
|
}
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return Activity;
|
|
case 1: return (SimultWithPrevious ? Strings.yes : Strings.no);
|
|
case 2: return (SimultWithNext ? Strings.yes : Strings.no);
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: Activity = strValue; return CfgUpdateFlags.None;
|
|
case 1: SimultWithPrevious = strValue.ToLower().Equals(Strings.yes.ToLower()); return CfgUpdateFlags.None;
|
|
case 2: SimultWithNext = strValue.ToLower().Equals(Strings.yes.ToLower()); return CfgUpdateFlags.None;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
return true;
|
|
case 1:
|
|
case 2:
|
|
if (strValue.Equals(Strings.yes) || strValue.Equals(Strings.no)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(iPerlCommunicationParams prms)
|
|
{
|
|
prms.Activity = this.Activity;
|
|
prms.SimultWithPrevious = this.SimultWithPrevious;
|
|
prms.SimultWithNext = this.SimultWithNext;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
iPerlCommunicationParams pars = new iPerlCommunicationParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override void UpdateFromDbEntity(ComponentTest dbEntity)
|
|
{
|
|
if (dbEntity == null) return;
|
|
try
|
|
{
|
|
iPerlCommunicationParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as iPerlCommunicationParams;
|
|
|
|
testParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
test = dbEntity.Test;
|
|
|
|
if (tmp != null) tmp.CopyContentTo(this);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parameterless constructor initializes the parameters
|
|
/// </summary>
|
|
public iPerlCommunicationParams()
|
|
{
|
|
}
|
|
|
|
public iPerlCommunicationParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public iPerlCommunicationParams(ComponentTest testParamsEntity, string componentName, Test test)
|
|
{
|
|
this.testParamsEntity = testParamsEntity;
|
|
this.componentName = componentName;
|
|
this.test = test;
|
|
}
|
|
}
|
|
}
|