diff --git a/Common/Common.Services.LaserImport/Common.Services.LaserImport.csproj b/Common/Common.Services.LaserImport/Common.Services.LaserImport.csproj index de15ea70..074510b1 100644 --- a/Common/Common.Services.LaserImport/Common.Services.LaserImport.csproj +++ b/Common/Common.Services.LaserImport/Common.Services.LaserImport.csproj @@ -12,6 +12,21 @@ 512 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -50,5 +65,12 @@ + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/Common/Common.Services.LaserImport/Program.cs b/Common/Common.Services.LaserImport/Program.cs index 99c3c2ad..e36d54df 100644 --- a/Common/Common.Services.LaserImport/Program.cs +++ b/Common/Common.Services.LaserImport/Program.cs @@ -31,6 +31,11 @@ clientWhatcher.IncludeSubdirectories = false; clientWhatcher.EnableRaisingEvents = true; + WaithLaserReady(); + } + + private static void WaithLaserReady() + { var fg = ConsoleColor.DarkGray; Console.ForegroundColor = fg; @@ -40,7 +45,7 @@ awaiter.Wait(); Console.ForegroundColor = ConsoleColor.White; - Console.Write($"FERTIGMELDEN"); + Console.Write($"LASERUNG BESTÄTIGEN"); Console.ReadLine(); Console.ForegroundColor = fg; @@ -59,6 +64,8 @@ Thread.Sleep(100); } } + + Console.Clear(); } } @@ -73,9 +80,9 @@ if (!File.Exists(fileToDelete)) { - fileToDelete = string.Empty; - Console.WriteLine($"{fileToDelete} - dose not exists!"); + + fileToDelete = string.Empty; } else { @@ -93,6 +100,8 @@ var sourceFilePath = args.FullPath; var destinationFilePath = Path.Combine(localFolder, args.Name); + Thread.Sleep(1000); + if (File.Exists(sourceFilePath)) { while (true) diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index 04fa7ee4..95edf21b 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -5,86 +5,64 @@ using Common.Hardware.WaterMeter.eRegister.Features; using System; - using System.Collections.Concurrent; using System.Collections.Generic; + + // { 4291923131, "6182ACF7E60266965951BBFB160C1707" }, + // { 4291922821, "B9CC9CCD2CDCB285100B44995497071E" }, + // { 4291868627, "4BC9FEBE927ADA57AE9EE699BBBAC4DC" }, + // { 4291134308, "B9CC9CCD2CDCB285100B44995497071E" }, + public static class Program { static int frequency = 868; static int timeout = 15_000; + static string defaultEncryptionKey = "E6C88800DEB868C0D6A84880CE982840"; static Dictionary testAddresses868 = new Dictionary { - // { 4291923131, "6182ACF7E60266965951BBFB160C1707" }, - // { 4291922821, "B9CC9CCD2CDCB285100B44995497071E" }, - // { 4291868627, "4BC9FEBE927ADA57AE9EE699BBBAC4DC" }, { 4291808024, "4BC9FEBE927ADA57AE9EE699BBBAC4DC" }, { 4291759578, "4BC9FEBE927ADA57AE9EE699BBBAC4DC" }, { 4291709169, "4BC9FEBE927ADA57AE9EE699BBBAC4DC" }, { 4291657730, "B9CC9CCD2CDCB285100B44995497071E" }, - { 4291535650, "E6C88800DEB868C0D6A84880CE982840" }, + { 4291535650, "5DD3EF5233B4DAA6836721F2866182DA" }, { 4291377834, "E6C88800DEB868C0D6A84880CE982840" }, { 4291377829, "E6C88800DEB868C0D6A84880CE982840" }, - // { 4291134308, "B9CC9CCD2CDCB285100B44995497071E" }, { 4291094212, "B9CC9CCD2CDCB285100B44995497071E" }, }; - static void Main() + static void Main_ER() { var sirt868 = new SIRTBroadcaster("COM7"); SIRTLogger.Message += Console.WriteLine; sirt868.Open(); - var etasks = new ConcurrentQueue(); - - foreach (var kvp in testAddresses868) + var CSD_38102_BU_Key = "5DD3EF5233B4DAA6836721F2866182DA"; + var task = new WritePamTask { - etasks.Enqueue(new WritePamTask - { - Timeout = timeout, - DelPamSemi = true, - WakeUpCmd = true, - WakeUpModul = true, - RequireLAT = true, - RequireDEBUG = true, - Frequency = frequency, - RequestAddress = kvp.Key, - ResponseAddress = kvp.Key, - EncryptionKeyI = kvp.Value.GetEncryptionKey(), - Data = new OpticalTelegram(1).Append(new ProvidePin(AuthLevel.III)) - }); - } - - var pendingAddresses = new Queue(); - - while (etasks.TryDequeue(out var etask)) - { - for (var i = 0; i < 2 && etask.State != SIRTTaskState.Completed && etask.State != SIRTTaskState.Cancelled; i++) - { - etask.SetPending(); - - if (sirt868.Start(etask)) - { - etask.Wait(); - } - } - - if (etask.State != SIRTTaskState.Completed) - { - pendingAddresses.Enqueue(etask.RequestAddress); - } + Timeout = timeout, + DelPamSemi = true, + WakeUpCmd = true, + WakeUpModul = true, + RequireLAT = true, + RequireDEBUG = true, + Frequency = frequency, + RequestAddress = 4291535650, + ResponseAddress = 4291535650, + EncryptionKeyI = CSD_38102_BU_Key.GetEncryptionKey(), + Data = new OpticalTelegram(1).Append(new ProvidePin(AuthLevel.III)) + }; + + for (var i = 0; i < 3 || task.State == SIRTTaskState.Completed || task.State == SIRTTaskState.Cancelled; i++) + { + sirt868.Start(task); + task.Wait(); } + Console.ReadKey(); sirt868.Close(); - - Console.WriteLine(); - - foreach (var address in pendingAddresses) - { - Console.WriteLine(address); - } } - static void Main_CSD_Alarms() + static void Main() { var alarmMask = 0 << AlarmMask.ALARM_REBOOT | 1 << AlarmMask.ALARM_LOW_BATTERY diff --git a/Common/Hardware/Common.Hardware.SIRT/Tasks/WritePamTask.cs b/Common/Hardware/Common.Hardware.SIRT/Tasks/WritePamTask.cs index 1ff16e1b..2d4cf063 100644 --- a/Common/Hardware/Common.Hardware.SIRT/Tasks/WritePamTask.cs +++ b/Common/Hardware/Common.Hardware.SIRT/Tasks/WritePamTask.cs @@ -3,6 +3,7 @@ using Common.Hardware.SIRT.Parameters; using System; + using System.Collections.Generic; public class WritePamTask : SIRTTask { @@ -29,6 +30,9 @@ this.SEMIReceived += this.OnSEMIReceived; this.UnknownReceived += this.OnUnknownReceived; this.RequireLAT = true; + this.PamStatusIX = 11; + this.DebugLength = 52; + this.SemiLength = 91; } public event Action MessageSent; @@ -42,7 +46,16 @@ public byte[] EncryptionKeyI { get; set; } - public byte[] EncryptionKeyII { get; set; } + private byte[] encryptionKeyII; + public byte[] EncryptionKeyII + { + get => this.encryptionKeyII; + set + { + this.encryptionKeyII = value; + this.IsEncrypted = true; + } + } public bool WakeUpModul { @@ -92,24 +105,33 @@ set => this.request.Payload = value; } + public byte DebugLength { get; set; } + + public byte SemiLength { get; set; } + + public byte PamStatusIX { get; set; } + public bool AnyTelegramReceived { get; set; } + public Queue MessageQueue { get; set; } = new Queue(); + public override void Receive(SIRTMessage response) { - if (response.Command == SIRTConstants.ACKN_ANSW) + if (this.UseEncryption(response)) { this.DecriptResponse(response); + } + + this.MessageQueue.Enqueue(response); + + if (response.Command == SIRTConstants.ACKN_ANSW) + { this.AKNReceived?.Invoke(response); } else if (response.Command == SIRTConstants.FROM_AIR) { var payload = response?.Payload; - if (this.UseEncryption(response)) - { - this.DecriptResponse(response); - } - if (payload != null && payload.Length > 0) { var type = payload[0]; @@ -208,7 +230,7 @@ protected virtual void OnSEMIReceived(SIRTMessage semi) { - if ((this.RequireLAT && !this.latReceived) || (this.RequireDEBUG && !this.debugReceived) || semi.Payload[11] != 0) + if ((this.RequireLAT && !this.latReceived) || (this.RequireDEBUG && !this.debugReceived) || semi.Payload[this.PamStatusIX] != 0) { this.SetPending(); } @@ -225,7 +247,7 @@ protected virtual bool UseEncryption(SIRTMessage response) { - if (response is null) + if (response is null || this.EncryptionKeyI is null) { return false; } @@ -239,7 +261,7 @@ var payloadLength = payload.Length; - if (payloadLength == 0) + if (payloadLength == 0 || payloadLength == this.DebugLength || payloadLength == this.SemiLength) { return false; } @@ -270,9 +292,22 @@ private void DecriptResponse(SIRTMessage response) { - this.IsEncrypted = true; + var payload = new byte[response.Length]; + Array.Copy(response.Payload, 0, payload, 0, payload.Length); - response.Payload = response.Payload.DecryptResponse(this.EncryptionKeyI); + response.Payload = payload.DecryptResponse(this.EncryptionKeyI); + + if (response.Payload[this.PamStatusIX] != 0 && this.EncryptionKeyII != null) + { + response.Payload = payload.DecryptResponse(this.EncryptionKeyII); + + if (response.Payload[this.PamStatusIX] == 0) + { + var oldEncryptionKey = this.EncryptionKeyI; + this.EncryptionKeyI = this.EncryptionKeyII; + this.EncryptionKeyII = oldEncryptionKey; + } + } } private void SetP811(Action p811Setter) diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs index 47ee65af..8b855856 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs @@ -139,12 +139,15 @@ { task.MessageReceived += this.history.Push; - while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled && !cancellationToken.IsCancellationRequested) + var next = 0; + + while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled && !cancellationToken.IsCancellationRequested && next < 5) { if (this.sirtHub.Start(task)) { this.history.Push(task); task.Wait(); + next++; } else { @@ -196,6 +199,11 @@ break; } + + if (next >= 5) + { + break; + } } if (stopProgramming) @@ -275,6 +283,7 @@ .Append(new ChangeNumberOfLatWindows(this.parameters.LatWindowsInitialization)) .Append(new ChangeTransmissionInterval(this.parameters.TransmissionIntervalInitialization)) .Append(new ProvidePin(AuthLevel.II)), + Timeout = 10_000 }); this.runningTasks.Enqueue(new EregisterCheckInitializationTask(this.parameters, frequency) diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EregisterTask.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EregisterTask.cs index ecfc9491..c24cb353 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EregisterTask.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EregisterTask.cs @@ -46,10 +46,6 @@ } } - public bool ChangeRadioAddress { get; set; } - - public bool ChangeEncryptionKey { get; set; } - public string RSSI { get; private set; } public P11 P11 { get; private set; } 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 56fa974e..000f56e3 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 @@ -270,7 +270,6 @@ // return features; //} - ///////////////////////////////////////////////////// features.Debug = new EregisterDebugFeatures(); features.ChangeMeterReading = this.DisplayVolume; diff --git a/Common/Ui/Common.UI/App.config b/Common/Ui/Common.UI/App.config index 27cd2dde..6cf404ce 100644 --- a/Common/Ui/Common.UI/App.config +++ b/Common/Ui/Common.UI/App.config @@ -7,7 +7,7 @@ - + diff --git a/Common/Ui/Common.UI/Models/AuftragDbContext.cs b/Common/Ui/Common.UI/Models/AuftragDbContext.cs index fc80c860..5decde20 100644 --- a/Common/Ui/Common.UI/Models/AuftragDbContext.cs +++ b/Common/Ui/Common.UI/Models/AuftragDbContext.cs @@ -36,7 +36,7 @@ , SemiDebugDatum = ISNULL(@{nameof(state.SemiDebugDatum)}, er.SemiDebugDatum) , GeschlossenDatum = ISNULL(@{nameof(state.GeschlossenDatum)}, er.GeschlossenDatum) , FunkadresseDatum = ISNULL(@{nameof(state.FunkadresseDatum)}, er.FunkadresseDatum) - , TempAdresse = ISNULL(@{nameof(state.TempAdresse)}, er.TempAdresse) + -- , TempAdresse = ISNULL(@{nameof(state.TempAdresse)}, er.TempAdresse) FROM eRegister AS er JOIN AuftragPositionSerienNr AS aps ON er.Seriennummer = aps.SerienNr @@ -101,6 +101,7 @@ SELECT CAST((SELECT DISTINCT * FROM VieweRegisterProgrammingParameters WHERE SharedId = @{nameof(sharedId)} + AND SerienNr IN (SELECT Serialno FROM eRegister_Shared WHERE P2000_Shared_Id = @{nameof(sharedId)} AND Completed = 0) -- AND Completed = @{nameof(completed)} -- AND SlotNr > 0 FOR XML PATH('{nameof(EregisterProgrammingParameters)}') diff --git a/Common/Ui/Common.UI/Models/SQLiteKeyStore.cs b/Common/Ui/Common.UI/Models/SQLiteKeyStore.cs index dc57ee91..6c6dc0c3 100644 --- a/Common/Ui/Common.UI/Models/SQLiteKeyStore.cs +++ b/Common/Ui/Common.UI/Models/SQLiteKeyStore.cs @@ -25,6 +25,18 @@ public bool TryGetKey(uint address1, uint address2, out string encryptionKey) { + //var existing = this.connection + // .Table() + // .Where(x => x.Address == 4291535650) + // .FirstOrDefault(); + + //if (existing != null) + //{ + // existing.EncryptionKey = "5DD3EF5233B4DAA6836721F2866182DA"; + + // this.connection.Update(existing); + //} + encryptionKey = this.connection .Table() .FirstOrDefault(x => x.Address == address1 || x.Address == address2)