diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index a9e559c9..815742af 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,101 +1,117 @@ namespace CommonConsole { - using OmniPlus; - using OmniPlus.Features; - using OmniPlus.Features.Enums; - using System; - using System.Text; - using System.Threading; + using System.Collections.Generic; public static class Program { public static void Main() { - var optionalUniDir = BitConverter.ToInt16(new byte[] { 0xFC, 0x01 }, 0); - var protokoll = new StringBuilder(); - var connection = new OmniIrdaConnection("COM36"); - connection.StateChenged += x => protokoll.AppendLine(x.ToString()); - connection.StateChenged += Console.WriteLine; - connection.Open(); + var hexString = "5E-CC-02-1A-00-00-00-00-5E-CC-02-1A-00-00-00-00-5E-CC-02-1A-00-00-00-00-5E-CC-02-1A-00-00-00-00"; + var bytes = new List(); + var hex = string.Empty; - if (connection.FactorySeal().Sealed) + foreach (var @char in hexString) { - var _sealed = connection.FactorySeal(false); + if (('0' <= @char && @char <= '9') || ('A' <= @char && @char <= 'F') || ('a' <= @char && @char <= 'f')) + { + hex += @char; + } + + if (hex.Length == 2) + { + bytes.Add(Convert.ToByte(hex, 16)); + + hex = string.Empty; + } } - - var system = connection.ViewSystemParameters(); - var register = connection.ViewRegisterSettings(); - var configuration = connection.ViewConfigurationParameters(); - var systemReset = connection.Set(new SystemTime()); - Thread.Sleep(10000); + Console.WriteLine(BitConverter.ToString(bytes.ToArray())); - var response = connection.Set(new RegisterSettings - { - IntPart = register.IntPart, - Fraction = register.Fraction, - Size = register.Size, - Range = register.Range, - VolumePerPulseUnit = 0x00, - MeterUnits = (byte)MessurementUnits.USGallons, - FlowUnits = (byte)MessurementUnits.USGallons, - FlowRate = (byte)TimeUnits.Minutes, - FactoryCorrection = 0x00, - FieldCorrection = 0x00, - PulseWeight = 1, - PulseWidth = 2, - PulseUpdate = 0, - }); + //var optionalUniDir = BitConverter.ToInt16(new byte[] { 0xFC, 0x01 }, 0); + //var protokoll = new StringBuilder(); + //var connection = new OmniIrdaConnection("COM36"); + //connection.StateChenged += x => protokoll.AppendLine(x.ToString()); + //connection.StateChenged += Console.WriteLine; + //connection.Open(); - response = connection.Set(new ConfigurationParametersSet - { - BuildInfo = "816232411982", - ProgrammableID = "816232411982", - FactoryID = "816232411982", - AlarmPercistancePeriodDays = 31, - DataLogIntervalMinutes = 60, - ManifacturingTime = system.ManifacturingTime.SecondsSince, - NumberOfReadingDigits = 8, - OptionalUniDirFields = 0x01FC, - ReadingPreset = "000000010", - RebootCount = 0, - SystemTime = Epoch20000101.UTCNow, - DeviceID = "OMNI-02" - }); + //if (connection.FactorySeal().Sealed) + //{ + // var _sealed = connection.FactorySeal(false); + //} - response = connection.ClearDisplay(); - response = connection.Set(new LeakAlarm - { - FlowRateGPM = 0.25F, - TimeLimit = 24 * 60 * 60 - }); - response = connection.Set(new HighFlowAlarm - { - FlowRateGPM = 25F, - TimeLimit = 1 * 60 * 60 - }); - response = connection.Set(new ReverseFlowAlarm - { - FlowRateGPM = -1F, - TimeLimit = 60 - }); - response = connection.ClearAlarms(); - response = connection.EnableNFC(); - var alarmsState = connection.ViewAlarmsState(); - response = connection.ViewAlarmSettings(0x01); - response = connection.ViewAlarmSettings(0x02); - response = connection.ViewAlarmSettings(0x04); - response = connection.FactorySeal(true); - response = connection.FactorySeal(); - system = connection.ViewSystemParameters(); - register = connection.ViewRegisterSettings(); - configuration = connection.ViewConfigurationParameters(); + //var system = connection.ViewSystemParameters(); + //var register = connection.ViewRegisterSettings(); + //var configuration = connection.ViewConfigurationParameters(); + //var systemReset = connection.Set(new SystemTime()); - connection.Close(); + //Thread.Sleep(10000); - Console.WriteLine(); - Console.WriteLine(protokoll.ToString()); + //var response = connection.Set(new RegisterSettings + //{ + // IntPart = register.IntPart, + // Fraction = register.Fraction, + // Size = register.Size, + // Range = register.Range, + // VolumePerPulseUnit = 0x00, + // MeterUnits = (byte)MessurementUnits.USGallons, + // FlowUnits = (byte)MessurementUnits.USGallons, + // FlowRate = (byte)TimeUnits.Minutes, + // FactoryCorrection = 0x00, + // FieldCorrection = 0x00, + // PulseWeight = 1, + // PulseWidth = 2, + // PulseUpdate = 0, + //}); + + //response = connection.Set(new ConfigurationParametersSet + //{ + // BuildInfo = "816232411982", + // ProgrammableID = "816232411982", + // FactoryID = "816232411982", + // AlarmPercistancePeriodDays = 31, + // DataLogIntervalMinutes = 60, + // ManifacturingTime = system.ManifacturingTime.SecondsSince, + // NumberOfReadingDigits = 8, + // OptionalUniDirFields = 0x01FC, + // ReadingPreset = "000000010", + // RebootCount = 0, + // SystemTime = Epoch20000101.UTCNow, + // DeviceID = "OMNI-02" + //}); + + //response = connection.ClearDisplay(); + //response = connection.Set(new LeakAlarm + //{ + // FlowRateGPM = 0.25F, + // TimeLimit = 24 * 60 * 60 + //}); + //response = connection.Set(new HighFlowAlarm + //{ + // FlowRateGPM = 25F, + // TimeLimit = 1 * 60 * 60 + //}); + //response = connection.Set(new ReverseFlowAlarm + //{ + // FlowRateGPM = -1F, + // TimeLimit = 60 + //}); + //response = connection.ClearAlarms(); + //response = connection.EnableNFC(); + //var alarmsState = connection.ViewAlarmsState(); + //response = connection.ViewAlarmSettings(0x01); + //response = connection.ViewAlarmSettings(0x02); + //response = connection.ViewAlarmSettings(0x04); + //response = connection.FactorySeal(true); + //response = connection.FactorySeal(); + //system = connection.ViewSystemParameters(); + //register = connection.ViewRegisterSettings(); + //configuration = connection.ViewConfigurationParameters(); + + //connection.Close(); + + //Console.WriteLine(); + //Console.WriteLine(protokoll.ToString()); } } } diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/PowerCorrection.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/PowerCorrection.cs index 5a9c874c..03c6c797 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/PowerCorrection.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/PowerCorrection.cs @@ -17,7 +17,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore public String PcbId { get; set; } /// - /// Date time UTC at EOL - Production + /// Date time UTC at EOL - Production /// public DateTime? ProductionDateTimeUtc { get; set; } @@ -37,7 +37,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore public Byte? ProductionRadioSystemState { get; set; } /// - /// Pulse adapter was installed during at EOL - Production + /// Pulse adapter was installed during at EOL - Production VAKO /// public Boolean ProductionPulseAdapterIsInstalled { get; set; } diff --git a/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache b/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache index 8d4994b0..82bc2c16 100644 --- a/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache +++ b/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -8fbe991b217e7692af4817ad205b768685aa5a72 +bf6bb8fceb3db5a9977dadc407cf576684bf7127 diff --git a/Common/OmniPlus/SqlExtensions/SQLReader.cs b/Common/OmniPlus/SqlExtensions/SQLReader.cs index e321481d..186f9d5f 100644 --- a/Common/OmniPlus/SqlExtensions/SQLReader.cs +++ b/Common/OmniPlus/SqlExtensions/SQLReader.cs @@ -106,7 +106,7 @@ public T GetValue(int index = -1) { - if (index > 0) + if (index >= 0) { if (!this.sqlDataReader.IsDBNull(index)) { diff --git a/Common/Service/MeterProcessState/Controllers/FwUpdateController.cs b/Common/Service/MeterProcessState/Controllers/FwUpdateController.cs index 63d8cfe9..183044a6 100644 --- a/Common/Service/MeterProcessState/Controllers/FwUpdateController.cs +++ b/Common/Service/MeterProcessState/Controllers/FwUpdateController.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Common.SqlExtensions; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; @@ -7,10 +8,12 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using System.Web.Http; using Xylem.Common.Cryptology.Security; +using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore; using Xylem.Common.Hardware.WaterMeter.Genesis.Registers; using Xylem.Common.Logic.ProductionOrderCore.OrderData; using Xylem.Common.Logic.ServiceCore; @@ -891,6 +894,178 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers }); } + + [HttpGet] + [Route("api/fwupdate/databaseateol/{pcbid}")] + public IHttpActionResult DataBaseAtEOL(string pcbid) + { + var databaseAtEOL = SQLConnection + .CreateSQLConnection(GlobalConfig.connectionString.Value, error => + { + throw new Exception(error); + }) + .CreateCommand($@" + DECLARE @pcb AS VARCHAR(15) = @{nameof(pcbid)}; + DECLARE @latestRegisters AS TABLE ( + [PcbId] VARCHAR(10) + , [Address] VARCHAR(10) + , [Value] VARCHAR(250) + , [Date] DATETIME); + + INSERT INTO @latestRegisters + SELECT [h].[PcbId] + , [h].[Address] + , [h].[Value] + , [h].[Date] + FROM (SELECT [PcbId] + , [Address] + , [Value] + , [date] AS [Date] + , RANK() OVER (PARTITION BY [Address] ORDER BY [Id] DESC) AS [Row] + FROM [GenesisMeterRegisterHistory] + WHERE [PcbId] = @pcb) + AS [h] + WHERE [h].[Row] = 1; + + SELECT (SELECT MAX([PcbId]) FROM @latestRegisters) AS [PcbId] + , (SELECT MAX([Date]) FROM @latestRegisters) AS [ProductionDate] + , (SELECT [Value] FROM @latestRegisters WHERE [Address] = '01-0A') AS [TotalUsedSeconds] + , (SELECT [Value] FROM @latestRegisters WHERE [Address] = '01-09') AS [TotalUsedCharge] + , (SELECT [Value] FROM @latestRegisters WHERE [Address] = '10-09') AS [RadioSystemState] + , (SELECT [Value] FROM @latestRegisters WHERE [Address] = '12-03') AS [PulseMode] + , (SELECT [Value] FROM @latestRegisters WHERE [Address] = '14-02') AS [PulseSequenceCounter] + , (SELECT [Value] FROM @latestRegisters WHERE [Address] = '12-11') AS [PulseEvenDistribution] + , (SELECT CAST(CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END AS BIT) + FROM [MapPcbIdToSerialNumber] AS [pcb2sn] + LEFT JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[SerienNrVon] <= [pcb2sn].[MapPcbIdToSerialNumber_SerialNumber] + AND [aap].[SerienNrBis] >= [pcb2sn].[MapPcbIdToSerialNumber_SerialNumber] + LEFT JOIN [Identnr] AS [idnr] + ON [idnr].[IdentNr] = [aap].[IdentNr] + WHERE [pcb2sn].[MapPcbIdToSerialNumber_PcbId] = @pcb + AND [idnr].[Typ] = 'GNS' + AND SUBSTRING([idnr].[VakoCode], 48, 1) IN ('K', 'Q')) AS [PulseAdapterIsInstalled];") + .SetParameter(nameof(pcbid), pcbid) + .FirstOrDefault(x => + { + var model = new PowerCorrection(); + + model.PcbId = x.GetValue(0); + + if (string.IsNullOrWhiteSpace(model.PcbId)) + { + return null; + } + + model.ProductionDateTimeUtc = x.GetValue(1); + model.ProductionTotalUsedSeconds_s = x.GetValue(2).ToUint(); + model.ProductionTotalUsedCharge_uAs = x.GetValue(3).ToUlong(); + model.ProductionRadioSystemState = x.GetValue(4).ToNullableByte(); + model.ProductionPulseMode = x.GetValue(5).ToByte(); + model.ProductionPulseSequenceCounter = x.GetValue(6).ToByte(); + model.ProductionPulseEvenDistribution = x.GetValue(7).ToBool(); + model.ProductionPulseAdapterIsInstalled = x.GetValue(8); + + return model; + }); + + return this.Json(databaseAtEOL, new JsonSerializerSettings + { + DefaultValueHandling = DefaultValueHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore + }); + } + } + + public static class BitConverterExtensions + { + public static bool ToBool(this string hexString) + { + var bytes = hexString.ToByteArray(); + + if (bytes.Length >= 1) + { + return BitConverter.ToBoolean(bytes, 0); + } + + return default(bool); + } + + public static byte ToByte(this string hexString) + { + var bytes = hexString.ToByteArray(); + + if (bytes.Length >= 1) + { + return bytes[0]; + } + + return default(byte); + } + + public static byte? ToNullableByte(this string hexString) + { + var bytes = hexString.ToByteArray(); + + if (bytes.Length >= 1) + { + return bytes[0]; + } + + return default(byte?); + } + + public static uint ToUint(this string hexString) + { + var bytes = hexString.ToByteArray(); + + if (bytes.Length >= 4) + { + return BitConverter.ToUInt32(bytes, 0); + } + + return default(uint); + } + + public static ulong ToUlong(this string hexString) + { + var bytes = hexString.ToByteArray(); + + if (bytes.Length >= 8) + { + return BitConverter.ToUInt64(bytes, 0); + } + + return default(ulong); + } + + public static byte[] ToByteArray(this string hexString) + { + if (!string.IsNullOrWhiteSpace(hexString)) + { + var bytes = new List(); + var hex = string.Empty; + + foreach (var @char in hexString) + { + if (('0' <= @char && @char <= '9') || ('A' <= @char && @char <= 'F') || ('a' <= @char && @char <= 'f')) + { + hex += @char; + } + + if (hex.Length == 2) + { + bytes.Add(Convert.ToByte(hex, 16)); + + hex = string.Empty; + } + } + + return bytes.ToArray(); + } + + return Array.Empty(); + } } } diff --git a/Common/Service/MeterProcessState/Controllers/TestBenchController.cs b/Common/Service/MeterProcessState/Controllers/TestBenchController.cs index edde80ca..4aaf3f8a 100644 --- a/Common/Service/MeterProcessState/Controllers/TestBenchController.cs +++ b/Common/Service/MeterProcessState/Controllers/TestBenchController.cs @@ -1,6 +1,6 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers { - using LaaProductionSQL; + using global::Common.SqlExtensions; using System; using System.Configuration; diff --git a/Common/Service/MeterProcessState/MeterProcessState.csproj b/Common/Service/MeterProcessState/MeterProcessState.csproj index c2c14ce0..049b468c 100644 --- a/Common/Service/MeterProcessState/MeterProcessState.csproj +++ b/Common/Service/MeterProcessState/MeterProcessState.csproj @@ -50,9 +50,6 @@ 7 - - ..\..\packages\LaaProductionSQL.1.0.4\lib\netstandard2.0\LaaProductionSQL.dll - ..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\lib\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll @@ -347,12 +344,6 @@ Designer - - Web.config - - - Web.config - @@ -434,6 +425,10 @@ {f7e3df42-4d35-4a0c-9182-90438f9956e1} ServiceCore + + {B8523894-2C40-4FF0-A399-B7A91FAE45EA} + SqlExtensions + {A33E3C6D-EAAE-4A20-A0EE-F9E6922FD029} SoftwareAccessHelper @@ -524,7 +519,8 @@ - copy $(SolutionDir)Hardware\WaterMeter\Genesis\GenesisCore\configuration.json $(ProjectDir) + +