Add AllyReader and AllyCalibration support with tests: Introduce new register readers, calibration methods, and comprehensive unit tests for integration and functionality validation. Update project files accordingly.
164 lines
5.2 KiB
C#
164 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.TestMethods.AllyCalibration
|
|
{
|
|
public class TestMethodParams : TestParamsBase, IParamsProvider, ITestParams
|
|
{
|
|
public static readonly XmlSerializer Serializer =
|
|
XmlSerializer.FromTypes(new[] { typeof(TestMethodParams) })[0];
|
|
|
|
public double CalibrationFactorPercent;
|
|
|
|
public override XmlSerializer GetSerializer()
|
|
{
|
|
return Serializer;
|
|
}
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
Activity = AllyCalibrationActivityNames.ReadSerialNumber;
|
|
CalibrationFactorPercent = 100D;
|
|
SimultWithPrevious = false;
|
|
SimultWithNext = false;
|
|
}
|
|
|
|
public override int ParamsCount()
|
|
{
|
|
return 4;
|
|
}
|
|
|
|
public override string ParamName(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return Strings.Activity;
|
|
case 1: return "Calibration factor [%]";
|
|
case 2: return Strings.Simultaneous_with_previous_step;
|
|
case 3: return Strings.Simultaneous_with_next_step;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public override ICollection<string> ParamValues(int i)
|
|
{
|
|
if (i == 0)
|
|
return AllyCalibrationActivityNames.All;
|
|
if (i == 2 || i == 3)
|
|
return new[] { Strings.yes, Strings.no };
|
|
return null;
|
|
}
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return Activity;
|
|
case 1: return CalibrationFactorPercent.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
case 2: return SimultWithPrevious ? Strings.yes : Strings.no;
|
|
case 3: return SimultWithNext ? Strings.yes : Strings.no;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public new CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: Activity = strValue; break;
|
|
case 1: CalibrationFactorPercent = Utils.ParseUDouble(strValue); break;
|
|
case 2: SimultWithPrevious = string.Equals(strValue, Strings.yes, StringComparison.OrdinalIgnoreCase); break;
|
|
case 3: SimultWithNext = string.Equals(strValue, Strings.yes, StringComparison.OrdinalIgnoreCase); break;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
|
|
public new bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
AllyCalibrationActivity activity;
|
|
double factor;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (AllyCalibrationActivityNames.TryParse(strValue, out activity))
|
|
return true;
|
|
break;
|
|
case 1:
|
|
if (double.TryParse(strValue, out factor) && factor > 0D && factor < 1600D)
|
|
return true;
|
|
break;
|
|
case 2:
|
|
case 3:
|
|
if (string.Equals(strValue, Strings.yes, StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(strValue, Strings.no, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
break;
|
|
default:
|
|
message = "Invalid parameter index.";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid.";
|
|
return false;
|
|
}
|
|
|
|
public new IParamsProvider Clone()
|
|
{
|
|
return new TestMethodParams
|
|
{
|
|
Activity = Activity,
|
|
CalibrationFactorPercent = CalibrationFactorPercent,
|
|
SimultWithPrevious = SimultWithPrevious,
|
|
SimultWithNext = SimultWithNext
|
|
};
|
|
}
|
|
|
|
public override void UpdateFromDbEntity(ComponentTest dbEntity)
|
|
{
|
|
if (dbEntity == null)
|
|
return;
|
|
|
|
try
|
|
{
|
|
TestMethodParams source = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as TestMethodParams;
|
|
testParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
test = dbEntity.Test;
|
|
|
|
if (source != null)
|
|
{
|
|
Activity = source.Activity;
|
|
CalibrationFactorPercent = source.CalibrationFactorPercent;
|
|
SimultWithPrevious = source.SimultWithPrevious;
|
|
SimultWithNext = source.SimultWithNext;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public TestMethodParams()
|
|
{
|
|
}
|
|
|
|
public TestMethodParams(bool initialize)
|
|
{
|
|
if (initialize)
|
|
InitializeAll();
|
|
}
|
|
}
|
|
}
|