From 2cc92f39801bdf47f043608bf79a6a3c2f4ae4f0 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 16 Sep 2021 14:20:26 +0200 Subject: [PATCH] iPerlCommunicationForm : "DEWA rework" activity --- .../iPerlCommunicationForm.cs | 59 +++++++++++++++++++ .../iPerlCommunicationParams.cs | 3 +- .../iPerlCommunication/iPerlDataWrite.cs | 23 ++++++++ TBF/Properties/AssemblyInfo.cs | 4 +- TBF/TBF.csproj | 1 + 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 TBF/BenchControl/TestMethods/iPerlCommunication/iPerlDataWrite.cs diff --git a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 9fd3209a2..0a2d804b3 100644 --- a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -88,6 +88,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication public const string ConditnlUpdateQ2CorrLRStr = "Conditional update of Q2 correction L-R"; /// Arguments: L-R_test_name public const string Reset2HzCorrectionStr = "Reset 2Hz correction"; public const string Write2HzCorrectionStr = "Write 2Hz correction"; + public const string DewaReworkStr = "DEWA rework"; public static Color DisabledColor = Color.DarkGray; public static Color OptoAndDirOKColor = Color.Green; @@ -843,6 +844,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication else if (currentActivity.ToLower() == Reset2HzCorrectionStr.ToLower()) error = Reset2HzCorrection(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower() == Write2HzCorrectionStr.ToLower()) error = Write2HzCorrection(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower() == GetDefaultQ2CorrectionsStr.ToLower()) error = GetQ2PreCorrectionsFormRest(threadID, ihead, wm, ref resultStr); + else if (currentActivity.ToLower() == DewaReworkStr.ToLower()) error = DewaRework(threadID, ihead, wm, ref resultStr); #endif else @@ -2562,6 +2564,63 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication return error; } + + /// + /// DEWA rework. + /// + /// iPERL head object + /// Water meter object + /// String passed to caller + /// true on success + static CommErr DewaRework(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) + { + iPerlDataWrite[] dataToBeWritten = new iPerlDataWrite[] + { + new iPerlDataWrite(MessageID.MetrologyMemory, 0x19A1, new byte[] { (byte)0xA5 }, "Open Sealing"), + new iPerlDataWrite(MessageID.RadioPassthrough, 0x1804, new byte[] { (byte)1 }, "System Status"), + new iPerlDataWrite(MessageID.MetrologyMemory, 0x1985, new byte[] { (byte)2 }, "Arrow"), + new iPerlDataWrite(MessageID.MetrologyMemory, 0x199C, new byte[5], "Clear S/N"), + new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetActiveMode }, "Set active mode"), + new iPerlDataWrite(MessageID.Configuration, 0x0015, new byte[] { (byte)0xA0 }, "Test mode config = A0"), + new iPerlDataWrite(MessageID.MetrologyMemory, 0x198E, new byte[] { (byte)(2510 & 0xFF), (byte)((2510 >> 8) & 0xFF) }, "Receipt mean current"), + new iPerlDataWrite(MessageID.RadioPassthrough, 0x18A2, new byte[] { (byte)0x4A, (byte)0x53, (byte)0x3B, (byte)0x8F, + (byte)0x70, (byte)0x31, (byte)0xC2, (byte)0x5D, + (byte)0x6F, (byte)0x2D, (byte)0xE8, (byte)0x07, + (byte)0x6E, (byte)0x0F, (byte)0x97, (byte)0xC3, }, "AES Key Crypted"), + }; + + if (ihead.CommFailed) return CommErr.CommFailed; + + int successfyllyWrittenFlags = 0; /// Ones in this word represent communication failures, LSB represents the first step + int mask = 1; + foreach (var wData in dataToBeWritten) + { + bool isSuccessfullyWritten = false; + for (int j = 0; j < cfg.MaxCommRetries; j++) + { + if (0 == WriteRequestPort(threadId, ihead, wData.MessageID, wData.Offset, wData.Data.Length, wData.Data, cfg.CommTimeout)) + { + isSuccessfullyWritten = true; + break; + } + + /// Delay between retries + if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); + } + + if (!isSuccessfullyWritten) + { + /// Communication failed in this step + successfyllyWrittenFlags = (successfyllyWrittenFlags | mask); + } + + mask = (mask << 1); /// Adjust the mask for the next step + } + + return (successfyllyWrittenFlags == 0) ? CommErr.None : CommErr.Write; + } + + static CommErr GetQ2PreCorrectionsFormRest(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) { if (!ProcessData.IsQ2PreCorrectionCalculated) diff --git a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs index c5a9aa99f..5e1d6895b 100644 --- a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs +++ b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015 Sensus Metering Systems +/// Copyright (c) 2015-2021 Sensus Slovensko a.s. /// using System; using System.IO; @@ -79,6 +79,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication retVal.Add("---"); retVal.Add(iPerlCommunicationForm.Reset2HzCorrectionStr); retVal.Add(iPerlCommunicationForm.Write2HzCorrectionStr); + retVal.Add(iPerlCommunicationForm.DewaReworkStr); retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); retVal.Add("iPerl_check prevWorkStep direction q2factors"); diff --git a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlDataWrite.cs b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlDataWrite.cs new file mode 100644 index 000000000..def6e0991 --- /dev/null +++ b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlDataWrite.cs @@ -0,0 +1,23 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead; + +namespace TBF.BenchControl.TestMethods.iPerlCommunication +{ + public class iPerlDataWrite + { + public MessageID MessageID; + public int Offset; + public byte[] Data; + public string Description; + + public iPerlDataWrite(MessageID mesageID, int offset, byte[] data, string description) + { + MessageID = mesageID; + Offset = offset; + Data = data; + Description = description; + } + } +} diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index dcd92e9e1..482c685dc 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.26.1729.0")] -[assembly: AssemblyFileVersion("2.26.1729.0")] +[assembly: AssemblyVersion("2.26.1735.0")] +[assembly: AssemblyFileVersion("2.26.1735.0")] diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 25b83955c..51d6ee16a 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -1597,6 +1597,7 @@ iPerlCommunicationForm.cs +