From 78faae944530cdefce94ec75b47607ab1200b5f7 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Mon, 10 Jun 2024 15:06:37 +0200 Subject: [PATCH] AuthLevel and pin added --- .../Messages/Responses/SirtResponse.cs | 2 + .../AuthLevel.cs | 45 +++++++++++++++++++ ....Hardware.Interfaces.Protocols.SIRT.csproj | 1 + .../Payloads/Bup.cs | 14 ------ .../Payloads/Semi.cs | 2 - .../SirtBroadcaster.cs | 36 --------------- .../SirtTask.cs | 13 ++++-- 7 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/AuthLevel.cs diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Messages/Responses/SirtResponse.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Messages/Responses/SirtResponse.cs index afe27d12..db694a09 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Messages/Responses/SirtResponse.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Messages/Responses/SirtResponse.cs @@ -9,6 +9,8 @@ public Boolean MatchCRC { get; } + public override String ToString() => BitConverter.ToString(this.Payload); + private Boolean CheckWhetherTelegramMatchCheckSum() { var existingCRC = this.message.CRC; diff --git a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/AuthLevel.cs b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/AuthLevel.cs new file mode 100644 index 00000000..9ce8c4ad --- /dev/null +++ b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/AuthLevel.cs @@ -0,0 +1,45 @@ +namespace Common.Hardware.Interfaces.Protocols.SIRT +{ + using System; + + public class AuthLevel + { + public enum Level : UInt64 + { + I = 0x004301143068D0, + II = 0x004302140E8040, + III = 0x00430363937322, + } + + private readonly Level pin; + private readonly Byte[] bytes; + + private AuthLevel(Level pin) + { + this.pin = pin; + this.bytes = new Byte[6]; + + var bytes = BitConverter.GetBytes((UInt64)this.pin); + Array.Copy(bytes, 0, this.bytes, 0, this.bytes.Length); + } + + public static readonly AuthLevel I = Level.I; + public static readonly AuthLevel II = Level.II; + public static readonly AuthLevel III = Level.III; + + public override String ToString() + => BitConverter.ToString(this.bytes); + + public static implicit operator AuthLevel(Level level) + => new AuthLevel(level); + + public static implicit operator UInt64(AuthLevel level) + => (UInt64)level.pin; + + public static implicit operator Byte[](AuthLevel level) + => level.bytes; + + public static implicit operator String (AuthLevel level) + => level.ToString(); + } +} diff --git a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Common.Hardware.Interfaces.Protocols.SIRT.csproj b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Common.Hardware.Interfaces.Protocols.SIRT.csproj index d91ef5a8..8a7919f7 100644 --- a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Common.Hardware.Interfaces.Protocols.SIRT.csproj +++ b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Common.Hardware.Interfaces.Protocols.SIRT.csproj @@ -40,6 +40,7 @@ + diff --git a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Bup.cs b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Bup.cs index e15c6260..200d9e24 100644 --- a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Bup.cs +++ b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Bup.cs @@ -29,17 +29,3 @@ public Byte Alarm { get; } } } - - -/* - - Select Case bLevel - Case 1 - ProvideAuthLevelHexCommand = "4301143068D0" - Case 2 - ProvideAuthLevelHexCommand = "4302140E8040" - Case 3 - ProvideAuthLevelHexCommand = "430363937322" - End Select - - */ diff --git a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Semi.cs b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Semi.cs index 98acf27e..7e2ad2dd 100644 --- a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Semi.cs +++ b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/Payloads/Semi.cs @@ -142,7 +142,5 @@ public UInt16 TimeOfLogReset { get; } public Byte MeterSize { get; } - - public override String ToString() => BitConverter.ToString(this.Payload); } } diff --git a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtBroadcaster.cs b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtBroadcaster.cs index 71a3d1fb..36433ee7 100644 --- a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtBroadcaster.cs +++ b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtBroadcaster.cs @@ -71,42 +71,6 @@ this.sirtPort.Close(); } - public SirtTask ReadPam(Action requestBuilder) - { - var request = new ReadPamRequest(); - - requestBuilder(request); - - return this.SirtTask(request); - } - - public SirtTask ReadReg(Action requestBuilder) - { - var request = new ReadRegRequest(); - - requestBuilder(request); - - return this.SirtTask(request); - } - - public SirtTask WritePam(Action requestBuilder) - { - var request = new WritePamRequest(); - - requestBuilder(request); - - return this.SirtTask(request); - } - - public SirtTask WriteReg(Action requestBuilder) - { - var request = new WriteRegRequest(); - - requestBuilder(request); - - return this.SirtTask(request); - } - private SirtTask SirtTask(SirtRequest request) { var task = new SirtTask(request); diff --git a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtTask.cs b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtTask.cs index 4c7f4f57..a61455f0 100644 --- a/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtTask.cs +++ b/Common/Hardware/Interfaces/Protocols/Common.Hardware.Interfaces.Protocols.SIRT/SirtTask.cs @@ -37,12 +37,12 @@ internal void Add(Bup bup) { - + Console.WriteLine(bup); } internal void Add(Lat lat) { - + Console.WriteLine(lat); } internal void Add(Semi semi) @@ -50,15 +50,18 @@ this.IsRunning = false; this.Done?.Invoke(this); + + Console.WriteLine(semi); } internal void Add(Debug debug) - { + { + Console.WriteLine(debug); } internal void Add(Ack ack) { - + Console.WriteLine(ack); } internal void Add(Answer answer) @@ -66,6 +69,8 @@ this.IsRunning = false; this.Done?.Invoke(this); + + Console.WriteLine(answer); } public static implicit operator SirtMessage(SirtTask task)