From 2890a0e851cd8d47de88e187f5af0e915462cd83 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Tue, 10 Sep 2024 16:51:39 +0200 Subject: [PATCH] eRegister tasks status refresh --- Common/CommonConsole/Program.cs | 24 +++++++++-- .../JustSirtBroadcaster.cs | 4 +- .../JustSirtTask.cs | 27 ++++++------ .../GenesisStatus/GenesisStatusHandler.cs | 2 +- .../DebugCmd.cs | 7 +--- .../OpticalTelegram.cs | 4 +- .../SetMetrologyParameters.cs | 39 ++++++++++-------- ...ommon.Hardware.WaterMeter.eRegister.csproj | 1 + .../JusteRegisterParameterSet.cs | 33 ++++++++------- .../JusteRegisterProgrammingBatch.cs | 18 +++++++- .../JusteRegisterProgrammingTask.cs | 39 +++++++++--------- .../PAMStatus.cs | 41 +++++++++++++++++++ .../State2ForegroundConverter.cs | 2 +- .../eRegisterPruefungInitialisierungView.xaml | 1 - 14 files changed, 163 insertions(+), 79 deletions(-) diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index 91f9ce30..ca8a6d2e 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,9 +1,8 @@ namespace CommonConsole { using Common.Hardware.Interfaces.Ports.Sirt; - using Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters; + using Common.Hardware.Interfaces.Ports.Sirt.Parameters; using Common.Hardware.WaterMeter.eRegister; - using System; public class Program @@ -14,13 +13,32 @@ if (programmingBatch.StartOnCOMPort("COM6")) { + var task = new JusteRegisterProgrammingTask + { + Cmd = JustSirtMessage.W_PAM, + P1 = new P811 + { + DelPamSemi = true + }, + Address = 319020415, + Data = new Byte[] + { + // Metrology parameters + 0x92, 0x10, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x71, 0x02, 0x00, 0x00, + + // Provide Pin Auth Level III + 0x43, 0x03, 0x63, 0x93, 0x73, 0x22, + } + }; + programmingBatch.Run(task); + Console.ReadKey(); programmingBatch.Stop(); } else { - + Console.WriteLine("Not connected!"); } } diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs index 612a9f7d..f98ea08c 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs @@ -141,7 +141,7 @@ task.PrepareForRun(); this.proxy.WriteBytes(task); - this.Log(BitConverter.ToString(task)); + this.Log($"{task.Address}|{BitConverter.ToString(task)}"); return JustTaskStatus.Sent; } @@ -153,7 +153,7 @@ if (runningTasks.TryGetValue(address, out var task) && task != null) { task.ReceiveMessage(message, this.MHz); - this.Log(message); + this.Log($"{address}|{message}"); } } diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs index f4dddb76..981ec80a 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs @@ -46,7 +46,7 @@ set => this.request.Data = value; } - public JustTaskStatus Status { get; private set; } + public JustTaskStatus Status { get; protected set; } public Byte[] LastPayload => this.responses.TryPeek(out var response) @@ -57,18 +57,21 @@ { this.responses.Push(response); - this.Status = JustTaskStatus.Running; + if (this.Status != JustTaskStatus.Completed) + { + this.Status = JustTaskStatus.Running; - if (this.request.Cmd == JustSirtMessage.W_PAM - && response.Cmd == JustSirtMessage.FROMAIR - && response.Data[0] == JustSirtMessage.SEMI) - { - this.Status = JustTaskStatus.Completed; - } - else if (response.P2 != JustSirtMessage.W_PAM - && response.Cmd == JustSirtMessage.ACKNANSW) - { - this.Status = JustTaskStatus.Completed; + if (this.request.Cmd == JustSirtMessage.W_PAM + && response.Cmd == JustSirtMessage.FROMAIR + && response.Data[0] == JustSirtMessage.SEMI) + { + this.Status = JustTaskStatus.Completed; + } + else if (response.P2 != JustSirtMessage.W_PAM + && response.Cmd == JustSirtMessage.ACKNANSW) + { + this.Status = JustTaskStatus.Completed; + } } if (this.Status == JustTaskStatus.Completed) diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisStatus/GenesisStatusHandler.cs b/Common/Hardware/WaterMeter/Genesis/GenesisStatus/GenesisStatusHandler.cs index 3862dfa1..267833fe 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisStatus/GenesisStatusHandler.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisStatus/GenesisStatusHandler.cs @@ -44,7 +44,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus try { - var url = ServiceUrls.GetProductionSkipAndLifeTimeInfoServiceUrl(); + var url = ""; // ServiceUrls.GetProductionSkipAndLifeTimeInfoServiceUrl(); url += $"{pcbId}&orderNumber={orderNumber}"; var response = LocalWebRequest.GetRequest(url, 2000); status = JsonConvert.DeserializeObject(response); diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs index d580b5fd..760d8d0e 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs @@ -4,11 +4,8 @@ public class DebugCmd : Pam { - protected DebugCmd(Byte code) : base(3, GetDebug) - { - this.bytes = new Byte[2]; - this.bytes[1] = code; - } + protected DebugCmd(Byte code) : base(3, GetDebug) + => this.bytes[2] = code; public static implicit operator Byte[] (DebugCmd cmd) => cmd.bytes; diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/OpticalTelegram.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/OpticalTelegram.cs index b540b091..4e4138b6 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/OpticalTelegram.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/OpticalTelegram.cs @@ -10,8 +10,8 @@ public Byte Minutes { - get => this.bytes[0]; - set => this.bytes[0] = value; + get => this.bytes[1]; + set => this.bytes[1] = value; } } } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetMetrologyParameters.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetMetrologyParameters.cs index 8e836ecf..3a75773b 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetMetrologyParameters.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetMetrologyParameters.cs @@ -11,7 +11,7 @@ public SetMetrologyParameters() : base(18, MetrologyParameters) => this.bitsFromByte11 = new Byte[8]; - public Byte PamLength => (Byte)(this.bytes.Length - 1); + public Byte PamLength => this.bytes[1]; public Int32 Vpp { @@ -36,37 +36,43 @@ get => this.bytes[11]; set => this.bytes[11] = value; } - + public MeterUnits Units { get { var bits = new Byte[8]; - bits[0] = this.bitsFromByte11[4]; - bits[1] = this.bitsFromByte11[3]; - bits[2] = this.bitsFromByte11[2]; - bits[3] = this.bitsFromByte11[1]; bits[4] = this.bitsFromByte11[0]; + bits[3] = this.bitsFromByte11[1]; + bits[2] = this.bitsFromByte11[2]; + bits[1] = this.bitsFromByte11[3]; + bits[0] = this.bitsFromByte11[4]; - return (MeterUnits)bits.ToByte(0, 5); + return (MeterUnits)bits.ToByte(); } set { var bits = ((Byte)value).GetBits(); - this.bitsFromByte11[4] = bits[0]; - this.bitsFromByte11[3] = bits[1]; - this.bitsFromByte11[2] = bits[2]; - this.bitsFromByte11[1] = bits[3]; this.bitsFromByte11[0] = bits[4]; + this.bitsFromByte11[1] = bits[3]; + this.bitsFromByte11[2] = bits[2]; + this.bitsFromByte11[3] = bits[1]; + this.bitsFromByte11[4] = bits[0]; } } public DecimalPointLocations DecimalPoint { get => (DecimalPointLocations)this.bitsFromByte11[6]; - set => this.bitsFromByte11[6] = (Byte)value; + set + { + var x = (Byte)value; + + this.bitsFromByte11[6] = (Byte)(x >> 5 & 1); + this.bitsFromByte11[5] = (Byte)(x >> 6 & 1); + } } /// @@ -96,12 +102,13 @@ protected override Byte[] ToByteArray() { - var bytes11 = new Byte[8]; + var bits11 = new Byte[8]; - Array.Copy(this.bitsFromByte11, 0, bytes11, 0, 8); - Array.Reverse(bytes11); + Array.Copy(this.bitsFromByte11, 0, bits11, 0, 8); + // Array.Reverse(bits11); - this.bytes[12] = bytes11.ToByte(); + this.bytes[12] = bits11.ToByte(); + this.bytes[1] = 0x10; return base.ToByteArray(); } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj index 2f61b872..63efad37 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj @@ -50,6 +50,7 @@ + diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs index 421ccb82..13d35cb8 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs @@ -96,22 +96,25 @@ Cmd = JustSirtMessage.W_PAM, P1 = new P811 { - DelPamSemi = true, - WakeUpCmd = true + DelPamSemi = true }, Address = this.RadioAddress, Data = new SetMetrologyParameters { - DecimalPoint = DecimalPointLocations.Three, - FactoryCalibration = this.FactoryCalibration, - MeterSize = this.MeterSize, + Vpp = this.Vpp, OffsetFactor = this.OffsetFactor, OffsetTime = this.OffsetTime, + FactoryCalibration = this.FactoryCalibration, Units = Features.MeterUnits.CubicMeters, + DecimalPoint = DecimalPointLocations.Three, UseCandIRules = true, - Vpp = this.Vpp, + MeterSize = this.MeterSize, VppLED = this.VpLp, - }, + } + .Append(new ProvidePin + { + AuthLevel = Features.AuthLevel.III + }), EncryptionKey = this.encryptionKey }; @@ -121,8 +124,7 @@ Cmd = JustSirtMessage.W_PAM, P1 = new P811 { - DelPamSemi = true, - WakeUpCmd = true + DelPamSemi = true }, Address = this.RadioAddress, Data = new Byte[] @@ -139,15 +141,16 @@ Cmd = JustSirtMessage.W_PAM, P1 = new P811 { - DelPamSemi = true, - WakeUpCmd = true + DelPamSemi = true }, Address = this.RadioAddress, - Data = new Byte[] + Data = new OpticalTelegram { - 0x1F, 0x01, 0x08, // LED on - 0x43, 0x03, 0x63, 0x93, 0x73, 0x22 // Pin level III - }, + Minutes = this.OptoTimeOn + }.Append(new ProvidePin + { + AuthLevel = Features.AuthLevel.III + }), EncryptionKey = this.encryptionKey }; } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs index c52b06cc..e3bc3247 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs @@ -46,6 +46,12 @@ this.OnProgress?.Invoke(0, rowno++, $"Parametersatz", JusteRegisterTaskState.Disabled); this.OnProgress?.Invoke(0, rowno++, $"Anzeige-111111111", JusteRegisterTaskState.Disabled); this.OnProgress?.Invoke(0, rowno++, $"Opto ein", JusteRegisterTaskState.Disabled); + // TODO: add following rows + //this.OnProgress?.Invoke(0, rowno++, $"MBus status", JusteRegisterTaskState.Disabled); + //this.OnProgress?.Invoke(0, rowno++, $"Batteriespannung", JusteRegisterTaskState.Disabled); + //this.OnProgress?.Invoke(0, rowno++, $"Batterie übrig", JusteRegisterTaskState.Disabled); + //this.OnProgress?.Invoke(0, rowno++, $"FW Version", JusteRegisterTaskState.Disabled); + //this.OnProgress?.Invoke(0, rowno++, $"Reboots", JusteRegisterTaskState.Disabled); foreach (var kvp in this.programmingParameters) { @@ -141,6 +147,16 @@ } } while (tasks.Count > 0); + + Thread.Sleep(1000); + + foreach (var kvp in this.completedTasks) + { + foreach (var task in kvp.Value) + { + task.Refresh(); + } + } } public void Run(JusteRegisterProgrammingTask task) @@ -162,7 +178,7 @@ this.Stop(); this.broadcaster = new JustSirtBroadcaster(portName); - this.broadcaster.Logging += Console.WriteLine; // this.logger.Debug(text); + this.broadcaster.Logging += this.logger.Debug; return this.broadcaster.TryActivate(); } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs index 0c376c48..900b66d5 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs @@ -4,24 +4,10 @@ using Common.Hardware.Interfaces.Ports.SirtBroadcaster; using System; - using System.Timers; public class JusteRegisterProgrammingTask : JustSirtTask { - private readonly Timer timer = new Timer(); - - public JusteRegisterProgrammingTask() : base() - { - this.timer = new Timer(); - this.timer.AutoReset = true; - this.timer.Interval = 500; - this.timer.Interval = 500; - this.timer.Elapsed += (_, _1) => - { - this.OnProgress?.Invoke(this.Slotno, this.Rowno, this.Label, this.State); - }; - this.timer.Start(); - } + private const String PENDING = nameof(PENDING); public event Action OnProgress; @@ -37,7 +23,7 @@ public override void PrepareForRun() { - this.OnProgress?.Invoke(this.Slotno, this.Rowno, "PENDING", JusteRegisterTaskState.None); + this.OnProgress?.Invoke(this.Slotno, this.Rowno, PENDING, JusteRegisterTaskState.None); base.PrepareForRun(); } @@ -49,16 +35,26 @@ this.DecryptResponse(response); } - if (response.Cmd == JustSirtMessage.FROMAIR) + if (this.State != JusteRegisterTaskState.Success && response.Cmd == JustSirtMessage.FROMAIR) { var type = response.Data[0]; var telegram = new object(); if (type == JustSirtMessage.SEMI) { - this.Label = nameof(JustSirtMessage.SEMI); - this.State = JusteRegisterTaskState.Success; - telegram = new SEMI(response.Data, (UInt16)mhz); + var semi = new SEMI(response.Data, (UInt16)mhz); + this.Label = semi.PAMStatus.ToString(); + + if (semi.PAMStatus == PAMStatus.OK) + { + this.State = JusteRegisterTaskState.Success; + this.Status = JustTaskStatus.Completed; + } + else + { + this.State = JusteRegisterTaskState.Error; + this.Status = JustTaskStatus.Cancelled; + } } else if (type == JustSirtMessage.BUP) { @@ -80,6 +76,7 @@ } } + this.OnProgress?.Invoke(this.Slotno, this.Rowno, this.Label, this.State); base.ReceiveMessage(response, mhz); } @@ -93,6 +90,8 @@ return base.ToByteArray(); } + internal void Refresh() => this.OnProgress?.Invoke(this.Slotno, this.Rowno, this.Label, this.State); + private void DecryptResponse(JustSirtMessage response) { var data = response.Data; diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/PAMStatus.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/PAMStatus.cs index 63cd01fe..b19dae33 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/PAMStatus.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/PAMStatus.cs @@ -20,5 +20,46 @@ public Boolean MIXED_TYPES => this.bits[3] == 1; public Boolean OUT_OF_RANGE => this.bits[4] == 1; + + public override String ToString() + { + var status = nameof(OK); + var value = this.bits.ToByte(); + + if ((value & 1) == 1) + { + status = nameof(CMD_UNKNOWN); + } + + if ((value & 2) == 2) + { + status = nameof(WRONG_AUTH); + } + + if ((value & 4) == 4) + { + status = nameof(EXPIRED_AUTH); + } + + if ((value & 8) == 8) + { + status = nameof(MIXED_TYPES); + } + + if ((value & 16) == 16) + { + status = nameof(OUT_OF_RANGE); + } + + return status; + } + + public static Byte OK = 0; + + public static implicit operator Byte(PAMStatus status) + => status?.bits?.ToByte() ?? 0xFF; + + public static implicit operator String(PAMStatus status) + => status?.ToString(); } } diff --git a/Common/Ui/Common.UI.WPF/Infrastructure/State2ForegroundConverter.cs b/Common/Ui/Common.UI.WPF/Infrastructure/State2ForegroundConverter.cs index 9e50a490..176c09c8 100644 --- a/Common/Ui/Common.UI.WPF/Infrastructure/State2ForegroundConverter.cs +++ b/Common/Ui/Common.UI.WPF/Infrastructure/State2ForegroundConverter.cs @@ -30,7 +30,7 @@ brush = Brushes.DarkOrange; break; case TaskState.Error: - brush = Brushes.Red; + brush = Brushes.DarkRed; break; default: brush = Brushes.Black; diff --git a/Common/Ui/Common.UI.WPF/Views/eRegisterPruefungInitialisierungView.xaml b/Common/Ui/Common.UI.WPF/Views/eRegisterPruefungInitialisierungView.xaml index c7bc2f10..10bd4649 100644 --- a/Common/Ui/Common.UI.WPF/Views/eRegisterPruefungInitialisierungView.xaml +++ b/Common/Ui/Common.UI.WPF/Views/eRegisterPruefungInitialisierungView.xaml @@ -55,7 +55,6 @@