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.
192 lines
6.2 KiB
C#
192 lines
6.2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO.Ports;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.RegisterReaders.AllyReader
|
|
{
|
|
public class AllyReaderCfg : ComponentCfgBase, IComponentCfg, IParamsProvider
|
|
{
|
|
public static readonly XmlSerializer Serializer =
|
|
XmlSerializer.FromTypes(new[] { typeof(AllyReaderCfg) })[0];
|
|
|
|
public int CommandComPortNr;
|
|
public int CommandBaudRate;
|
|
public int OptoComPortNr;
|
|
public int OptoBaudRate;
|
|
public AllyMeterSize ConfiguredMeterSize;
|
|
public double MeterPulsesPerLiter;
|
|
|
|
private AllyReaderCfg()
|
|
{
|
|
}
|
|
|
|
public AllyReaderCfg(IComponentFactory factory)
|
|
{
|
|
Factory = factory;
|
|
Name = "Ally";
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public override XmlSerializer GetSerializer()
|
|
{
|
|
return Serializer;
|
|
}
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities)
|
|
{
|
|
return new Configs.ParamsProvider.ComponentCfgCtrl(this, null);
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
CommandComPortNr = 1;
|
|
CommandBaudRate = 2400;
|
|
OptoComPortNr = 2;
|
|
OptoBaudRate = 9600;
|
|
ConfiguredMeterSize = AllyMeterSize.AutoDetect;
|
|
MeterPulsesPerLiter = 1000D;
|
|
}
|
|
|
|
public int ParamsCount()
|
|
{
|
|
return 6;
|
|
}
|
|
|
|
public string ParamName(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return "Touch-Read COM port";
|
|
case 1: return "Touch-Read baud rate";
|
|
case 2: return "Optical COM port";
|
|
case 3: return "Optical baud rate";
|
|
case 4: return "Configured ALLY meter size";
|
|
case 5: return "Meter pulses per liter";
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 1:
|
|
return new[] { "1200", "2400", "4800", "9600" };
|
|
case 3:
|
|
return new[] { "9600", "19200", "38400", "57600" };
|
|
case 4:
|
|
return new[]
|
|
{
|
|
AllyMeterSize.AutoDetect.ToString(),
|
|
AllyMeterSize.FiveEighths.ToString(),
|
|
AllyMeterSize.ThreeQuarterShort.ToString(),
|
|
AllyMeterSize.ThreeQuarterLong.ToString(),
|
|
AllyMeterSize.OneInch.ToString()
|
|
};
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return CommandComPortNr.ToString();
|
|
case 1: return CommandBaudRate.ToString();
|
|
case 2: return OptoComPortNr.ToString();
|
|
case 3: return OptoBaudRate.ToString();
|
|
case 4: return ConfiguredMeterSize.ToString();
|
|
case 5: return MeterPulsesPerLiter.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
default:
|
|
return string.Format(
|
|
"{0}: Touch-Read=COM{1}/{2}, Optical=COM{3}/{4}, Size={5}",
|
|
Name,
|
|
CommandComPortNr,
|
|
CommandBaudRate,
|
|
OptoComPortNr,
|
|
OptoBaudRate,
|
|
ConfiguredMeterSize);
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: CommandComPortNr = int.Parse(strValue); break;
|
|
case 1: CommandBaudRate = int.Parse(strValue); break;
|
|
case 2: OptoComPortNr = int.Parse(strValue); break;
|
|
case 3: OptoBaudRate = int.Parse(strValue); break;
|
|
case 4: ConfiguredMeterSize = (AllyMeterSize)System.Enum.Parse(typeof(AllyMeterSize), strValue); break;
|
|
case 5: MeterPulsesPerLiter = Utils.ParseUDouble(strValue); break;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int integerValue;
|
|
double doubleValue;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
case 2:
|
|
if (int.TryParse(strValue, out integerValue) && integerValue > 0)
|
|
return true;
|
|
break;
|
|
case 1:
|
|
case 3:
|
|
if (int.TryParse(strValue, out integerValue) && integerValue > 0)
|
|
return true;
|
|
break;
|
|
case 4:
|
|
AllyMeterSize meterSize;
|
|
if (System.Enum.TryParse(strValue, out meterSize))
|
|
return true;
|
|
break;
|
|
case 5:
|
|
if (double.TryParse(strValue, out doubleValue) && doubleValue > 0)
|
|
return true;
|
|
break;
|
|
default:
|
|
message = "Invalid parameter index.";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid.";
|
|
return false;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
return new AllyReaderCfg
|
|
{
|
|
Name = Name,
|
|
ParentName = ParentName,
|
|
Factory = Factory,
|
|
CommandComPortNr = CommandComPortNr,
|
|
CommandBaudRate = CommandBaudRate,
|
|
OptoComPortNr = OptoComPortNr,
|
|
OptoBaudRate = OptoBaudRate,
|
|
ConfiguredMeterSize = ConfiguredMeterSize,
|
|
MeterPulsesPerLiter = MeterPulsesPerLiter
|
|
};
|
|
}
|
|
}
|
|
}
|