From 1691c634c6677e425fafd1cf674e1dc4f53dfee8 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 18 Aug 2023 13:48:43 +0200 Subject: [PATCH] Diverter.Resolution 1, 2, 4, and 8 ms implemented, ver. 3.7.2092 --- Common/Enums.cs | 11 ++++- TBF/Properties/AssemblyInfo.cs | 4 +- TBF/Rig/ControlBoard/Uni/DivTransitionData.cs | 10 ++--- TBF/Rig/ControlBoard/Uni/Enums.cs | 1 - .../ControlBoard/Uni/FlyingStartStopTestOp.cs | 1 + TBF/Rig/ControlBoard/Uni/GeneralData.cs | 6 +-- .../Uni/StandingStartStopTestOp.cs | 1 + TBF/Rig/ControlBoard/Uni/UniCB.cs | 23 +++++++++-- TBF/Rig/Uni/Diverter/Diverter.cs | 7 ++-- TBF/Rig/Uni/Diverter/DiverterCfg.cs | 5 ++- .../Uni/Diverter/DiverterCfgCtrl.Designer.cs | 26 +++++++++++- TBF/Rig/Uni/Diverter/DiverterCfgCtrl.cs | 40 ++++++++++++++++++- 12 files changed, 113 insertions(+), 22 deletions(-) diff --git a/Common/Enums.cs b/Common/Enums.cs index bfa8828ef..505e35b22 100644 --- a/Common/Enums.cs +++ b/Common/Enums.cs @@ -653,7 +653,16 @@ namespace Common Count, } - public enum ImageRotation + public enum DivResolution : int + { + [Description("1 ms (0.25 s)")] _1ms = 0, + [Description("2 ms (0.5 s)")] _2ms = 1, + [Description("4 ms (1 s)")] _4ms = 2, + [Description("8 ms (2 s)")] _8ms = 3, + Count, + } + + public enum ImageRotation { [Description("0 deg")] None, [Description("90 deg")] Deg90, diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index b438e9741..dc6beb30b 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.7.2088.0")] -[assembly: AssemblyFileVersion("3.7.2088.0")] +[assembly: AssemblyVersion("3.7.2092.0")] +[assembly: AssemblyFileVersion("3.7.2092.0")] diff --git a/TBF/Rig/ControlBoard/Uni/DivTransitionData.cs b/TBF/Rig/ControlBoard/Uni/DivTransitionData.cs index 08d8379ff..adba9105a 100644 --- a/TBF/Rig/ControlBoard/Uni/DivTransitionData.cs +++ b/TBF/Rig/ControlBoard/Uni/DivTransitionData.cs @@ -29,10 +29,10 @@ namespace TBF.Rig.ControlBoard.Uni const int SamplesCount = 247; - DivTransitionData() + DivTransitionData(int divResolutionMs) { Samples = new byte[SamplesCount]; - Resolution_ms = Const.DivTimeResolution; + Resolution_ms = divResolutionMs; } /// @@ -62,12 +62,12 @@ namespace TBF.Rig.ControlBoard.Uni /// /// Received data /// Offset of the message - public static DivTransitionData GetData(byte[] rcvdData, int offset) + public static DivTransitionData GetData(byte[] rcvdData, int offset, int divResolutionMs) { log.DebugFormat("DivTransitionDataGetData() ... Diverter = {0}, DiverterAssociationValidUntil-StateMachine.Time = {1}s left", (Diverter != null) ? Diverter.Name : "none", DiverterAssociationValidUntil - StateMachine.Time); - var data = new DivTransitionData(); + var data = new DivTransitionData(divResolutionMs); for (int i = 0; i < SamplesCount; i++) { data.Samples[i] = rcvdData[offset + 6 + i]; @@ -75,7 +75,7 @@ namespace TBF.Rig.ControlBoard.Uni if (Diverter != null && StateMachine.Time <= DiverterAssociationValidUntil) { - data.TransitionTime_ms = Const.DivTimeResolution * CalculateDivTransitionTime(data.Samples, Diverter.ThresholdLo, Diverter.ThresholdHi); + data.TransitionTime_ms = divResolutionMs * CalculateDivTransitionTime(data.Samples, Diverter.ThresholdLo, Diverter.ThresholdHi); log.InfoFormat("{0} transition time = {1} ms", Diverter.Name, data.TransitionTime_ms); if (ToTank) { diff --git a/TBF/Rig/ControlBoard/Uni/Enums.cs b/TBF/Rig/ControlBoard/Uni/Enums.cs index 36e8e5ec5..9d1613afa 100644 --- a/TBF/Rig/ControlBoard/Uni/Enums.cs +++ b/TBF/Rig/ControlBoard/Uni/Enums.cs @@ -11,7 +11,6 @@ namespace TBF.Rig.ControlBoard.Uni public const int RVsCount = 8; /// 0..7 public const int FlowmtrsCount = 7; /// ID=1..7, ID=0 ... flowmeters 1,2,3 parallel public const int DivertersCount = 5; /// 1..5 - public const int DivTimeResolution = 2; /// [ms] public const double TimeResolution = 0.0002; /// [s] } diff --git a/TBF/Rig/ControlBoard/Uni/FlyingStartStopTestOp.cs b/TBF/Rig/ControlBoard/Uni/FlyingStartStopTestOp.cs index 7ae4e762a..af97fc83b 100644 --- a/TBF/Rig/ControlBoard/Uni/FlyingStartStopTestOp.cs +++ b/TBF/Rig/ControlBoard/Uni/FlyingStartStopTestOp.cs @@ -96,6 +96,7 @@ namespace TBF.Rig.ControlBoard.Uni regV.Idx1, flowMeter.Idx1, (diverter != null) ? diverter.DiverterNr : 0, qFrom, qTo); /// Start the test (and the flow measurement) + if (withDiverter) { uniCB.DivResolution = diverter.Resolution; } uniCB.SetActivity((diverter != null) ? Activity.FlyingStartStopTestWithDiverter : Activity.FlyingStartStopTest); uniCB.StartTest(false, flowMeter.Idx1, (diverter != null) ? diverter.DiverterNr : 0, (diverter != null) ? diverter.StartThreshold : 0, true, withDiverter, false, isProlonged, pulsesCount, massPulsesCount); diff --git a/TBF/Rig/ControlBoard/Uni/GeneralData.cs b/TBF/Rig/ControlBoard/Uni/GeneralData.cs index 95b731d7b..80e68777c 100644 --- a/TBF/Rig/ControlBoard/Uni/GeneralData.cs +++ b/TBF/Rig/ControlBoard/Uni/GeneralData.cs @@ -86,7 +86,7 @@ namespace TBF.Rig.ControlBoard.Uni /// /// Received data /// Offset of the message - public void UpdateData(byte[] data, int offs) + public void UpdateData(byte[] data, int offs, int divResolutionMs) { State = GetUInt40(data, offs + (int)Poz.State) | /// Byte 5,6,7,8,9,80,81 ((ulong)data[offs + (int)Poz.Stat5] << 40) | @@ -188,7 +188,7 @@ namespace TBF.Rig.ControlBoard.Uni ReferenceFreq[0] = ReferenceFreq[1] + ReferenceFreq[2] + ReferenceFreq[3]; } - DivTime = Const.DivTimeResolution * data[offs + (int)Poz.CasKl]; /// Byte 271 + DivTime = divResolutionMs * data[offs + (int)Poz.CasKl]; /// Byte 271 byte spare4 = data[offs + (int)Poz.spare4]; /// Byte 272 Chyby485 = GetUInt16(data, offs + (int)Poz.Chyb485); /// Byte 273, 274 !!!!!!!!!!!!!!! uint timeRefRaw = GetUInt24(data, offs + (int)Poz.Tim2); /// Byte 274,275,276 !!!!!!!!!!!!!!! @@ -203,7 +203,7 @@ namespace TBF.Rig.ControlBoard.Uni EtPulses3 = Convert.ToInt32(GetUInt24(data, offs + (int)Poz.ETX3)); /// Byte 297,298.299 !!!!!!!!!!!!!!! log.InfoFormat("Et={0} State={1:X14} Route={2} Freq={3} EtPulses={4} TTime={5} WMPulses[3]={6} WMRefPulses[3]={7}, Time[3]={8}", - (State & 7), State, Utils.ToBin40(((UInt64)Vystupy) >> 8), ReferenceFreq[0], EtPulses[0], Ttime, WMeterPuls[3], EtPulses[3], ImpulseTime[3]); + State & 7, State, Utils.ToBin40(Vystupy >> 8), ReferenceFreq[0], EtPulses[0], Ttime, WMeterPuls[3], EtPulses[3], ImpulseTime[3]); } /// diff --git a/TBF/Rig/ControlBoard/Uni/StandingStartStopTestOp.cs b/TBF/Rig/ControlBoard/Uni/StandingStartStopTestOp.cs index b5dae668f..ccd131beb 100644 --- a/TBF/Rig/ControlBoard/Uni/StandingStartStopTestOp.cs +++ b/TBF/Rig/ControlBoard/Uni/StandingStartStopTestOp.cs @@ -74,6 +74,7 @@ namespace TBF.Rig.ControlBoard.Uni log.InfoFormat("Start() Et#={0} pulses={1} withDiverter={2}", flowMeter.Idx1, pulsesCount, withDiverter); /// Start the test (and the flow measurement) + if (withDiverter) { uniCB.DivResolution = diverter.Resolution; } uniCB.SetActivity(Activity.StandingStartStopTest); uniCB.StartTest(false, flowMeter.Idx1, (withDiverter ? diverter.DiverterNr : 0), 0, false, withDiverter, true, false, pulsesCount); diff --git a/TBF/Rig/ControlBoard/Uni/UniCB.cs b/TBF/Rig/ControlBoard/Uni/UniCB.cs index 1072195a2..9cfa31106 100644 --- a/TBF/Rig/ControlBoard/Uni/UniCB.cs +++ b/TBF/Rig/ControlBoard/Uni/UniCB.cs @@ -28,7 +28,24 @@ namespace TBF.Rig.ControlBoard.Uni /// TBF component configuration and useful wrappers readonly UniCBCfg cbCfg; string comPort { get { return string.Format("COM{0}", cbCfg.ComPortNr); } } - short config { get { return (short)((cbCfg.DrainValvesCount << 8) + ((cbCfg.DivertersCount - 1) << 3) + cbCfg.RegValvesCount - 4); } } + + public DivResolution DivResolution { get; set; } + public int DivResolutionMs + { + get + { + switch (DivResolution) + { + case DivResolution._1ms: return 1; + default: + case DivResolution._2ms: return 2; + case DivResolution._4ms: return 4; + case DivResolution._8ms: return 8; + } + } + } + + short config { get { return (short)((cbCfg.DrainValvesCount << 8) + ((int)DivResolution << 6) + ((cbCfg.DivertersCount - 1) << 3) + cbCfg.RegValvesCount - 4); } } /// IDrawingItCmpnt interface implementation public SchematicDrawing.IDrawingItem DrawingItem { get { return cbCfg as SchematicDrawing.IDrawingItem; } } @@ -382,7 +399,7 @@ namespace TBF.Rig.ControlBoard.Uni { /// Regular data received generalDataReceived = true; - Data.UpdateData(rcvdData, offset); + Data.UpdateData(rcvdData, offset, DivResolutionMs); caption.Append(GeneralData.Caption()); offset += GeneralData.MessageLen; anyProcessed = true; @@ -398,7 +415,7 @@ namespace TBF.Rig.ControlBoard.Uni else if (DivTransitionData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset)) { /// Diverter transition data received - divTransitionData = DivTransitionData.GetData(rcvdData, offset); + divTransitionData = DivTransitionData.GetData(rcvdData, offset, DivResolutionMs); caption.Append(DivTransitionData.Caption()); offset += DivTransitionData.MessageLen; anyProcessed = true; diff --git a/TBF/Rig/Uni/Diverter/Diverter.cs b/TBF/Rig/Uni/Diverter/Diverter.cs index f535650d4..266b94786 100644 --- a/TBF/Rig/Uni/Diverter/Diverter.cs +++ b/TBF/Rig/Uni/Diverter/Diverter.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2021 Sensus Slovensko a.s. +/// Copyright (c) 2021-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -16,8 +16,8 @@ using TBF.Resources; namespace TBF.Rig.Uni.Diverter { public class Diverter : ComponentBase, IDevice, GenericDevices.IDiverter, GenericDevices.ISequenceCondition, GenericDevices.IHasCalendarEvents, IDrawingItCmpnt - { - private static readonly ILog log = LogManager.GetLogger(typeof(Diverter)); + { + private static readonly ILog log = LogManager.GetLogger(typeof(Diverter)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } /// Configuration and wrappers @@ -27,6 +27,7 @@ namespace TBF.Rig.Uni.Diverter public int AdcNr { get { return divCfg.AdcNr; } } public int AdcValueToSink { get { return divCfg.AdcValueToSink; } } public int AdcValueToTank { get { return divCfg.AdcValueToTank; } } + public DivResolution Resolution { get { return divCfg.Resolution; } } public IDrawingItem DrawingItem { get { return divCfg as IDrawingItem; } } /// public int StartThreshold diff --git a/TBF/Rig/Uni/Diverter/DiverterCfg.cs b/TBF/Rig/Uni/Diverter/DiverterCfg.cs index 753003266..4cc53e7e5 100644 --- a/TBF/Rig/Uni/Diverter/DiverterCfg.cs +++ b/TBF/Rig/Uni/Diverter/DiverterCfg.cs @@ -1,9 +1,10 @@ /// -/// Copyright (c) 2021 Sensus Slovensko a.s. +/// Copyright (c) 2021-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Xml.Serialization; +using Common; using Config.Entities; using SchematicDrawing; using TBF.Rig.Generic; @@ -34,6 +35,7 @@ namespace TBF.Rig.Uni.Diverter public int ThresholdHiPct; /// 0..100 in %, threshold for high level when diverter transition time is measured public int DfltSwithTimeStartMs; /// Default diverter transition time 'start' or 'to tank' in ms public int DfltSwithTimeEndMs; /// Default diverter transition time 'end' or 'to sink' in ms + public DivResolution Resolution; /// Calibration info serialized parameters displayed in Metrology tab page public string CalibCertificateNr { get; set; } @@ -82,6 +84,7 @@ namespace TBF.Rig.Uni.Diverter ThresholdHiPct = 90; DfltSwithTimeStartMs = 1; DfltSwithTimeEndMs = 1; + Resolution = DivResolution._2ms; CalibCertificateNr = string.Empty; } diff --git a/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.Designer.cs b/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.Designer.cs index e67ac61e6..5d93e02fd 100644 --- a/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.Designer.cs +++ b/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.Designer.cs @@ -81,6 +81,8 @@ namespace TBF.Rig.Uni.Diverter this.label10 = new System.Windows.Forms.Label(); this.divNr1TextBox = new System.Windows.Forms.TextBox(); this.divIx1Label = new System.Windows.Forms.Label(); + this.resolutionComboBox = new System.Windows.Forms.ComboBox(); + this.resolutionLabel = new System.Windows.Forms.Label(); this.groupBox4.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -536,10 +538,30 @@ namespace TBF.Rig.Uni.Diverter this.divIx1Label.TabIndex = 36; this.divIx1Label.Text = "Diverter nr. (1 .. 5)"; // + // resolutionComboBox + // + this.resolutionComboBox.Enabled = false; + this.resolutionComboBox.FormattingEnabled = true; + this.resolutionComboBox.Location = new System.Drawing.Point(144, 318); + this.resolutionComboBox.Name = "resolutionComboBox"; + this.resolutionComboBox.Size = new System.Drawing.Size(68, 21); + this.resolutionComboBox.TabIndex = 39; + // + // resolutionLabel + // + this.resolutionLabel.AutoSize = true; + this.resolutionLabel.Location = new System.Drawing.Point(21, 321); + this.resolutionLabel.Name = "resolutionLabel"; + this.resolutionLabel.Size = new System.Drawing.Size(57, 13); + this.resolutionLabel.TabIndex = 38; + this.resolutionLabel.Text = "Resolution"; + // // DiverterCfgCtrl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.resolutionComboBox); + this.Controls.Add(this.resolutionLabel); this.Controls.Add(this.divNr1TextBox); this.Controls.Add(this.divIx1Label); this.Controls.Add(this.label10); @@ -642,5 +664,7 @@ namespace TBF.Rig.Uni.Diverter private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox divNr1TextBox; private System.Windows.Forms.Label divIx1Label; - } + private System.Windows.Forms.ComboBox resolutionComboBox; + private System.Windows.Forms.Label resolutionLabel; + } } diff --git a/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.cs b/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.cs index cd9d62e88..9221ca5a1 100644 --- a/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.cs +++ b/TBF/Rig/Uni/Diverter/DiverterCfgCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2021 Sensus Metering Systems +/// Copyright (c) 2021-2023 Sensus Metering Systems /// using System; using System.Linq; @@ -49,7 +49,12 @@ namespace TBF.Rig.Uni.Diverter } } - if (config != null) + for (DivResolution res = 0; res < DivResolution.Count; res++) + { + resolutionComboBox.Items.Add(res.ToDescription()); + } + + if (config != null) { adc1 = config.AdcValueToSink; pct1 = 0; @@ -83,6 +88,7 @@ namespace TBF.Rig.Uni.Diverter thresholdHiTextBox.Text = config.ThresholdHiPct.ToString(); dfltSwitchTimeStartTextBox.Text = config.DfltSwithTimeStartMs.ToString(); dfltSwitchTimeEndTextBox.Text = config.DfltSwithTimeEndMs.ToString(); + resolutionComboBox.Text = config.Resolution.ToDescription(); adcTextBox1.Text = adc1.ToString(); adcTextBox2.Text = adc2.ToString(); @@ -104,6 +110,7 @@ namespace TBF.Rig.Uni.Diverter thresholdHiTextBox.Enabled = true; dfltSwitchTimeStartTextBox.Enabled = true; dfltSwitchTimeEndTextBox.Enabled = true; + resolutionComboBox.Enabled = true; } public CfgUpdateFlags VerifyCfg(ref string message) @@ -182,6 +189,22 @@ namespace TBF.Rig.Uni.Diverter flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Default switch time end' should be positive integer"; } + + bool isValidRes = false; + for (DivResolution res = 0; res < DivResolution.Count; res++) + { + if (resolutionComboBox.Text == res.ToDescription()) + { + isValidRes = true; + break; + } + } + if (!isValidRes) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Resolution' is invalid"; + } + return flags; } @@ -275,6 +298,19 @@ namespace TBF.Rig.Uni.Diverter flags |= CfgUpdateFlags.RestartRqrd; } + for (DivResolution res = 0; res < DivResolution.Count; res++) + { + if (resolutionComboBox.Text == res.ToDescription()) + { + if (config.Resolution != res) + { + config.Resolution = res; + flags |= CfgUpdateFlags.RestartRqrd; + } + break; + } + } + return flags; }