diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs index 986f8f24..817d145e 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs @@ -236,6 +236,16 @@ public bool Sealed { get; set; } + public bool IsEbeling { get; set; } + + public bool IsFuhzoe { get; set; } + + public bool SkipChecks { get; set; } + + public bool Completed { get; set; } + + public bool IsValid { get; set; } = true; + public uint RequestAddress => (uint)(this.TempAdresse % 10_000_000_000); public uint ResponseAddress => (uint)(this.Adresse % 10_000_000_000); @@ -285,14 +295,69 @@ EncryptionKey = this.EncryptionKey.GetEncryptionKey(), }; - if (this.StatusFertigung < 30) + if (!this.IsValid || this.StatusFertigung != 30) { return features; } + + features.Debug = new EregisterDebugFeatures(); + + if (!this.IsEbeling && !this.IsFuhzoe) + { + features.ChangeWakeUp = new ChangeWakeUp + { + WakeUpMode = WakeUpMode.StayAwake + }; + features.ChangeMeterReading = new ChangeMeterReading(this.DisplayVolume); + features.Debug.SetActivationByThreshold = new SetActivationByThreshold + { + Rotations = this.ActivationByThreshold + }; + features.Debug.DisableOTAFirmwareUpdate = new DisableOTAFirmwareUpdate + { + Mode = (OTAMode)this.DisableOTA + }; + //features.Debug.ChangeState = new ChangeState + //{ + // Mode = FactoryState.Shipment + //}; + features.ChangeTransmissionInterval = new ChangeTransmissionInterval + { + Seconds = this.TransmissionIntervalFinalization, + }; + features.OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus + { + Seconds = this.OpenMeteringTransmissionIntervalSeconds + }; + } + + if (!this.IsEbeling) + { + features.ChangeSensusRFEncryptionKey = new ChangeSensusRFEncryptionKey + { + HexKey = this.EncryptionKey + }; + features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows + { + N = this.LATWindowsFinalization + }; + } + + if (!this.IsFuhzoe) + { + + } features.ChangeRadioId = new ChangeRadioId(this.ResponseAddress); features.ChangeMeterId = new ChangeMeterId(this.MeterId); - features.ChangeMeterReading = new ChangeMeterReading(this.DisplayVolume); + features.SetDateAndTime = new SetDateAndTime + { + SecondsSince20000101 = new Epoch20000101 + { + DateTime = DateTime.UtcNow.AddHours(this.UTC_Offset) + } + }; + features.WirelessMBusMode = new WirelessMBusMode(this.MBusStatus); features.SetPowerLevelSensusRF = new SetPowerLevel { Value = (byte)(this.PowerLevelHex & 127) @@ -301,21 +366,8 @@ { Value = (byte)(this.PowerLevelHex | 128) }; - features.Debug = new EregisterDebugFeatures - { - DisableOTAFirmwareUpdate = new DisableOTAFirmwareUpdate - { - Mode = (OTAMode)this.DisableOTA - }, - SetActivationByThreshold = new SetActivationByThreshold - { - Rotations = this.ActivationByThreshold - }, - ChangeState = new ChangeState - { - Mode = FactoryState.Shipment - } - }; + + features.DeactivateAlarms = new DeactivateAlarms { Backflow = this.Alarm_Backflow, @@ -378,30 +430,6 @@ Counter = this.FDR_Counter, AlarmState = this.FDR_Alarm_State, }; - features.SetDateAndTime = new SetDateAndTime - { - SecondsSince20000101 = new Epoch20000101 - { - DateTime = DateTime.UtcNow.AddHours(this.UTC_Offset) - } - }; - features.WirelessMBusMode = new WirelessMBusMode(this.MBusStatus); - features.OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus - { - Seconds = this.OpenMeteringTransmissionIntervalSeconds - }; - features.ChangeSensusRFEncryptionKey = new ChangeSensusRFEncryptionKey - { - HexKey = this.EncryptionKey - }; - features.ChangeTransmissionInterval = new ChangeTransmissionInterval - { - Seconds = this.TransmissionIntervalFinalization, - }; - features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows - { - N = this.LATWindowsFinalization - }; return features; } @@ -419,6 +447,11 @@ EncryptionKey = this.EncryptionKey.GetEncryptionKey(), }; + if (!this.IsValid) + { + return features; + } + features.ChangeWakeUp = new ChangeWakeUp(WakeUpMode.StayAwake); features.ChangeTransmissionInterval = new ChangeTransmissionInterval(this.TransmissionIntervalInitialization); features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows(this.LatWindowsInitialization); @@ -436,6 +469,7 @@ Vpp = this.VolumePerPulse, VppLED = (uint)this.VolumePerLedPulse }; + features.Debug = new EregisterDebugFeatures { SetMeterType = new SetMeterType @@ -444,6 +478,18 @@ }, }; + if (this.IsFuhzoe) + { + features.Debug.RequestDebugTelegram = new RequestDebugTelegram(); + } + else + { + features.Debug.OpticalTelegram = new OpticalTelegram + { + Minutes = this.LED_On_Minutes + }; + } + return features; } } diff --git a/Common/Ui/Common.UI/App.xaml.cs b/Common/Ui/Common.UI/App.xaml.cs index 09a921e5..a594862c 100644 --- a/Common/Ui/Common.UI/App.xaml.cs +++ b/Common/Ui/Common.UI/App.xaml.cs @@ -8,7 +8,6 @@ using System; using System.Diagnostics; using System.Windows; - using System.Windows.Controls; public partial class App : Application { diff --git a/Common/Ui/Common.UI/Models/AuftragDbContext.cs b/Common/Ui/Common.UI/Models/AuftragDbContext.cs index 402a7b5f..3ac72555 100644 --- a/Common/Ui/Common.UI/Models/AuftragDbContext.cs +++ b/Common/Ui/Common.UI/Models/AuftragDbContext.cs @@ -32,14 +32,10 @@ { var xmlList = sqlConnection .CreateCommand($@" - SELECT CAST((SELECT ersh.P2000_Shared_Id - , ersh.Slotno - , erpp.* - FROM eRegister_Shared AS ersh - JOIN VieweRegisterProgrammingParameters AS erpp - ON ersh.Serialno = erpp.SerienNr - WHERE ersh.P2000_Shared_Id = @{nameof(sharedId)} - AND ersh.Completed = 0 + SELECT CAST((SELECT DISTINCT * + FROM VieweRegisterProgrammingParameters + WHERE SharedId = @{nameof(sharedId)} + AND Completed = 0 FOR XML PATH('{nameof(EregisterProgrammingParameters)}') , ROOT('{nameof(EregisterProgrammingParametersList)}')) AS XML)") diff --git a/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs b/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs index 857783e9..78bd420f 100644 --- a/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs +++ b/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs @@ -15,6 +15,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; + using System.Windows; using System.Windows.Input; internal class EregisterInitializeVM : ViewModel @@ -105,7 +106,8 @@ this.timestamp = DateTime.Now; this.cancellationTokenSource = new CancellationTokenSource(); this.cancellationToken = this.cancellationTokenSource.Token; - this.programmingTask = Task.Run(async () => + this.programmingTask = Task + .Run(async () => { await this.PrepareProgrammingAsync(); await this.eregisterFactory.StartProgrammingAsync(this.cancellationToken); @@ -157,25 +159,28 @@ foreach (var epp in parametersList) { - var finalAddress = actions.FirstOrDefault(x => x.SerialNr == epp.SerienNr).FinalAddress; - var tempAddress = actions.FirstOrDefault(x => x.SerialNr == epp.SerienNr).TempAddress; - - epp.Adresse = finalAddress; - epp.TempAdresse = tempAddress; - - using (var httpResponeMessage = await httpClient.GetAsync(string.Format(uriFormat, epp.SerienNr))) + try { - if (httpResponeMessage.IsSuccessStatusCode) + using (var httpResponeMessage = await httpClient.GetAsync(string.Format(uriFormat, epp.SerienNr))) { - var content = await httpResponeMessage.Content?.ReadAsStringAsync(); - epp.EncryptionKey = content?.Trim('"'); + if (httpResponeMessage?.IsSuccessStatusCode == true) + { + var content = await httpResponeMessage.Content?.ReadAsStringAsync(); + epp.EncryptionKey = content?.Trim('"'); + epp.IsValid = true; + } } } + catch (Exception e) + { + MessageBox.Show(e.ToString(), $"Fehler beim Laden des Schlüssels!", MessageBoxButton.OK); + + epp.IsValid = false; + } } if (taskSource != null) { - var programmingTasksEnumerable = taskSource(parametersList); var col = 0; diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs index 90369ee4..05571cfd 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs @@ -764,7 +764,19 @@ return; } - if (eolProgress.StandardRequirementId != requirements.StandardId) + if (requirements.IsStandardActive == false) + { + this.ThrowSentinelException($"Standard requirement is not active"); + } + else if (requirements.IsStandardActive == true && requirements.IsStandardApproved == false) + { + this.ThrowSentinelException($"Standard requirement is active but not approved"); + } + else if (requirements.IsSpecialActive == true && requirements.IsSpecialApproved == false) + { + this.ThrowSentinelException($"Special requirement is active but not approved"); + } + else if (eolProgress.StandardRequirementId != requirements.StandardId) { this.ThrowSentinelException( nameof(EOLProgressModel) @@ -804,18 +816,6 @@ , nameof(requirements.SpecialVersion) , requirements.SpecialVersion); } - else if (requirements.IsStandardActive == false) - { - this.ThrowSentinelException($"Standard requirement is not active"); - } - else if (requirements.IsStandardActive == true && requirements.IsStandardApproved == false) - { - this.ThrowSentinelException($"Standard requirement is active but not approved"); - } - else if (requirements.IsSpecialActive == true && requirements.IsSpecialApproved == false) - { - this.ThrowSentinelException($"Special requirement is active but not approved"); - } } internal void TryGetCordonelAppsAndRegisterValues(int pcbId, out CordonelAppsDictionary apps) @@ -1042,6 +1042,7 @@ var sentinelVersion = $"{nameof(Sentinel)} - V{assemblyVersion.Major}.{assemblyVersion.MajorRevision}.{assemblyVersion.Minor}"; var exported = this.meterProcessState.MakeSAPExport(pcbId, state, nameof(Sentinel)); + //TODO //if (!exported) //{ // this.ThrowSentinelException($"SAP export für PcbId: {pcbId} wurde nicht durchgeführt"); @@ -1052,9 +1053,9 @@ => throw new SentinelException(method, message); private SentinelException ThrowSentinelException(object class1, object property1, object value1, object class2, object property2, object value2, [CallerMemberName] string method = "") - => throw new SentinelException(method, string.Format("{0}.{1}({2}) != {3}.{4}({5})", class1, property1, value1, class2, property2, value2)); + => throw new SentinelException(method, string.Format("{0}.{1}({2}) != {3}.{4}({5})", class1, property1, value1 ?? "NULL", class2, property2, value2 ?? "NULL")); private SentinelException ThrowSentinelException(string class1, string property1, object value1, string sign, string class2, string property2, object value2, [CallerMemberName] string method = "") - => throw new SentinelException(method, string.Format("{0}.{1}({2}) {3} {4}.{5}({6})", class1, property1, value1, sign, class2, property2, value2)); + => throw new SentinelException(method, string.Format("{0}.{1}({2}) {3} {4}.{5}({6})", class1, property1, value1 ?? "NULL", sign, class2, property2, value2 ?? "NULL")); } }