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.
187 lines
5.8 KiB
C#
187 lines
5.8 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.TestMethods.AllyCalibration
|
|
{
|
|
public class TestMethodCfg : ComponentCfgBase, IComponentCfg, IParamsProvider
|
|
{
|
|
public static readonly XmlSerializer Serializer =
|
|
XmlSerializer.FromTypes(new[] { typeof(TestMethodCfg) })[0];
|
|
|
|
public int CommandTimeoutMs;
|
|
public int MaxAttempts;
|
|
public int DelayBetweenAttemptsMs;
|
|
public string ExpectedDeviceType;
|
|
public string ExpectedFirmwareVersion;
|
|
|
|
[XmlIgnore]
|
|
public ITestParams TestParams { get; set; }
|
|
|
|
private TestMethodCfg()
|
|
{
|
|
}
|
|
|
|
public TestMethodCfg(IComponentFactory factory)
|
|
{
|
|
Factory = factory;
|
|
Name = "AllyCalibrationCommunication";
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
TestParams = CreateTestParamsProvider() as TestMethodParams;
|
|
}
|
|
|
|
public override XmlSerializer GetSerializer()
|
|
{
|
|
return Serializer;
|
|
}
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Component> cmpntEntities)
|
|
{
|
|
return new Configs.ParamsProvider.ComponentCfgCtrl(this, null);
|
|
}
|
|
|
|
public override IParamsProvider GetRuntimeTestParamsProvider()
|
|
{
|
|
return TestParams;
|
|
}
|
|
|
|
public override IParamsProvider CreateTestParamsProvider()
|
|
{
|
|
return new TestMethodParams(true);
|
|
}
|
|
|
|
public override IParamsProvider GetUITestParamsProvider(Test test)
|
|
{
|
|
return test.Method == Name ? base.GetUITestParamsProvider(test) : null;
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
CommandTimeoutMs = 5000;
|
|
MaxAttempts = 4;
|
|
DelayBetweenAttemptsMs = 250;
|
|
ExpectedDeviceType = "SWM003";
|
|
ExpectedFirmwareVersion = string.Empty;
|
|
}
|
|
|
|
public int ParamsCount()
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
public string ParamName(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return "Command timeout [ms]";
|
|
case 1: return "Maximum command attempts";
|
|
case 2: return "Delay between attempts [ms]";
|
|
case 3: return "Expected ALLY device type";
|
|
case 4: return "Expected firmware version";
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return CommandTimeoutMs.ToString();
|
|
case 1: return MaxAttempts.ToString();
|
|
case 2: return DelayBetweenAttemptsMs.ToString();
|
|
case 3: return ExpectedDeviceType;
|
|
case 4: return ExpectedFirmwareVersion;
|
|
default:
|
|
return string.Format(
|
|
"{0}: timeout={1}ms, attempts={2}, device={3}, firmware={4}",
|
|
Name,
|
|
CommandTimeoutMs,
|
|
MaxAttempts,
|
|
ExpectedDeviceType,
|
|
string.IsNullOrEmpty(ExpectedFirmwareVersion) ? "not checked" : ExpectedFirmwareVersion);
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: CommandTimeoutMs = int.Parse(strValue); break;
|
|
case 1: MaxAttempts = int.Parse(strValue); break;
|
|
case 2: DelayBetweenAttemptsMs = int.Parse(strValue); break;
|
|
case 3: ExpectedDeviceType = strValue; break;
|
|
case 4: ExpectedFirmwareVersion = strValue; break;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int value;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (int.TryParse(strValue, out value) && value >= 100 && value <= 60000)
|
|
return true;
|
|
break;
|
|
case 1:
|
|
if (int.TryParse(strValue, out value) && value >= 1 && value <= 4)
|
|
return true;
|
|
break;
|
|
case 2:
|
|
if (int.TryParse(strValue, out value) && value >= 0 && value <= 10000)
|
|
return true;
|
|
break;
|
|
case 3:
|
|
if (!string.IsNullOrWhiteSpace(strValue))
|
|
return true;
|
|
break;
|
|
case 4:
|
|
return true;
|
|
default:
|
|
message = "Invalid parameter index.";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid.";
|
|
return false;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
return new TestMethodCfg
|
|
{
|
|
Name = Name,
|
|
ParentName = ParentName,
|
|
Factory = Factory,
|
|
CommandTimeoutMs = CommandTimeoutMs,
|
|
MaxAttempts = MaxAttempts,
|
|
DelayBetweenAttemptsMs = DelayBetweenAttemptsMs,
|
|
ExpectedDeviceType = ExpectedDeviceType,
|
|
ExpectedFirmwareVersion = ExpectedFirmwareVersion,
|
|
TestParams = TestParams == null ? null : TestParams.Clone() as ITestParams
|
|
};
|
|
}
|
|
}
|
|
}
|