40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
|
|
using System;
|
||
|
|
using System.Globalization;
|
||
|
|
|
||
|
|
namespace TBF.Rig.TestMethods.GenesisCommunication
|
||
|
|
{
|
||
|
|
public static class GenesisCalibrationFactors
|
||
|
|
{
|
||
|
|
// Preserve the special branch default only when no channel has been configured.
|
||
|
|
public const ushort DefaultFactor = 15625;
|
||
|
|
|
||
|
|
public static bool TryParse(string text1, string text2, string text3,
|
||
|
|
out double[] factors, out string error)
|
||
|
|
{
|
||
|
|
factors = null;
|
||
|
|
error = null;
|
||
|
|
var text = new[] { text1, text2, text3 };
|
||
|
|
if (Array.TrueForAll(text, string.IsNullOrWhiteSpace))
|
||
|
|
{
|
||
|
|
factors = new double[] { DefaultFactor, DefaultFactor, DefaultFactor };
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
var parsed = new double[3];
|
||
|
|
for (int channel = 0; channel < parsed.Length; channel++)
|
||
|
|
{
|
||
|
|
ushort value;
|
||
|
|
if (!ushort.TryParse(text[channel]?.Trim(), NumberStyles.None,
|
||
|
|
CultureInfo.InvariantCulture, out value) || value == 0)
|
||
|
|
{
|
||
|
|
error = "Genesis calibration Text" + (channel + 1) + " must be an integer from 1 to 65535. Set all three channels.";
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
parsed[channel] = value;
|
||
|
|
}
|
||
|
|
factors = parsed;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|