diff --git a/Common/CommonConsole/CommonConsole.csproj b/Common/CommonConsole/CommonConsole.csproj index bf303d6d..4299715c 100644 --- a/Common/CommonConsole/CommonConsole.csproj +++ b/Common/CommonConsole/CommonConsole.csproj @@ -55,6 +55,14 @@ + + {F408DE9E-01E6-4CFF-AE79-B572B0674FA2} + Common.Hardware.Interfaces.Ports.SirtBroadcaster + + + {B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD} + Common.Hardware.Interfaces.Ports.Sirt + {9ae071c0-db12-4e09-a3c7-43f6dcd518d6} Common.Hardware.Interfaces.Ports diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index 0a24caff..cc47d8c5 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,48 +1,360 @@ namespace CommonConsole { + using Common.Hardware.Interfaces.Ports.Sirt; + using Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters; using Common.Hardware.WaterMeter.eRegister; - using Common.Hardware.WaterMeter.OmniPlus; - using Common.UI.WPFConnector; using System; + using System.Threading; public class Program { public static void Main() { - //var connector = EregisterConnector.CreateNew("COM6", 1000); + var programmingBatch = new JusteRegisterProgrammingBatch(); - //connector.Add(1, 0319020415, 0319020415);//433 - //connector.AddHexCommand(1, "00-00"); - //connector.Add(2, 0319020441, 0319020441);//433 - //connector.AddHexCommand(2, "00-00"); - //connector.Add(3, 4291317405, 4291317405);//433 - //connector.AddHexCommand(3, "00-00"); + if (programmingBatch.StartOnCOMPort("COM6")) + { + // 01020304050607081112131415161718 + var encryptionKey = new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 }; + var task = new JusteRegisterTask + { + Cmd = JustSirtMessage.W_PAM, + P1 = new P811 + { + DelPamSemi = true, + WakeUpCmd = true + }, + Address = 4291305226, + // Address = 319020415, + Data = new Byte[] + { + // Change Key + // 0x6C, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - //connector.RunCommands(); + // LED on + 0x1F, 0x01, 0x08, + + // Provide Pin Auth Level I + // 0x43, 0x01, 0x14, 0x30, 0x68, 0xD0, + + // Provide Pin Auth Level II + // 0x43, 0x02, 0x14, 0x0E, 0x80, 0x40, + + // Provide Pin Auth Level III + 0x43, 0x03, 0x63, 0x93, 0x73, 0x22, + + // Reset credits + // 0x1F, 0x03, 0x03, + }, + EncryptionKey = encryptionKey + }; + + // 55-81-14-00-FF-C8-1F-0A-0B-07-FA-E3-AA-EA-8A-7B-7B-D9-A7-D7-D5-B8-16 + // 55-81-14-00-FF-C8-1F-0A-0B-07-FA-E3-AA-EA-8A-7B-7B-D9-A7-D7-D5-B8-16 + + programmingBatch.Run(task); + task.Wait(); + + Thread.Sleep(5000); + + programmingBatch.Stop(); + } + } - //var connector = EregisterConnector.CreateNew("COM6", 1000); - //connector.Add(1, 0319020415, 0319020415);//433 - //connector.AddHexCommand(1, "00-00"); - //connector.Add(2, 0319020441, 0319020441);//433 - //connector.AddHexCommand(2, "00-00"); - //connector.Add(3, 4291317405, 4291317405);//433 - //connector.AddHexCommand(3, "00-00"); - //connector.InitInspection(); - var connection = new OmniConnection(); - connection.UseUniPro("COM16"); - var system = connection.ViewSystemParameters(); - connection.Disconnect(); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + public static byte[] Decrypt(Byte[] key, params Byte[] message) + { + var decryptLength = message.Length; + var decryptedBytes = new Byte[decryptLength]; + + for (int i = 0; i < decryptLength; i++) + { + decryptedBytes[i] = message[i]; + } + + var start = 14; + var end = start + decryptedBytes[7] - 6; + var token = decryptedBytes[9]; + + for (var i = start; i < end; i++) + { + token += (Byte)(decryptedBytes[i - (token & 0x3) - 1] >> ((token >> 6) & 0x1)); + + decryptedBytes[i] ^= key[(token >> 2) & 0x0F]; + + if (token > 127) + { + decryptedBytes[i] = (Byte)~decryptedBytes[i]; + } + } + + return decryptedBytes; + } + + public static byte[] Encrypt(Byte[] key, UInt32 address, params Byte[] telegramBytes) + { + Console.WriteLine(address); + Console.WriteLine(BitConverter.ToString(key)); + Console.WriteLine(BitConverter.ToString(telegramBytes)); + + var telegramLength = telegramBytes.Length; + var telegramIndex = 0; + + var encryptedBytes = new Byte[telegramLength + 6]; + var encryptLength = encryptedBytes.Length; + var index = 0; + + encryptedBytes[index++] = (Byte)(address >> 24); + encryptedBytes[index++] = (Byte)(address >> 16); + encryptedBytes[index++] = (Byte)(address >> 8); + encryptedBytes[index++] = (Byte)(address >> 0); + + foreach (var _byte in telegramBytes) + { + encryptedBytes[index++] = telegramBytes[telegramIndex++]; + } + + var telegramCRC = CalculateCrc(encryptedBytes, 1, (UInt16)(encryptLength - 3)); + + encryptedBytes[index++] = (Byte)(telegramCRC >> 8); + encryptedBytes[index++] = (Byte)(telegramCRC >> 0); + + Console.WriteLine(BitConverter.ToString(encryptedBytes)); + + var token = (Byte)0xFF; + var reference = address; + + for (var i = 0; i < encryptLength; i++) + { + // Update pKeyDefinition for this byte + token += (Byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1)); + + // Update the unencrypted reference before the byte gets encrypted + reference = (reference << 8); + reference += encryptedBytes[i]; + + // Encrypt the data by applying the resepective key + encryptedBytes[i] ^= key[((token >> 2) & 0x0F)]; + + // Check if data has to be inverted + if (token > 127) + { + encryptedBytes[i] = (Byte)~encryptedBytes[i]; + } + } + + Console.WriteLine(BitConverter.ToString(encryptedBytes)); + Console.WriteLine(); + + return encryptedBytes; + } + + public static ushort CalculateCrc(byte[] data, ushort start, ushort length) + { + byte zeichen, test; + ushort crc_result; + ushort ui_index; + byte h; + + crc_result = 0xFFFF; + ui_index = start; + + if (data.Length >= length + start) + { + while (ui_index < length + start) + { + zeichen = data[ui_index]; + ui_index++; + + for (h = 0; h < 8; h++) + { + test = 0; + + if ((crc_result & 0x8000) != 0) + { + test = 0x80; + } + + crc_result <<= 1; + + if (((zeichen & 0x80) ^ test) != 0) + { + crc_result ^= 0x1021; + } + zeichen <<= 1; + } + } + } + + return crc_result; } } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +//var connector = EregisterConnector.CreateNew("COM6", 1000); + +//connector.Add(1, 0319020415, 0319020415);//433 +//connector.AddHexCommand(1, "00-00"); + +//connector.Add(2, 0319020441, "4291317405", "4291317405", null, false); // 433 +//connector.InitInspection(); + +//connector.Add(3, 4291317405, 4291317405);//433 +//connector.AddHexCommand(3, "00-00"); + +// connector.RunCommands(); + + +//var connector = EregisterConnector.CreateNew("COM6", 1000); + +//connector.Add(1, 0319020415, 0319020415);//433 +//connector.AddHexCommand(1, "00-00"); +//connector.Add(2, 0319020441, 0319020441);//433 +//connector.AddHexCommand(2, "00-00"); +//connector.Add(3, 4291317405, 4291317405);//433 +//connector.AddHexCommand(3, "00-00"); + +//connector.InitInspection(); + +//var connection = new OmniConnection(); +//connection.UseUniPro("COM16"); + +//var system = connection.ViewSystemParameters(); + +//connection.Disconnect(); // 0x08, 0x0E, 0x13, 0x03, 0xEE, 0xAC, 0x00, 0x00, 0x01, 0xF4, 0x00, 0x00, 0x92, 0x0A, 0x00, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x13, 0x13, 0x03, 0xEE, 0xAC, 0x07, 0x0E, 0x10, 0xA0, 0x57, 0x4E, 0xDA, 0xC0, 0x00, 0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x03, 0x05, 0xA0, 0x0C, 0x03, 0x01, 0x2E, 0x46, 0x7C, 0x76, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x25, 0x14, 0x3B // 0x0B, 0x10, 0x13, 0x03, 0xEE, 0xAC, 0x00, 0x0A, 0x11, 0x0B, 0x11, 0x08, 0x04, 0x02, 0xC8, 0xF4, 0xFB, 0xA7, 0x18, 0x00, 0x65, 0x00, 0x35, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0xEE, 0x34, 0x02, 0x01, 0x01, 0x16, 0x00, 0x25, 0x02, 0x71, 0x00, 0x00, 0x82, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0xC3 diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Common.Hardware.Interfaces.Ports.SIRT.csproj b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Common.Hardware.Interfaces.Ports.SIRT.csproj index 260e2b49..f9f5ff7f 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Common.Hardware.Interfaces.Ports.SIRT.csproj +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Common.Hardware.Interfaces.Ports.SIRT.csproj @@ -7,8 +7,8 @@ {B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD} Library Properties - Common.Hardware.Interfaces.Ports.SIRT - Common.Hardware.Interfaces.Ports.SIRT + Common.Hardware.Interfaces.Ports.Sirt + Common.Hardware.Interfaces.Ports.Sirt v4.0 512 true @@ -41,6 +41,8 @@ + + diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/JustSirtMessage.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/JustSirtMessage.cs new file mode 100644 index 00000000..d941900d --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/JustSirtMessage.cs @@ -0,0 +1,163 @@ +namespace Common.Hardware.Interfaces.Ports.Sirt +{ + using System; + + public class JustSirtMessage + { + public const Byte MIN_LEN = 12; + public const Byte PC2SIRT = 0x55; + public const Byte SIRT2PC = 0xFF; + public const Byte W_PAM = 0x81; + public const Byte R_PAM = 0x82; + public const Byte W_REG = 0x84; + public const Byte R_REG = 0x87; + public const Byte FROMAIR = 0x11; + public const Byte ACKNANSW = 0x12; + public const Byte STOP = 0x16; + public const Byte BUP = 0x00; + public const Byte LAT = 0x01; + public const Byte DEBUG = 0x0B; + public const Byte SEMI = 0x08; + + private readonly DateTime timestamp; + + private Byte[] bytes; + + public JustSirtMessage(DateTime? timestamp = null) + { + this.timestamp = timestamp ?? DateTime.Now; + this.bytes = new Byte[MIN_LEN]; + this.bytes[0] = PC2SIRT; + } + + public JustSirtMessage(Byte[] bytes, DateTime? timestamp = null) + { + this.timestamp = timestamp ?? DateTime.Now; + this.bytes = bytes; + } + + public Byte Cmd + { + get => this.bytes[1]; + set => this.bytes[1] = value; + } + + public Byte P1 + { + get => this.bytes[2]; + set => this.bytes[2] = value; + } + + public Byte P2 + { + get => this.bytes[3]; + set => this.bytes[3] = value; + } + + public UInt32 Address + { + get + { + var address = 0U; + + address ^= (UInt32)this.bytes[4] << 24; + address ^= (UInt32)this.bytes[5] << 16; + address ^= (UInt32)this.bytes[6] << 8; + address ^= (UInt32)this.bytes[7] << 0; + + return address; + } + set + { + this.bytes[4] = (Byte)(value >> 24); + this.bytes[5] = (Byte)(value >> 16); + this.bytes[6] = (Byte)(value >> 8); + this.bytes[7] = (Byte)(value >> 0); + } + } + + public Byte Length => this.bytes[8]; + + public Byte[] Data + { + get + { + var data = new Byte[this.Length]; + + Array.Copy(this.bytes, 9, data, 0, this.Length); + + return data; + } + set + { + if (value is null) + { + value = new Byte[0]; + } + + this.bytes[8] = (Byte)value.Length; + + Array.Resize(ref this.bytes, MIN_LEN + this.Length); + Array.Clear(this.bytes, 9, this.bytes.Length - 9); + Array.Copy(value, 0, this.bytes, 9, this.Length); + } + } + + public UInt16 CRC + { + get + { + var length = this.bytes.Length; + var crc = default(UInt16); + + crc ^= (UInt16)(this.bytes[length - 3] << 8); + crc ^= (UInt16)(this.bytes[length - 2] << 0); + + return crc; + } + } + + public Byte[] ToByteArray() + { + var length = this.bytes.Length; + var crc = this.CRCCCITT(1, length - 3); + + this.bytes[length - 3] = (Byte)(crc >> 8); + this.bytes[length - 2] = (Byte)(crc >> 0); + this.bytes[length - 1] = STOP; + + return this.bytes; + } + + public override String ToString() + => BitConverter.ToString(this.ToByteArray()); + + private UInt16 CRCCCITT(Int32 start, Int32 length) + { + var crc = (UInt16)0xFFFF; + + for (var b = start; b < length; b++) + { + var _byte = this.bytes[b]; + var token = (UInt16)((_byte << 8) & 0xFF00); + + for (var i = 0; i < 8; i++) + { + if (0x8000 == ((crc ^ token) & 0x8000)) + { + crc <<= 1; + crc ^= 0x1021; + } + else + { + crc <<= 1; + } + + token <<= 1; + } + } + + return crc; + } + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/JustSirtProxy.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/JustSirtProxy.cs new file mode 100644 index 00000000..d5c1e748 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/JustSirtProxy.cs @@ -0,0 +1,161 @@ +namespace Common.Hardware.Interfaces.Ports.Sirt +{ + using System; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + public class JustSirtProxy + { + private readonly JustSerialPort serialPort; + private readonly List buffer; + + private Task listener; + private CancellationToken cancellationToken; + private CancellationTokenSource cancellationTokenSource; + + public JustSirtProxy(String portName) + { + var settings = new SerialPortSettings + { + BaudRate = SerialPortBaudRate.X115200, + DataBits = SerialPortDataBits.X8, + Parity = SerialPortParity.None, + PortName = portName, + StopBits = SerialPortStopBits.One + }; + this.serialPort = new JustSerialPort(settings); + this.buffer = new List(); + } + + public event Action MessageReceived; + + public Boolean IsOpen => this.serialPort.IsOpen; + + public event Action Logging + { + add => this.serialPort.Logging += value; + remove => this.serialPort.Logging -= value; + } + + public void Log(Object value) => this.serialPort.Log(value); + + public Boolean TryClose() + { + var closed = false; + + try + { + this.cancellationTokenSource.Cancel(); + this.listener.Dispose(); + + this.listener = null; + this.cancellationTokenSource = null; + this.cancellationToken = CancellationToken.None; + + closed = this.serialPort.TryClose(); + } + catch (Exception e) + { + this.Log(e); + } + + return closed; + } + + public Boolean TryOpen() + { + var opened = this.serialPort.TryOpen(); + + if (opened) + { + opened = this.StartListening(); + } + + return opened; + } + + public void WriteBytes(params Byte[] bytes) => this.serialPort.WriteBytes(bytes); + + private Boolean StartListening() + { + this.cancellationTokenSource = new CancellationTokenSource(); + this.cancellationToken = this.cancellationTokenSource.Token; + this.listener = Task.Factory.StartNew(state => + { + if (state is JustSirtProxy proxy) + { + var serialPort = proxy.serialPort; + var bytes = new Byte[] { }; + + while (serialPort.IsOpen) + { + bytes = serialPort.ReadBytes(); + + proxy.TryParseMessage(bytes); + } + } + }, this, this.cancellationToken) + .ContinueWith(task => + { + if (task.Exception != null && task.AsyncState is JustSirtProxy proxy) + { + proxy.Log(task.Exception); + } + }); + + return this.listener.Status == TaskStatus.WaitingForActivation + || this.listener.Status == TaskStatus.WaitingToRun + || this.listener.Status == TaskStatus.Running; + } + + private void TryParseMessage(Byte[] bytes) + { + var bytesLength = bytes?.Length ?? 0; + + if (bytesLength > 0) + { + this.buffer.AddRange(bytes); + } + + var bufferLength = this.buffer.Count; + var start = this.buffer.IndexOf(JustSirtMessage.SIRT2PC); + + if (start < 0) + { + this.buffer.Clear(); + + return; + } + + var lengthIX = start + 8; + + if (lengthIX >= bufferLength) + { + return; + } + + var length = this.buffer[lengthIX]; + var stopIX = lengthIX + length + 3; + + if (stopIX >= bufferLength) + { + return; + } + else if (this.buffer[stopIX] != JustSirtMessage.STOP) + { + return; + } + + bytesLength = stopIX - start + 1; + bytes = new Byte[bytesLength]; + + this.buffer.CopyTo(start, bytes, 0, bytesLength); + + var message = new JustSirtMessage(bytes); + + this.MessageReceived?.Invoke(message); + this.buffer.RemoveRange(0, start + bytesLength); + } + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/AuthLevel.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/AuthLevel.cs index 773aba4d..b44d72cb 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/AuthLevel.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/AuthLevel.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/BluetoothOperating.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/BluetoothOperating.cs index 08dc29bd..99808a1e 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/BluetoothOperating.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/BluetoothOperating.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/ByteExtensions.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/ByteExtensions.cs index 7998ddce..126d2107 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/ByteExtensions.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/ByteExtensions.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/OperatingModes.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/OperatingModes.cs index 40e3c564..d3f71913 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/OperatingModes.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/OperatingModes.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { public enum OperatingModes { diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P11.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P11.cs index 8db46bc4..5190ae48 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P11.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P11.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P12.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P12.cs index a08d608b..84df10ad 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P12.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P12.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P811.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P811.cs index b75e6f3e..1560ca73 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P811.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/P811.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/PamTimeout.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/PamTimeout.cs index 82439494..c4de0a52 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/PamTimeout.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/PamTimeout.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/RFModuleOperating.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/RFModuleOperating.cs index 1bd570b9..46e6ab45 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/RFModuleOperating.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/RFModuleOperating.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/SirtOperating.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/SirtOperating.cs index 0ca06941..3f1ae2c3 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/SirtOperating.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Parameters/SirtOperating.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters +namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadPamRequest.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadPamRequest.cs index 1286ac80..163d86b0 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadPamRequest.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadPamRequest.cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Requests +namespace Common.Hardware.Interfaces.Ports.Sirt.Requests { - using Common.Hardware.Interfaces.Ports.SIRT; + using Common.Hardware.Interfaces.Ports.Sirt; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadRegRequest.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadRegRequest.cs index 63204a19..ffa8a30c 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadRegRequest.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/ReadRegRequest.cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Requests +namespace Common.Hardware.Interfaces.Ports.Sirt.Requests { - using Common.Hardware.Interfaces.Ports.SIRT; + using Common.Hardware.Interfaces.Ports.Sirt; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WritePamRequest.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WritePamRequest.cs index 6ee93778..4a8ad6de 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WritePamRequest.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WritePamRequest.cs @@ -1,7 +1,7 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Requests +namespace Common.Hardware.Interfaces.Ports.Sirt.Requests { - using Common.Hardware.Interfaces.Ports.SIRT; - using Common.Hardware.Interfaces.Ports.SIRT.Parameters; + using Common.Hardware.Interfaces.Ports.Sirt; + using Common.Hardware.Interfaces.Ports.Sirt.Parameters; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WriteRegRequest.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WriteRegRequest.cs index 6bb31c25..2884faef 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WriteRegRequest.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Requests/WriteRegRequest.cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Requests +namespace Common.Hardware.Interfaces.Ports.Sirt.Requests { - using Common.Hardware.Interfaces.Ports.SIRT; + using Common.Hardware.Interfaces.Ports.Sirt; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/AcknOrAnswerResponse.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/AcknOrAnswerResponse.cs index 694d24b9..85edc932 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/AcknOrAnswerResponse.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/AcknOrAnswerResponse.cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Responses +namespace Common.Hardware.Interfaces.Ports.Sirt.Responses { - using Common.Hardware.Interfaces.Ports.SIRT.Parameters; + using Common.Hardware.Interfaces.Ports.Sirt.Parameters; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/FromAirResponse.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/FromAirResponse.cs index 0e2fe379..f047291f 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/FromAirResponse.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Responses/FromAirResponse.cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Responses +namespace Common.Hardware.Interfaces.Ports.Sirt.Responses { - using Common.Hardware.Interfaces.Ports.SIRT.Parameters; + using Common.Hardware.Interfaces.Ports.Sirt.Parameters; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTRequest.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTRequest.cs index 3d5dad0d..f69f0a82 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTRequest.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTRequest.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTResponse.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTResponse.cs index 9639b92a..9f6183e9 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTResponse.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTResponse.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTTask[TRequest].cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTTask[TRequest].cs index 3a2aaee5..0df55bcc 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTTask[TRequest].cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SIRTTask[TRequest].cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtBroadcaster.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtBroadcaster.cs index 95ba8780..81a5dd56 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtBroadcaster.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtBroadcaster.cs @@ -1,7 +1,7 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { - using Common.Hardware.Interfaces.Ports.SIRT.Responses; - using Common.Hardware.Interfaces.Ports.SIRT.Tasks; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Tasks; using System; using System.Collections.Concurrent; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtConstants.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtConstants.cs index a65dd005..b32094de 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtConstants.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtConstants.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtMessage.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtMessage.cs index fb65ac63..84efb828 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtMessage.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtMessage.cs @@ -1,4 +1,4 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtTask.cs index 65c9ddaa..ef5eb16e 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/SirtTask.cs @@ -1,7 +1,7 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { - using Common.Hardware.Interfaces.Ports.SIRT.Requests; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Requests; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ActivateSIRTTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ActivateSIRTTask.cs index 3edcd315..90e854ed 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ActivateSIRTTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ActivateSIRTTask.cs @@ -1,8 +1,8 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Tasks +namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks { - using Common.Hardware.Interfaces.Ports.SIRT.Parameters; - using Common.Hardware.Interfaces.Ports.SIRT.Requests; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Parameters; + using Common.Hardware.Interfaces.Ports.Sirt.Requests; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using System; @@ -20,7 +20,7 @@ new BluetoothOperating { BtOff = true }, new RFModuleOperating { RfOff = true }, new RFModuleOperating { OpMode = OperatingModes.ReceiveF1TransmitSensusRFF3 }, - // new PamTimeout { Minutes = 1 } + new PamTimeout { Minutes = 1 } }; } diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/DeleteFromPamPoolTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/DeleteFromPamPoolTask.cs index 2d6f52f4..ecaacb53 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/DeleteFromPamPoolTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/DeleteFromPamPoolTask.cs @@ -1,8 +1,8 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Tasks +namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks { using System; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; public class DeleteFromPamPoolTask : WritePamTask { diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/IdentifySIRTTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/IdentifySIRTTask.cs index 18f0e7c5..21cf0319 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/IdentifySIRTTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/IdentifySIRTTask.cs @@ -1,7 +1,7 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Tasks +namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks { - using Common.Hardware.Interfaces.Ports.SIRT.Requests; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Requests; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ReadPamPoolTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ReadPamPoolTask.cs index b88b4d94..d4c24c25 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ReadPamPoolTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/ReadPamPoolTask.cs @@ -1,7 +1,7 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT.Tasks +namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks { - using Common.Hardware.Interfaces.Ports.SIRT.Requests; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Requests; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/WritePamTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/WritePamTask.cs index fedde649..2fce37d7 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/WritePamTask.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SIRT/Tasks/WritePamTask.cs @@ -1,6 +1,6 @@ -namespace Common.Hardware.Interfaces.Ports.SIRT +namespace Common.Hardware.Interfaces.Ports.Sirt { - using Common.Hardware.Interfaces.Ports.SIRT.Requests; + using Common.Hardware.Interfaces.Ports.Sirt.Requests; using System; diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Common.Hardware.Interfaces.Ports.SirtBroadcaster.csproj b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Common.Hardware.Interfaces.Ports.SirtBroadcaster.csproj new file mode 100644 index 00000000..265aec45 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Common.Hardware.Interfaces.Ports.SirtBroadcaster.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {F408DE9E-01E6-4CFF-AE79-B572B0674FA2} + Library + Common.Hardware.Interfaces.Ports.SirtBroadcaster + Common.Hardware.Interfaces.Ports.SirtBroadcaster + v4.0 + 512 + true + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD} + Common.Hardware.Interfaces.Ports.Sirt + + + + \ No newline at end of file diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs new file mode 100644 index 00000000..56a3ad00 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtBroadcaster.cs @@ -0,0 +1,173 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster +{ + using Common.Hardware.Interfaces.Ports.Sirt; + + using System; + using System.Collections.Concurrent; + + public class JustSirtBroadcaster + { + private static readonly ConcurrentDictionary runningTasks + = new ConcurrentDictionary(); + private readonly JustSirtProxy proxy; + private readonly UInt32[] pampool; + + public JustSirtBroadcaster(String portName) + { + this.proxy = new JustSirtProxy(portName); + this.proxy.MessageReceived += this.Proxy_MessageReceived; + this.pampool = new UInt32[5]; + } + + public event Action Logging + { + add => this.proxy.Logging += value; + remove => this.proxy.Logging -= value; + } + + public String SirtId { get; private set; } + + public Int32 MHz { get; private set; } + + public void Log(Object value) => this.proxy.Log(value); + + public Boolean TryActivate() + { + var activated = this.proxy.TryOpen(); + + if (activated) + { + runningTasks.Clear(); + Array.Clear(this.pampool, 0, 5); + } + + var task = JustSirtTask.ActivateSIRT; + task = runningTasks.AddOrUpdate(task.Address, task, (a, t) => task); + + task.PrepareForRun(); + this.proxy.WriteBytes(task); + task.Wait(); + this.Log(task); + + activated = task.Status == JustTaskStatus.Completed; + + if (activated) + { + task = JustSirtTask.IdentifySIRT; + task = runningTasks.AddOrUpdate(task.Address, task, (a, t) => task); + + task.PrepareForRun(); + this.proxy.WriteBytes(task); + task.Wait(); + this.Log(task); + + activated = task.Status == JustTaskStatus.Completed; + + if (activated) + { + this.SirtId = BitConverter.ToString(task.LastPayload); + this.MHz = this.SirtId[10] == '0' ? 868 : 433; + } + } + + return activated; + } + + public Boolean TryDeactivate() + { + this.proxy.MessageReceived -= this.Proxy_MessageReceived; + + return this.proxy.TryClose(); + } + + public Boolean TryRemove(UInt32 address, out JustSirtTask task) + => runningTasks.TryRemove(address, out task); + + public JustTaskStatus TryRun(JustSirtTask task) + { + if (!this.proxy.IsOpen) + { + return JustTaskStatus.ProxyNotOpen; + } + + var address = task.Address; + + if (runningTasks.TryGetValue(address, out var runningTask)) + { + return JustTaskStatus.InRunningTasks; + } + + this.UpdatePamPool(); + + if (Array.Exists(this.pampool, x => x == address)) + { + return JustTaskStatus.InPamPool; + } + else if (!Array.Exists(this.pampool, x => 0 == x || x == UInt32.MaxValue)) + { + return JustTaskStatus.PamPoolIsFull; + } + + task.PrepareForRun(); + runningTasks.AddOrUpdate(address, task, (a, t) => task); + this.proxy.WriteBytes(task); + this.Log(task); + + return JustTaskStatus.Sent; + } + + private void Proxy_MessageReceived(JustSirtMessage message) + { + var address = message.Address; + + if (runningTasks.TryGetValue(address, out var task)) + { + task.ReceiveMessage(message); + + if (task.Status == JustTaskStatus.Completed) + { + _ = runningTasks.TryRemove(address, out var _); + } + else if (task.Status == JustTaskStatus.Cancelled) + { + this.proxy.WriteBytes(JustSirtTask.DeleteFromPamPool(address)); + } + } + + this.Log(message); + } + + private void UpdatePamPool() + { + Array.Clear(this.pampool, 0, 5); + + if (!this.proxy.IsOpen) + { + return; + } + + var task = JustSirtTask.ReadPamPool; + task = runningTasks.AddOrUpdate(task.Address, task, (a, t) => task); + + task.PrepareForRun(); + this.proxy.WriteBytes(task); + task.Wait(); + this.Log(task); + + var address = 0U; + var addressesBytes = task.LastPayload; + var addressesBytesLength = addressesBytes.Length; + + for (Int32 i = 0, x = 0; i < addressesBytesLength && x < 5;) + { + address = 0U; + address ^= (UInt32)addressesBytes[i++] << 24; + address ^= (UInt32)addressesBytes[i++] << 16; + address ^= (UInt32)addressesBytes[i++] << 8; + address ^= (UInt32)addressesBytes[i++] << 0; + + this.pampool[x++] = address; + } + } + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs new file mode 100644 index 00000000..46560bb6 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustSirtTask.cs @@ -0,0 +1,138 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster +{ + using Common.Hardware.Interfaces.Ports.Sirt; + using Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters; + + using System; + using System.Collections.Concurrent; + using System.Threading; + + public class JustSirtTask + { + private readonly JustSirtMessage request = new JustSirtMessage(); + private readonly ManualResetEventSlim awaiter = new ManualResetEventSlim(); + private readonly ConcurrentStack responses = new ConcurrentStack(); + + public Byte Cmd + { + get => this.request.Cmd; + set => this.request.Cmd = value; + } + + public Byte P1 + { + get => this.request.P1; + set => this.request.P1 = value; + } + + public Byte P2 + { + get => this.request.P2; + set => this.request.P2 = value; + } + + public UInt32 Address + { + get => this.request.Address; + set => this.request.Address = value; + } + + public Byte[] Data + { + get => this.request.Data; + set => this.request.Data = value; + } + + public JustTaskStatus Status { get; private set; } + + public Byte[] LastPayload + => this.responses.TryPeek(out var response) + ? response.Data + : new Byte[0]; + + public virtual void ReceiveMessage(JustSirtMessage response) + { + this.responses.Push(response); + + this.Status = JustTaskStatus.Running; + + if (this.request.Cmd == JustSirtMessage.W_PAM + && response.Cmd == JustSirtMessage.FROMAIR + && response.Data[0] == JustSirtMessage.SEMI) + { + this.Status = JustTaskStatus.Completed; + } + else if (response.Cmd == JustSirtMessage.ACKNANSW) + { + this.Status = JustTaskStatus.Completed; + } + + if (this.Status == JustTaskStatus.Completed) + { + this.awaiter.Set(); + } + } + + public void PrepareForRun() + { + this.Status = JustTaskStatus.Pending; + + this.responses.Clear(); + this.awaiter.Reset(); + } + + public virtual Byte[] ToByteArray() + => this.request.ToByteArray(); + + public override String ToString() + => BitConverter.ToString(this.ToByteArray()); + + public void Wait(Int32 timeout = 15_000) + { + this.awaiter.Wait(timeout); + + if (this.Status != JustTaskStatus.Completed) + { + this.Status = JustTaskStatus.Cancelled; + } + } + + public static implicit operator Byte[] (JustSirtTask task) + => task?.ToByteArray() ?? new Byte[] { }; + + public static readonly JustSirtTask ActivateSIRT = new JustSirtTask + { + Cmd = JustSirtMessage.W_REG, + Address = 0x20000000, + P2 = 0x05, // The data length + Data = new Byte[] + { + new SirtOperating { /* default */ }, + new BluetoothOperating { BtOff = true }, + new RFModuleOperating { RfOff = true }, + new RFModuleOperating { OpMode = OperatingModes.ReceiveF1TransmitSensusRFF3 }, + new PamTimeout { Minutes = 1 } + } + }; + + public static readonly JustSirtTask IdentifySIRT = new JustSirtTask + { + Cmd = JustSirtMessage.R_REG, + Address = 0x11001820, + P2 = 0x08 + }; + + public static readonly JustSirtTask ReadPamPool = new JustSirtTask + { + Cmd = JustSirtMessage.R_PAM, + Address = 0xFFFFFFFF + }; + + public static JustSirtTask DeleteFromPamPool(UInt32 address) => new JustSirtTask + { + Cmd = JustSirtMessage.W_PAM, + P1 = new P811 { DelPamAdr = true }, + Address = address + }; +} +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustTaskStatus.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustTaskStatus.cs new file mode 100644 index 00000000..d554b507 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/JustTaskStatus.cs @@ -0,0 +1,15 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster +{ + public enum JustTaskStatus + { + Pending = 0, + Running = 1, + Completed = 2, + Cancelled = 3, + InRunningTasks = 4, + PamPoolIsFull = 5, + InPamPool = 6, + Sent = 7, + ProxyNotOpen = 8, + } +} \ No newline at end of file diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/BluetoothOperating.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/BluetoothOperating.cs new file mode 100644 index 00000000..b06d1b6e --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/BluetoothOperating.cs @@ -0,0 +1,63 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + public class BluetoothOperating + { + private readonly Byte[] bits; + + public BluetoothOperating() => this.bits = new Byte[8]; + + private BluetoothOperating(Byte[] bits) => this.bits = bits; + + /// + /// 0 -> Transparent Mode at 115k2 Baud 8,n,1 + /// + public Boolean BtOpMode + { + get => this.bits[0] == 1; + } + + /// + /// + /// + /// true + /// after "TIME_OFF" is elapsed without any command via Bluetooth, Bluetooth interface will be switched off + /// + /// + /// false + /// normal operation + /// + /// + /// + public Boolean BtPwrSave + { + get => this.bits[6] == 1; + set => this.bits[6] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// BT module will be switched off + /// + /// + /// false + /// normal operation + /// + /// + /// + public Boolean BtOff + { + get => this.bits[7] == 1; + set => this.bits[7] = (Byte)(value ? 1 : 0); + } + + public static implicit operator Byte(BluetoothOperating param) + => param.bits.GetByte(); + + public static implicit operator BluetoothOperating(Byte _byte) + => new BluetoothOperating(_byte.GetBits()); + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/ByteExtensions.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/ByteExtensions.cs new file mode 100644 index 00000000..1eea4a9b --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/ByteExtensions.cs @@ -0,0 +1,31 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + public static class ByteExtensions + { + public static Byte[] GetBits(this Byte @byte) + { + var bits = new Byte[8]; + + for (int i = 0; i < 8; i++) + { + bits[i] = (Byte)((@byte >> i) & 1); + } + + return bits; + } + + public static Byte GetByte(this Byte[] bits) + { + var @byte = default(int); + + for (int i = 0; i < 8; i++) + { + @byte |= bits[i] << i; + } + + return (Byte)@byte; + } + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/OperatingModes.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/OperatingModes.cs new file mode 100644 index 00000000..2611e461 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/OperatingModes.cs @@ -0,0 +1,14 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + public enum OperatingModes + { + Off = 0, + ReceiveF1TransmitSensusRFF3 = 1, + ReceiveF2TransmitSensusRFF2 = 2, + ReceiveWirelessMbusT1CMode = 3, + ReceiveWirelessMbusS1Mode = 4, + Receive = 5, + TestMode = 8, + Undefined = 15 + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P11.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P11.cs new file mode 100644 index 00000000..6d6f1b1b --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P11.cs @@ -0,0 +1,178 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + /// + /// Parameter P11 is given at third position of "Telegram from Air" telegram and give more detailed information about the + /// received packets from radio section of SIRT.The bits of Parameter 11 are decoded as following, where Bit 0 is the least + /// significant bit: + /// + public class P11 + { + private readonly Byte[] bits; + + public P11() => this.bits = new Byte[8]; + + private P11(Byte[] bits) => this.bits = bits; + + /// + /// + /// + /// true + /// RF-Module2 is source + /// + /// + /// false + /// RF-Module1 is source + /// + /// + /// only valid if both RF-Module programmed for Sensus RF + /// + public Boolean SrcChannel + { + get => this.bits[0] == 1; + set => this.bits[0] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// both RF module data are valid + /// + /// + /// false + /// only one RF module data is valid + /// + /// + /// only valid if both RF-Module programmed for Sensus RF + /// + public Boolean BothValid + { + get => this.bits[1] == 1; + set => this.bits[1] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// RF-Module1 data is invalid + /// + /// + /// false + /// RF-Module1 data is valid + /// + /// + /// i.e. radio checksum is wrong ... + /// + public Boolean InvalidMod1 + { + get => this.bits[2] == 1; + set => this.bits[2] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// RF-Module2 data is invalid + /// + /// + /// false + /// RF-Module2 data is valid + /// + /// + /// i.e. radio checksum is wrong ... + /// + public Boolean InvalidMod2 + { + get => this.bits[3] == 1; + set => this.bits[3] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// invalid -> module detects length > 128 + /// + /// + /// false + /// all ok + /// + /// + /// + public Boolean LenOverflow + { + get => this.bits[4] == 1; + set => this.bits[4] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// will look at PAM / RAC Pool + /// + /// + /// false + /// no attention for PAM / RAC + /// + /// + /// + public Boolean Attention + { + get => this.bits[5] == 1; + set => this.bits[5] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// + /// If .modeSensus = 0 wireless M-busMode -> T1 - Mode + /// If .modeSensus = 1 SensusRF -> receive at f2 + /// + /// + /// + /// false + /// + /// If .modeSensus = 0 wireless M-busMode -> S1 - Mode + /// If .modeSensus = 1 SensusRF -> receive at f1 + /// + /// + /// + /// + public Boolean ModeRF + { + get => this.bits[6] == 1; + set => this.bits[6] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// Sensus RF Mode + /// + /// + /// false + /// wireless M-Bus Mode + /// + /// + /// + public Boolean ModeSensus + { + get => this.bits[7] == 1; + set => this.bits[7] = (Byte)(value ? 1 : 0); + } + + public static implicit operator Byte(P11 param) + => param.bits.GetByte(); + + public static implicit operator P11(Byte _byte) + => new P11(_byte.GetBits()); + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P12.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P12.cs new file mode 100644 index 00000000..6e435376 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P12.cs @@ -0,0 +1,170 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + /// + /// P12 is the parameter of "Acknowledge or Answer" message and is placed at third position, + /// if telegram from SIRT-> PC begins with {0xFF, 0x12}. + /// This parameter gives more detailed information about the last command or request which + /// was send to SIRT. + /// Parameter 12 is given at third position of acknowledge- or answer telegram from SIRT. + /// + public class P12 + { + private readonly Byte[] bits; + + public P12() => this.bits = new Byte[8]; + + private P12(Byte[] bits) => this.bits = bits; + + /// + /// + /// + /// true + /// requested buffer is full or not available + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean BufFull + { + get => this.bits[0] == 1; + set => this.bits[0] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// operating system is busy + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean OsBusy + { + get => this.bits[1] == 1; + set => this.bits[1] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// wrong CRC recognized + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean WrongCRC + { + get => this.bits[2] == 1; + set => this.bits[2] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// command cannot be executed + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean CmdNotExecuted + { + get => this.bits[3] == 1; + set => this.bits[3] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// telegram or command Byte unknown + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean CmdUnknown + { + get => this.bits[4] == 1; + set => this.bits[4] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// no such entry found + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean NoEntry + { + get => this.bits[5] == 1; + set => this.bits[5] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// unknown fixed byte + /// + /// + /// false + /// Ok + /// + /// + /// + public Boolean ByteUnknown + { + get => this.bits[6] == 1; + set => this.bits[6] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// address was 0xFFFFFFFF + /// + /// + /// false + /// normal address + /// + /// + /// + public Boolean WildCardAddr + { + get => this.bits[7] == 1; + set => this.bits[7] = (Byte)(value ? 1 : 0); + } + + public static implicit operator Byte(P12 param) + => param.bits.GetByte(); + + public static implicit operator P12(Byte _byte) + => new P12(_byte.GetBits()); + } +} \ No newline at end of file diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P811.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P811.cs new file mode 100644 index 00000000..bafefbac --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/P811.cs @@ -0,0 +1,241 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + /// + /// Parameter P81-1 is the first modifier of "Write to PAM Pool" command and is placed at third position, + /// if telegram from PC -> SIRT begins with {0x55, 0x81}. + /// This Byte describe in detailed what PAM message should do in detail. + /// There is an public priority within the bits which are described at next table: + /// + /// + /// 7 + /// 6 + /// 5 + /// 4 + /// 3 + /// 2 + /// 1 + /// 0 + /// Description + /// + /// + /// 1 + /// X + /// X + /// X + /// X + /// X + /// X + /// X + /// delete all entries from pool, regardless of address + /// + /// + /// 0 + /// 1 + /// X + /// X + /// X + /// X + /// X + /// X + /// delete entry with this radio address from pool + /// + /// + /// 0 + /// 0 + /// 1 + /// X + /// X + /// X + /// X + /// X + /// write entry with this radio address to pool and delete after transmit + /// + /// + /// 0 + /// 0 + /// 0 + /// 1 + /// X + /// X + /// X + /// X + /// write entry with this radio address to pool and delete after SEMI received + /// + /// + /// 0 + /// 0 + /// 0 + /// 0 + /// 1 + /// X + /// X + /// X + /// write entry with this radio address to pool and leave entry at pool + /// + /// + /// 0 + /// 0 + /// 0 + /// 0 + /// 0 + /// 1 + /// X + /// 0/1 + /// write entry with this radio address to pool, create Wake Up sequence and send out PAM after receive a BUP(LAT) from this address and delete after timeOutPam is elapsed + /// + /// + /// 0 + /// 0 + /// 0 + /// 0 + /// 0 + /// 0 + /// X + /// X + /// write entry with this radio address to pool and delete after timeOutPam is elapsed + /// + /// + /// + public class P811 + { + private readonly Byte[] bits; + + public P811() => this.bits = new Byte[8]; + + private P811(Byte[] bits) => this.bits = bits; + + /// + /// + /// + /// true + /// module 2 is Wakeup Transmitter + /// + /// + /// false + /// module 1 is Wakeup Transmitter + /// + /// + /// + public Boolean WakeUpModul + { + get => this.bits[0] == 1; + set => this.bits[0] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// first transmit Wakeup Sequence and afterwards normal PAM + /// + /// + /// false + /// normal PAM + /// + /// + /// + public Boolean WakeUpCmd + { + get => this.bits[2] == 1; + set => this.bits[2] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// ignore timeout register for automatic delete of PAM + /// + /// + /// false + /// do nothing special + /// + /// + /// + public Boolean IgnoreTimeout + { + get => this.bits[3] == 1; + set => this.bits[3] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// delete entry from PAM pool after SEMI receipt + /// + /// + /// false + /// do nothing after SEMI receipt + /// + /// + /// + public Boolean DelPamSemi + { + get => this.bits[4] == 1; + set => this.bits[4] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// delete entry from PAM pool after PAM transmit + /// + /// + /// false + /// do nothing after PAM transmit + /// + /// + /// + public Boolean DelPamTx + { + get => this.bits[5] == 1; + set => this.bits[5] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// delete from PAM pool + /// + /// + /// false + /// write to PAM pool + /// + /// + /// + public Boolean DelPamAdr + { + get => this.bits[6] == 1; + set => this.bits[6] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// delete all entries from PAM pool + /// + /// + /// false + /// do nothing special + /// + /// + /// + public Boolean DelPamAll + { + get => this.bits[7] == 1; + set => this.bits[7] = (Byte)(value ? 1 : 0); + } + + public static implicit operator Byte(P811 param) + => param.bits.GetByte(); + + public static implicit operator P811(Byte _byte) + => new P811(_byte.GetBits()); + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/PamTimeout.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/PamTimeout.cs new file mode 100644 index 00000000..70b95d7f --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/PamTimeout.cs @@ -0,0 +1,32 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + public class PamTimeout + { + public PamTimeout() => this.Minutes = 0; + + private PamTimeout(Byte minutes) => this.Minutes = minutes; + + /// + /// + /// + /// value == 0 + /// PAM will never automatically deleted + /// + /// + /// value != 0 + /// duration after a PAM will be automatically deleted out of PAM-Pool, if no other rule deletes entry before + /// + /// + /// Several bits at parameter P81-1 or P81-2 may delete entry at PAM-Pool before 5 minutes elapsed. + /// + public Byte Minutes { get; set; } + + public static implicit operator Byte(PamTimeout param) + => param.Minutes; + + public static implicit operator PamTimeout(Byte _byte) + => new PamTimeout(_byte); + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/RFModuleOperating.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/RFModuleOperating.cs new file mode 100644 index 00000000..37c5fe33 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/RFModuleOperating.cs @@ -0,0 +1,76 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + public class RFModuleOperating + { + private readonly Byte[] bits; + + public RFModuleOperating() => this.bits = new Byte[8]; + + private RFModuleOperating(Byte[] bits) => this.bits = bits; + + /// + /// 0 -> Transparent Mode at 115k2 Baud 8,n,1 + /// + public OperatingModes OpMode + { + get + { + var bits = new Byte[8]; + + Array.Copy(this.bits, 0, bits, 0, 4); + + return (OperatingModes)bits.GetByte(); + } + set + { + var bits = ((Byte)value).GetBits(); + + Array.Copy(bits, 0, this.bits, 0, 4); + } + } + + /// + /// + /// + /// true + /// external antenna + /// + /// + /// false + /// internal antenna + /// + /// + /// + public Boolean Antenna + { + get => this.bits[4] == 1; + set => this.bits[4] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// Module not powered + /// + /// + /// false + /// Module powered + /// + /// + /// + public Boolean RfOff + { + get => this.bits[7] == 1; + set => this.bits[7] = (Byte)(value ? 1 : 0); + } + + public static implicit operator Byte(RFModuleOperating param) + => param.bits.GetByte(); + + public static implicit operator RFModuleOperating(Byte _byte) + => new RFModuleOperating(_byte.GetBits()); + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/SirtOperating.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/SirtOperating.cs new file mode 100644 index 00000000..93446ba5 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Parameters/SirtOperating.cs @@ -0,0 +1,136 @@ +namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters +{ + using System; + + public class SirtOperating + { + private readonly Byte[] bits; + + public SirtOperating() => this.bits = new Byte[8]; + + private SirtOperating(Byte[] bits) => this.bits = bits; + + /// + /// + /// + /// true + /// Bluetooth is output for non-requested messages + /// + /// + /// false + /// USB port is output for non-requested messages + /// + /// + /// non requested messages are received radio payloads if a radio module is switched on + /// + public Boolean DataBtOut + { + get => this.bits[0] == 1; + set => this.bits[0] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// : if both RF-Modules are set to SensusRF Mode, both payloads of RF-Modules will be send out + /// + /// + /// false + /// if both RF-Modules are set to SensusRF Mode, the channel with higher RSSI Level will be send out + /// + /// + /// for test purposes both receiver outputs can be shown - but remember Double traffic rate on Bluetoothor USB-output + /// + public Boolean BothChsOut + { + get => this.bits[1] == 1; + set => this.bits[1] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// also payloads with incorrect radio-CRC will send out! + /// + /// + /// false + /// normal operation + /// + /// + /// may be only interesting for test purposes + /// + public Boolean IgnoreCRC + { + get => this.bits[2] == 1; + set => this.bits[2] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// don't switch Power path off if going to USB Suspend and drawing more current as allowed + /// + /// + /// false + /// switch Power path off if going to USB Suspend + /// + /// + /// New at Version 1.0.0.6 + /// + public Boolean IgnoreUSBrules + { + get => this.bits[3] == 1; + set => this.bits[3] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// after "TIME_OFF" is elapsed without any command to SIRT, SIRT will be switched off + /// + /// + /// false + /// normal operation + /// + /// + /// timeout starts at beginning, if any command or communication to and from SIRT is initiated + /// + public Boolean SirtPwrSave + { + get => this.bits[6] == 1; + set => this.bits[6] = (Byte)(value ? 1 : 0); + } + + /// + /// + /// + /// true + /// SIRT will be switched off {like push off button} + /// + /// + /// false + /// normal operation + /// + /// + /// + /// SIRT can be switched off per command, but no answer will send if this bit was set.SIRT can not be switched + /// on per command only by pushing green button for a second + /// + /// + public Boolean SirtOff + { + get => this.bits[7] == 1; + set => this.bits[7] = (Byte)(value ? 1 : 0); + } + + public static implicit operator Byte(SirtOperating param) + => param.bits.GetByte(); + + public static implicit operator SirtOperating(Byte _byte) + => new SirtOperating(_byte.GetBits()); + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Properties/AssemblyInfo.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b18a3667 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports.SirtBroadcaster/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Common.Hardware.Interfaces.Ports.SirtBroadcaster")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Common.Hardware.Interfaces.Ports.SirtBroadcaster")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f408de9e-01e6-4cff-ae79-b572b0674fa2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/Common.Hardware.Interfaces.Ports.csproj b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/Common.Hardware.Interfaces.Ports.csproj index b94e8bae..d98df42c 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/Common.Hardware.Interfaces.Ports.csproj +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/Common.Hardware.Interfaces.Ports.csproj @@ -42,6 +42,7 @@ + diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/JustSerialPort.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/JustSerialPort.cs new file mode 100644 index 00000000..3c7a4d65 --- /dev/null +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/JustSerialPort.cs @@ -0,0 +1,133 @@ +namespace Common.Hardware.Interfaces.Ports +{ + using System; + using System.Collections.Concurrent; + using System.IO.Ports; + + public class JustSerialPort + { + private static readonly ConcurrentDictionary serialPorts + = new ConcurrentDictionary(); + private readonly SerialPortSettings serialPortSettings; + private readonly String portName; + private Int32 readBufferSize; + private Byte[] buffer; + + public Boolean IsOpen + { + get => serialPorts.TryGetValue(this.portName, out var serialPort) + && serialPort.IsOpen; + } + + public JustSerialPort(SerialPortSettings serialPortSettings) + { + + this.serialPortSettings = serialPortSettings; + this.portName = this.serialPortSettings.PortName; + } + + public event Action Logging; + + public void Log(Object message) + => this.Logging?.Invoke($"{DateTime.Now:yyyy-MM-dd|HH:mm:ss.fff}|{this.portName}|{message}"); + + public Boolean TryClose() + { + var closed = false; + + try + { + if (serialPorts.TryRemove(this.portName, out var serialPort)) + { + serialPort.Close(); + serialPort = null; + closed = true; + } + } + catch (Exception e) + { + this.Log(e); + } + + return closed; + } + + public Boolean TryOpen() + { + var opened = false; + + _ = this.TryClose(); + + try + { + var serialPort = new SerialPort + { + BaudRate = this.serialPortSettings.BaudRate, + DataBits = this.serialPortSettings.DataBits, + Parity = this.serialPortSettings.Parity, + PortName = this.serialPortSettings.PortName, + StopBits = this.serialPortSettings.StopBits, + }; + + if (serialPorts.TryAdd(this.portName, serialPort)) + { + serialPort.Open(); + + this.readBufferSize = serialPort.ReadBufferSize; + this.buffer = new Byte[this.readBufferSize]; + opened = serialPort.IsOpen; + } + } + catch (Exception e) + { + this.Log(e); + } + + return opened; + } + + public Byte[] ReadBytes() + { + var length = 0; + var bytes = new Byte[length]; + + if (serialPorts.TryGetValue(this.portName, out var serialPort)) + { + if (serialPort.IsOpen && serialPort.BytesToRead > 0) + { + Array.Clear(this.buffer, 0, this.readBufferSize); + + length = serialPort.Read(this.buffer, 0, this.readBufferSize); + bytes = new Byte[length]; + + Array.Copy(this.buffer, 0, bytes, 0, length); + } + } + + return bytes; + } + + public override String ToString() + => $"{this.serialPortSettings.PortName}, " + + $"{this.serialPortSettings.BaudRate}, " + + $"{this.serialPortSettings.DataBits}, " + + $"{this.serialPortSettings.Parity}, " + + $"{this.serialPortSettings.StopBits}"; + + public void WriteBytes(params Byte[] bytes) + { + if (bytes != null) + { + var bytesLength = bytes.Length; + + if (bytes.Length > 0 && serialPorts.TryGetValue(this.portName, out var serialPort)) + { + if (serialPort.IsOpen) + { + serialPort.Write(bytes, 0, bytes.Length); + } + } + } + } + } +} diff --git a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/SerialPortBase.cs b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/SerialPortBase.cs index 71143b4c..5da34d03 100644 --- a/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/SerialPortBase.cs +++ b/Common/Hardware/Interfaces/Ports/Common.Hardware.Interfaces.Ports/SerialPortBase.cs @@ -105,7 +105,7 @@ } else { - this.LogMessage($"{this.PortName} cann't be addedd!"); + this.LogMessage($"{this.PortName} can not be addedd!"); } } catch (Exception e) @@ -116,16 +116,16 @@ public override String ToString() => serialPorts.TryGetValue(this.PortName, out var serialPort) - ? $"{serialPort.PortName}, " + - $"{serialPort.BaudRate}, " + - $"{serialPort.DataBits}, " + - $"{serialPort.Parity}, " + - $"{serialPort.StopBits}" - : $"{this.settings.PortName}, " + - $"{this.settings.BaudRate}, " + - $"{this.settings.DataBits}, " + - $"{this.settings.Parity}, " + - $"{this.settings.StopBits}"; + ? $"{serialPort.PortName}, " + + $"{serialPort.BaudRate}, " + + $"{serialPort.DataBits}, " + + $"{serialPort.Parity}, " + + $"{serialPort.StopBits}" + : $"{this.settings.PortName}, " + + $"{this.settings.BaudRate}, " + + $"{this.settings.DataBits}, " + + $"{this.settings.Parity}, " + + $"{this.settings.StopBits}"; public virtual Byte[] Write(params Byte[] data) { diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/SystemParameters.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/SystemParameters.cs index 06b7968c..d2d67b28 100644 --- a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/SystemParameters.cs +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/SystemParameters.cs @@ -62,11 +62,29 @@ { this.IsValid = true; - var firmwareTokens = this.VersionAndType - ?.Value + var versionAndType = this.VersionAndType?.Value; + var firmwareTokens = versionAndType ?.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[2]; + this.IsValid = firmwareTokens.Length == 3; + + if (!this.IsValid) + { + this.ValidationMessage = $"Fehlender FW-Versionsparameter! - {versionAndType}"; + + return; + } + + this.IsValid = firmwareTokens[2].CompareTo("R0.3.19") >= 0; + + if (!this.IsValid) + { + this.ValidationMessage = $"FW-Version {firmwareTokens[2]} ist zu alt!"; + + return; + } + var versionString = string.Empty; if (firmwareTokens?.Length > 0 && firmwareTokens[0]?.Length > 0) @@ -78,7 +96,7 @@ if (!this.IsValid) { - this.ValidationMessage = $"{this.VersionAndType.Value} ist kleiner als 1.23"; + this.ValidationMessage = $"{firmwareTokens[0]} ist kleiner als R1.23"; return; } @@ -105,17 +123,19 @@ if (!this.IsValid) { - if (3190 > volts) + var _volts = volts / 1000.0; + + if (3.19 > _volts) { - this.ValidationMessage = $"Zu wenig baterie spannung: {volts / 1000.0}."; + this.ValidationMessage = $"Zu wenig baterie spannung: {_volts}."; } - else if (3750 < volts) + else if (3.75 < _volts) { - this.ValidationMessage = $"Zu fiel baterie spannung: {volts / 1000.0}."; + this.ValidationMessage = $"Zu fiel baterie spannung: {_volts}."; } else { - this.ValidationMessage = $"Die byterie spannung ist nicht in ordnung: {volts / 1000.0}."; + this.ValidationMessage = $"Die byterie spannung ist nicht in ordnung: {_volts}."; } return; diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs index 9d8d6272..d580b5fd 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/DebugCmd.cs @@ -2,22 +2,16 @@ { using System; - public class DebugCmd + public class DebugCmd : Pam { - protected readonly Byte[] bytes; - - protected DebugCmd(Byte code) + protected DebugCmd(Byte code) : base(3, GetDebug) { this.bytes = new Byte[2]; this.bytes[1] = code; } - private DebugCmd(Byte[] bytes) => this.bytes = bytes; - public static implicit operator Byte[] (DebugCmd cmd) => cmd.bytes; - public static implicit operator DebugCmd(Byte[] bytes) => new DebugCmd(bytes); - /// /// Change from Production Mode to Shipment Mode. 1 = Shipment /// diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetAlarms.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetAlarms.cs index ca68323b..b850458d 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetAlarms.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister.Features/SetAlarms.cs @@ -5,7 +5,5 @@ public SetAlarms() : base(2, DebugCmd.SetAlarms) { } - - public static implicit operator DebugCmd(SetAlarms alarms) => alarms.bytes; } } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ACKN.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ACKN.cs index 31c7ade4..cde15dbe 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ACKN.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ACKN.cs @@ -1,6 +1,6 @@ namespace Common.Hardware.WaterMeter.eRegister { - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using System; diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj index 814ebfee..43a2b8ab 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Common.Hardware.WaterMeter.eRegister.csproj @@ -57,6 +57,8 @@ + + @@ -72,9 +74,13 @@ {05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3} Common.Utils.Extensions - + + {F408DE9E-01E6-4CFF-AE79-B572B0674FA2} + Common.Hardware.Interfaces.Ports.SirtBroadcaster + + {B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD} - Common.Hardware.Interfaces.Ports.SIRT + Common.Hardware.Interfaces.Ports.Sirt {9AE071C0-DB12-4E09-A3C7-43F6DCD518D6} diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Endpoint.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Endpoint.cs index 0a9d44cb..77b1fa69 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Endpoint.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Endpoint.cs @@ -1,6 +1,6 @@ namespace Common.Hardware.WaterMeter.eRegister { - using Common.Hardware.Interfaces.Ports.SIRT; + using Common.Hardware.Interfaces.Ports.Sirt; using Common.Hardware.WaterMeter.eRegister.Features; using NLog; @@ -33,7 +33,9 @@ public Int32 SerialNo { get; set; } - public String HexKey { get; set; } + public Byte[] Key { get; set; } + + public Boolean Sealed { get; set; } public DEBUG DEBUG { get; private set; } @@ -41,67 +43,9 @@ public LAT LAT { get; private set; } - public void AddHexCommand(String command) - { - if (String.IsNullOrWhiteSpace(command)) - { - return; - } - - command = command - .Replace("0x", "") - .Replace("h", "") - .Replace(";", "") - .Replace(",", "") - .Replace("-", "") - .Replace(" ", "") - .Trim(); - - if (command.Length % 2 != 0) - { - return; - } - - Boolean TryParse(Char _char, out Int32 _byte) - { - _byte = 0; - - if ('0' <= _char && _char <= '9') - { - _byte = _char - '0'; - } - else if ('A' <= _char && _char <= 'F') - { - _byte = 16 - ('F' - _char) - 1; - } - else - { - return false; - } - - return true; - } - - var length = command.Length; - var bytes = new Byte[length / 2]; - - for (Int32 c = 0, b = 0; c < length; c += 2, b++) - { - if (TryParse(command[c], out var b1) && TryParse(command[c + 1], out var b2)) - { - bytes[b] = (Byte)(b1 * 16 + b2); - } - else - { - this.logger.Error($"Invalid hex char: {command}"); - - bytes = null; - - break; - } - } - - if (bytes != null) + public void AddHexCommand(Byte[] bytes) + { + if (bytes?.Length > 0) { this.commands.Enqueue(bytes); } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EndpointTask.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EndpointTask.cs index 169370f5..51a3901a 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EndpointTask.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/EndpointTask.cs @@ -1,7 +1,7 @@ namespace Common.Hardware.WaterMeter.eRegister { - using Common.Hardware.Interfaces.Ports.SIRT; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using Common.Utils.Extensions; using System; diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs new file mode 100644 index 00000000..f244f6cd --- /dev/null +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs @@ -0,0 +1,46 @@ +namespace Common.Hardware.WaterMeter.eRegister +{ + using Common.Hardware.Interfaces.Ports.SirtBroadcaster; + + using System; + using System.Threading; + + public class JusteRegisterProgrammingBatch + { + private JustSirtBroadcaster broadcaster; + + public Boolean StartOnCOMPort(String portName) + { + this.Stop(); + + this.broadcaster = new JustSirtBroadcaster(portName); + this.broadcaster.Logging += this.Broadcaster_Logging; + + return this.broadcaster.TryActivate(); + } + + private void Broadcaster_Logging(String value) => Console.WriteLine(value); + + public void Stop() + { + if (this.broadcaster != null) + { + this.broadcaster.TryDeactivate(); + this.broadcaster.Logging -= this.Broadcaster_Logging; + this.broadcaster = null; + } + } + + public void Run(JusteRegisterTask task) + { + var status = this.broadcaster.TryRun(task); + + while (status != JustTaskStatus.Sent) + { + Thread.Sleep(1000); + + status = this.broadcaster.TryRun(task); + } + } + } +} diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterTask.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterTask.cs new file mode 100644 index 00000000..cd23d885 --- /dev/null +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterTask.cs @@ -0,0 +1,151 @@ +namespace Common.Hardware.WaterMeter.eRegister +{ + using Common.Hardware.Interfaces.Ports.Sirt; + using Common.Hardware.Interfaces.Ports.SirtBroadcaster; + + using System; + + public class JusteRegisterTask : JustSirtTask + { + public Byte[] EncryptionKey { get; set; } + + public override void ReceiveMessage(JustSirtMessage response) + { + base.ReceiveMessage(response); + + if (this.EncryptionKey != null && this.EncryptionKey.Length == 16) + { + this.DecryptResponse(response); + } + } + + public override Byte[] ToByteArray() + { + if (this.EncryptionKey != null && this.EncryptionKey.Length == 16) + { + this.EncryptRequest(); + } + + return base.ToByteArray(); + } + + private void DecryptResponse(JustSirtMessage response) + { + var data = response.Data; + var length = data.Length; + + if (length < 13) + { + return; + } + + var bytes = new Byte[length]; + var hex = BitConverter.ToString(bytes); + + Array.Copy(data, 0, bytes, 0, length); + + var token = bytes[1]; + + for (var x = 6; x < length; x++) + { + token += (Byte)(bytes[x - (token & 0x3) - 1] >> ((token >> 6) & 0x1)); + + bytes[x] ^= this.EncryptionKey[(token >> 2) & 0x0F]; + + if (token >= 0x80) + { + bytes[x] = (Byte)~bytes[x]; + } + } + + hex = BitConverter.ToString(bytes); + + var crc = this.CalculateCRC(bytes, 5, length); + + if (crc == 0) + { + response.Data = bytes; + } + } + + private void EncryptRequest() + { + var data = this.Data; + var dataLength = data.Length; + var telegramLength = dataLength + 2; + var telegram = new Byte[telegramLength]; + + Array.Copy(data, 0, telegram, 0, dataLength); + + var telegramForCRCLength = telegramLength + 4; + var telegramForCRC = new Byte[telegramForCRCLength]; + var address = this.Address; + + telegramForCRC[0] = (Byte)(address >> 24); + telegramForCRC[1] = (Byte)(address >> 16); + telegramForCRC[2] = (Byte)(address >> 8); + telegramForCRC[3] = (Byte)(address >> 0); + + Array.Copy(telegram, 0, telegramForCRC, 4, telegramLength); + + var telegramCRC = this.CalculateCRC(telegramForCRC, 1, telegramForCRCLength - 2); + + telegram[telegramLength - 2] = (Byte)(telegramCRC >> 8); + telegram[telegramLength - 1] = (Byte)(telegramCRC >> 0); + + var reference = address; + var token = (Byte)0xFF; + + for (var i = 0; i < telegramLength; i++) + { + token += (Byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1)); + + reference = reference << 8; + reference += telegram[i]; + + telegram[i] ^= this.EncryptionKey[(token >> 2) & 0x0F]; + + if (token >= 0x80) + { + telegram[i] = (Byte)~telegram[i]; + } + } + + this.Data = telegram; + } + + private UInt16 CalculateCRC(Byte[] data, Int32 start, Int32 length) + { + var crc = (UInt16)0xFFFF; + var dataLength = data?.Length ?? 0; + + if (start + length > dataLength) + { + return crc; + } + + for (var b = start; b < length; b++) + { + var _byte = data[b]; + var token = (UInt16)((_byte << 8) & 0xFF00); + + for (var i = 0; i < 8; i++) + { + if (0x8000 == ((crc ^ token) & 0x8000)) + { + crc <<= 1; + crc ^= 0x1021; + } + else + { + crc <<= 1; + } + + token <<= 1; + } + } + + return crc; + } + } +} diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/MeterUnits.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/MeterUnits.cs index b03594f8..27bfd53b 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/MeterUnits.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/MeterUnits.cs @@ -2,6 +2,7 @@ { public enum MeterUnits { + NA = 0, m3 = 19, CF = 35, GAL = 24, diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ProgrammingBatch.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ProgrammingBatch.cs index 4189e653..b1407b2e 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ProgrammingBatch.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/ProgrammingBatch.cs @@ -1,7 +1,7 @@ namespace Common.Hardware.WaterMeter.eRegister { using Common.Hardware.Interfaces.Ports; - using Common.Hardware.Interfaces.Ports.SIRT; + using Common.Hardware.Interfaces.Ports.Sirt; using NLog; using NLog.Config; @@ -43,18 +43,21 @@ remove => this.broadcaster.Activated -= value; } - public void Add(Int32 slotno, Int32 serialno, UInt32 address) + public void Add(Int32 slotno, Int32 serialno, UInt32 address, UInt32 finalAddress, Byte[] key, Boolean @sealed) { this.endpoints[slotno] = new Endpoint(this.logger) { Slot = slotno, SerialNo = serialno, - Address = address + Address = address, + FinalAddress = finalAddress, + Key = key, + Sealed = @sealed }; this.endpoints[slotno].Done += this.Endpoint_Done; } - public void AddHexCommand(Int32 slotno, String command) + public void AddHexCommand(Int32 slotno, Byte[] command) { if (this.endpoints.ContainsKey(slotno)) { diff --git a/Common/OmniPlus/InspectionUI.Plugins.Omni/TestBatch.cs b/Common/OmniPlus/InspectionUI.Plugins.Omni/TestBatch.cs index 0bf773c6..37ca2e05 100644 --- a/Common/OmniPlus/InspectionUI.Plugins.Omni/TestBatch.cs +++ b/Common/OmniPlus/InspectionUI.Plugins.Omni/TestBatch.cs @@ -8,15 +8,10 @@ using System; using System.Collections.Generic; + using System.Text; using System.Threading; using System.Threading.Tasks; - /// - /// if $(ConfigurationName) == Development rmdir "Z:\Programme_Sensus\plugins\omni" /s - /// if $(ConfigurationName) == Development mkdir "Z:\Programme_Sensus\plugins\omni" /s - /// if $(ConfigurationName) == Development xcopy $(TargetDir) "Z:\Programme_Sensus\plugins\omni" /s /y - /// - [TestBatch("OMNI+ Prüfung")] public partial class TestBatch : TestBatchBase { @@ -85,7 +80,7 @@ var testPointsCount = testPoints.Count; var layout = this.testBench.Layout; var columnsCount = this.SetColumnDefinitions(testPointsCount, layout); - this.info = this.remoteControl.GetInfo(); + this.info = new InfoMessage(); // this.remoteControl.GetInfo(); this.SetTestHead(layout, columnsCount); this.SetOrderHead(inspectionOrder, layout, columnsCount); @@ -271,6 +266,18 @@ } }) .Wait(); + + var stringBuilder = new StringBuilder(); + + foreach (var meter in this.uimeters) + { + if (meter.IsInvalid) + { + stringBuilder.AppendLine(meter.Messages); + } + } + + this.testBench.Notify(stringBuilder.ToString()); } private void SetTestMeters(Int32 testPointsCount, IGrid layout) diff --git a/Common/OmniPlus/InspectionUI.Plugins.Omni/UIMeter.cs b/Common/OmniPlus/InspectionUI.Plugins.Omni/UIMeter.cs index 385ebe90..be1fe674 100644 --- a/Common/OmniPlus/InspectionUI.Plugins.Omni/UIMeter.cs +++ b/Common/OmniPlus/InspectionUI.Plugins.Omni/UIMeter.cs @@ -38,7 +38,7 @@ set => this[1].Text = value; } - public String Messages => this.meter.Messages; + public String Messages => $"{this.Slot} {this.meter.Messages}"; protected Int32 currentTPCellIndex; @@ -48,6 +48,8 @@ set => this.currentTPCellIndex = value; } + public Boolean IsInvalid => !this.meter.IsActive && !String.IsNullOrWhiteSpace(this.meter.Messages); + public Task ConnectAsync(CancellationToken cancellationToken) { void Connect(Object state) @@ -72,6 +74,11 @@ } }; } + else if (!meter.IsActive && !String.IsNullOrWhiteSpace(meter.Messages)) + { + this[1].Background = TestBatch.Brushes.Red; + this[1].Foreground = TestBatch.Brushes.White; + } uimeter.Pcb = meter.Pcb; } diff --git a/Common/OmniPlus/InspectionUI.RemoteControl/RemoteConnection.cs b/Common/OmniPlus/InspectionUI.RemoteControl/RemoteConnection.cs index 1bc0ce2e..50d034ad 100644 --- a/Common/OmniPlus/InspectionUI.RemoteControl/RemoteConnection.cs +++ b/Common/OmniPlus/InspectionUI.RemoteControl/RemoteConnection.cs @@ -11,15 +11,13 @@ using Microsoft.AspNet.SignalR.Client; - // xcopy "$(TargetDir)*.dll" "\\sla12file\Auftrag\Programme_Sensus\Pruefstation2000\TLB\Remote control" /Y - [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(IRemoteConnectionEvents))] [Guid("FB571D10-F46A-4B32-B1B1-6E7DCE362CC1")] [ComVisible(true)] public class RemoteConnection : IRemoteConnection { - const string LogFile = @".\signalR.txt"; + private const string LogFile = @".\signalR.txt"; private readonly ICollection disposables = new List(); diff --git a/Common/OmniPlus/InspectionUI/App.config b/Common/OmniPlus/InspectionUI/App.config index b86b950d..cd98da8d 100644 --- a/Common/OmniPlus/InspectionUI/App.config +++ b/Common/OmniPlus/InspectionUI/App.config @@ -4,10 +4,9 @@ - - - - + + + diff --git a/Common/OmniPlus/InspectionUI/App.xaml b/Common/OmniPlus/InspectionUI/App.xaml index 30938e9e..1d3170bf 100644 --- a/Common/OmniPlus/InspectionUI/App.xaml +++ b/Common/OmniPlus/InspectionUI/App.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Converters="clr-namespace:InspectionUI.Converters" - StartupUri="eRegister/Init.xaml" > + StartupUri="MainWindow.xaml" > diff --git a/Common/OmniPlus/InspectionUI/InspectionUI.csproj b/Common/OmniPlus/InspectionUI/InspectionUI.csproj index fc585af5..c410fd5d 100644 --- a/Common/OmniPlus/InspectionUI/InspectionUI.csproj +++ b/Common/OmniPlus/InspectionUI/InspectionUI.csproj @@ -111,8 +111,8 @@ - - + + Designer MSBuild:Compile diff --git a/Common/OmniPlus/InspectionUI/ItemsGrid.xaml.cs b/Common/OmniPlus/InspectionUI/ItemsGrid.xaml.cs index f3a54f97..278e1936 100644 --- a/Common/OmniPlus/InspectionUI/ItemsGrid.xaml.cs +++ b/Common/OmniPlus/InspectionUI/ItemsGrid.xaml.cs @@ -1,5 +1,6 @@ namespace InspectionUI { + using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; @@ -45,52 +46,55 @@ private void ReorderItems(object sender, PropertyChangedEventArgs e) { - this.Children.Clear(); - this.RowDefinitions.Clear(); - this.ColumnDefinitions.Clear(); - - var row = 0; - var col = 0; - - foreach (var rowItem in this.ItemsSource) + this.Dispatcher.Invoke(new Action(() => { - this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); + this.Children.Clear(); + this.RowDefinitions.Clear(); + this.ColumnDefinitions.Clear(); - foreach (var cell in rowItem) + var row = 0; + var col = 0; + + foreach (var rowItem in this.ItemsSource) { - if (row == 0) - { - if (cell is ItemsGridCellVM header) - { - for (int i = 0; i < header.ColSpan; i++) - { - var width = header.Width <= 0 - ? GridLength.Auto - : new GridLength(header.Width, GridUnitType.Star); + this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); - this.ColumnDefinitions.Add(new ColumnDefinition { Width = width }); + foreach (var cell in rowItem) + { + if (row == 0) + { + if (cell is ItemsGridCellVM header) + { + for (int i = 0; i < header.ColSpan; i++) + { + var width = header.Width <= 0 + ? GridLength.Auto + : new GridLength(header.Width, GridUnitType.Star); + + this.ColumnDefinitions.Add(new ColumnDefinition { Width = width }); + } } } + + cell.Col = col; + cell.Row = row; + + var cellContent = new ContentControl { Content = cell }; + + Grid.SetRow(cellContent, row); + Grid.SetRowSpan(cellContent, cell.RowSpan); + Grid.SetColumn(cellContent, col); + Grid.SetColumnSpan(cellContent, cell.ColSpan); + + this.Children.Add(cellContent); + + col += cell.ColSpan; } - cell.Col = col; - cell.Row = row; - - var cellContent = new ContentControl { Content = cell }; - - Grid.SetRow(cellContent, row); - Grid.SetRowSpan(cellContent, cell.RowSpan); - Grid.SetColumn(cellContent, col); - Grid.SetColumnSpan(cellContent, cell.ColSpan); - - this.Children.Add(cellContent); - - col += cell.ColSpan; + col = 0; + row++; } - - col = 0; - row++; - } + })); } } } diff --git a/Common/OmniPlus/InspectionUI/VM.cs b/Common/OmniPlus/InspectionUI/ViewModels/VM.cs similarity index 100% rename from Common/OmniPlus/InspectionUI/VM.cs rename to Common/OmniPlus/InspectionUI/ViewModels/VM.cs diff --git a/Common/OmniPlus/InspectionUI/VM[T].cs b/Common/OmniPlus/InspectionUI/ViewModels/VM[T].cs similarity index 100% rename from Common/OmniPlus/InspectionUI/VM[T].cs rename to Common/OmniPlus/InspectionUI/ViewModels/VM[T].cs diff --git a/Common/PendingEmails/PendingEmails.csproj b/Common/PendingEmails/PendingEmails.csproj index b5f7f4df..f66d0fa0 100644 --- a/Common/PendingEmails/PendingEmails.csproj +++ b/Common/PendingEmails/PendingEmails.csproj @@ -57,15 +57,18 @@ true - true + false - true + false + + true + diff --git a/Common/PendingEmails/Program.cs b/Common/PendingEmails/Program.cs index b07d289e..c1f2cd07 100644 --- a/Common/PendingEmails/Program.cs +++ b/Common/PendingEmails/Program.cs @@ -70,7 +70,7 @@ command.CommandTimeout = 60000; command.CommandText = @" INSERT INTO Messages - ( Source + ( Source , InDate , StationNr , PCName @@ -90,9 +90,9 @@ , 'Xylem.Common.Service.PendingMails' , 'noreplay@xylem.com' , ISNULL(ag.Kundenort, 'Kundenort') + ' - ' + CAST(ag.Auftrag AS VARCHAR(15)) + '/' + CAST(ag.Position AS VARCHAR(10)) - + ' erfolgreich geprüft - bitte Garantiescheine drucken und bereitlegen!' - , 'Auftrag: ' + CAST(ag.Auftrag AS VARCHAR(15)) + '/' + CAST(ag.Position AS VARCHAR(10)) + CHAR(10) + 'FertigungsauftragNr: ' + CAST(ag.Fertigungsauftrag AS VARCHAR(15)) + CHAR(10) - + CHAR(10) + CAST(ag.Menge AS VARCHAR(10)) + ' Stück ' + ag.Bezeichnung + CHAR(10) + 'wurde an der Prüfstation: ' + CAST(ag.Pruefstation AS VARCHAR(5)) + CHAR(10) + 'am ' + CONVERT(VARCHAR(10), ag.Pruefdatum, 105) + ' um ' + CONVERT(VARCHAR(5), ag.Pruefdatum, 108) + ' Uhr' + CHAR(10) + 'von ' + ag.Mitarbaiter + ' vollständig geprüft.' + CHAR(10) + + ' erfolgreich geprüft - bitte Garantiescheine drucken und bereitlegen!' + , 'Auftrag: ' + CAST(ag.Auftrag AS VARCHAR(15)) + '/' + CAST(ag.Position AS VARCHAR(10)) + CHAR(10) + 'FertigungsauftragNr: ' + CAST(ISNULL(ag.Fertigungsauftrag, 0) AS VARCHAR(15)) + CHAR(10) + + CHAR(10) + CAST(ISNULL(ag.Menge, 0) AS VARCHAR(10)) + ' Stück ' + ag.Bezeichnung + CHAR(10) + 'wurde an der Prüfstation: ' + CAST(ISNULL(ag.Pruefstation, 0) AS VARCHAR(5)) + CHAR(10) + 'am ' + CONVERT(VARCHAR(10), ag.Pruefdatum, 105) + ' um ' + CONVERT(VARCHAR(5), ag.Pruefdatum, 108) + ' Uhr' + CHAR(10) + 'von ' + ag.Mitarbaiter + ' vollständig geprüft.' + CHAR(10) + CHAR(10) + 'Seriennummern: ' + CAST(ag.SerienNrVon AS VARCHAR(15)) + ' - ' + CAST(ag.SerienNrBis AS VARCHAR(15)) + '' + CHAR(10) + CHAR(10) + ag.Merkmal + CHAR(10) @@ -101,7 +101,7 @@ , 'Automatische fertigmeldung für garantiescheine.' FROM AlleGepruefteAuftraegeMitGarantieAusLetzte24Hours AS ag LEFT JOIN Messages AS msg - ON ag.Fertigungsauftrag LIKE msg.Source + ON ag.Fertigungsauftrag LIKE msg.Source WHERE msg.Id IS NULL"; LogToFile($"Inserted: {command.ExecuteNonQuery()}"); diff --git a/Common/Ui/Common.UI.SIRTBroadcaster/Common.UI.SIRTBroadcaster.csproj b/Common/Ui/Common.UI.SIRTBroadcaster/Common.UI.SIRTBroadcaster.csproj index 75043f30..62e083e4 100644 --- a/Common/Ui/Common.UI.SIRTBroadcaster/Common.UI.SIRTBroadcaster.csproj +++ b/Common/Ui/Common.UI.SIRTBroadcaster/Common.UI.SIRTBroadcaster.csproj @@ -122,9 +122,9 @@ - + {b23bfaf9-08ae-4311-8c08-fb2bb49ea2ad} - Common.Hardware.Interfaces.Ports.SIRT + Common.Hardware.Interfaces.Ports.Sirt {9ae071c0-db12-4e09-a3c7-43f6dcd518d6} diff --git a/Common/Ui/Common.UI.SIRTBroadcaster/Models/SIRTBroadcasterModel.cs b/Common/Ui/Common.UI.SIRTBroadcaster/Models/SIRTBroadcasterModel.cs index 1819d40f..41d87b11 100644 --- a/Common/Ui/Common.UI.SIRTBroadcaster/Models/SIRTBroadcasterModel.cs +++ b/Common/Ui/Common.UI.SIRTBroadcaster/Models/SIRTBroadcasterModel.cs @@ -1,7 +1,7 @@ namespace Common.UI.SIRTBroadcaster.Models { using Common.Hardware.Interfaces.Ports; - using Common.Hardware.Interfaces.Ports.SIRT; + using Common.Hardware.Interfaces.Ports.Sirt; using Common.UI.SIRTBroadcaster.Utilities; using NLog; diff --git a/Common/Ui/Common.UI.SIRTBroadcaster/Models/WritePamTask.cs b/Common/Ui/Common.UI.SIRTBroadcaster/Models/WritePamTask.cs index d5f27c32..e3ed461c 100644 --- a/Common/Ui/Common.UI.SIRTBroadcaster/Models/WritePamTask.cs +++ b/Common/Ui/Common.UI.SIRTBroadcaster/Models/WritePamTask.cs @@ -1,8 +1,8 @@ namespace Common.UI.SIRTBroadcaster.Models { - using Common.Hardware.Interfaces.Ports.SIRT; - using Common.Hardware.Interfaces.Ports.SIRT.Requests; - using Common.Hardware.Interfaces.Ports.SIRT.Responses; + using Common.Hardware.Interfaces.Ports.Sirt; + using Common.Hardware.Interfaces.Ports.Sirt.Requests; + using Common.Hardware.Interfaces.Ports.Sirt.Responses; using Common.Hardware.WaterMeter.eRegister; using Common.Utils.Extensions; diff --git a/Common/Ui/Common.UI.VFM/Common.UI.VFM.csproj b/Common/Ui/Common.UI.VFM/Common.UI.VFM.csproj index be0ed99c..3ca91531 100644 --- a/Common/Ui/Common.UI.VFM/Common.UI.VFM.csproj +++ b/Common/Ui/Common.UI.VFM/Common.UI.VFM.csproj @@ -66,7 +66,7 @@ true - true + false @@ -151,8 +151,6 @@ Resources.Designer.cs - - SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Common/Ui/Common.UI.WPF/ViewModels/EregisterRunCommandsVM.cs b/Common/Ui/Common.UI.WPF/ViewModels/EregisterRunCommandsVM.cs index 38e5af62..6e0f8987 100644 --- a/Common/Ui/Common.UI.WPF/ViewModels/EregisterRunCommandsVM.cs +++ b/Common/Ui/Common.UI.WPF/ViewModels/EregisterRunCommandsVM.cs @@ -71,75 +71,103 @@ this.SIRT = $"SIRT({sirtID}) - {MHz}MHz"; this.programmingBatch.Activated -= this.LoadEndpoints; - this.DispatcherInvoke(() => + this.StartTask(() => { - var gridRow = 0; - var first = false; - - foreach (var commands in this.programmingBatch.RunCommands()) + this.DispatcherInvoke(() => { - var gridColumn = 0; + var gridRow = 0; + var first = false; - if (!first) + foreach (var commands in this.programmingBatch.RunCommands()) { - this.ItemsSource.Add(new TextVM - { - GridColumn = gridColumn++, - GridRow = gridRow, - View = "Einbauplatz", - TextAlignment = TextAlignment.Right, - FontWeight = FontWeights.SemiBold, - Background = Brushes.WhiteSmoke - }); + var gridColumn = 0; - foreach (var slot in this.programmingBatch.Slots()) + if (!first) { this.ItemsSource.Add(new TextVM { GridColumn = gridColumn++, GridRow = gridRow, - View = $"{slot}", + View = "Einbauplatz", + TextAlignment = TextAlignment.Right, FontWeight = FontWeights.SemiBold, Background = Brushes.WhiteSmoke }); + + foreach (var slot in this.programmingBatch.Slots()) + { + this.ItemsSource.Add(new TextVM + { + GridColumn = gridColumn++, + GridRow = gridRow, + View = $"{slot}", + FontWeight = FontWeights.SemiBold, + Background = Brushes.WhiteSmoke + }); + } + + gridRow++; + gridColumn = 0; + + this.ItemsSource.Add(new TextVM + { + GridColumn = gridColumn++, + GridRow = gridRow, + View = "Adresse", + TextAlignment = TextAlignment.Right, + FontWeight = FontWeights.SemiBold, + Background = Brushes.WhiteSmoke + }); + + foreach (var addr in this.programmingBatch.RadioAddresses()) + { + this.ItemsSource.Add(new TextVM + { + GridColumn = gridColumn++, + GridRow = gridRow, + View = $"{addr}", + FontWeight = FontWeights.SemiBold, + Background = Brushes.WhiteSmoke + }); + } + + gridRow++; + gridColumn = 0; + first = true; + } + + var headerSet = false; + var header = new TextVM + { + GridColumn = gridColumn++, + GridRow = gridRow, + View = "PAM -1", + TextAlignment = TextAlignment.Right, + FontWeight = FontWeights.SemiBold, + Background = Brushes.WhiteSmoke + }; + + this.ItemsSource.Add(header); + + foreach (var command in commands) + { + if (command is null) + { + continue; + } + + if (!headerSet) + { + header.View = command.FirstPamId; + headerSet = true; + } + + this.ItemsSource.Add(new EregisterTaskVM(gridRow, gridColumn++, command)); } gridRow++; - gridColumn = 0; - first = true; } - - var headerSet = false; - var header = new TextVM - { - GridColumn = gridColumn++, - GridRow = gridRow, - View = "PAM -1", - TextAlignment = TextAlignment.Right, - FontWeight = FontWeights.SemiBold, - Background = Brushes.WhiteSmoke - }; - - this.ItemsSource.Add(header); - - foreach (var command in commands) - { - if (command is null) - { - continue; - } - - if (!headerSet) - { - header.View = command.FirstPamId; - headerSet = true; - } - - this.ItemsSource.Add(new EregisterTaskVM(gridRow, gridColumn++, command)); - } - - gridRow++; - } + }); }); } } diff --git a/Common/Ui/Common.UI.WPFConnector/Common.UI.WPFConnector.csproj b/Common/Ui/Common.UI.WPFConnector/Common.UI.WPFConnector.csproj index ba3a3fb7..40faa37b 100644 --- a/Common/Ui/Common.UI.WPFConnector/Common.UI.WPFConnector.csproj +++ b/Common/Ui/Common.UI.WPFConnector/Common.UI.WPFConnector.csproj @@ -8,7 +8,7 @@ Library Properties Common.UI.WPFConnector - Common.UI.WPFConnector + WPFConnector v4.0 512 true @@ -45,6 +45,7 @@ + @@ -56,5 +57,12 @@ Common.UI.WPF + + + + + del "$(TargetDir)*.pdb" +del "$(TargetDir)*.xml" + \ No newline at end of file diff --git a/Common/Ui/Common.UI.WPFConnector/EregisterConnector.cs b/Common/Ui/Common.UI.WPFConnector/EregisterConnector.cs index e494f2cd..72a788b4 100644 --- a/Common/Ui/Common.UI.WPFConnector/EregisterConnector.cs +++ b/Common/Ui/Common.UI.WPFConnector/EregisterConnector.cs @@ -2,25 +2,41 @@ { using Common.UI.WPF; using Common.UI.WPF.ViewModels; - using Hardware.WaterMeter.eRegister; + using Common.Hardware.WaterMeter.eRegister; using System; using System.Threading; - using System.Windows; + using System.Runtime.InteropServices; + [ComVisible(true)] + [Guid("6D354B75-388E-41FB-AFBF-19D12250EA54")] + [ClassInterface(ClassInterfaceType.AutoDual)] public class EregisterConnector { private readonly ProgrammingBatch programmingBatch; - public EregisterConnector() : this("COM6", 1000) + public EregisterConnector() : this("COM6", 3000) { + } public EregisterConnector(String portName, Int32 rwTimeout) => this.programmingBatch = new ProgrammingBatch(portName, rwTimeout); - public void Add(Int32 slotno, UInt32 serialno, UInt32 address) => this.programmingBatch.Add(slotno, (Int32)serialno, address); + public void Add(Int32 slotno, Int32 serialno, String address, String finalAddress, String hexKey, Boolean @sealed) + { + _ = UInt32.TryParse(address, out var _address); + _ = UInt32.TryParse(finalAddress, out var _finalAddress); + _ = hexKey.TryParseHexString(out var hexKeyBytes); - public void AddHexCommand(Int32 slotno, String command) => this.programmingBatch.AddHexCommand(slotno, command); + this.programmingBatch.Add(slotno, serialno, _address, _finalAddress, hexKeyBytes, @sealed); + } + + public void AddHexCommand(Int32 slotno, String command) + { + _ = command.TryParseHexString(out var bytes); + + this.programmingBatch.AddHexCommand(slotno, bytes); + } public void InitInspection() { @@ -71,7 +87,7 @@ staThread.Start(this.programmingBatch); manualResetEventSlim.Wait(); } - + public static EregisterConnector CreateNew(String portName, Int32 rwTimeout) => new EregisterConnector(portName, rwTimeout); } } diff --git a/Common/Ui/Common.UI.WPFConnector/Properties/AssemblyInfo.cs b/Common/Ui/Common.UI.WPFConnector/Properties/AssemblyInfo.cs index ece2b4ee..8300c083 100644 --- a/Common/Ui/Common.UI.WPFConnector/Properties/AssemblyInfo.cs +++ b/Common/Ui/Common.UI.WPFConnector/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/Common/Ui/Common.UI.WPFConnector/WPFConnectorExtensions.cs b/Common/Ui/Common.UI.WPFConnector/WPFConnectorExtensions.cs new file mode 100644 index 00000000..65b4b2ed --- /dev/null +++ b/Common/Ui/Common.UI.WPFConnector/WPFConnectorExtensions.cs @@ -0,0 +1,74 @@ +namespace Common.UI.WPFConnector +{ + using System; + + public static class WPFConnectorExtensions + { + public static Boolean TryParseHexString(this String hexString, out Byte[] bytes) + { + bytes = default(Byte[]); + + if (String.IsNullOrWhiteSpace(hexString)) + { + return false; + } + + hexString = hexString + .Replace("0x", "") + .Replace("h", "") + .Replace(";", "") + .Replace(",", "") + .Replace("-", "") + .Replace(" ", "") + .Trim(); + + if (hexString.Length % 2 != 0) + { + return false; + } + + var length = hexString.Length; + bytes = new Byte[length / 2]; + + for (Int32 c = 0, b = 0; c < length; c += 2, b++) + { + if (TryParseChar(hexString[c], out var b1) && TryParseChar(hexString[c + 1], out var b2)) + { + bytes[b] = (Byte)(b1 * 16 + b2); + } + else + { + bytes = null; + + break; + } + } + + return bytes != null; + } + + public static Boolean TryParseChar(Char _char, out Byte _byte) + { + _byte = 0; + + if ('0' <= _char && _char <= '9') + { + _byte = (Byte)(_char - '0'); + } + else if ('a' <= _char && _char <= 'f') + { + _byte = (Byte)(16 - ('f' - _char) - 1); + } + else if ('A' <= _char && _char <= 'F') + { + _byte = (Byte)(16 - ('F' - _char) - 1); + } + else + { + return false; + } + + return true; + } + } +} diff --git a/Common/Ui/Common.UI.WPFConnector/app.config b/Common/Ui/Common.UI.WPFConnector/app.config new file mode 100644 index 00000000..49cc43e1 --- /dev/null +++ b/Common/Ui/Common.UI.WPFConnector/app.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Common/Ui/GenesisToolBox/GenesisToolBox.csproj b/Common/Ui/GenesisToolBox/GenesisToolBox.csproj index 371c288c..7ce6dadf 100644 --- a/Common/Ui/GenesisToolBox/GenesisToolBox.csproj +++ b/Common/Ui/GenesisToolBox/GenesisToolBox.csproj @@ -13,9 +13,8 @@ 512 true - false - C:\Users\SZLATEV\Desktop\GenesisToolBox\ - false + publish\ + true Disk false Foreground @@ -24,10 +23,10 @@ false false true - 5 + 0 1.0.0.%2a + false false - true true @@ -81,12 +80,6 @@ false true - - 14673934DFE995F28E9579F4A18DBDA05F7C1AFE - - - GenesisToolBox_TemporaryKey.pfx - true @@ -107,9 +100,7 @@ LocalIntranet - - Properties\app.manifest - + true bin\x64\Debug\ @@ -158,6 +149,9 @@ false true + + Properties\app.manifest + @@ -617,13 +611,12 @@ status.json Always + - PreserveNewest - @@ -783,9 +776,9 @@ - + False - Microsoft .NET Framework 4 %28x86 and x64%29 + Microsoft .NET Framework 4.8 %28x86 and x64%29 true @@ -793,13 +786,7 @@ .NET Framework 3.5 SP1 false - - False - Windows Installer 4.5 - true - - + + + + + + + + + + + + + - \ No newline at end of file + + diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs index 1cc8b332..e5673afc 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs @@ -114,30 +114,30 @@ public EOLProgressModel Read(EOLProgressModel model) => this.sqlConnection .CreateCommand($@" - SELECT [Id] - , [PcbId] - , [StartDate] - , [StandardRequirementId] - , [StandardRequirementV] - , [SpecialRequirementId] - , [SpecialRequirementV] - , [RequirementChecked] - , [ProductionStatusChecked] - , [ParameterizationDone] - , [StoreConfigurationDone] - , [RebootDone] - , [ParameterizationChecked] - , [RaioCheckId] - , [PasswordFileInstalled] - , [AttachmentsChecked] - , [EOLCompleted] - , [EOLCompleteDate] - , [EOLSoftwareNameAndVersion] - , [SAPExportDone] - , [SentinelCompleted] - , [SentinelCompletedDate] - FROM [Cordonel_EOL_Progress] - WHERE [PcbId] = @{nameof(model.PcbId)}") + SELECT Id + , PcbId + , StartDate + , StandardRequirementId + , StandardRequirementV + , SpecialRequirementId + , SpecialRequirementV + , RequirementChecked + , ProductionStatusChecked + , ParameterizationDone + , StoreConfigurationDone + , RebootDone + , ParameterizationChecked + , RaioCheckId + , PasswordFileInstalled + , AttachmentsChecked + , EOLCompleted + , EOLCompleteDate + , EOLSoftwareNameAndVersion + , SAPExportDone + , SentinelCompleted + , SentinelCompletedDate + FROM Cordonel_EOL_Progress + WHERE PcbId = @{nameof(model.PcbId)}") .SetParameter(nameof(model.PcbId), model.PcbId) .FirstOrDefault(reader => new EOLProgressModel { @@ -169,24 +169,24 @@ { this.sqlConnection .CreateCommand($@" - UPDATE [dbo].[Cordonel_EOL_Progress] - SET [StandardRequirementId] = ISNULL([StandardRequirementId], @{nameof(model.StandardRequirementId)}) - , [StandardRequirementV] = ISNULL([StandardRequirementV], @{nameof(model.StandardRequirementVersion)}) - , [SpecialRequirementId] = ISNULL([SpecialRequirementId], @{nameof(model.SpecialRequirementId)}) - , [SpecialRequirementV] = ISNULL([SpecialRequirementV], @{nameof(model.SpecialRequirementVersion)}) - , [RequirementChecked] = ISNULL([RequirementChecked], @{nameof(model.RequirementChecked)}) - , [ProductionStatusChecked] = ISNULL([ProductionStatusChecked], @{nameof(model.ProductionStatusChecked)}) - , [ParameterizationDone] = ISNULL([ParameterizationDone], @{nameof(model.ParameterizationDone)}) - , [StoreConfigurationDone] = ISNULL([StoreConfigurationDone], @{nameof(model.StoreConfigurationDone)}) - , [RebootDone] = ISNULL([RebootDone], @{nameof(model.RebootDone)}) - , [ParameterizationChecked] = ISNULL([ParameterizationChecked], @{nameof(model.ParameterizationChecked)}) - , [RaioCheckId] = ISNULL([RaioCheckId], @{nameof(model.RaioCheckId)}) - , [PasswordFileInstalled] = ISNULL([PasswordFileInstalled], @{nameof(model.PasswordFileInstalled)}) - , [AttachmentsChecked] = ISNULL([AttachmentsChecked], @{nameof(model.AttachmentsChecked)}) - , [EOLSoftwareNameAndVersion] = ISNULL([EOLSoftwareNameAndVersion], @{nameof(model.EOLSoftwareNameAndVersion)}) - , [SAPExportDone] = ISNULL([SAPExportDone], @{nameof(model.SAPExportDone)}) - WHERE [PcbId] = @{nameof(model.PcbId)} - AND [EOLCompleted] IS NULL") + UPDATE Cordonel_EOL_Progress + SET StandardRequirementId = ISNULL(StandardRequirementId, @{nameof(model.StandardRequirementId)}) + , StandardRequirementV = ISNULL(StandardRequirementV, @{nameof(model.StandardRequirementVersion)}) + , SpecialRequirementId = ISNULL(SpecialRequirementId, @{nameof(model.SpecialRequirementId)}) + , SpecialRequirementV = ISNULL(SpecialRequirementV, @{nameof(model.SpecialRequirementVersion)}) + , RequirementChecked = ISNULL(RequirementChecked, @{nameof(model.RequirementChecked)}) + , ProductionStatusChecked = ISNULL(ProductionStatusChecked, @{nameof(model.ProductionStatusChecked)}) + , ParameterizationDone = ISNULL(ParameterizationDone, @{nameof(model.ParameterizationDone)}) + , StoreConfigurationDone = ISNULL(StoreConfigurationDone, @{nameof(model.StoreConfigurationDone)}) + , RebootDone = ISNULL(RebootDone, @{nameof(model.RebootDone)}) + , ParameterizationChecked = ISNULL(ParameterizationChecked, @{nameof(model.ParameterizationChecked)}) + , RaioCheckId = ISNULL(RaioCheckId, @{nameof(model.RaioCheckId)}) + , PasswordFileInstalled = ISNULL(PasswordFileInstalled, @{nameof(model.PasswordFileInstalled)}) + , AttachmentsChecked = ISNULL(AttachmentsChecked, @{nameof(model.AttachmentsChecked)}) + , EOLSoftwareNameAndVersion = ISNULL(EOLSoftwareNameAndVersion, @{nameof(model.EOLSoftwareNameAndVersion)}) + , SAPExportDone = ISNULL(SAPExportDone, @{nameof(model.SAPExportDone)}) + WHERE PcbId = @{nameof(model.PcbId)} + AND EOLCompleted IS NULL") .SetParameter(nameof(model.PcbId), model.PcbId) .SetParameter(nameof(model.StandardRequirementId), model.StandardRequirementId) .SetParameter(nameof(model.StandardRequirementVersion), model.StandardRequirementVersion) diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs index f92e512b..1ca437a7 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs @@ -13,6 +13,8 @@ using System.Linq; using System.Net; using System.Web.Mvc; + using Hash256 = System.Security.Cryptography.SHA256; + using System.Text; public class SearchController : Controller { @@ -220,5 +222,80 @@ return result.Trim('"'); } + + [HttpGet] + public String SHA256(String value) + { + if (String.IsNullOrWhiteSpace(value)) + { + return String.Empty; + } + + value = value + .Replace("0x", "") + .Replace("h", "") + .Replace(";", "") + .Replace(",", "") + .Replace("-", "") + .Replace(" ", "") + .Trim(); + + if (value.Length % 2 != 0) + { + return String.Empty; + } + + Boolean TryParse(Char _char, out Int32 _byte) + { + _byte = 0; + + if ('0' <= _char && _char <= '9') + { + _byte = _char - '0'; + } + else if ('A' <= _char && _char <= 'F') + { + _byte = 16 - ('F' - _char) - 1; + } + else + { + return false; + } + + return true; + } + + var length = value.Length; + var bytes = new Byte[length / 2]; + + for (Int32 c = 0, b = 0; c < length; c += 2, b++) + { + if (TryParse(value[c], out var b1) && TryParse(value[c + 1], out var b2)) + { + bytes[b] = (Byte)(b1 * 16 + b2); + } + else + { + bytes = null; + + break; + } + } + + if (bytes is null) + { + return String.Empty; + } + + var hash = String.Empty; + + if (!String.IsNullOrWhiteSpace(value)) + { + var hashBytes = Hash256.Create().ComputeHash(bytes); + hash = BitConverter.ToString(hashBytes); + } + + return hash; + } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Hubs/RemoteControl.cs b/LaaProductionWeb/LaaProductionWeb/Hubs/RemoteControl.cs index 8123f323..901b78c3 100644 --- a/LaaProductionWeb/LaaProductionWeb/Hubs/RemoteControl.cs +++ b/LaaProductionWeb/LaaProductionWeb/Hubs/RemoteControl.cs @@ -39,53 +39,39 @@ public override async Task OnReconnected() => await this.Groups.Add(this.ConnectionId, this.GroupName); - public void StartFlow(FlowMessage message) - { - this.Clients + public void StartFlow(FlowMessage message) + => this.Clients .OthersInGroup(this.GroupName) .StartFlow(message); - } - public void GetFlow(FlowMessage message) - { - this.Clients + public void GetFlow(FlowMessage message) + => this.Clients .OthersInGroup(this.GroupName) .GetFlow(message); - } - public void StopFlow(FlowMessage message) - { - this.Clients + public void StopFlow(FlowMessage message) + => this.Clients .OthersInGroup(this.GroupName) .StopFlow(message); - } - public void StartRM(ReferenceMessage message) - { - this.Clients + public void StartRM(ReferenceMessage message) + => this.Clients .OthersInGroup(this.GroupName) .StartRM(message); - } - public void GetRM(ReferenceMessage message) - { - this.Clients + public void GetRM(ReferenceMessage message) + => this.Clients .OthersInGroup(this.GroupName) .GetRM(message); - } - public void StopRM(ReferenceMessage message) - { - this.Clients + public void StopRM(ReferenceMessage message) + => this.Clients .OthersInGroup(this.GroupName) .StopRM(message); - } - public void GetInfo(InfoMessage message) - { - this.Clients + public void GetInfo(InfoMessage message) + => this.Clients .OthersInGroup(this.GroupName) .GetInfo(message); - } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml index 1472a5bb..b01dc71f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml @@ -92,7 +92,7 @@