From 8b154b2a92c48b94a3de6da539f07e281d5268b3 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Thu, 26 Sep 2024 15:55:58 +0200 Subject: [PATCH] Sentinel up to battery --- Common/CommonConsole/CommonConsole.csproj | 14 -- Common/CommonConsole/Program.cs | 15 +- .../Models/CordonelRequirements.cs | 35 ++-- .../Models/EOLProgressModel.cs | 24 +-- .../Repositories/EOLProgressRepository.cs | 152 ++++++++++++++++-- LaaProductionWeb/LaaPackages | 2 +- .../LaaProduction.Console/Program.cs | 46 +----- .../API/Cordonel/EOLProgressController.cs | 1 - 8 files changed, 182 insertions(+), 107 deletions(-) diff --git a/Common/CommonConsole/CommonConsole.csproj b/Common/CommonConsole/CommonConsole.csproj index d9a0822e..763a69e3 100644 --- a/Common/CommonConsole/CommonConsole.csproj +++ b/Common/CommonConsole/CommonConsole.csproj @@ -51,19 +51,8 @@ - - - - - - - - - - - @@ -111,9 +100,6 @@ Common.Utils.Extensions - - - \ No newline at end of file diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index 6dcfbb15..b91c0256 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,17 +1,14 @@ -namespace CommonConsole +using System.Text; + +namespace CommonConsole { - using CommonConsole.Schema; - - using Newtonsoft.Json; - - using System; - using System.Collections.Generic; - using System.IO; - public class Program { public static void Main() { + var bytes = new byte[] { 0x43, 0x6F, 0x72, 0x64, 0x6F, 0x6E, 0x65, 0x6C, 0x20, 0x31, 0x2E, 0x35, 0x36, 0x00, 0x4E, 0xE4 }; + + System.Console.WriteLine(Encoding.ASCII.GetString(bytes)); } } } \ No newline at end of file diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/CordonelRequirements.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/CordonelRequirements.cs index 87be367b..2b838da9 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/CordonelRequirements.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/CordonelRequirements.cs @@ -4,28 +4,40 @@ public class CordonelRequirements { + // Done public Int32? SpecialId { get; set; } - + + // Done public Int32? SpecialVersion { get; set; } + // Done public Int32? StandardId { get; set; } - + + // Done public Int32? StandardVersion { get; set; } - + + // Done public String Region { get; set; } - + + // Done public String MeterSize { get; set; } - public Int32 ProductionOrderNr { get; set; } + // TODO: How to check? + public Int32 ProductionOrderNr { get; set; } + // TODO: How to check? public Int32? PcbId { get; set; } + // Done public Boolean? SkipCalibration { get; set; } + // Done public Boolean? SkipRadioCheck { get; set; } + // Done public String FwVersion { get; set; } - + + // Done public String LutCrc { get; set; } public Double? RequiredLifeTimeYearsAssembly { get; set; } @@ -43,15 +55,20 @@ public Double? EstimatedProductionBatteryLoadPercent { get; set; } public DateTime? KitronProductionDate { get; set; } - + + // Not relevant public DateTime? RequirementTimestamp { get; set; } - + + // Not relevant public String ApprovalName { get; set; } - + + // Not relevant public String ApprovalComment { get; set; } + // Done public Boolean? IsSpecialActive { get; set; } + // Done public Boolean? IsStandardActive { get; set; } } } \ No newline at end of file diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/EOLProgressModel.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/EOLProgressModel.cs index e19a0889..25f59da5 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/EOLProgressModel.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/EOLProgressModel.cs @@ -23,68 +23,68 @@ public DateTime? StartDate { get; set; } /// - /// Requirement ID if standard requirement should be used, else leave as is (null) + /// Requirement ID if standard requirement should be used, else leave as is (null). Done! /// [NotNull] public Int32? StandardRequirementId { get; set; } /// - /// Version if standard requirement should be used, else leave as is (null) + /// Version if standard requirement should be used, else leave as is (null). Done! /// [NotNull] public Int32? StandardRequirementVersion { get; set; } /// - /// Requirement ID if special requirement should be used, else leave as is (null) + /// Requirement ID if special requirement should be used, else leave as is (null). Done! /// public Int32? SpecialRequirementId { get; set; } /// - /// Version if special requirement should be used, else leave as is (null) + /// Version if special requirement should be used, else leave as is (null). Done! /// public Int32? SpecialRequirementVersion { get; set; } /// - /// Requirement could be loaded for this device + /// Requirement could be loaded for this device. Done! /// [NotFailed] public EOLStatus RequirementRequestChecked { get; set; } /// - /// Requirement PcbId equals PcbId of EOLProgress and Cordonel + /// Requirement PcbId equals PcbId of EOLProgress and Cordonel. How? /// [NotFailed] public EOLStatus RequirementPcbIdChecked { get; set; } /// - /// Requirement order equals Cordonel order + /// Requirement order equals Cordonel order. How? /// [NotFailed] public EOLStatus RequirementOrderChecked { get; set; } /// - /// Requirement region equals Cordonel region + /// Requirement region equals Cordonel region. Done! /// [NotFailed] public EOLStatus RequirementRegionChecked { get; set; } /// /// Installed LUT CRC, should never be null or empty - /// will only be set if requirement LUT CRC is equal to Cordonel LUT CRC + /// will only be set if requirement LUT CRC is equal to Cordonel LUT CRC. Done! /// [NotNull] public String ProductionStatusLutCrc { get; set; } /// /// Installed FW, should never be null or empty, - /// will only be set if requirement FW is equal to Cordonel FW + /// will only be set if requirement FW is equal to Cordonel FW. Done! /// [NotNull] public String ProductionStatusFwVersion { get; set; } /// /// Detected meter size, should never be null or empty - /// will only be set if requirement MeterSIze is equal to Cordonel MeterSize + /// will only be set if requirement MeterSIze is equal to Cordonel MeterSize. Done! /// [NotNull] public String ProductionStatusMeterSize { get; set; } @@ -150,7 +150,7 @@ public EOLStatus ParametrizationCompareChecked { get; set; } /// - /// Id for radio check, can be null for NA region or if radio check has been skipped by requirement + /// Id for radio check, can be null for NA region or if radio check has been skipped by requirement. Done! /// [NotNull] public Int64? RadioCheckId { get; set; } diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs index f1a386b2..e4b4f83a 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; + using System.Globalization; using System.Linq; public class EOLProgressRepository : IEOLProgressRepository @@ -195,13 +196,12 @@ return deleted; } - - // Test pcb: 233410052 + public IEnumerable> RunSentinel(EOLProgressModel model, CordonelAppsDictionary cordonelApps) { if (model is null) { - yield return new KeyValuePair("EOLProgressModel", "Empty model is not allowed."); + yield return new KeyValuePair("EOLProgressModel", "Is missing."); yield break; } @@ -211,7 +211,7 @@ if (cordonelInfoList.Length != 1) { - yield return new KeyValuePair(pcbidString, "More than 1 entry in the database is not allowed."); + yield return new KeyValuePair(pcbidString, "More than 1 entry found."); yield break; } @@ -219,12 +219,7 @@ if (cordonelInfo.Sealed == false) { - yield return new KeyValuePair(pcbidString, $"Is not correctly sealed."); - yield break; - } - else if (cordonelInfo.Pending == false) - { - yield return new KeyValuePair(pcbidString, $"Was allready finisched."); + yield return new KeyValuePair(pcbidString, $"Is not sealed."); yield break; } @@ -245,7 +240,7 @@ } else if (requirement.IsStandardActive == false || requirement.SpecialId != null && requirement.IsSpecialActive == false) { - yield return new KeyValuePair(pcbidString, $"The bounded requirement is not active."); + yield return new KeyValuePair(pcbidString, $"One or both of the bounded requirements are not active."); yield break; } else if (requirement.SkipCalibration == false && cordonelInfo.TestStatus != 30) @@ -253,15 +248,15 @@ yield return new KeyValuePair(pcbidString, $"Is not correctly calibrated, status: {cordonelInfo.TestStatus}."); yield break; } - + this.sqlConnection .CreateCommand($@" SELECT x.Id - , x.Address - , x.Value + , CONVERT(VARBINARY(MAX), REPLACE(ISNULL(x.Address, '00'), '-', ''), 2) AS Address + , CONVERT(VARBINARY(MAX), REPLACE(REPLACE(ISNULL(x.Value, '00'), 'NULL', '00'), '-', ''), 2) AS Value FROM (SELECT gmh.ID AS Id - , CONVERT(VARBINARY(MAX), REPLACE(ISNULL(gmh.Address, '00'), '-', ''), 2) AS Address - , CONVERT(VARBINARY(MAX), REPLACE(REPLACE(ISNULL(gmh.Value, '00'), 'NULL', '00'), '-', ''), 2) AS Value + , gmh.Address + , gmh.Value , ROW_NUMBER() OVER (PARTITION BY gmh.Address ORDER BY gmh.date DESC) AS Row FROM GenesisMeterRegisterHistory AS gmh WHERE gmh.PcbId = @{nameof(pcbidString)}) AS x @@ -283,6 +278,131 @@ } }); + var meterSize = default(Byte); + var hasRadio = default(Boolean); + + this.sqlConnection + .CreateCommand($@" + SELECT cms.Dn_InternalId + , CAST(CASE WHEN vmm.Radio = 'Z' THEN 0 ELSE 1 END AS BIT) HasRadio + FROM (SELECT DISTINCT TOP 1 + (SELECT DISTINCT TOP 1 vm.Charcode + FROM VAKO_Merkmale AS vm + WHERE SUBSTRING(idn.VakoCode, 1, LEN(vm.Basis)) = vm.Basis + AND SUBSTRING(idn.VakoCode, vm.Stelle, vm.Laenge) = vm.Charcode + AND vm.Bezeichnung = 'NW') AS DN + , (SELECT DISTINCT TOP 1 vm.Wert + FROM VAKO_Merkmale AS vm + WHERE SUBSTRING(idn.VakoCode, 1, LEN(vm.Basis)) = vm.Basis + AND SUBSTRING(idn.VakoCode, vm.Stelle, vm.Laenge) = vm.Charcode + AND vm.Bezeichnung = 'Funkfrequenz') AS Radio + FROM MapPcbIdToSerialNumber AS map + JOIN AuftragPositionSerienNr AS aps + ON map.MapPcbIdToSerialNumber_SerialNumber = aps.SerienNr + JOIN AlleAuftragPositionen AS aap + ON aps.AuftragNr = aap.AuftragNr + AND aps.PositionNr = aap.PositionNr + JOIN Identnr AS idn + ON aap.IdentNr = idn.IdentNr + WHERE map.MapPcbIdToSerialNumber_PcbId = 212120036) AS vmm + JOIN CordonelMeterSizes AS cms + ON vmm.DN = cms.Dn_VakoID") + .SetParameter(nameof(pcbid), pcbid) + .FirstOrDefault(reader => + { + meterSize = reader.GetValue(0); + hasRadio = reader.GetValue(1); + }); + + var meterSizeRegister = cordonelApps[Apps.GENESISFLOW][GENESISFLOW.MeterSize]; + + if (meterSizeRegister.IsEquals(meterSize)) + { + yield return new KeyValuePair(pcbidString, $"Wrong meter size: {meterSize} - expected was {meterSizeRegister.Value}."); + yield break; + } + + if (hasRadio) + { + var radioCheckId = model.RadioCheckId; + + if (radioCheckId is null) + { + yield return new KeyValuePair(pcbidString, $"RSSI test id was null."); + yield break; + } + + var radioCheckState = this.sqlConnection + .CreateCommand($@" + SELECT Result + FROM Cordonel_Radio_RSSI_History + WHERE id = @{nameof(radioCheckId)} + ORDER BY Datum DESC") + .SetParameter(nameof(radioCheckId), radioCheckId) + .FirstOrDefault(reader => reader.GetValue(0)); + + if (radioCheckState == false) + { + yield return new KeyValuePair(pcbidString, $"RSSI test failed - id: {radioCheckId}."); + yield break; + } + + var rssiCheckId = this.sqlConnection + .CreateCommand($@" + SELECT id + FROM Cordonel_Radio_RSSI_History + WHERE RadioAdress = @{nameof(cordonelInfo.Address)} + AND Result = 1 + ORDER BY Datum DESC") + .SetParameter(nameof(cordonelInfo.Address), cordonelInfo.Address) + .FirstOrDefault(reader => reader.GetValue(0)); + + if (rssiCheckId != radioCheckId) + { + yield return new KeyValuePair(pcbidString, $"RSSI test id ambiguous between {rssiCheckId}(latest) and {radioCheckId}(EOL)."); + yield break; + } + } + + var version = this.sqlConnection + .CreateCommand($@" + SELECT TOP 1 Version + FROM CordonelProgress AS cp + JOIN CordonelAppVersion AS cv + ON cp.Id = cv.ProgressId + AND appid = 24 + WHERE cp.PcbId = @{nameof(pcbid)} + ORDER BY 1 DESC") + .SetParameter(nameof(pcbid), pcbid) + .FirstOrDefault(reader => reader.GetValue(0)); + + if (requirement.FwVersion != version) + { + yield return new KeyValuePair(pcbidString, $"FW version ambiguous between {requirement.FwVersion}(requirement) and {version}(db)."); + yield break; + } + + var requiremetLutCrc = requirement.LutCrc; + var lutCrcString = $"{requiremetLutCrc}".Replace("0x", String.Empty).Trim(); + + if (UInt16.TryParse(lutCrcString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var lutCRCValue)) + { + var lutCRCRegister = cordonelApps[Apps.GENESISFLOW][GENESISFLOW.LookupFileCrc]; + + if (!lutCRCRegister.IsEquals(lutCRCValue)) + { + var registerLutCrc = lutCRCRegister.GetValue(); + + yield return new KeyValuePair(pcbidString, $"LUT CRC ambiguous between {requiremetLutCrc}(requirement) and 0x{registerLutCrc:X2}(register)."); + yield break; + } + } + else + { + yield return new KeyValuePair(pcbidString, $"LUT CRC {requiremetLutCrc} is not valid."); + yield break; + } + this.sqlConnection .CreateCommand($@" UPDATE Cordonel_EOL_Progress diff --git a/LaaProductionWeb/LaaPackages b/LaaProductionWeb/LaaPackages index ece81474..3837dad0 160000 --- a/LaaProductionWeb/LaaPackages +++ b/LaaProductionWeb/LaaPackages @@ -1 +1 @@ -Subproject commit ece81474c3d99d9479dbbc17241bffb033ae3297 +Subproject commit 3837dad0a935fb89c06cb8410e1d35e60acf0448 diff --git a/LaaProductionWeb/LaaProduction.Console/Program.cs b/LaaProductionWeb/LaaProduction.Console/Program.cs index 2ed1781b..306278da 100644 --- a/LaaProductionWeb/LaaProduction.Console/Program.cs +++ b/LaaProductionWeb/LaaProduction.Console/Program.cs @@ -1,56 +1,12 @@ namespace LaaProduction.Console { - using LaaPackages.Features.Cordonel; - using LaaPackages.HttpClient; - using LaaPackages.SqlClient; - using System; public class Program { public static void Main(String[] args) { - var pcbidString = "192000024"; - var cordonelApps = HttpConnection - .CreateHttpConnection("http://10.49.40.25/") - .Get(x => x.SetPath("/MeterProcessState/api/ConfigurationJson")) - ?.Value ?? new CordonelAppsDictionary(); - SqlConnection - .CreateSqlConnection("Server=SLASQL01;Database=Auftrag;User Id=sa;Password=sqlserver") - .CreateCommand($@" - SELECT x.Id - , x.Address - , x.Value - FROM (SELECT gmh.ID AS Id - , CONVERT(VARBINARY(MAX), REPLACE(ISNULL(gmh.Address, '00'), '-', ''), 2) AS Address - , CONVERT(VARBINARY(MAX), REPLACE(REPLACE(ISNULL(gmh.Value, '00'), 'NULL', '00'), '-', ''), 2) AS Value - , ROW_NUMBER() OVER (PARTITION BY gmh.Address ORDER BY gmh.date DESC) AS Row - FROM GenesisMeterRegisterHistory AS gmh - WHERE gmh.PcbId = @{nameof(pcbidString)}) AS x - WHERE x.Row = 1 - ORDER BY x.Address") - .SetParameter(nameof(pcbidString), pcbidString) - .ExecuteReader(reader => - { - var addressBytes = reader.GetValue(1); - - if (addressBytes?.Length == 2) - { - var appId = addressBytes[0]; - var registerId = addressBytes[1]; - var register = cordonelApps[appId][registerId]; - - register.HistoryId = reader.GetValue(0); - register.Value = reader.GetValue(2); - } - }); - } - } - - public class MPSConnection : HttpConnection - { - public MPSConnection(string baseURL) : base(baseURL) - { + Console.WriteLine(typeof(Program).Namespace); } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs b/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs index 2ed8b476..34efe9f8 100644 --- a/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs +++ b/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs @@ -1,7 +1,6 @@ namespace LaaProductionWeb.API.Cordonel { using LaaPackages.Features.Cordonel; - using LaaPackages.HttpClient; using LaaProduction.Data.Cordonel; using LaaProduction.Data.Cordonel.Models; using LaaProductionWeb.App_Infrastructure;