A – Registration and execution - Register GenesisCommunication Factory in the component list. - Separate the Genesis form and sequence from iPerl communication. B – Communication activities - Restore initialization, connection, PCB reading, password and login. - Include grouped login, mode switching and disconnection. - Support processing up to 10 slots. C1 – Input calibration factors - Read three factors from Water meters / Text1–Text3. - Validate integer values in the range 1–65535. - Preserve the default of 15625 when all three fields are empty. D – Q3 calibration - Connect the Prepare Q3 → measurement → Write Q3 workflow. - Add channel processing to FlyingStart and FlyingStartMassCollection. - Reset previous measurement data and validate calculated factors. - Mark factors as stored only after StoreCalibration succeeds. E – Results and database - Store calibration factors separately for each meter and channel. - Add result entities, mappings and Q3 data. - Extend DB.cs / EnsureSchema to create and update the schema. - Preserve compatibility with the existing binary format. Validation: - Debug build and 18 tests passed. - Simulated communication runs follow the same activity sequence. - The complete Q3 workflow has not yet been verified on hardware. Known limitation: - An inherited mismatch in simulated responses and error propagation can produce an incorrect OK result; this change does not fix it.
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;
|
|
}
|
|
}
|
|
}
|