Refactor `ISmartReader` and related classes to support `SmartHeadsUni`. Remove redundant `IperlHeadsUni` references and introduce `SmartMeterFlyingStartMassCollection` functionality. Enhance regex-based head position extraction.
301 lines
14 KiB
C#
301 lines
14 KiB
C#
///
|
|
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
|
|
///
|
|
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Rig.TestMethods.iPerlCommunication;
|
|
|
|
namespace TBF.Rig.TestMethods.SmartMeterFlyingStartMassCollection
|
|
{
|
|
public partial class TestMethodCfgCtrl : Configs.ConfigCtrlUtils, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
TestMethodCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as TestMethodCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public TestMethodCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void EntryFormCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
commTimeoutTextBox.Text = config.CommTimeout.ToString();
|
|
maxCommRetriesTextBox.Text = config.MaxCommRetries.ToString();
|
|
delayBetweenRetriesTextBox.Text = config.DelayBetweenRetries.ToString();
|
|
nrThreadsTextBox.Text = config.NrThreads.ToString();
|
|
iperlCheckErrorsToStopTextBox.Text = config.IperlCheckErrorsToStop.ToString();
|
|
|
|
textBox15rl.Text = config.DfltQ2c_15_rl.ToString();
|
|
textBox15lr.Text = config.DfltQ2c_15_lr.ToString();
|
|
textBox20rl.Text = config.DfltQ2c_20_rl.ToString();
|
|
textBox20lr.Text = config.DfltQ2c_20_lr.ToString();
|
|
textBox25_63rl.Text = config.DfltQ2c_25_63_rl.ToString();
|
|
textBox25_63lr.Text = config.DfltQ2c_25_63_lr.ToString();
|
|
textBox25_10rl.Text = config.DfltQ2c_25_10_rl.ToString();
|
|
textBox25_10lr.Text = config.DfltQ2c_25_10_lr.ToString();
|
|
textBox32rl.Text = config.DfltQ2c_32_rl.ToString();
|
|
textBox32lr.Text = config.DfltQ2c_32_lr.ToString();
|
|
textBox40rl.Text = config.DfltQ2c_40_rl.ToString();
|
|
textBox40lr.Text = config.DfltQ2c_40_lr.ToString();
|
|
|
|
useWebServiceCheckBox.Checked = config.UseWebService;
|
|
baseUrlTextBox.Text = config.BaseUrl;
|
|
relativeUrlTextBox.Text = config.RelativeUrl;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
commTimeoutTextBox.Enabled = true;
|
|
maxCommRetriesTextBox.Enabled = true;
|
|
delayBetweenRetriesTextBox.Enabled = true;
|
|
nrThreadsTextBox.Enabled = true;
|
|
iperlCheckErrorsToStopTextBox.Enabled = true;
|
|
|
|
textBox15rl.Enabled = true;
|
|
textBox15lr.Enabled = true;
|
|
textBox20rl.Enabled = true;
|
|
textBox20lr.Enabled = true;
|
|
textBox25_63rl.Enabled = true;
|
|
textBox25_63lr.Enabled = true;
|
|
textBox25_10rl.Enabled = true;
|
|
textBox25_10lr.Enabled = true;
|
|
textBox32rl.Enabled = true;
|
|
textBox32lr.Enabled = true;
|
|
textBox40rl.Enabled = true;
|
|
textBox40lr.Enabled = true;
|
|
|
|
useWebServiceCheckBox.Enabled = true;
|
|
ManageCheckGroupBox(useWebServiceCheckBox, useWebServiceGroupBox);
|
|
baseUrlTextBox.Enabled = useWebServiceCheckBox.Enabled;
|
|
relativeUrlTextBox.Enabled = useWebServiceCheckBox.Enabled;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!int.TryParse(commTimeoutTextBox.Text, out dummy) || dummy < 500 || dummy > 5000)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Comm. timeout' should be in range 500 .. 5000";
|
|
}
|
|
if (!int.TryParse(maxCommRetriesTextBox.Text, out dummy) || dummy < 1 || dummy > 10)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Max. retries' should be in range 1 .. 10";
|
|
}
|
|
if (!int.TryParse(delayBetweenRetriesTextBox.Text, out dummy) || dummy < 0 || dummy > 5000)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Comm. timeout' should be in range 0 .. 5000";
|
|
}
|
|
if (!int.TryParse(nrThreadsTextBox.Text, out dummy) || (dummy != 1 && dummy != 2 && dummy != 4))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Nr. threads' should be 1, 2 or 4";
|
|
}
|
|
if (!int.TryParse(iperlCheckErrorsToStopTextBox.Text, out dummy) || ((dummy < 1) && (dummy > 40)))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, iperlCheckErrorsToStopLabel.Text);
|
|
}
|
|
|
|
if (!int.TryParse(textBox15rl.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN15 RL should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox15lr.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN15 LR should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox20rl.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN20 RL should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox20lr.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN20 LR should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox25_63rl.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN25 Q3 6.3 RL should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox25_63lr.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN25 Q3 6.3 LR should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox25_10rl.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN25 Q3 10 RL should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox25_10lr.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN25 Q3 10 LR should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox32rl.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN32 RL should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox32lr.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN32 LR should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox40rl.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN40 RL should be in range -50 .. 50";
|
|
}
|
|
if (!int.TryParse(textBox40lr.Text, out dummy) || dummy < -50 || dummy > 50)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Default Q2 correction factor DN40 LR should be in range -50 .. 50";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
if (config.Name != nameTextBox.Text)
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
|
}
|
|
|
|
var CommTimeout = config.CommTimeout;;
|
|
var MaxCommRetries = config.MaxCommRetries;
|
|
var DelayBetweenRetries = config.DelayBetweenRetries;
|
|
var NrThreads = config.NrThreads;
|
|
var IperlCheckErrorsToStop = config.IperlCheckErrorsToStop;
|
|
var DfltQ2c_15_rl = config.DfltQ2c_15_rl;
|
|
var DfltQ2c_15_lr = config.DfltQ2c_15_lr;
|
|
var DfltQ2c_20_rl = config.DfltQ2c_20_rl;
|
|
var DfltQ2c_20_lr = config.DfltQ2c_20_lr;
|
|
var DfltQ2c_25_63_rl = config.DfltQ2c_25_63_rl;
|
|
var DfltQ2c_25_63_lr = config.DfltQ2c_25_63_lr;
|
|
var DfltQ2c_25_10_rl = config.DfltQ2c_25_10_rl;
|
|
var DfltQ2c_25_10_lr = config.DfltQ2c_25_10_lr;
|
|
var DfltQ2c_32_rl = config.DfltQ2c_32_rl;
|
|
var DfltQ2c_32_lr = config.DfltQ2c_32_lr;
|
|
var DfltQ2c_40_rl = config.DfltQ2c_40_rl;
|
|
var DfltQ2c_40_lr = config.DfltQ2c_40_lr;
|
|
var UseWebService = config.UseWebService;
|
|
var BaseUrl = config.BaseUrl;
|
|
var RelativeUrl = config.RelativeUrl;
|
|
|
|
flags |= UpdateDifferent(ref CommTimeout, commTimeoutTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref MaxCommRetries, maxCommRetriesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DelayBetweenRetries, delayBetweenRetriesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref NrThreads, nrThreadsTextBox.Text, CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref IperlCheckErrorsToStop, iperlCheckErrorsToStopTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
|
|
flags |= UpdateDifferent(ref DfltQ2c_15_rl, textBox15rl.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_15_lr, textBox15lr.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_20_rl, textBox20rl.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_20_lr, textBox20lr.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_25_63_rl, textBox25_63rl.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_25_63_lr, textBox25_63lr.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_25_10_rl, textBox25_10rl.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_25_10_lr, textBox25_10lr.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_32_rl, textBox32rl.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_32_lr, textBox32lr.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_40_rl, textBox40rl.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref DfltQ2c_40_lr, textBox40lr.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
|
|
flags |= UpdateDifferent(ref UseWebService, useWebServiceCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref BaseUrl, baseUrlTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
flags |= UpdateDifferent(ref RelativeUrl, relativeUrlTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
|
|
|
|
config.CommTimeout = CommTimeout;
|
|
config.MaxCommRetries = MaxCommRetries;
|
|
config.DelayBetweenRetries = DelayBetweenRetries;
|
|
config.NrThreads = NrThreads;
|
|
config.IperlCheckErrorsToStop = IperlCheckErrorsToStop;
|
|
config.DfltQ2c_15_rl = DfltQ2c_15_rl;
|
|
config.DfltQ2c_15_lr = DfltQ2c_15_lr;
|
|
config.DfltQ2c_20_rl = DfltQ2c_20_rl;
|
|
config.DfltQ2c_20_lr = DfltQ2c_20_lr;
|
|
config.DfltQ2c_25_63_rl = DfltQ2c_25_63_rl;
|
|
config.DfltQ2c_25_63_lr = DfltQ2c_25_63_lr;
|
|
config.DfltQ2c_25_10_rl = DfltQ2c_25_10_rl;
|
|
config.DfltQ2c_25_10_lr = DfltQ2c_25_10_lr;
|
|
config.DfltQ2c_32_rl = DfltQ2c_32_rl;
|
|
config.DfltQ2c_32_lr = DfltQ2c_32_lr;
|
|
config.DfltQ2c_40_rl = DfltQ2c_40_rl;
|
|
config.DfltQ2c_40_lr = DfltQ2c_40_lr;
|
|
config.UseWebService = UseWebService;
|
|
config.BaseUrl = BaseUrl;
|
|
config.RelativeUrl = RelativeUrl;
|
|
|
|
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
|
{
|
|
TestMethod.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void ManageCheckGroupBox(CheckBox chk, GroupBox grp)
|
|
{
|
|
/// Make sure the CheckBox isn't in the GroupBox. This will only happen the first time.
|
|
if (chk.Parent == grp)
|
|
{
|
|
grp.Parent.Controls.Add(chk); /// Reparent the CheckBox so it's not in the GroupBox.
|
|
chk.Location = new System.Drawing.Point(chk.Left + grp.Left, chk.Top + grp.Top); /// Adjust the CheckBox's location.
|
|
chk.BringToFront(); /// Move the CheckBox to the top of the stacking order.
|
|
}
|
|
|
|
/// Enable or disable the GroupBox.
|
|
grp.Enabled = chk.Checked;
|
|
}
|
|
|
|
private void useWebServiceCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
useWebServiceGroupBox.Enabled = useWebServiceCheckBox.Checked;
|
|
}
|
|
}
|
|
}
|