From f1b8f88a80cf8d6aca8877e16b79db8dbf58e5b1 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 21 Nov 2023 17:03:26 +0100 Subject: [PATCH 01/22] add B4R2 --- .../InterfaceSpecificationSciCc.cs | 6 + .../InterfaceSpecificationSciGeneric.cs | 2535 +++++++++++++++++ .../InterfaceSpecificationSciIls.cs | 872 ++++++ .../InterfaceSpecificationSciIo.cs | 6 + .../InterfaceSpecificationSciLc.cs | 31 + .../InterfaceSpecificationSciLs.cs | 71 + .../InterfaceSpecificationSciLx.cs | 31 + .../Baseline4R2/InterfaceSpecificationSciP.cs | 139 + .../InterfaceSpecificationSciRbc.cs | 6 + .../InterfaceSpecificationSciTds.cs | 311 ++ src/Messages/Baseline4R2/Message.cs | 178 ++ 11 files changed, 4186 insertions(+) create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs create mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs create mode 100644 src/Messages/Baseline4R2/Message.cs diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs new file mode 100644 index 0000000..088e721 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs @@ -0,0 +1,6 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs new file mode 100644 index 0000000..df2e861 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs @@ -0,0 +1,2535 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record AdjacentInterlockingSystemPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static AdjacentInterlockingSystemPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new AdjacentInterlockingSystemPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record TrainDetectionSystemPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static TrainDetectionSystemPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new TrainDetectionSystemPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record LightSignalPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static LightSignalPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new LightSignalPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record PointPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static PointPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new PointPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record RadioBlockCenterPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static RadioBlockCenterPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new RadioBlockCenterPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record LevelCrossingPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static LevelCrossingPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new LevelCrossingPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record CCPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static CCPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new CCPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record GenericIOPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static GenericIOPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new GenericIOPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + +public record ExternalLevelCrossingSystemPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int PdiVersionOfSenderOffset = 43; + public static readonly ushort MessageType = 0x0024; + + public new static ExternalLevelCrossingSystemPdiVersionCheckCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; + return new ExternalLevelCrossingSystemPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; + return result; + } +} + + + + +public record AdjacentInterlockingSystemInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static AdjacentInterlockingSystemInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static TrainDetectionSystemInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static LightSignalInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static PointInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static RadioBlockCenterInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static LevelCrossingInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static CCInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static GenericIOInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0021; + + public new static ExternalLevelCrossingSystemInitialisationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static AdjacentInterlockingSystemStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static TrainDetectionSystemStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static LightSignalStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static PointStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static RadioBlockCenterStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static LevelCrossingStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static CCStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static GenericIOStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0022; + + public new static ExternalLevelCrossingSystemStartInitialisationMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static AdjacentInterlockingSystemStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static TrainDetectionSystemStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static LightSignalStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static PointStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static RadioBlockCenterStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static LevelCrossingStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static CCStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static GenericIOStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0026; + + public new static ExternalLevelCrossingSystemStatusReportCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static AdjacentInterlockingSystemInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static TrainDetectionSystemInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static LightSignalInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static PointInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static RadioBlockCenterInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static LevelCrossingInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static CCInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static GenericIOInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0023; + + public new static ExternalLevelCrossingSystemInitialisationCompletedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, AdjacentInterlockingSystemClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static AdjacentInterlockingSystemClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (AdjacentInterlockingSystemClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new AdjacentInterlockingSystemClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum AdjacentInterlockingSystemClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record TrainDetectionSystemClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static TrainDetectionSystemClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (TrainDetectionSystemClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new TrainDetectionSystemClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum TrainDetectionSystemClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record LightSignalClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, LightSignalClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static LightSignalClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (LightSignalClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new LightSignalClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum LightSignalClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record PointClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, PointClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static PointClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (PointClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new PointClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum PointClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record RadioBlockCenterClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, RadioBlockCenterClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static RadioBlockCenterClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (RadioBlockCenterClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new RadioBlockCenterClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum RadioBlockCenterClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record LevelCrossingClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, LevelCrossingClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static LevelCrossingClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (LevelCrossingClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new LevelCrossingClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum LevelCrossingClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record CCClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, CCClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static CCClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (CCClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new CCClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum CCClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record GenericIOClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, GenericIOClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static GenericIOClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (GenericIOClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new GenericIOClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum GenericIOClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record ExternalLevelCrossingSystemClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, ExternalLevelCrossingSystemClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CloseReasonOffset = 43; + public static readonly ushort MessageType = 0x0027; + + public new static ExternalLevelCrossingSystemClosePdiCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CloseReason = (ExternalLevelCrossingSystemClosePdiCommandCloseReason)message[CloseReasonOffset]; + return new ExternalLevelCrossingSystemClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CloseReasonOffset] = (byte)CloseReason; + return result; + } +} + +public enum ExternalLevelCrossingSystemClosePdiCommandCloseReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03, + NormalClose = 0x04, + OtherVersionRequired = 0x05, + Timeout = 0x06, + ChecksumMismatch = 0x07 +} + +public record AdjacentInterlockingSystemReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static AdjacentInterlockingSystemReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static TrainDetectionSystemReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static LightSignalReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static PointReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static RadioBlockCenterReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static LevelCrossingReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static CCReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static GenericIOReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0028; + + public new static ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static AdjacentInterlockingSystemPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static TrainDetectionSystemPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static LightSignalPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static PointPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static RadioBlockCenterPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static LevelCrossingPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static CCPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static GenericIOPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0029; + + public new static ExternalLevelCrossingSystemPdiAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static AdjacentInterlockingSystemPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new AdjacentInterlockingSystemPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static TrainDetectionSystemPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LightSignalPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static LightSignalPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LightSignalPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static PointPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record RadioBlockCenterPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static RadioBlockCenterPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new RadioBlockCenterPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record LevelCrossingPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static LevelCrossingPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record CCPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static CCPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new CCPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record GenericIOPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static GenericIOPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new GenericIOPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record ExternalLevelCrossingSystemPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x002A; + + public new static ExternalLevelCrossingSystemPdiNotAvailableMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, AdjacentInterlockingSystemResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static AdjacentInterlockingSystemResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (AdjacentInterlockingSystemResetPdiMessageResetReason)message[ResetReasonOffset]; + return new AdjacentInterlockingSystemResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum AdjacentInterlockingSystemResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record TrainDetectionSystemResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static TrainDetectionSystemResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (TrainDetectionSystemResetPdiMessageResetReason)message[ResetReasonOffset]; + return new TrainDetectionSystemResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum TrainDetectionSystemResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record LightSignalResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, LightSignalResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static LightSignalResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (LightSignalResetPdiMessageResetReason)message[ResetReasonOffset]; + return new LightSignalResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum LightSignalResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record PointResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, PointResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static PointResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (PointResetPdiMessageResetReason)message[ResetReasonOffset]; + return new PointResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum PointResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record RadioBlockCenterResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, RadioBlockCenterResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static RadioBlockCenterResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (RadioBlockCenterResetPdiMessageResetReason)message[ResetReasonOffset]; + return new RadioBlockCenterResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.RadioBlockCenter; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum RadioBlockCenterResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record LevelCrossingResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, LevelCrossingResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static LevelCrossingResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (LevelCrossingResetPdiMessageResetReason)message[ResetReasonOffset]; + return new LevelCrossingResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum LevelCrossingResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record CCResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, CCResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static CCResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (CCResetPdiMessageResetReason)message[ResetReasonOffset]; + return new CCResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.CC; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum CCResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record GenericIOResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, GenericIOResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static GenericIOResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (GenericIOResetPdiMessageResetReason)message[ResetReasonOffset]; + return new GenericIOResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.GenericIO; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum GenericIOResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} + +public record ExternalLevelCrossingSystemResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, ExternalLevelCrossingSystemResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ResetReasonOffset = 43; + public static readonly ushort MessageType = 0x002B; + + public new static ExternalLevelCrossingSystemResetPdiMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ResetReason = (ExternalLevelCrossingSystemResetPdiMessageResetReason)message[ResetReasonOffset]; + return new ExternalLevelCrossingSystemResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ResetReasonOffset] = (byte)ResetReason; + return result; + } +} + +public enum ExternalLevelCrossingSystemResetPdiMessageResetReason : byte { + ProtocolError = 0x01, + FormalTelegramError = 0x02, + ContentTelegramError = 0x03 +} diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs new file mode 100644 index 0000000..af08c20 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs @@ -0,0 +1,872 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record AdjacentInterlockingSystemActivationZoneStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string ActivationZoneId, AdjacentInterlockingSystemActivationZoneStatusMessageActivationZoneStatus ActivationZoneStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int ActivationZoneIdOffset = 63; + private const int ActivationZoneStatusOffset = 83; + public static readonly ushort MessageType = 0x0001; + + public new static AdjacentInterlockingSystemActivationZoneStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var ActivationZoneId = Encoding.Latin1.GetString(message, ActivationZoneIdOffset, 20); + var ActivationZoneStatus = (AdjacentInterlockingSystemActivationZoneStatusMessageActivationZoneStatus)message[ActivationZoneStatusOffset]; + return new AdjacentInterlockingSystemActivationZoneStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, ActivationZoneId, ActivationZoneStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[84]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(ActivationZoneId.PadRight(20, '_')).CopyTo(result, ActivationZoneIdOffset); + result[ActivationZoneStatusOffset] = (byte)ActivationZoneStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemActivationZoneStatusMessageActivationZoneStatus : byte { + Active = 0x01, + NotActive = 0x02 +} + +public record AdjacentInterlockingSystemApproachZoneStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string ApproachZoneId, AdjacentInterlockingSystemApproachZoneStatusMessageApproachZoneStatus ApproachZoneStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int ApproachZoneIdOffset = 63; + private const int ApproachZoneStatusOffset = 83; + public static readonly ushort MessageType = 0x0002; + + public new static AdjacentInterlockingSystemApproachZoneStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var ApproachZoneId = Encoding.Latin1.GetString(message, ApproachZoneIdOffset, 20); + var ApproachZoneStatus = (AdjacentInterlockingSystemApproachZoneStatusMessageApproachZoneStatus)message[ApproachZoneStatusOffset]; + return new AdjacentInterlockingSystemApproachZoneStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, ApproachZoneId, ApproachZoneStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[84]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(ApproachZoneId.PadRight(20, '_')).CopyTo(result, ApproachZoneIdOffset); + result[ApproachZoneStatusOffset] = (byte)ApproachZoneStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemApproachZoneStatusMessageApproachZoneStatus : byte { + Active = 0x01, + NotActive = 0x02 +} + +public record AdjacentInterlockingSystemAccessRestrictionRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemAccessRestrictionRequestCommandAccessRestrictionType AccessRestrictionType) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int AccessRestrictionTypeOffset = 63; + public static readonly ushort MessageType = 0x0003; + + public new static AdjacentInterlockingSystemAccessRestrictionRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var AccessRestrictionType = (AdjacentInterlockingSystemAccessRestrictionRequestCommandAccessRestrictionType)message[AccessRestrictionTypeOffset]; + return new AdjacentInterlockingSystemAccessRestrictionRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, AccessRestrictionType); + } + + public override byte[] ToByteArray() { + var result = new byte[64]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[AccessRestrictionTypeOffset] = (byte)AccessRestrictionType; + return result; + } +} + +public enum AdjacentInterlockingSystemAccessRestrictionRequestCommandAccessRestrictionType : byte { + NoAccess = 0x01, + WorkTrack = 0x02, + TrackOutOfService = 0x03, + EmergencyTrain = 0x04, + SecondaryVehicle = 0x05, + WorkTeam = 0x06, + LevelCrossingInDegradedOperation = 0x07, + ClearanceCheckRequired = 0x08, + SectionCheckRequired = 0x09, + NoElectricTrains = 0x10, + ExtraordinaryTransport = 0x11, + CatenaryOffPantographDown = 0x12, + WrittenOrderRequired = 0x13, + AccessRestrictionTypeNotApplicable = 0xFF +} + +public record AdjacentInterlockingSystemAccessRestrictionStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionActivationStatus AccessRestrictionActivationStatus, AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionType AccessRestrictionType) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int AccessRestrictionActivationStatusOffset = 63; + private const int AccessRestrictionTypeOffset = 64; + public static readonly ushort MessageType = 0x0012; + + public new static AdjacentInterlockingSystemAccessRestrictionStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var AccessRestrictionActivationStatus = (AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionActivationStatus)message[AccessRestrictionActivationStatusOffset]; + var AccessRestrictionType = (AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionType)message[AccessRestrictionTypeOffset]; + return new AdjacentInterlockingSystemAccessRestrictionStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, AccessRestrictionActivationStatus, AccessRestrictionType); + } + + public override byte[] ToByteArray() { + var result = new byte[65]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[AccessRestrictionActivationStatusOffset] = (byte)AccessRestrictionActivationStatus; + result[AccessRestrictionTypeOffset] = (byte)AccessRestrictionType; + return result; + } +} + +public enum AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionActivationStatus : byte { + Active = 0x01, + NotActive = 0x02 +} + +public enum AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionType : byte { + NoAccess = 0x01, + WorkTrack = 0x02, + TrackOutOfService = 0x03, + EmergencyTrain = 0x04, + SecondaryVehicle = 0x05, + WorkTeam = 0x06, + LevelCrossingInDegradedOperation = 0x07, + ClearanceCheckRequired = 0x08, + SectionCheckRequired = 0x09, + NoElectricTrains = 0x10, + ExtraordinaryTransport = 0x11, + CatenaryOffPantographDown = 0x12, + WrittenOrderRequired = 0x13, + ManualRouteCondition = 0x14, + DoNotUseOppositeDirection = 0x15, + UseOppositeDirection = 0x16, + NoLxRemoteSupervision = 0x17, + LxRemoteSupervisionTimeout = 0x18, + AccessRestrictionTypeNotApplicable = 0xFF +} + +public record AdjacentInterlockingSystemLineStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemLineStatusMessageLineStatus LineStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int LineStatusOffset = 63; + public static readonly ushort MessageType = 0x0004; + + public new static AdjacentInterlockingSystemLineStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var LineStatus = (AdjacentInterlockingSystemLineStatusMessageLineStatus)message[LineStatusOffset]; + return new AdjacentInterlockingSystemLineStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, LineStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[64]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[LineStatusOffset] = (byte)LineStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemLineStatusMessageLineStatus : byte { + Vacant = 0x01, + Occupied = 0x02, + RequestForLineBlockReset = 0x03 +} + +public record AdjacentInterlockingSystemFlankProtectionRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemFlankProtectionRequestCommandFlankProtectionRequestType FlankProtectionRequestType) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int FlankProtectionRequestTypeOffset = 63; + public static readonly ushort MessageType = 0x0005; + + public new static AdjacentInterlockingSystemFlankProtectionRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var FlankProtectionRequestType = (AdjacentInterlockingSystemFlankProtectionRequestCommandFlankProtectionRequestType)message[FlankProtectionRequestTypeOffset]; + return new AdjacentInterlockingSystemFlankProtectionRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, FlankProtectionRequestType); + } + + public override byte[] ToByteArray() { + var result = new byte[64]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[FlankProtectionRequestTypeOffset] = (byte)FlankProtectionRequestType; + return result; + } +} + +public enum AdjacentInterlockingSystemFlankProtectionRequestCommandFlankProtectionRequestType : byte { + Provision = 0x01, + Cancellation = 0x02 +} + +public record AdjacentInterlockingSystemFlankProtectionStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemFlankProtectionStatusMessageFlankProtectionStatus FlankProtectionStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int FlankProtectionStatusOffset = 63; + public static readonly ushort MessageType = 0x0013; + + public new static AdjacentInterlockingSystemFlankProtectionStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var FlankProtectionStatus = (AdjacentInterlockingSystemFlankProtectionStatusMessageFlankProtectionStatus)message[FlankProtectionStatusOffset]; + return new AdjacentInterlockingSystemFlankProtectionStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, FlankProtectionStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[64]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[FlankProtectionStatusOffset] = (byte)FlankProtectionStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemFlankProtectionStatusMessageFlankProtectionStatus : byte { + Provided = 0x01, + NotProvided = 0x02 +} + +public record AdjacentInterlockingSystemRouteRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRouteRequestCommandRouteType RouteType) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + private const int RouteTypeOffset = 83; + public static readonly ushort MessageType = 0x0007; + + public new static AdjacentInterlockingSystemRouteRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + var RouteType = (AdjacentInterlockingSystemRouteRequestCommandRouteType)message[RouteTypeOffset]; + return new AdjacentInterlockingSystemRouteRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType); + } + + public override byte[] ToByteArray() { + var result = new byte[84]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + result[RouteTypeOffset] = (byte)RouteType; + return result; + } +} + +public enum AdjacentInterlockingSystemRouteRequestCommandRouteType : byte { + MainRoute = 0x01, + ShuntingRoute = 0x02, + OnSightRoute = 0x03, + SrTrainRoute = 0x04, + SpecialTrainRoute = 0x05, + TemporaryShuntingArea = 0x06 +} + +public record AdjacentInterlockingSystemRouteStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRouteStatusMessageRouteType RouteType, AdjacentInterlockingSystemRouteStatusMessageRouteStatus RouteStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + private const int RouteTypeOffset = 83; + private const int RouteStatusOffset = 84; + public static readonly ushort MessageType = 0x0008; + + public new static AdjacentInterlockingSystemRouteStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + var RouteType = (AdjacentInterlockingSystemRouteStatusMessageRouteType)message[RouteTypeOffset]; + var RouteStatus = (AdjacentInterlockingSystemRouteStatusMessageRouteStatus)message[RouteStatusOffset]; + return new AdjacentInterlockingSystemRouteStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType, RouteStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[85]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + result[RouteTypeOffset] = (byte)RouteType; + result[RouteStatusOffset] = (byte)RouteStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemRouteStatusMessageRouteType : byte { + MainRoute = 0x01, + ShuntingRoute = 0x02, + OnSightRoute = 0x03, + SrTrainRoute = 0x04, + SpecialTrainRoute = 0x05, + TemporaryShuntingArea = 0x06 +} + +public enum AdjacentInterlockingSystemRouteStatusMessageRouteStatus : byte { + Initiated = 0x01, + Locked = 0x02, + NoRoute = 0x03, + Cancelling = 0x04 +} + +public record AdjacentInterlockingSystemRouteMonitoringStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteType RouteType, string OverlapId, AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteMonitoring RouteMonitoring, AdjacentInterlockingSystemRouteMonitoringStatusMessageOccupancyMonitoring OccupancyMonitoring, AdjacentInterlockingSystemRouteMonitoringStatusMessageLevelCrossingMonitoring LevelCrossingMonitoring, byte EntranceSpeed, byte TargetSpeed, AdjacentInterlockingSystemRouteMonitoringStatusMessageDynamicOrStaticTargetSpeed DynamicOrStaticTargetSpeed) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + private const int RouteTypeOffset = 83; + private const int OverlapIdOffset = 84; + private const int RouteMonitoringOffset = 104; + private const int OccupancyMonitoringOffset = 105; + private const int LevelCrossingMonitoringOffset = 106; + private const int EntranceSpeedOffset = 107; + private const int TargetSpeedOffset = 108; + private const int DynamicOrStaticTargetSpeedOffset = 109; + public static readonly ushort MessageType = 0x0009; + + public new static AdjacentInterlockingSystemRouteMonitoringStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + var RouteType = (AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteType)message[RouteTypeOffset]; + var OverlapId = Encoding.Latin1.GetString(message, OverlapIdOffset, 20); + var RouteMonitoring = (AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteMonitoring)message[RouteMonitoringOffset]; + var OccupancyMonitoring = (AdjacentInterlockingSystemRouteMonitoringStatusMessageOccupancyMonitoring)message[OccupancyMonitoringOffset]; + var LevelCrossingMonitoring = (AdjacentInterlockingSystemRouteMonitoringStatusMessageLevelCrossingMonitoring)message[LevelCrossingMonitoringOffset]; + var EntranceSpeed = (byte)message[EntranceSpeedOffset]; + var TargetSpeed = (byte)message[TargetSpeedOffset]; + var DynamicOrStaticTargetSpeed = (AdjacentInterlockingSystemRouteMonitoringStatusMessageDynamicOrStaticTargetSpeed)message[DynamicOrStaticTargetSpeedOffset]; + return new AdjacentInterlockingSystemRouteMonitoringStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType, OverlapId, RouteMonitoring, OccupancyMonitoring, LevelCrossingMonitoring, EntranceSpeed, TargetSpeed, DynamicOrStaticTargetSpeed); + } + + public override byte[] ToByteArray() { + var result = new byte[110]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + result[RouteTypeOffset] = (byte)RouteType; + Encoding.Latin1.GetBytes(OverlapId.PadRight(20, '_')).CopyTo(result, OverlapIdOffset); + result[RouteMonitoringOffset] = (byte)RouteMonitoring; + result[OccupancyMonitoringOffset] = (byte)OccupancyMonitoring; + result[LevelCrossingMonitoringOffset] = (byte)LevelCrossingMonitoring; + result[EntranceSpeedOffset] = (byte)EntranceSpeed; + result[TargetSpeedOffset] = (byte)TargetSpeed; + result[DynamicOrStaticTargetSpeedOffset] = (byte)DynamicOrStaticTargetSpeed; + return result; + } +} + +public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteType : byte { + MainRoute = 0x01, + ShuntingRoute = 0x02, + OnSightRoute = 0x03, + SrTrainRoute = 0x04, + SpecialTrainRoute = 0x05, + TemporaryShuntingArea = 0x06 +} + +public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteMonitoring : byte { + RouteMonitoringConditionsOfSecondaryRoutePresent = 0x01, + RouteMonitoringConditionsOfSecondaryRouteNotPresent = 0x02, + RouteMonitoringConditionsOfSecondaryRoutePresentUpToNextBlockIndicator = 0x03, + ShuntingRouteMonitoringConditionsOfSecondaryRoutePresent = 0x04 +} + +public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageOccupancyMonitoring : byte { + Occupation = 0x01, + NoOccupation = 0x02, + OccupancyMonitoringNotApplicable = 0xFF +} + +public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageLevelCrossingMonitoring : byte { + LevelCrossingMonitoringConditionsOfSecondaryRoutePresent = 0x01, + LevelCrossingMonitoringConditionsOfSecondaryRouteNotPresent = 0x02, + LevelCrossingMonitoringConditionsPresentUpToNextBlockIndicator = 0x03, + LevelCrossingMonitoringNotApplicable = 0xFF +} + +public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageDynamicOrStaticTargetSpeed : byte { + Dynamic = 0x01, + Static = 0x02, + DynamicOrStaticTargetSpeedNotApplicable = 0xFF +} + +public record AdjacentInterlockingSystemRouteCancellationRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + public static readonly ushort MessageType = 0x000A; + + public new static AdjacentInterlockingSystemRouteCancellationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + return new AdjacentInterlockingSystemRouteCancellationRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId); + } + + public override byte[] ToByteArray() { + var result = new byte[83]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessageTrainOperatedRouteReleaseStatus TrainOperatedRouteReleaseStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int TrainOperatedRouteReleaseStatusOffset = 63; + public static readonly ushort MessageType = 0x000B; + + public new static AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var TrainOperatedRouteReleaseStatus = (AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessageTrainOperatedRouteReleaseStatus)message[TrainOperatedRouteReleaseStatusOffset]; + return new AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, TrainOperatedRouteReleaseStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[64]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[TrainOperatedRouteReleaseStatusOffset] = (byte)TrainOperatedRouteReleaseStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessageTrainOperatedRouteReleaseStatus : byte { + TvpsAdjacentToTheBoundaryIsInACorrectOccupancySequence = 0x01, + TvpsAdjacentToTheBoundaryIsReleasedByTrain = 0x02, + TvpsAdjacentToTheBoundaryIsNotInACorrectOccupancySequenceAndNotReleasedByTrain = 0x03 +} + +public record AdjacentInterlockingSystemSignalStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, byte AspectLampCombinations, byte AspectExtensionLampCombinations, byte SpeedIndicator, byte SpeedIndicatorAnnouncement, byte DirectionIndicator, byte DirectionIndicatorAnnouncement, AdjacentInterlockingSystemSignalStatusMessageIntentionallyDark IntentionallyDark) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int AspectLampCombinationsOffset = 63; + private const int AspectExtensionLampCombinationsOffset = 64; + private const int SpeedIndicatorOffset = 65; + private const int SpeedIndicatorAnnouncementOffset = 66; + private const int DirectionIndicatorOffset = 67; + private const int DirectionIndicatorAnnouncementOffset = 68; + private const int IntentionallyDarkOffset = 69; + public static readonly ushort MessageType = 0x000C; + + public new static AdjacentInterlockingSystemSignalStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var AspectLampCombinations = (byte)message[AspectLampCombinationsOffset]; + var AspectExtensionLampCombinations = (byte)message[AspectExtensionLampCombinationsOffset]; + var SpeedIndicator = (byte)message[SpeedIndicatorOffset]; + var SpeedIndicatorAnnouncement = (byte)message[SpeedIndicatorAnnouncementOffset]; + var DirectionIndicator = (byte)message[DirectionIndicatorOffset]; + var DirectionIndicatorAnnouncement = (byte)message[DirectionIndicatorAnnouncementOffset]; + var IntentionallyDark = (AdjacentInterlockingSystemSignalStatusMessageIntentionallyDark)message[IntentionallyDarkOffset]; + return new AdjacentInterlockingSystemSignalStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, AspectLampCombinations, AspectExtensionLampCombinations, SpeedIndicator, SpeedIndicatorAnnouncement, DirectionIndicator, DirectionIndicatorAnnouncement, IntentionallyDark); + } + + public override byte[] ToByteArray() { + var result = new byte[70]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[AspectLampCombinationsOffset] = (byte)AspectLampCombinations; + result[AspectExtensionLampCombinationsOffset] = (byte)AspectExtensionLampCombinations; + result[SpeedIndicatorOffset] = (byte)SpeedIndicator; + result[SpeedIndicatorAnnouncementOffset] = (byte)SpeedIndicatorAnnouncement; + result[DirectionIndicatorOffset] = (byte)DirectionIndicator; + result[DirectionIndicatorAnnouncementOffset] = (byte)DirectionIndicatorAnnouncement; + result[IntentionallyDarkOffset] = (byte)IntentionallyDark; + return result; + } +} + +public enum AdjacentInterlockingSystemSignalStatusMessageIntentionallyDark : byte { + TheCommandedSignalAspectIsIndicatedInTheSetLuminosity = 0x01, + TheCommandedSignalAspectIsIndicatedDark = 0x0F, + IntentionallyDarkNotApplicable = 0xFF +} + +public record AdjacentInterlockingSystemTvpsStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemTvpsStatusMessageOccupancyStatus OccupancyStatus, AdjacentInterlockingSystemTvpsStatusMessageFoulingStatus FoulingStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int OccupancyStatusOffset = 63; + private const int FoulingStatusOffset = 64; + public static readonly ushort MessageType = 0x000D; + + public new static AdjacentInterlockingSystemTvpsStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var OccupancyStatus = (AdjacentInterlockingSystemTvpsStatusMessageOccupancyStatus)message[OccupancyStatusOffset]; + var FoulingStatus = (AdjacentInterlockingSystemTvpsStatusMessageFoulingStatus)message[FoulingStatusOffset]; + return new AdjacentInterlockingSystemTvpsStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, OccupancyStatus, FoulingStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[65]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[OccupancyStatusOffset] = (byte)OccupancyStatus; + result[FoulingStatusOffset] = (byte)FoulingStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemTvpsStatusMessageOccupancyStatus : byte { + Vacant = 0x01, + Occupied = 0x02, + Disturbed = 0x03 +} + +public enum AdjacentInterlockingSystemTvpsStatusMessageFoulingStatus : byte { + Fouling = 0x01, + NotFouling = 0x02, + FoulingStatusNotApplicable = 0xFF +} + +public record AdjacentInterlockingSystemOppositeMainSignalStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + public static readonly ushort MessageType = 0x000E; + + public new static AdjacentInterlockingSystemOppositeMainSignalStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + return new AdjacentInterlockingSystemOppositeMainSignalStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId); + } + + public override byte[] ToByteArray() { + var result = new byte[63]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemRoutePretestRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRoutePretestRequestCommandRouteType RouteType) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + private const int RouteTypeOffset = 83; + public static readonly ushort MessageType = 0x000F; + + public new static AdjacentInterlockingSystemRoutePretestRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + var RouteType = (AdjacentInterlockingSystemRoutePretestRequestCommandRouteType)message[RouteTypeOffset]; + return new AdjacentInterlockingSystemRoutePretestRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType); + } + + public override byte[] ToByteArray() { + var result = new byte[84]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + result[RouteTypeOffset] = (byte)RouteType; + return result; + } +} + +public enum AdjacentInterlockingSystemRoutePretestRequestCommandRouteType : byte { + MainRoute = 0x01, + ShuntingRoute = 0x02, + OnSightRoute = 0x03, + SrTrainRoute = 0x04, + SpecialTrainRoute = 0x05, + TemporaryShuntingArea = 0x06 +} + +public record AdjacentInterlockingSystemRoutePretestStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRoutePretestStatusMessageRouteType RouteType, AdjacentInterlockingSystemRoutePretestStatusMessageRouteStatus RouteStatus, AdjacentInterlockingSystemRoutePretestStatusMessagePretestResponse PretestResponse) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + private const int RouteTypeOffset = 83; + private const int RouteStatusOffset = 84; + private const int PretestResponseOffset = 85; + public static readonly ushort MessageType = 0x0010; + + public new static AdjacentInterlockingSystemRoutePretestStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + var RouteType = (AdjacentInterlockingSystemRoutePretestStatusMessageRouteType)message[RouteTypeOffset]; + var RouteStatus = (AdjacentInterlockingSystemRoutePretestStatusMessageRouteStatus)message[RouteStatusOffset]; + var PretestResponse = (AdjacentInterlockingSystemRoutePretestStatusMessagePretestResponse)message[PretestResponseOffset]; + return new AdjacentInterlockingSystemRoutePretestStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType, RouteStatus, PretestResponse); + } + + public override byte[] ToByteArray() { + var result = new byte[86]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + result[RouteTypeOffset] = (byte)RouteType; + result[RouteStatusOffset] = (byte)RouteStatus; + result[PretestResponseOffset] = (byte)PretestResponse; + return result; + } +} + +public enum AdjacentInterlockingSystemRoutePretestStatusMessageRouteType : byte { + MainRoute = 0x01, + ShuntingRoute = 0x02, + OnSightRoute = 0x03, + SrTrainRoute = 0x04, + SpecialTrainRoute = 0x05, + TemporaryShuntingArea = 0x06 +} + +public enum AdjacentInterlockingSystemRoutePretestStatusMessageRouteStatus : byte { + Initiated = 0x01, + Locked = 0x02, + NoRoute = 0x03 +} + +public enum AdjacentInterlockingSystemRoutePretestStatusMessagePretestResponse : byte { + PossibleAndVacant = 0x01, + PossibleAndOccupied = 0x02, + Queue = 0x03, + Rejected = 0x04 +} + +public record AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + public static readonly ushort MessageType = 0x0011; + + public new static AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + return new AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId); + } + + public override byte[] ToByteArray() { + var result = new byte[63]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + return result; + } +} + + + +public record AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessageRouteReleaseInhibitionStatus RouteReleaseInhibitionStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteReleaseInhibitionStatusOffset = 63; + public static readonly ushort MessageType = 0x0014; + + public new static AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteReleaseInhibitionStatus = (AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessageRouteReleaseInhibitionStatus)message[RouteReleaseInhibitionStatusOffset]; + return new AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteReleaseInhibitionStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[64]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + result[RouteReleaseInhibitionStatusOffset] = (byte)RouteReleaseInhibitionStatus; + return result; + } +} + +public enum AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessageRouteReleaseInhibitionStatus : byte { + Activated = 0x01, + Deactivated = 0x02 +} + +public record AdjacentInterlockingSystemAbortRouteCancellationRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int BoundaryIdOffset = 43; + private const int RouteIdOffset = 63; + public static readonly ushort MessageType = 0x0016; + + public new static AdjacentInterlockingSystemAbortRouteCancellationRequestCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); + var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); + return new AdjacentInterlockingSystemAbortRouteCancellationRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId); + } + + public override byte[] ToByteArray() { + var result = new byte[83]; + result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); + Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); + return result; + } +} + + diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs new file mode 100644 index 0000000..088e721 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs @@ -0,0 +1,6 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs new file mode 100644 index 0000000..2aa1490 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs @@ -0,0 +1,31 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record LevelCrossingDeactivationCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0002; + + public new static LevelCrossingDeactivationCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new LevelCrossingDeactivationCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.LevelCrossing; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs new file mode 100644 index 0000000..03030b6 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs @@ -0,0 +1,71 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record LightSignalSetLuminosityCommand (string SenderIdentifier, string ReceiverIdentifier, LightSignalSetLuminosityCommandByteNr43:Luminosity ByteNr43:Luminosity) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ByteNr43:LuminosityOffset = 43; + public static readonly ushort MessageType = 0x0002; + + public new static LightSignalSetLuminosityCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ByteNr43:Luminosity = (LightSignalSetLuminosityCommandByteNr43:Luminosity)message[ByteNr43:LuminosityOffset]; + return new LightSignalSetLuminosityCommand(SenderIdentifier, ReceiverIdentifier, ByteNr43:Luminosity); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ByteNr43:LuminosityOffset] = (byte)ByteNr43:Luminosity; + return result; + } +} + +public enum LightSignalSetLuminosityCommandByteNr43:Luminosity : byte { + LuminosityForDay = 0x01, + LuminosityForNight = 0x02, + IntentionallyDeleted = 0xFE +} + +public record LightSignalSetLuminosityMessage (string SenderIdentifier, string ReceiverIdentifier, LightSignalSetLuminosityMessageByteNr43:Luminosity ByteNr43:Luminosity) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ByteNr43:LuminosityOffset = 43; + public static readonly ushort MessageType = 0x0004; + + public new static LightSignalSetLuminosityMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ByteNr43:Luminosity = (LightSignalSetLuminosityMessageByteNr43:Luminosity)message[ByteNr43:LuminosityOffset]; + return new LightSignalSetLuminosityMessage(SenderIdentifier, ReceiverIdentifier, ByteNr43:Luminosity); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.LightSignal; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ByteNr43:LuminosityOffset] = (byte)ByteNr43:Luminosity; + return result; + } +} + +public enum LightSignalSetLuminosityMessageByteNr43:Luminosity : byte { + LuminosityForDay = 0x01, + LuminosityForNight = 0x02, + IntentionallyDeleted = 0xFE +} diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs new file mode 100644 index 0000000..e012594 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs @@ -0,0 +1,31 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record ExternalLevelCrossingSystemCrossingClearCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0007; + + public new static ExternalLevelCrossingSystemCrossingClearCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new ExternalLevelCrossingSystemCrossingClearCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs new file mode 100644 index 0000000..9196806 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs @@ -0,0 +1,139 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record PointMovePointCommand (string SenderIdentifier, string ReceiverIdentifier, PointMovePointCommandCommandedPointPosition CommandedPointPosition) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int CommandedPointPositionOffset = 43; + public static readonly ushort MessageType = 0x0001; + + public new static PointMovePointCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var CommandedPointPosition = (PointMovePointCommandCommandedPointPosition)message[CommandedPointPositionOffset]; + return new PointMovePointCommand(SenderIdentifier, ReceiverIdentifier, CommandedPointPosition); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[CommandedPointPositionOffset] = (byte)CommandedPointPosition; + return result; + } +} + +public enum PointMovePointCommandCommandedPointPosition : byte { + SubsystemElectronicInterlockingRequestsARightHandPointMoving = 0x01, + SubsystemElectronicInterlockingRequestsALeftHandPointMoving = 0x02 +} + +public record PointPointPositionMessage (string SenderIdentifier, string ReceiverIdentifier, PointPointPositionMessageReportedPointPosition ReportedPointPosition, PointPointPositionMessageReportedDegradedPointPosition ReportedDegradedPointPosition) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ReportedPointPositionOffset = 43; + private const int ReportedDegradedPointPositionOffset = 44; + public static readonly ushort MessageType = 0x000B; + + public new static PointPointPositionMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ReportedPointPosition = (PointPointPositionMessageReportedPointPosition)message[ReportedPointPositionOffset]; + var ReportedDegradedPointPosition = (PointPointPositionMessageReportedDegradedPointPosition)message[ReportedDegradedPointPositionOffset]; + return new PointPointPositionMessage(SenderIdentifier, ReceiverIdentifier, ReportedPointPosition, ReportedDegradedPointPosition); + } + + public override byte[] ToByteArray() { + var result = new byte[45]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ReportedPointPositionOffset] = (byte)ReportedPointPosition; + result[ReportedDegradedPointPositionOffset] = (byte)ReportedDegradedPointPosition; + return result; + } +} + +public enum PointPointPositionMessageReportedPointPosition : byte { + PointIsInARightHandPositionDefinedEndPosition = 0x01, + PointIsInALeftHandPositionDefinedEndPosition = 0x02, + PointIsInNoEndPosition = 0x03, + PointIsInUnintendedPosition = 0x04 +} + +public enum PointPointPositionMessageReportedDegradedPointPosition : byte { + PointIsInADegradedRightHandPosition = 0x01, + PointIsInADegradedLeftHandPosition = 0x02, + PointIsNotInADegradedPosition = 0x03, + DegradedPointPositionIsNotApplicable = 0xFF +} + +public record PointMovementFailedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x000C; + + public new static PointMovementFailedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new PointMovementFailedMessage(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record PointAbilityToMovePointMessage (string SenderIdentifier, string ReceiverIdentifier, PointAbilityToMovePointMessageReportedAbilityToMovePointStatus ReportedAbilityToMovePointStatus) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ReportedAbilityToMovePointStatusOffset = 43; + public static readonly ushort MessageType = 0x000D; + + public new static PointAbilityToMovePointMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ReportedAbilityToMovePointStatus = (PointAbilityToMovePointMessageReportedAbilityToMovePointStatus)message[ReportedAbilityToMovePointStatusOffset]; + return new PointAbilityToMovePointMessage(SenderIdentifier, ReceiverIdentifier, ReportedAbilityToMovePointStatus); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.Point; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ReportedAbilityToMovePointStatusOffset] = (byte)ReportedAbilityToMovePointStatus; + return result; + } +} + +public enum PointAbilityToMovePointMessageReportedAbilityToMovePointStatus : byte { + PointIsAbleToMove = 0x01, + PointIsUnableToMove = 0x02 +} diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs new file mode 100644 index 0000000..088e721 --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs @@ -0,0 +1,6 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs new file mode 100644 index 0000000..f80550b --- /dev/null +++ b/src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs @@ -0,0 +1,311 @@ +using System; +using System.Text; +using System.Linq; + +namespace EulynxLive.Messages.Baseline4R2; + +public record TrainDetectionSystemUpdateFillingLevelCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0002; + + public new static TrainDetectionSystemUpdateFillingLevelCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemUpdateFillingLevelCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemCancelCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0008; + + public new static TrainDetectionSystemCancelCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemCancelCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + public static readonly ushort MessageType = 0x0003; + + public new static TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + return new TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand(SenderIdentifier, ReceiverIdentifier); + } + + public override byte[] ToByteArray() { + var result = new byte[43]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + return result; + } +} + + + +public record TrainDetectionSystemTvpsOccupancyStatusMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTvpsOccupancyStatusMessageOccupancyStatus OccupancyStatus, TrainDetectionSystemTvpsOccupancyStatusMessageAbilityToBeForcedToClear AbilityToBeForcedToClear, ushort FillingLevel, TrainDetectionSystemTvpsOccupancyStatusMessagePomStatus PomStatus, TrainDetectionSystemTvpsOccupancyStatusMessageDisturbanceStatus DisturbanceStatus, TrainDetectionSystemTvpsOccupancyStatusMessageChangeTrigger ChangeTrigger) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int OccupancyStatusOffset = 43; + private const int AbilityToBeForcedToClearOffset = 44; + private const int FillingLevelOffset = 45; + private const int PomStatusOffset = 47; + private const int DisturbanceStatusOffset = 48; + private const int ChangeTriggerOffset = 49; + public static readonly ushort MessageType = 0x0007; + + public new static TrainDetectionSystemTvpsOccupancyStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var OccupancyStatus = (TrainDetectionSystemTvpsOccupancyStatusMessageOccupancyStatus)message[OccupancyStatusOffset]; + var AbilityToBeForcedToClear = (TrainDetectionSystemTvpsOccupancyStatusMessageAbilityToBeForcedToClear)message[AbilityToBeForcedToClearOffset]; + var FillingLevelBytes = new byte[] { message[FillingLevelOffset], message[FillingLevelOffset + 1] }; + if (!BitConverter.IsLittleEndian) Array.Reverse(FillingLevelBytes); + var FillingLevel = BitConverter.ToUInt16(FillingLevelBytes); + var PomStatus = (TrainDetectionSystemTvpsOccupancyStatusMessagePomStatus)message[PomStatusOffset]; + var DisturbanceStatus = (TrainDetectionSystemTvpsOccupancyStatusMessageDisturbanceStatus)message[DisturbanceStatusOffset]; + var ChangeTrigger = (TrainDetectionSystemTvpsOccupancyStatusMessageChangeTrigger)message[ChangeTriggerOffset]; + return new TrainDetectionSystemTvpsOccupancyStatusMessage(SenderIdentifier, ReceiverIdentifier, OccupancyStatus, AbilityToBeForcedToClear, FillingLevel, PomStatus, DisturbanceStatus, ChangeTrigger); + } + + public override byte[] ToByteArray() { + var result = new byte[50]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[OccupancyStatusOffset] = (byte)OccupancyStatus; + result[AbilityToBeForcedToClearOffset] = (byte)AbilityToBeForcedToClear; + var FillingLevelBytes = BitConverter.GetBytes(FillingLevel); + if (!BitConverter.IsLittleEndian) Array.Reverse(FillingLevelBytes); + FillingLevelBytes.Take(2).ToArray().CopyTo(result, FillingLevelOffset); + result[PomStatusOffset] = (byte)PomStatus; + result[DisturbanceStatusOffset] = (byte)DisturbanceStatus; + result[ChangeTriggerOffset] = (byte)ChangeTrigger; + return result; + } +} + +public enum TrainDetectionSystemTvpsOccupancyStatusMessageOccupancyStatus : byte { + TvpsIsInStateVacant = 0x01, + TvpsIsInStateOccupied = 0x02, + TvpsIsInStateDisturbed = 0x03, + TvpsIsInStateWaitingForASweepingTrainAfterFcPAOrFcPCommand = 0x04, + TvpsIsInStateWaitingForAnAcknowledgmentAfterFcPACommand = 0x05, + TvpsIsInStateSweepingTrainDetected = 0x06 +} + +public enum TrainDetectionSystemTvpsOccupancyStatusMessageAbilityToBeForcedToClear : byte { + TvpsIsNotAbleToBeForcedToClear = 0x01, + TvpsIsAbleToBeForcedToClear = 0x02 +} + +public enum TrainDetectionSystemTvpsOccupancyStatusMessagePomStatus : byte { + PowerSupplyOk = 0x01, + PowerSupplyNok = 0x02, + PomStatusIsNotApplicable = 0xFF +} + +public enum TrainDetectionSystemTvpsOccupancyStatusMessageDisturbanceStatus : byte { + DisturbanceIsOperational = 0x01, + DisturbanceIsTechnical = 0x02, + DisturbanceStatusIsNotApplicable = 0xFF +} + +public enum TrainDetectionSystemTvpsOccupancyStatusMessageChangeTrigger : byte { + PassingDetected = 0x01, + CommandFromEilAccepted = 0x02, + CommandFromMaintainerAccepted = 0x03, + TechnicalFailure = 0x04, + InitialSectionState = 0x05, + InternalTrigger = 0x06, + ChangeTriggerIsNotApplicable = 0xFF +} + +public record TrainDetectionSystemCommandRejectedMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemCommandRejectedMessageReasonForRejection ReasonForRejection) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ReasonForRejectionOffset = 43; + public static readonly ushort MessageType = 0x0006; + + public new static TrainDetectionSystemCommandRejectedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ReasonForRejection = (TrainDetectionSystemCommandRejectedMessageReasonForRejection)message[ReasonForRejectionOffset]; + return new TrainDetectionSystemCommandRejectedMessage(SenderIdentifier, ReceiverIdentifier, ReasonForRejection); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ReasonForRejectionOffset] = (byte)ReasonForRejection; + return result; + } +} + +public enum TrainDetectionSystemCommandRejectedMessageReasonForRejection : byte { + OperationalRejected = 0x01, + TechnicalRejected = 0x02 +} + +public record TrainDetectionSystemTvpsFcPFailedMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTvpsFcPFailedMessageReasonForFailure ReasonForFailure) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ReasonForFailureOffset = 43; + public static readonly ushort MessageType = 0x0010; + + public new static TrainDetectionSystemTvpsFcPFailedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ReasonForFailure = (TrainDetectionSystemTvpsFcPFailedMessageReasonForFailure)message[ReasonForFailureOffset]; + return new TrainDetectionSystemTvpsFcPFailedMessage(SenderIdentifier, ReceiverIdentifier, ReasonForFailure); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ReasonForFailureOffset] = (byte)ReasonForFailure; + return result; + } +} + +public enum TrainDetectionSystemTvpsFcPFailedMessageReasonForFailure : byte { + IncorrectCountOfTheSweepingTrain = 0x01, + ExpirationOfTimerConTmaxResponseTimeFcP = 0x02, + BoundingDetectionPointIsConfiguredAsNotPermittedForFcP = 0x03, + IntentionallyDeleted = 0x04, + OutgoingAxleDetectedBeforeExpirationOfMinimumTimer = 0x05, + ProcessCancelled = 0x06 +} + +public record TrainDetectionSystemTvpsFcPAFailedMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTvpsFcPAFailedMessageReasonForFailure ReasonForFailure) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int ReasonForFailureOffset = 43; + public static readonly ushort MessageType = 0x0011; + + public new static TrainDetectionSystemTvpsFcPAFailedMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var ReasonForFailure = (TrainDetectionSystemTvpsFcPAFailedMessageReasonForFailure)message[ReasonForFailureOffset]; + return new TrainDetectionSystemTvpsFcPAFailedMessage(SenderIdentifier, ReceiverIdentifier, ReasonForFailure); + } + + public override byte[] ToByteArray() { + var result = new byte[44]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[ReasonForFailureOffset] = (byte)ReasonForFailure; + return result; + } +} + +public enum TrainDetectionSystemTvpsFcPAFailedMessageReasonForFailure : byte { + IncorrectCountOfTheSweepingTrain = 0x01, + ExpirationOfTimerConTmaxResponseTimeFcPA = 0x02, + BoundingDetectionPointIsConfiguredAsNotPermittedForFcPA = 0x03, + IntentionallyDeleted = 0x04, + OutgoingAxleDetectedBeforeExpirationOfMinimumTimer = 0x05, + ProcessCancelled = 0x06 +} + +public record TrainDetectionSystemTdpStatusMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTdpStatusMessageStateOfPassing StateOfPassing, TrainDetectionSystemTdpStatusMessageDirectionOfPassing DirectionOfPassing) : Message(SenderIdentifier, ReceiverIdentifier) { + private const int MessageTypeOffset = 1; + private const int SenderIdentifierOffset = 3; + private const int ReceiverIdentifierOffset = 23; + private const int StateOfPassingOffset = 43; + private const int DirectionOfPassingOffset = 44; + public static readonly ushort MessageType = 0x000B; + + public new static TrainDetectionSystemTdpStatusMessage FromBytes(byte[] message) { + var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); + var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); + var StateOfPassing = (TrainDetectionSystemTdpStatusMessageStateOfPassing)message[StateOfPassingOffset]; + var DirectionOfPassing = (TrainDetectionSystemTdpStatusMessageDirectionOfPassing)message[DirectionOfPassingOffset]; + return new TrainDetectionSystemTdpStatusMessage(SenderIdentifier, ReceiverIdentifier, StateOfPassing, DirectionOfPassing); + } + + public override byte[] ToByteArray() { + var result = new byte[45]; + result[0] = (byte)ProtocolType.TrainDetectionSystem; + var MessageTypeBytes = BitConverter.GetBytes(MessageType); + if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); + MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); + Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); + Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); + result[StateOfPassingOffset] = (byte)StateOfPassing; + result[DirectionOfPassingOffset] = (byte)DirectionOfPassing; + return result; + } +} + +public enum TrainDetectionSystemTdpStatusMessageStateOfPassing : byte { + NotPassed = 0x01, + Passed = 0x02, + Disturbed = 0x03 +} + +public enum TrainDetectionSystemTdpStatusMessageDirectionOfPassing : byte { + ReferenceDirection = 0x01, + AgainstReferenceDirection = 0x02, + WithoutIndicatedDirection = 0x03 +} diff --git a/src/Messages/Baseline4R2/Message.cs b/src/Messages/Baseline4R2/Message.cs new file mode 100644 index 0000000..1c6dc40 --- /dev/null +++ b/src/Messages/Baseline4R2/Message.cs @@ -0,0 +1,178 @@ +using System; + +namespace EulynxLive.Messages.Baseline4R2; + +public abstract record Message(string SenderIdentifier, string ReceiverIdentifier) { + + public abstract byte[] ToByteArray(); + + public static Message FromBytes(byte[] message) { + var protocolType = (ProtocolType)message[0]; + var messageType = BitConverter.ToUInt16(new byte[2] { message[1], message[2] }); + return protocolType switch { + ProtocolType.AdjacentInterlockingSystem => messageType switch { + 0x0001 => AdjacentInterlockingSystemActivationZoneStatusMessage.FromBytes(message), + 0x0002 => AdjacentInterlockingSystemApproachZoneStatusMessage.FromBytes(message), + 0x0003 => AdjacentInterlockingSystemAccessRestrictionRequestCommand.FromBytes(message), + 0x0012 => AdjacentInterlockingSystemAccessRestrictionStatusMessage.FromBytes(message), + 0x0004 => AdjacentInterlockingSystemLineStatusMessage.FromBytes(message), + 0x0005 => AdjacentInterlockingSystemFlankProtectionRequestCommand.FromBytes(message), + 0x0013 => AdjacentInterlockingSystemFlankProtectionStatusMessage.FromBytes(message), + 0x0007 => AdjacentInterlockingSystemRouteRequestCommand.FromBytes(message), + 0x0008 => AdjacentInterlockingSystemRouteStatusMessage.FromBytes(message), + 0x0009 => AdjacentInterlockingSystemRouteMonitoringStatusMessage.FromBytes(message), + 0x000A => AdjacentInterlockingSystemRouteCancellationRequestCommand.FromBytes(message), + 0x000B => AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage.FromBytes(message), + 0x000C => AdjacentInterlockingSystemSignalStatusMessage.FromBytes(message), + 0x000D => AdjacentInterlockingSystemTvpsStatusMessage.FromBytes(message), + 0x000E => AdjacentInterlockingSystemOppositeMainSignalStatusMessage.FromBytes(message), + 0x000F => AdjacentInterlockingSystemRoutePretestRequestCommand.FromBytes(message), + 0x0010 => AdjacentInterlockingSystemRoutePretestStatusMessage.FromBytes(message), + 0x0011 => AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand.FromBytes(message), + 0x0014 => AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage.FromBytes(message), + 0x0016 => AdjacentInterlockingSystemAbortRouteCancellationRequestCommand.FromBytes(message), + 0x0024 => AdjacentInterlockingSystemPdiVersionCheckCommand.FromBytes(message), + 0x0025 => AdjacentInterlockingSystemPdiVersionCheckMessage.FromBytes(message), + 0x0021 => AdjacentInterlockingSystemInitialisationRequestCommand.FromBytes(message), + 0x0022 => AdjacentInterlockingSystemStartInitialisationMessage.FromBytes(message), + 0x0026 => AdjacentInterlockingSystemStatusReportCompletedMessage.FromBytes(message), + 0x0023 => AdjacentInterlockingSystemInitialisationCompletedMessage.FromBytes(message), + 0x0027 => AdjacentInterlockingSystemClosePdiCommand.FromBytes(message), + 0x0028 => AdjacentInterlockingSystemReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => AdjacentInterlockingSystemPdiAvailableMessage.FromBytes(message), + 0x002A => AdjacentInterlockingSystemPdiNotAvailableMessage.FromBytes(message), + 0x002B => AdjacentInterlockingSystemResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.TrainDetectionSystem => messageType switch { + 0x0002 => TrainDetectionSystemUpdateFillingLevelCommand.FromBytes(message), + 0x0008 => TrainDetectionSystemCancelCommand.FromBytes(message), + 0x0003 => TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand.FromBytes(message), + 0x0007 => TrainDetectionSystemTvpsOccupancyStatusMessage.FromBytes(message), + 0x0006 => TrainDetectionSystemCommandRejectedMessage.FromBytes(message), + 0x0010 => TrainDetectionSystemTvpsFcPFailedMessage.FromBytes(message), + 0x0011 => TrainDetectionSystemTvpsFcPAFailedMessage.FromBytes(message), + 0x000B => TrainDetectionSystemTdpStatusMessage.FromBytes(message), + 0x0024 => TrainDetectionSystemPdiVersionCheckCommand.FromBytes(message), + 0x0025 => TrainDetectionSystemPdiVersionCheckMessage.FromBytes(message), + 0x0021 => TrainDetectionSystemInitialisationRequestCommand.FromBytes(message), + 0x0022 => TrainDetectionSystemStartInitialisationMessage.FromBytes(message), + 0x0026 => TrainDetectionSystemStatusReportCompletedMessage.FromBytes(message), + 0x0023 => TrainDetectionSystemInitialisationCompletedMessage.FromBytes(message), + 0x0027 => TrainDetectionSystemClosePdiCommand.FromBytes(message), + 0x0028 => TrainDetectionSystemReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => TrainDetectionSystemPdiAvailableMessage.FromBytes(message), + 0x002A => TrainDetectionSystemPdiNotAvailableMessage.FromBytes(message), + 0x002B => TrainDetectionSystemResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.LightSignal => messageType switch { + 0x0002 => LightSignalSetLuminosityCommand.FromBytes(message), + 0x0004 => LightSignalSetLuminosityMessage.FromBytes(message), + 0x0024 => LightSignalPdiVersionCheckCommand.FromBytes(message), + 0x0025 => LightSignalPdiVersionCheckMessage.FromBytes(message), + 0x0021 => LightSignalInitialisationRequestCommand.FromBytes(message), + 0x0022 => LightSignalStartInitialisationMessage.FromBytes(message), + 0x0026 => LightSignalStatusReportCompletedMessage.FromBytes(message), + 0x0023 => LightSignalInitialisationCompletedMessage.FromBytes(message), + 0x0027 => LightSignalClosePdiCommand.FromBytes(message), + 0x0028 => LightSignalReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => LightSignalPdiAvailableMessage.FromBytes(message), + 0x002A => LightSignalPdiNotAvailableMessage.FromBytes(message), + 0x002B => LightSignalResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.Point => messageType switch { + 0x0001 => PointMovePointCommand.FromBytes(message), + 0x000B => PointPointPositionMessage.FromBytes(message), + 0x000C => PointMovementFailedMessage.FromBytes(message), + 0x000D => PointAbilityToMovePointMessage.FromBytes(message), + 0x0024 => PointPdiVersionCheckCommand.FromBytes(message), + 0x0025 => PointPdiVersionCheckMessage.FromBytes(message), + 0x0021 => PointInitialisationRequestCommand.FromBytes(message), + 0x0022 => PointStartInitialisationMessage.FromBytes(message), + 0x0026 => PointStatusReportCompletedMessage.FromBytes(message), + 0x0023 => PointInitialisationCompletedMessage.FromBytes(message), + 0x0027 => PointClosePdiCommand.FromBytes(message), + 0x0028 => PointReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => PointPdiAvailableMessage.FromBytes(message), + 0x002A => PointPdiNotAvailableMessage.FromBytes(message), + 0x002B => PointResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.RadioBlockCenter => messageType switch { + 0x0024 => RadioBlockCenterPdiVersionCheckCommand.FromBytes(message), + 0x0025 => RadioBlockCenterPdiVersionCheckMessage.FromBytes(message), + 0x0021 => RadioBlockCenterInitialisationRequestCommand.FromBytes(message), + 0x0022 => RadioBlockCenterStartInitialisationMessage.FromBytes(message), + 0x0026 => RadioBlockCenterStatusReportCompletedMessage.FromBytes(message), + 0x0023 => RadioBlockCenterInitialisationCompletedMessage.FromBytes(message), + 0x0027 => RadioBlockCenterClosePdiCommand.FromBytes(message), + 0x0028 => RadioBlockCenterReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => RadioBlockCenterPdiAvailableMessage.FromBytes(message), + 0x002A => RadioBlockCenterPdiNotAvailableMessage.FromBytes(message), + 0x002B => RadioBlockCenterResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.LevelCrossing => messageType switch { + 0x0002 => LevelCrossingDeactivationCommand.FromBytes(message), + 0x0024 => LevelCrossingPdiVersionCheckCommand.FromBytes(message), + 0x0025 => LevelCrossingPdiVersionCheckMessage.FromBytes(message), + 0x0021 => LevelCrossingInitialisationRequestCommand.FromBytes(message), + 0x0022 => LevelCrossingStartInitialisationMessage.FromBytes(message), + 0x0026 => LevelCrossingStatusReportCompletedMessage.FromBytes(message), + 0x0023 => LevelCrossingInitialisationCompletedMessage.FromBytes(message), + 0x0027 => LevelCrossingClosePdiCommand.FromBytes(message), + 0x0028 => LevelCrossingReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => LevelCrossingPdiAvailableMessage.FromBytes(message), + 0x002A => LevelCrossingPdiNotAvailableMessage.FromBytes(message), + 0x002B => LevelCrossingResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.CC => messageType switch { + 0x0024 => CCPdiVersionCheckCommand.FromBytes(message), + 0x0025 => CCPdiVersionCheckMessage.FromBytes(message), + 0x0021 => CCInitialisationRequestCommand.FromBytes(message), + 0x0022 => CCStartInitialisationMessage.FromBytes(message), + 0x0026 => CCStatusReportCompletedMessage.FromBytes(message), + 0x0023 => CCInitialisationCompletedMessage.FromBytes(message), + 0x0027 => CCClosePdiCommand.FromBytes(message), + 0x0028 => CCReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => CCPdiAvailableMessage.FromBytes(message), + 0x002A => CCPdiNotAvailableMessage.FromBytes(message), + 0x002B => CCResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.GenericIO => messageType switch { + 0x0024 => GenericIOPdiVersionCheckCommand.FromBytes(message), + 0x0025 => GenericIOPdiVersionCheckMessage.FromBytes(message), + 0x0021 => GenericIOInitialisationRequestCommand.FromBytes(message), + 0x0022 => GenericIOStartInitialisationMessage.FromBytes(message), + 0x0026 => GenericIOStatusReportCompletedMessage.FromBytes(message), + 0x0023 => GenericIOInitialisationCompletedMessage.FromBytes(message), + 0x0027 => GenericIOClosePdiCommand.FromBytes(message), + 0x0028 => GenericIOReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => GenericIOPdiAvailableMessage.FromBytes(message), + 0x002A => GenericIOPdiNotAvailableMessage.FromBytes(message), + 0x002B => GenericIOResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + ProtocolType.ExternalLevelCrossingSystem => messageType switch { + 0x0007 => ExternalLevelCrossingSystemCrossingClearCommand.FromBytes(message), + 0x0024 => ExternalLevelCrossingSystemPdiVersionCheckCommand.FromBytes(message), + 0x0025 => ExternalLevelCrossingSystemPdiVersionCheckMessage.FromBytes(message), + 0x0021 => ExternalLevelCrossingSystemInitialisationRequestCommand.FromBytes(message), + 0x0022 => ExternalLevelCrossingSystemStartInitialisationMessage.FromBytes(message), + 0x0026 => ExternalLevelCrossingSystemStatusReportCompletedMessage.FromBytes(message), + 0x0023 => ExternalLevelCrossingSystemInitialisationCompletedMessage.FromBytes(message), + 0x0027 => ExternalLevelCrossingSystemClosePdiCommand.FromBytes(message), + 0x0028 => ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand.FromBytes(message), + 0x0029 => ExternalLevelCrossingSystemPdiAvailableMessage.FromBytes(message), + 0x002A => ExternalLevelCrossingSystemPdiNotAvailableMessage.FromBytes(message), + 0x002B => ExternalLevelCrossingSystemResetPdiMessage.FromBytes(message), + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }, + _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") + }; + } +} From b28fbf8f42829694a3540f4efba5c7577f00a930 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 21 Nov 2023 17:03:56 +0100 Subject: [PATCH 02/22] add interface and implementation --- .../IPointToInterlockingConnection.cs | 39 ++++ .../PointToInterlockingConnectionB4R1Impl.cs | 204 ++++++++++++++++++ 2 files changed, 243 insertions(+) create mode 100644 src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs create mode 100644 src/Point/PointToInterlockingConnectionB4R1Impl.cs diff --git a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs new file mode 100644 index 0000000..a4c17df --- /dev/null +++ b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; + +public interface IPointToInterlockingConnection { + void SendPointPosition(IPointState state); + void SendTimeoutMessage(); + void Reset(); + void Setup(); + void Connect(); + void InitializeConnection(); + public Task ReceivePointPosition(); + + public interface IMessage + { + public IMessage FromBytes(byte[] message); + public abstract byte[] ToByteArray(); + } + + public interface IPointState + { + PointPosition PointPosition { get; set; } + DegradedPointPosition DegradedPointPosition { get; set; } + } + + public enum PointPosition + { + LEFT, + RIGHT, + TRAILED, + NO_ENDPOSITION + } + + public enum DegradedPointPosition + { + DEGRADED_LEFT, + DEGRADED_RIGHT, + NOT_DEGRADED, + NOT_APPLICABLE + } +} diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs new file mode 100644 index 0000000..67561d2 --- /dev/null +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -0,0 +1,204 @@ +using System.Net.WebSockets; +using EulynxLive.Messages.Baseline4R1; +using EulynxLive.Point; +using Google.Protobuf; +using Grpc.Core; +using Grpc.Net.Client; +using Sci; +using static IPointToInterlockingConnection; +using static Sci.Rasta; + +public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConnection +{ + public bool AllPointMachinesCrucial { get; } + private readonly ILogger _logger; + private readonly string _localId; + private readonly string _localRastaId; + private readonly string _remoteId; + private readonly string _remoteEndpoint; + AsyncDuplexStreamingCall? _currentConnection; + private GrpcChannel _channel; + private RastaClient _client; + private Metadata _metadata; + private CancellationTokenSource _timeout; + + public PointToInterlockingConnectionB4R1Impl( + ILogger logger, + IConfiguration configuration) + { + _logger = logger; + _currentConnection = null; + + var config = configuration.GetSection("PointSettings").Get() ?? throw new Exception("No configuration provided"); + if (config.AllPointMachinesCrucial == null) + { + _logger.LogInformation("Assuming all point machines are crucial."); + } + + AllPointMachinesCrucial = config.AllPointMachinesCrucial ?? false; + _localId = config.LocalId; + _localRastaId = config.LocalRastaId.ToString(); + _remoteId = config.RemoteId; + _remoteEndpoint = config.RemoteEndpoint; + } + + public void Connect() + { + + } + + public async Task InitializeConnection(IPointState state) + { + using (_currentConnection = _client.Stream(_metadata, cancellationToken: _timeout.Token)) + { + _logger.LogTrace("Connected. Waiting for request..."); + if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) + || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) + { + _logger.LogError("Unexpected message."); + return 1; + } + + var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(versionCheckResponse.ToByteArray()) }); + + if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) + || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) + { + _logger.LogError("Unexpected message."); + return 1; + } + + var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(startInitialization.ToByteArray()) }); + + var pointState = new B4R1PointStateImpl(state); + var initialPosition = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(initialPosition.ToByteArray()) }); + + var completeInitialization = new PointInitialisationCompletedMessage(_localId, _remoteId); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(completeInitialization.ToByteArray()) }); + } + return 0; + } + + public void Setup() + { + _channel = GrpcChannel.ForAddress(_remoteEndpoint); + _client = new RastaClient(_channel); + _logger.LogTrace("Connecting..."); + _timeout = new CancellationTokenSource(); + _timeout.CancelAfter(10000); + _metadata = new Metadata { { "rasta-id", _localRastaId } }; + } + + public async void SendPointPosition(IPointState state) + { + var pointState = new B4R1PointStateImpl(state); + var response = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); + } + + public void Reset() + { + + } + + void IPointToInterlockingConnection.InitializeConnection() + { + throw new NotImplementedException(); + } + + async public void SendTimeoutMessage() + { + var response = new PointTimeoutMessage(_localId, _remoteId); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); + } + + public async Task ReceivePointPosition() + { + if (!await _currentConnection.ResponseStream.MoveNext()) + { + return null; + } + var message = Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()); + + if (message is PointMovePointCommand movePointCommand) + { + return movePointCommand.CommandedPointPosition switch + { + PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving => PointPosition.RIGHT, + PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.LEFT, + }; + } + _logger.LogInformation("Received unknown message {}", message.GetType()); + return null; + } +} + +public class B4R1PointStateImpl +{ + private IPointState _state; + public PointPointPositionMessageReportedPointPosition PointPosition { get => map(_state.PointPosition); } + public PointPointPositionMessageReportedDegradedPointPosition DegradedPointPosition { get => map(_state.DegradedPointPosition); } + + public B4R1PointStateImpl(IPointState state){ + _state = state; + } + + private PointPointPositionMessageReportedPointPosition map(PointPosition value) => value switch + { + IPointToInterlockingConnection.PointPosition.LEFT => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, + IPointToInterlockingConnection.PointPosition.RIGHT => PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, + IPointToInterlockingConnection.PointPosition.TRAILED => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, + IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION => PointPointPositionMessageReportedPointPosition.PointIsTrailed, + }; + + private PointPosition map(PointPointPositionMessageReportedPointPosition position) => position switch + { + PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition => IPointToInterlockingConnection.PointPosition.LEFT, + PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => IPointToInterlockingConnection.PointPosition.RIGHT, + PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition => IPointToInterlockingConnection.PointPosition.TRAILED, + PointPointPositionMessageReportedPointPosition.PointIsTrailed => IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION, + }; + + + private PointPointPositionMessageReportedDegradedPointPosition map(DegradedPointPosition value) => value switch + { + IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_LEFT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, + IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_RIGHT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + IPointToInterlockingConnection.DegradedPointPosition.NOT_DEGRADED => PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition, + IPointToInterlockingConnection.DegradedPointPosition.NOT_APPLICABLE => PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable, + }; + + private DegradedPointPosition map(PointPointPositionMessageReportedDegradedPointPosition degradedPosition) => degradedPosition switch + { + PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition => IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_LEFT, + PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition => IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_RIGHT, + PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition => IPointToInterlockingConnection.DegradedPointPosition.NOT_DEGRADED, + PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable => IPointToInterlockingConnection.DegradedPointPosition.NOT_APPLICABLE, + }; +} + +public class B4R1MessageImpl : IPointToInterlockingConnection.IMessage +{ + private Message _message; + + public B4R1MessageImpl() { } + + public B4R1MessageImpl(Message message) + { + _message = message; + } + public byte[] ToByteArray() + { + throw new System.NotImplementedException(); + } + + public IPointToInterlockingConnection.IMessage FromBytes(byte[] message) => + new B4R1MessageImpl(Message.FromBytes(message)); + +} + + + From 4f49f9127827565b4d167c989efce644a8f77341 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 21 Nov 2023 17:04:02 +0100 Subject: [PATCH 03/22] update Point --- src/Point/Point.cs | 245 +++++++++++++++++---------------------------- 1 file changed, 90 insertions(+), 155 deletions(-) diff --git a/src/Point/Point.cs b/src/Point/Point.cs index d46ad2a..29dd806 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -4,8 +4,9 @@ using Grpc.Core; using Sci; using EulynxLive.Messages.Baseline4R1; -using PointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedPointPosition; -using DegradedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedDegradedPointPosition; +using PointPosition = IPointToInterlockingConnection.PointPosition ; +using DegradedPointPosition = IPointToInterlockingConnection.DegradedPointPosition; +using IPointState = IPointToInterlockingConnection.IPointState; using static Sci.Rasta; using System.Text; using Grpc.Net.Client; @@ -20,6 +21,7 @@ public class Point : BackgroundService private readonly ILogger _logger; private readonly List _webSockets; + private readonly PointToInterlockingConnectionB4R1Impl _connection; private readonly string _localId; private readonly string _localRastaId; private readonly string _remoteId; @@ -28,32 +30,13 @@ public class Point : BackgroundService private readonly bool _simulateRandomTimeouts; private bool _initialized; AsyncDuplexStreamingCall? _currentConnection; - private readonly PointMachineState _pointState; - public PointMachineState PointState { get { return _pointState; } } + private readonly IPointState _pointState; + public IPointState PointState { get { return _pointState; } } public Point(ILogger logger, IConfiguration configuration) { - _logger = logger; _webSockets = new List(); - _currentConnection = null; - _random = new Random(); - - var config = configuration.GetSection("PointSettings").Get() ?? throw new Exception("No configuration provided"); - if (config.AllPointMachinesCrucial == null) - { - _logger.LogInformation("Assuming all point machines are crucial."); - } - - AllPointMachinesCrucial = config.AllPointMachinesCrucial ?? false; - _localId = config.LocalId; - _localRastaId = config.LocalRastaId.ToString(); - _remoteId = config.RemoteId; - _remoteEndpoint = config.RemoteEndpoint; - _simulateRandomTimeouts = config.SimulateRandomTimeouts ?? false; - - _pointState = new PointMachineState(); - _pointState.PointPosition = PointPosition.PointIsInARightHandPositionDefinedEndPosition; - _pointState.DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.DegradedPointPositionIsNotApplicable : DegradedPointPosition.PointIsNotInADegradedPosition; + _connection = new PointToInterlockingConnectionB4R1Impl(logger, configuration); } public async Task HandleWebSocket(WebSocket webSocket) @@ -83,44 +66,47 @@ public async Task HandleWebSocket(WebSocket webSocket) public async Task SimulateUnintendedPosition() { - _pointState.PointPosition = PointPosition.PointIsTrailed; + _pointState.PointPosition = PointPosition.TRAILED; + if (_currentConnection != null) { - var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); + _connection.SendPointPosition(PointState); } await UpdateConnectedWebClients(); } private static DegradedPointPosition? GetDegradedPointPosition(PointPosition previousReportedPosition) - => previousReportedPosition switch { - PointPosition.PointIsInARightHandPositionDefinedEndPosition - => DegradedPointPosition.PointIsInADegradedRightHandPosition, - PointPosition.PointIsInALeftHandPositionDefinedEndPosition - => DegradedPointPosition.PointIsInADegradedLeftHandPosition, - PointPosition.PointIsInNoEndPosition - => null, - PointPosition.PointIsTrailed - => null, - _ => null, - }; + => previousReportedPosition switch + { + PointPosition.RIGHT + => DegradedPointPosition.DEGRADED_RIGHT, + PointPosition.LEFT + => DegradedPointPosition.DEGRADED_LEFT, + PointPosition.TRAILED + => null, + PointPosition.NO_ENDPOSITION + => null, + _ => null, + }; private static PointPosition? GetPointPositionDegraded(Proto.PointPosition pointPosition) => pointPosition switch { - Proto.PointPosition.NoEndPosition => PointPosition.PointIsInNoEndPosition, - Proto.PointPosition.UnintendedPosition => PointPosition.PointIsTrailed, + Proto.PointPosition.NoEndPosition => PointPosition.NO_ENDPOSITION, + Proto.PointPosition.UnintendedPosition => PointPosition.TRAILED, _ => null, }; - private void UpdatePointState(PointPosition pointPosition, DegradedPointPosition degradedPointPosition) { - UpdatePointState(pointPosition); - _pointState.DegradedPointPosition = degradedPointPosition; + private void UpdatePointState(PointPosition pointPosition) + { + _pointState.PointPosition = pointPosition; } - private void UpdatePointState(PointPosition pointPosition) { + private void UpdatePointState(PointPosition pointPosition, DegradedPointPosition degradedPointPosition) + { _pointState.PointPosition = pointPosition; + _pointState.DegradedPointPosition = degradedPointPosition; } /// @@ -130,12 +116,12 @@ private void UpdatePointState(PointPosition pointPosition) { /// public async Task SetDegraded(PointDegradedMessage message) { - _pointState.PointPosition = PointPosition.PointIsInNoEndPosition; + _pointState.PointPosition = PointPosition.NO_ENDPOSITION; if (_currentConnection != null) { var degradedPointPosition = AllPointMachinesCrucial ? - DegradedPointPosition.DegradedPointPositionIsNotApplicable : GetDegradedPointPosition(_pointState.PointPosition); + DegradedPointPosition.NOT_APPLICABLE : GetDegradedPointPosition(_pointState.PointPosition); if (degradedPointPosition != null) { @@ -143,8 +129,7 @@ public async Task SetDegraded(PointDegradedMessage message) if (pointPosition != null) { UpdatePointState(pointPosition.Value, degradedPointPosition.Value); - var occupancyStatus = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(occupancyStatus.ToByteArray()) }); + _connection.SendPointPosition(PointState); } } } @@ -156,28 +141,29 @@ public async Task SetDegraded(PointDegradedMessage message) /// Sets the ReportedPointPosition to the latest final position (left/right). /// /// - public async Task PutInEndPosition(){ + public async Task PutInEndPosition() + { if (_currentConnection != null) { - if (_pointState.PointPosition != PointPosition.PointIsInARightHandPositionDefinedEndPosition && - _pointState.PointPosition != PointPosition.PointIsInALeftHandPositionDefinedEndPosition) { + if (_pointState.PointPosition != PointPosition.RIGHT && + _pointState.PointPosition != PointPosition.LEFT) + { var reportedDegradedPointPosition = AllPointMachinesCrucial ? - DegradedPointPosition.DegradedPointPositionIsNotApplicable : DegradedPointPosition.PointIsNotInADegradedPosition; + DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED; PointPosition? finalPosition = _pointState.DegradedPointPosition switch { - DegradedPointPosition.PointIsInADegradedRightHandPosition => PointPosition.PointIsInARightHandPositionDefinedEndPosition, - DegradedPointPosition.PointIsInADegradedLeftHandPosition => PointPosition.PointIsInALeftHandPositionDefinedEndPosition, - DegradedPointPosition.PointIsNotInADegradedPosition => null, - DegradedPointPosition.DegradedPointPositionIsNotApplicable => null, + DegradedPointPosition.DEGRADED_RIGHT => PointPosition.RIGHT, + DegradedPointPosition.DEGRADED_LEFT => PointPosition.LEFT, + DegradedPointPosition.NOT_DEGRADED => null, + DegradedPointPosition.NOT_APPLICABLE => null, _ => null, }; if (finalPosition != null) { UpdatePointState((PointPosition)finalPosition, reportedDegradedPointPosition); - var positionMessage = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(positionMessage.ToByteArray()) }); + _connection.SendPointPosition(PointState); } } } @@ -193,121 +179,70 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await Reset(); try { - var channel = GrpcChannel.ForAddress(_remoteEndpoint); - var client = new RastaClient(channel); - _logger.LogTrace("Connecting..."); - var timeout = new CancellationTokenSource(); - timeout.CancelAfter(10000); - var metadata = new Metadata { { "rasta-id", _localRastaId } }; - - using (_currentConnection = client.Stream(metadata, cancellationToken: timeout.Token)) + _connection.Setup(); + + var result = await _connection.InitializeConnection(PointState); + if (result != 0) { - _logger.LogTrace("Connected. Waiting for request..."); - if (!await _currentConnection.ResponseStream.MoveNext(timeout.Token) - || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) + continue; + } + await UpdateConnectedWebClients(); + + while (true) + { + var commandedPointPosition = await _connection.ReceivePointPosition(); + if (commandedPointPosition != null) { - _logger.LogError("Unexpected message."); break; } - var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(versionCheckResponse.ToByteArray()) }); - - if (!await _currentConnection.ResponseStream.MoveNext(timeout.Token) - || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) + if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) + || (commandedPointPosition == PointPosition.RIGHT && _pointState.PointPosition == PointPosition.RIGHT)) { - _logger.LogError("Unexpected message."); - break; + _connection.SendPointPosition(PointState); + continue; } - var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(startInitialization.ToByteArray()) }); - - var initialPosition = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(initialPosition.ToByteArray()) }); + UpdatePointState(PointPosition.NO_ENDPOSITION, DegradedPointPosition.NOT_APPLICABLE); - _initialized = true; + await UpdateConnectedWebClients(); - var completeInitialization = new PointInitialisationCompletedMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(completeInitialization.ToByteArray()) }); + // Simulate point movement + var transitioningTime = _random.Next(1, 5); + var transitioningTask = Task.Delay(transitioningTime * 1000); + var pointMovementTimeout = 3 * 1000; - await UpdateConnectedWebClients(); + _logger.LogDebug("Moving to {}.", commandedPointPosition); - while (true) + if (_simulateRandomTimeouts) { - if (!await _currentConnection.ResponseStream.MoveNext()) + if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) { - break; - } - var message = Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()); - - if (message is PointMovePointCommand movePointCommand) - { - if ((movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving && _pointState.PointPosition == PointPosition.PointIsInARightHandPositionDefinedEndPosition) - || (movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving && _pointState.PointPosition == PointPosition.PointIsInALeftHandPositionDefinedEndPosition)) - { - var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); - continue; - } - - UpdatePointState(PointPosition.PointIsInNoEndPosition, DegradedPointPosition.DegradedPointPositionIsNotApplicable); + // transition completed within timeout + UpdatePointState(commandedPointPosition.Value); await UpdateConnectedWebClients(); - // Simulate point movement - var transitioningTime = _random.Next(1, 5); - var transitioningTask = Task.Delay(transitioningTime * 1000); - var pointMovementTimeout = 3 * 1000; - - _logger.LogDebug("Moving to {}.", movePointCommand.CommandedPointPosition); - - if (_simulateRandomTimeouts) - { - if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) - { - // transition completed within timeout - UpdatePointState( - movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving - ? PointPosition.PointIsInARightHandPositionDefinedEndPosition - : PointPosition.PointIsInALeftHandPositionDefinedEndPosition - ); - - await UpdateConnectedWebClients(); - - _logger.LogInformation("End position reached."); - var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); - } - else - { - // timeout - _logger.LogInformation("Timeout"); - var response = new PointTimeoutMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); - } - } - else - { - await transitioningTask; - UpdatePointState( - movePointCommand.CommandedPointPosition == PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving - ? PointPosition.PointIsInARightHandPositionDefinedEndPosition - : PointPosition.PointIsInALeftHandPositionDefinedEndPosition - ); - - await UpdateConnectedWebClients(); - - _logger.LogInformation("End position reached."); - var response = new PointPointPositionMessage(_localId, _remoteId, _pointState.PointPosition, _pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); - } + _logger.LogInformation("End position reached."); + _connection.SendPointPosition(_pointState); } else { - _logger.LogInformation("Received unknown message {}", message.GetType()); + // timeout + _logger.LogInformation("Timeout"); + _connection.SendTimeoutMessage(); } } + else + { + await transitioningTask; + UpdatePointState(commandedPointPosition.Value); + + await UpdateConnectedWebClients(); + + _logger.LogInformation("End position reached."); + _connection.SendPointPosition(_pointState); + } } } catch (RpcException) @@ -348,10 +283,10 @@ private async Task UpdateConnectedWebClients() private async Task UpdateWebClient(WebSocket webSocket) { var positions = new Dictionary { - {PointPosition.PointIsInARightHandPositionDefinedEndPosition, "right"}, - {PointPosition.PointIsInALeftHandPositionDefinedEndPosition, "left"}, - {PointPosition.PointIsInNoEndPosition, "noEndPosition"}, - {PointPosition.PointIsTrailed, "trailed"}, + {PointPosition.RIGHT, "right"}, + {PointPosition.LEFT, "left"}, + {PointPosition.NO_ENDPOSITION, "noEndPosition"}, + {PointPosition.TRAILED, "trailed"}, }; var options = new JsonSerializerOptions { WriteIndented = true }; var serializedState = JsonSerializer.Serialize(new From 5adf79e69fd3f5bee8135887eb9a1771d85f1ea4 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 22 Nov 2023 10:27:00 +0100 Subject: [PATCH 04/22] fixes --- .../IPointToInterlockingConnection.cs | 16 +-- src/Point/Point.cs | 25 ++-- .../PointToInterlockingConnectionB4R1Impl.cs | 113 ++++++------------ .../ReportedPointPositionProtoConversion.cs | 20 ++-- src/Point/Services/PointService.cs | 12 +- 5 files changed, 75 insertions(+), 111 deletions(-) diff --git a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs index a4c17df..d3cde12 100644 --- a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs +++ b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -public interface IPointToInterlockingConnection { - void SendPointPosition(IPointState state); +public interface IPointToInterlockingConnection: System.IDisposable { + void SendPointPosition(PointState state); void SendTimeoutMessage(); void Reset(); void Setup(); @@ -9,16 +9,10 @@ public interface IPointToInterlockingConnection { void InitializeConnection(); public Task ReceivePointPosition(); - public interface IMessage + public record PointState { - public IMessage FromBytes(byte[] message); - public abstract byte[] ToByteArray(); - } - - public interface IPointState - { - PointPosition PointPosition { get; set; } - DegradedPointPosition DegradedPointPosition { get; set; } + public PointPosition PointPosition { get; set; } + public DegradedPointPosition DegradedPointPosition { get; set; } } public enum PointPosition diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 29dd806..13be7fa 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -6,7 +6,7 @@ using EulynxLive.Messages.Baseline4R1; using PointPosition = IPointToInterlockingConnection.PointPosition ; using DegradedPointPosition = IPointToInterlockingConnection.DegradedPointPosition; -using IPointState = IPointToInterlockingConnection.IPointState; +using PointState = IPointToInterlockingConnection.PointState; using static Sci.Rasta; using System.Text; using Grpc.Net.Client; @@ -22,21 +22,24 @@ public class Point : BackgroundService private readonly ILogger _logger; private readonly List _webSockets; private readonly PointToInterlockingConnectionB4R1Impl _connection; - private readonly string _localId; - private readonly string _localRastaId; - private readonly string _remoteId; - private readonly string _remoteEndpoint; private readonly Random _random; private readonly bool _simulateRandomTimeouts; private bool _initialized; AsyncDuplexStreamingCall? _currentConnection; - private readonly IPointState _pointState; - public IPointState PointState { get { return _pointState; } } + private readonly PointState _pointState; + public PointState PointState { get { return _pointState; } } public Point(ILogger logger, IConfiguration configuration) { _webSockets = new List(); - _connection = new PointToInterlockingConnectionB4R1Impl(logger, configuration); + using var connection = new PointToInterlockingConnectionB4R1Impl(logger, configuration); + _connection = connection; + _pointState = new PointState() { + PointPosition = PointPosition.NO_ENDPOSITION, + DegradedPointPosition = AllPointMachinesCrucial? DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED + }; + _random = new Random(); + _logger = logger; } public async Task HandleWebSocket(WebSocket webSocket) @@ -191,9 +194,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) while (true) { var commandedPointPosition = await _connection.ReceivePointPosition(); - if (commandedPointPosition != null) + if (commandedPointPosition == null) { - break; + continue; } if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) @@ -245,7 +248,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } } } - catch (RpcException) + catch (RpcException ex) { _logger.LogWarning("Could not communicate with remote endpoint."); } diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index 67561d2..3d92ded 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -47,38 +47,36 @@ public void Connect() } - public async Task InitializeConnection(IPointState state) + public async Task InitializeConnection(PointState state) { - using (_currentConnection = _client.Stream(_metadata, cancellationToken: _timeout.Token)) + _currentConnection = _client.Stream(_metadata, cancellationToken: _timeout.Token); + _logger.LogTrace("Connected. Waiting for request..."); + if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) + || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) { - _logger.LogTrace("Connected. Waiting for request..."); - if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) - || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) - { - _logger.LogError("Unexpected message."); - return 1; - } + _logger.LogError("Unexpected message."); + return 1; + } - var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(versionCheckResponse.ToByteArray()) }); + var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(versionCheckResponse.ToByteArray()) }); - if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) - || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) - { - _logger.LogError("Unexpected message."); - return 1; - } + if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) + || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) + { + _logger.LogError("Unexpected message."); + return 1; + } - var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(startInitialization.ToByteArray()) }); + var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(startInitialization.ToByteArray()) }); - var pointState = new B4R1PointStateImpl(state); - var initialPosition = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(initialPosition.ToByteArray()) }); + var pointState = new B4R1PointStateImpl(state); + var initialPosition = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(initialPosition.ToByteArray()) }); - var completeInitialization = new PointInitialisationCompletedMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(completeInitialization.ToByteArray()) }); - } + var completeInitialization = new PointInitialisationCompletedMessage(_localId, _remoteId); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(completeInitialization.ToByteArray()) }); return 0; } @@ -92,7 +90,7 @@ public void Setup() _metadata = new Metadata { { "rasta-id", _localRastaId } }; } - public async void SendPointPosition(IPointState state) + public async void SendPointPosition(PointState state) { var pointState = new B4R1PointStateImpl(state); var response = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); @@ -117,6 +115,7 @@ async public void SendTimeoutMessage() public async Task ReceivePointPosition() { + if (!await _currentConnection.ResponseStream.MoveNext()) { return null; @@ -131,74 +130,40 @@ async public void SendTimeoutMessage() PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.LEFT, }; } + _logger.LogInformation("Received unknown message {}", message.GetType()); return null; } + + public void Dispose() + { + _currentConnection?.Dispose(); + } } public class B4R1PointStateImpl { - private IPointState _state; + private PointState _state; public PointPointPositionMessageReportedPointPosition PointPosition { get => map(_state.PointPosition); } public PointPointPositionMessageReportedDegradedPointPosition DegradedPointPosition { get => map(_state.DegradedPointPosition); } - public B4R1PointStateImpl(IPointState state){ + public B4R1PointStateImpl(PointState state){ _state = state; } private PointPointPositionMessageReportedPointPosition map(PointPosition value) => value switch { - IPointToInterlockingConnection.PointPosition.LEFT => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, - IPointToInterlockingConnection.PointPosition.RIGHT => PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, - IPointToInterlockingConnection.PointPosition.TRAILED => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, - IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION => PointPointPositionMessageReportedPointPosition.PointIsTrailed, - }; - - private PointPosition map(PointPointPositionMessageReportedPointPosition position) => position switch - { - PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition => IPointToInterlockingConnection.PointPosition.LEFT, - PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => IPointToInterlockingConnection.PointPosition.RIGHT, - PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition => IPointToInterlockingConnection.PointPosition.TRAILED, - PointPointPositionMessageReportedPointPosition.PointIsTrailed => IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION, + IPointToInterlockingConnection.PointPosition.LEFT => PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, + IPointToInterlockingConnection.PointPosition.RIGHT => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, + IPointToInterlockingConnection.PointPosition.TRAILED => PointPointPositionMessageReportedPointPosition.PointIsTrailed, + IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, }; - private PointPointPositionMessageReportedDegradedPointPosition map(DegradedPointPosition value) => value switch { - IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_LEFT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, - IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_RIGHT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_LEFT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_RIGHT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, IPointToInterlockingConnection.DegradedPointPosition.NOT_DEGRADED => PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition, IPointToInterlockingConnection.DegradedPointPosition.NOT_APPLICABLE => PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable, }; - - private DegradedPointPosition map(PointPointPositionMessageReportedDegradedPointPosition degradedPosition) => degradedPosition switch - { - PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition => IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_LEFT, - PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition => IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_RIGHT, - PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition => IPointToInterlockingConnection.DegradedPointPosition.NOT_DEGRADED, - PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable => IPointToInterlockingConnection.DegradedPointPosition.NOT_APPLICABLE, - }; -} - -public class B4R1MessageImpl : IPointToInterlockingConnection.IMessage -{ - private Message _message; - - public B4R1MessageImpl() { } - - public B4R1MessageImpl(Message message) - { - _message = message; - } - public byte[] ToByteArray() - { - throw new System.NotImplementedException(); - } - - public IPointToInterlockingConnection.IMessage FromBytes(byte[] message) => - new B4R1MessageImpl(Message.FromBytes(message)); - } - - - diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index 5d00fcb..8e74886 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -1,6 +1,8 @@ using System; using EulynxLive.Point.Proto; -using ReportedPointPosition = EulynxLive.Messages.Baseline4R1.PointPointPositionMessageReportedPointPosition; + +using ReportedPointPosition = IPointToInterlockingConnection.PointPosition ; +using DegradedPointPosition = IPointToInterlockingConnection.DegradedPointPosition; namespace Point.Services.Extensions { @@ -8,19 +10,19 @@ public static class ReportedPointPositionProtoConversion { public static PointPosition ConvertToProtoMessage(this ReportedPointPosition reportedPointPosition) => reportedPointPosition switch { - ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition => PointPosition.Right, - ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition => PointPosition.Left, - ReportedPointPosition.PointIsInNoEndPosition => PointPosition.NoEndPosition, - ReportedPointPosition.PointIsTrailed => PointPosition.UnintendedPosition, + ReportedPointPosition.RIGHT => PointPosition.Right, + ReportedPointPosition.LEFT => PointPosition.Left, + ReportedPointPosition.NO_ENDPOSITION => PointPosition.NoEndPosition, + ReportedPointPosition.TRAILED => PointPosition.UnintendedPosition, _ => throw new InvalidCastException($"Unable to convert reported point position {reportedPointPosition} to proto enum") }; public static ReportedPointPosition ConvertToReportedPointPosition(this PointPosition pointPositionMessage) => pointPositionMessage switch { - PointPosition.Right => ReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, - PointPosition.Left => ReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, - PointPosition.NoEndPosition => ReportedPointPosition.PointIsInNoEndPosition, - PointPosition.UnintendedPosition => ReportedPointPosition.PointIsTrailed, + PointPosition.Right => ReportedPointPosition.RIGHT, + PointPosition.Left => ReportedPointPosition.LEFT, + PointPosition.NoEndPosition => ReportedPointPosition.NO_ENDPOSITION, + PointPosition.UnintendedPosition => ReportedPointPosition.TRAILED, _ => throw new InvalidCastException($"Unable to convert point position message {pointPositionMessage} to reported point position.") }; } diff --git a/src/Point/Services/PointService.cs b/src/Point/Services/PointService.cs index b60a458..af75c35 100644 --- a/src/Point/Services/PointService.cs +++ b/src/Point/Services/PointService.cs @@ -52,10 +52,10 @@ public override Task EstablishPointMachineState(PointMachineStateMessage throw new InvalidOperationException("Point has only crucial point machines"); } - _point.PointState.AbilityToMove = request.AbilityToMove; - _point.PointState.LastPointPosition = request.LastPointPosition; + // _point.PointState.AbilityToMove = request.AbilityToMove; + // _point.PointState.LastPointPosition = request.LastPointPosition; _point.PointState.PointPosition = request.PointPosition.ConvertToReportedPointPosition(); - _point.PointState.Target = request.Target; + // _point.PointState.Target = request.Target; return Task.FromResult(new Empty()); } @@ -64,11 +64,11 @@ public override Task GetPointMachineState(Empty reques { return Task.FromResult(new PointMachineStateMessage() { - AbilityToMove = _point.PointState.AbilityToMove, + // AbilityToMove = _point.PointState.AbilityToMove, Crucial = _point.AllPointMachinesCrucial ? PointMachineStateMessage.Types.Crucial.Crucial : PointMachineStateMessage.Types.Crucial.NonCrucial, - LastPointPosition = _point.PointState.LastPointPosition, + // LastPointPosition = _point.PointState.LastPointPosition, PointPosition = _point.PointState.PointPosition.ConvertToProtoMessage(), - Target = _point.PointState.Target, + // Target = _point.PointState.Target, }); } } From b88ee222e62e07c1d648dc09808ba9f1d5285fe3 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 22 Nov 2023 11:48:35 +0100 Subject: [PATCH 05/22] more fixes and cleanup --- .../IPointToInterlockingConnection.cs | 4 +- src/Point/Point.cs | 141 +++++++++--------- .../PointToInterlockingConnectionB4R1Impl.cs | 32 ++-- 3 files changed, 84 insertions(+), 93 deletions(-) diff --git a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs index d3cde12..d101942 100644 --- a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs +++ b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs @@ -1,8 +1,8 @@ using System.Threading.Tasks; public interface IPointToInterlockingConnection: System.IDisposable { - void SendPointPosition(PointState state); - void SendTimeoutMessage(); + Task SendPointPosition(PointState state); + Task SendTimeoutMessage(); void Reset(); void Setup(); void Connect(); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 13be7fa..74918f5 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -4,7 +4,7 @@ using Grpc.Core; using Sci; using EulynxLive.Messages.Baseline4R1; -using PointPosition = IPointToInterlockingConnection.PointPosition ; +using PointPosition = IPointToInterlockingConnection.PointPosition; using DegradedPointPosition = IPointToInterlockingConnection.DegradedPointPosition; using PointState = IPointToInterlockingConnection.PointState; using static Sci.Rasta; @@ -20,8 +20,9 @@ public class Point : BackgroundService public bool AllPointMachinesCrucial { get; } private readonly ILogger _logger; + private readonly IConfiguration _configuration; private readonly List _webSockets; - private readonly PointToInterlockingConnectionB4R1Impl _connection; + private PointToInterlockingConnectionB4R1Impl _connection; private readonly Random _random; private readonly bool _simulateRandomTimeouts; private bool _initialized; @@ -32,14 +33,14 @@ public class Point : BackgroundService public Point(ILogger logger, IConfiguration configuration) { _webSockets = new List(); - using var connection = new PointToInterlockingConnectionB4R1Impl(logger, configuration); - _connection = connection; - _pointState = new PointState() { + _pointState = new PointState() + { PointPosition = PointPosition.NO_ENDPOSITION, - DegradedPointPosition = AllPointMachinesCrucial? DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED + DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED }; _random = new Random(); _logger = logger; + _configuration = configuration; } public async Task HandleWebSocket(WebSocket webSocket) @@ -74,7 +75,7 @@ public async Task SimulateUnintendedPosition() if (_currentConnection != null) { - _connection.SendPointPosition(PointState); + await _connection.SendPointPosition(PointState); } await UpdateConnectedWebClients(); @@ -132,7 +133,7 @@ public async Task SetDegraded(PointDegradedMessage message) if (pointPosition != null) { UpdatePointState(pointPosition.Value, degradedPointPosition.Value); - _connection.SendPointPosition(PointState); + await _connection.SendPointPosition(PointState); } } } @@ -177,89 +178,91 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { // Main loop. - while (true) + using (_connection = new PointToInterlockingConnectionB4R1Impl(_logger, _configuration)) { - await Reset(); - try + while (true) { - _connection.Setup(); - - var result = await _connection.InitializeConnection(PointState); - if (result != 0) - { - continue; - } - await UpdateConnectedWebClients(); - - while (true) + _connection.Connect(); + await Reset(); + try { - var commandedPointPosition = await _connection.ReceivePointPosition(); - if (commandedPointPosition == null) + var result = await _connection.InitializeConnection(PointState); + if (result != 0) { continue; } + await UpdateConnectedWebClients(); - if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) - || (commandedPointPosition == PointPosition.RIGHT && _pointState.PointPosition == PointPosition.RIGHT)) + while (true) { - _connection.SendPointPosition(PointState); - continue; - } + var commandedPointPosition = await _connection.ReceivePointPosition(); + if (commandedPointPosition == null) + { + break; + } - UpdatePointState(PointPosition.NO_ENDPOSITION, DegradedPointPosition.NOT_APPLICABLE); + if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) + || (commandedPointPosition == PointPosition.RIGHT && _pointState.PointPosition == PointPosition.RIGHT)) + { + _connection.SendPointPosition(PointState); + continue; + } - await UpdateConnectedWebClients(); + UpdatePointState(PointPosition.NO_ENDPOSITION, DegradedPointPosition.NOT_APPLICABLE); - // Simulate point movement - var transitioningTime = _random.Next(1, 5); - var transitioningTask = Task.Delay(transitioningTime * 1000); - var pointMovementTimeout = 3 * 1000; + await UpdateConnectedWebClients(); - _logger.LogDebug("Moving to {}.", commandedPointPosition); + // Simulate point movement + var transitioningTime = _random.Next(1, 5); + var transitioningTask = Task.Delay(transitioningTime * 1000); + var pointMovementTimeout = 3 * 1000; - if (_simulateRandomTimeouts) - { - if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) + _logger.LogDebug("Moving to {}.", commandedPointPosition); + + if (_simulateRandomTimeouts) + { + if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) + { + // transition completed within timeout + UpdatePointState(commandedPointPosition.Value); + + await UpdateConnectedWebClients(); + + _logger.LogInformation("End position reached."); + await _connection.SendPointPosition(_pointState); + } + else + { + // timeout + _logger.LogInformation("Timeout"); + await _connection.SendTimeoutMessage(); + } + } + else { - // transition completed within timeout + await transitioningTask; UpdatePointState(commandedPointPosition.Value); await UpdateConnectedWebClients(); _logger.LogInformation("End position reached."); - _connection.SendPointPosition(_pointState); - } - else - { - // timeout - _logger.LogInformation("Timeout"); - _connection.SendTimeoutMessage(); + await _connection.SendPointPosition(_pointState); } } - else - { - await transitioningTask; - UpdatePointState(commandedPointPosition.Value); - - await UpdateConnectedWebClients(); - - _logger.LogInformation("End position reached."); - _connection.SendPointPosition(_pointState); - } } - } - catch (RpcException ex) - { - _logger.LogWarning("Could not communicate with remote endpoint."); - } - catch (Exception ex) - { - _logger.LogWarning(ex, "Exception during simulation."); - } - finally - { - await Reset(); - await Task.Delay(1000, stoppingToken); + catch (RpcException ex) + { + _logger.LogWarning("Could not communicate with remote endpoint."); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Exception during simulation."); + } + finally + { + await Reset(); + await Task.Delay(1000, stoppingToken); + } } } } diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index 3d92ded..d125771 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -17,9 +17,6 @@ public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConn private readonly string _remoteId; private readonly string _remoteEndpoint; AsyncDuplexStreamingCall? _currentConnection; - private GrpcChannel _channel; - private RastaClient _client; - private Metadata _metadata; private CancellationTokenSource _timeout; public PointToInterlockingConnectionB4R1Impl( @@ -40,16 +37,22 @@ public PointToInterlockingConnectionB4R1Impl( _localRastaId = config.LocalRastaId.ToString(); _remoteId = config.RemoteId; _remoteEndpoint = config.RemoteEndpoint; + _timeout = new CancellationTokenSource(); } public void Connect() { - + var channel = GrpcChannel.ForAddress(_remoteEndpoint); + var client = new RastaClient(channel); + _logger.LogTrace("Connecting..."); + _timeout = new CancellationTokenSource(); + _timeout.CancelAfter(10000); + var metadata = new Metadata { { "rasta-id", _localRastaId } }; + _currentConnection = client.Stream(metadata, cancellationToken: _timeout.Token); } public async Task InitializeConnection(PointState state) { - _currentConnection = _client.Stream(_metadata, cancellationToken: _timeout.Token); _logger.LogTrace("Connected. Waiting for request..."); if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) @@ -80,34 +83,19 @@ public async Task InitializeConnection(PointState state) return 0; } - public void Setup() - { - _channel = GrpcChannel.ForAddress(_remoteEndpoint); - _client = new RastaClient(_channel); - _logger.LogTrace("Connecting..."); - _timeout = new CancellationTokenSource(); - _timeout.CancelAfter(10000); - _metadata = new Metadata { { "rasta-id", _localRastaId } }; - } - - public async void SendPointPosition(PointState state) + public async Task SendPointPosition(PointState state) { var pointState = new B4R1PointStateImpl(state); var response = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } - public void Reset() - { - - } - void IPointToInterlockingConnection.InitializeConnection() { throw new NotImplementedException(); } - async public void SendTimeoutMessage() + async public Task SendTimeoutMessage() { var response = new PointTimeoutMessage(_localId, _remoteId); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); From cf72809aa66f51891650435c056712a8c7bcc36f Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 22 Nov 2023 11:50:42 +0100 Subject: [PATCH 06/22] clean --- .../Baseline4MessageInterface/IPointToInterlockingConnection.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs index d101942..5c41afd 100644 --- a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs +++ b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs @@ -3,8 +3,6 @@ public interface IPointToInterlockingConnection: System.IDisposable { Task SendPointPosition(PointState state); Task SendTimeoutMessage(); - void Reset(); - void Setup(); void Connect(); void InitializeConnection(); public Task ReceivePointPosition(); From 5b584b85907bfc1cf5860dd4a58de616718ab35a Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 22 Nov 2023 13:28:10 +0100 Subject: [PATCH 07/22] update interface --- .../IPointToInterlockingConnection.cs | 2 +- src/Point/Point.cs | 6 +++--- src/Point/PointToInterlockingConnectionB4R1Impl.cs | 13 ++++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs index 5c41afd..bfaae59 100644 --- a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs +++ b/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs @@ -4,7 +4,7 @@ public interface IPointToInterlockingConnection: System.IDisposable { Task SendPointPosition(PointState state); Task SendTimeoutMessage(); void Connect(); - void InitializeConnection(); + Task InitializeConnection(PointState state); public Task ReceivePointPosition(); public record PointState diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 74918f5..4322b2e 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -22,7 +22,7 @@ public class Point : BackgroundService private readonly ILogger _logger; private readonly IConfiguration _configuration; private readonly List _webSockets; - private PointToInterlockingConnectionB4R1Impl _connection; + private IPointToInterlockingConnection _connection; private readonly Random _random; private readonly bool _simulateRandomTimeouts; private bool _initialized; @@ -186,8 +186,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await Reset(); try { - var result = await _connection.InitializeConnection(PointState); - if (result != 0) + var success = await _connection.InitializeConnection(PointState); + if (!success) { continue; } diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index d125771..6459448 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -51,14 +51,14 @@ public void Connect() _currentConnection = client.Stream(metadata, cancellationToken: _timeout.Token); } - public async Task InitializeConnection(PointState state) + public async Task InitializeConnection(PointState state) { _logger.LogTrace("Connected. Waiting for request..."); if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) { _logger.LogError("Unexpected message."); - return 1; + return false; } var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); @@ -68,7 +68,7 @@ public async Task InitializeConnection(PointState state) || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) { _logger.LogError("Unexpected message."); - return 1; + return false; } var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); @@ -80,7 +80,7 @@ public async Task InitializeConnection(PointState state) var completeInitialization = new PointInitialisationCompletedMessage(_localId, _remoteId); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(completeInitialization.ToByteArray()) }); - return 0; + return true; } public async Task SendPointPosition(PointState state) @@ -90,11 +90,6 @@ public async Task SendPointPosition(PointState state) await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); } - void IPointToInterlockingConnection.InitializeConnection() - { - throw new NotImplementedException(); - } - async public Task SendTimeoutMessage() { var response = new PointTimeoutMessage(_localId, _remoteId); From 5c5c428b1218df54d785112d42fb2c6f1692970f Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 22 Nov 2023 15:57:55 +0100 Subject: [PATCH 08/22] update name space & inject connection into Point --- .../Point/PointTest.cs | 3 +- .../IPointToInterlockingConnection.cs | 2 + src/Point/Point.cs | 135 +++++++++--------- .../PointToInterlockingConnectionB4R1Impl.cs | 9 +- .../PointToInterlockingConnectionMockImpl.cs | 56 ++++++++ .../ReportedPointPositionProtoConversion.cs | 4 +- src/Point/Startup.cs | 10 +- 7 files changed, 136 insertions(+), 83 deletions(-) rename src/Messages/{Baseline4MessageInterface => IPointToInterlockingConnection}/IPointToInterlockingConnection.cs (92%) create mode 100644 src/Point/PointToInterlockingConnectionMockImpl.cs diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index b3d0ac1..44e4448 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -1,5 +1,6 @@ using Castle.Core.Logging; using EulynxLive.Messages.Baseline4R1; +using EulynxLive.Messages.IPointToInterlockingConnection; using EulynxLive.Point; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -24,7 +25,7 @@ public void PointShouldParseConfiguration() .AddInMemoryCollection(testSettings) .Build(); - var point = new EulynxLive.Point.Point(Mock.Of>(), configuration); + var point = new EulynxLive.Point.Point(Mock.Of>(), configuration, Mock.Of()); Assert.True(point.AllPointMachinesCrucial); } diff --git a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs b/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs similarity index 92% rename from src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs rename to src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs index bfaae59..0b543cb 100644 --- a/src/Messages/Baseline4MessageInterface/IPointToInterlockingConnection.cs +++ b/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs @@ -1,5 +1,7 @@ using System.Threading.Tasks; +namespace EulynxLive.Messages.IPointToInterlockingConnection; + public interface IPointToInterlockingConnection: System.IDisposable { Task SendPointPosition(PointState state); Task SendTimeoutMessage(); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 4322b2e..93bb929 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -3,10 +3,10 @@ using Google.Protobuf; using Grpc.Core; using Sci; -using EulynxLive.Messages.Baseline4R1; -using PointPosition = IPointToInterlockingConnection.PointPosition; -using DegradedPointPosition = IPointToInterlockingConnection.DegradedPointPosition; -using PointState = IPointToInterlockingConnection.PointState; +using EulynxLive.Messages.IPointToInterlockingConnection; +using PointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition; +using DegradedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.DegradedPointPosition; +using PointState = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointState; using static Sci.Rasta; using System.Text; using Grpc.Net.Client; @@ -30,7 +30,7 @@ public class Point : BackgroundService private readonly PointState _pointState; public PointState PointState { get { return _pointState; } } - public Point(ILogger logger, IConfiguration configuration) + public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) { _webSockets = new List(); _pointState = new PointState() @@ -41,6 +41,7 @@ public Point(ILogger logger, IConfiguration configuration) _random = new Random(); _logger = logger; _configuration = configuration; + _connection = connection; } public async Task HandleWebSocket(WebSocket webSocket) @@ -177,70 +178,50 @@ public async Task PutInEndPosition() protected override async Task ExecuteAsync(CancellationToken stoppingToken) { // Main loop. - - using (_connection = new PointToInterlockingConnectionB4R1Impl(_logger, _configuration)) + while (true) { - while (true) + _connection.Connect(); + await Reset(); + try { - _connection.Connect(); - await Reset(); - try + var success = await _connection.InitializeConnection(PointState); + if (!success) + { + continue; + } + await UpdateConnectedWebClients(); + + while (true) { - var success = await _connection.InitializeConnection(PointState); - if (!success) + var commandedPointPosition = await _connection.ReceivePointPosition(); + if (commandedPointPosition == null) { - continue; + break; } - await UpdateConnectedWebClients(); - while (true) + if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) + || (commandedPointPosition == PointPosition.RIGHT && _pointState.PointPosition == PointPosition.RIGHT)) { - var commandedPointPosition = await _connection.ReceivePointPosition(); - if (commandedPointPosition == null) - { - break; - } - - if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) - || (commandedPointPosition == PointPosition.RIGHT && _pointState.PointPosition == PointPosition.RIGHT)) - { - _connection.SendPointPosition(PointState); - continue; - } + _connection.SendPointPosition(PointState); + continue; + } - UpdatePointState(PointPosition.NO_ENDPOSITION, DegradedPointPosition.NOT_APPLICABLE); + UpdatePointState(PointPosition.NO_ENDPOSITION, DegradedPointPosition.NOT_APPLICABLE); - await UpdateConnectedWebClients(); + await UpdateConnectedWebClients(); - // Simulate point movement - var transitioningTime = _random.Next(1, 5); - var transitioningTask = Task.Delay(transitioningTime * 1000); - var pointMovementTimeout = 3 * 1000; + // Simulate point movement + var transitioningTime = _random.Next(1, 5); + var transitioningTask = Task.Delay(transitioningTime * 1000); + var pointMovementTimeout = 3 * 1000; - _logger.LogDebug("Moving to {}.", commandedPointPosition); + _logger.LogDebug("Moving to {}.", commandedPointPosition); - if (_simulateRandomTimeouts) - { - if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) - { - // transition completed within timeout - UpdatePointState(commandedPointPosition.Value); - - await UpdateConnectedWebClients(); - - _logger.LogInformation("End position reached."); - await _connection.SendPointPosition(_pointState); - } - else - { - // timeout - _logger.LogInformation("Timeout"); - await _connection.SendTimeoutMessage(); - } - } - else + if (_simulateRandomTimeouts) + { + if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) { - await transitioningTask; + // transition completed within timeout UpdatePointState(commandedPointPosition.Value); await UpdateConnectedWebClients(); @@ -248,21 +229,37 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) _logger.LogInformation("End position reached."); await _connection.SendPointPosition(_pointState); } + else + { + // timeout + _logger.LogInformation("Timeout"); + await _connection.SendTimeoutMessage(); + } + } + else + { + await transitioningTask; + UpdatePointState(commandedPointPosition.Value); + + await UpdateConnectedWebClients(); + + _logger.LogInformation("End position reached."); + await _connection.SendPointPosition(_pointState); } } - catch (RpcException ex) - { - _logger.LogWarning("Could not communicate with remote endpoint."); - } - catch (Exception ex) - { - _logger.LogWarning(ex, "Exception during simulation."); - } - finally - { - await Reset(); - await Task.Delay(1000, stoppingToken); - } + } + catch (RpcException ex) + { + _logger.LogWarning("Could not communicate with remote endpoint."); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Exception during simulation."); + } + finally + { + await Reset(); + await Task.Delay(1000, stoppingToken); } } } diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index 6459448..1801443 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -5,13 +5,14 @@ using Grpc.Core; using Grpc.Net.Client; using Sci; -using static IPointToInterlockingConnection; +using EulynxLive.Messages.IPointToInterlockingConnection; +using static EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection; using static Sci.Rasta; -public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConnection +public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConnection { public bool AllPointMachinesCrucial { get; } - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly string _localId; private readonly string _localRastaId; private readonly string _remoteId; @@ -20,7 +21,7 @@ public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConn private CancellationTokenSource _timeout; public PointToInterlockingConnectionB4R1Impl( - ILogger logger, + ILogger logger, IConfiguration configuration) { _logger = logger; diff --git a/src/Point/PointToInterlockingConnectionMockImpl.cs b/src/Point/PointToInterlockingConnectionMockImpl.cs new file mode 100644 index 0000000..91c22ec --- /dev/null +++ b/src/Point/PointToInterlockingConnectionMockImpl.cs @@ -0,0 +1,56 @@ +using System.Diagnostics; +using EulynxLive.Point.Proto; +using EulynxLive.Messages.IPointToInterlockingConnection; +using PointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition; + +class PointToInterlockingConnectionMockImpl : IPointToInterlockingConnection +{ + private readonly ILogger _logger; + int _timeoutS = 3; + Stopwatch _sw = new Stopwatch(); + PointPosition commandedPosition = PointPosition.RIGHT; + + public PointToInterlockingConnectionMockImpl(ILogger logger) + { + _logger = logger; + } + + public void Connect() { } + + public void Dispose() { } + + async public Task InitializeConnection(IPointToInterlockingConnection.PointState state) + { + _sw = Stopwatch.StartNew(); + await Task.Delay(1000); + return true; + } + + async public Task ReceivePointPosition() + { + await Task.Delay(1000); + if (_sw.Elapsed.TotalSeconds >= _timeoutS) + { + _sw = Stopwatch.StartNew(); + commandedPosition = commandedPosition switch + { + PointPosition.RIGHT => PointPosition.LEFT, + PointPosition.LEFT => PointPosition.RIGHT, + PointPosition.NO_ENDPOSITION => throw new NotImplementedException(), + PointPosition.TRAILED => throw new NotImplementedException(), + }; + return commandedPosition; + } + return null; + } + + async public Task SendPointPosition(IPointToInterlockingConnection.PointState state) + { + await Task.Delay(1000); + } + + async public Task SendTimeoutMessage() + { + await Task.Delay(1000); + } +} diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index 8e74886..f4f1e36 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -1,8 +1,8 @@ using System; using EulynxLive.Point.Proto; -using ReportedPointPosition = IPointToInterlockingConnection.PointPosition ; -using DegradedPointPosition = IPointToInterlockingConnection.DegradedPointPosition; +using ReportedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition ; +using DegradedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.DegradedPointPosition; namespace Point.Services.Extensions { diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index 4fb6601..72d1383 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -1,12 +1,6 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using EulynxLive.Point.Services; -using EulynxLive.Point.Components; -using System; +using EulynxLive.Messages.IPointToInterlockingConnection; namespace EulynxLive.Point { @@ -26,6 +20,8 @@ public void ConfigureServices(IServiceCollection services) services.AddGrpc(); services.AddGrpcReflection(); + services.AddSingleton(); + // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { From 9f4ac9482748cfb34065f4ef2f8392023593d0cb Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Fri, 24 Nov 2023 10:14:02 +0100 Subject: [PATCH 09/22] tmp remove faulty message definitions --- .../InterfaceSpecificationSciCc.cs | 6 - .../InterfaceSpecificationSciGeneric.cs | 2535 ----------------- .../InterfaceSpecificationSciIls.cs | 872 ------ .../InterfaceSpecificationSciIo.cs | 6 - .../InterfaceSpecificationSciLc.cs | 31 - .../InterfaceSpecificationSciLs.cs | 71 - .../InterfaceSpecificationSciLx.cs | 31 - .../Baseline4R2/InterfaceSpecificationSciP.cs | 139 - .../InterfaceSpecificationSciRbc.cs | 6 - .../InterfaceSpecificationSciTds.cs | 311 -- src/Messages/Baseline4R2/Message.cs | 178 -- 11 files changed, 4186 deletions(-) delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs delete mode 100644 src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs delete mode 100644 src/Messages/Baseline4R2/Message.cs diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs deleted file mode 100644 index 088e721..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciCc.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs deleted file mode 100644 index df2e861..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciGeneric.cs +++ /dev/null @@ -1,2535 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record AdjacentInterlockingSystemPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static AdjacentInterlockingSystemPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new AdjacentInterlockingSystemPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record TrainDetectionSystemPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static TrainDetectionSystemPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new TrainDetectionSystemPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record LightSignalPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static LightSignalPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new LightSignalPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record PointPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static PointPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new PointPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record RadioBlockCenterPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static RadioBlockCenterPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new RadioBlockCenterPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record LevelCrossingPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static LevelCrossingPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new LevelCrossingPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record CCPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static CCPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new CCPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record GenericIOPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static GenericIOPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new GenericIOPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - -public record ExternalLevelCrossingSystemPdiVersionCheckCommand (string SenderIdentifier, string ReceiverIdentifier, byte PdiVersionOfSender) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int PdiVersionOfSenderOffset = 43; - public static readonly ushort MessageType = 0x0024; - - public new static ExternalLevelCrossingSystemPdiVersionCheckCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var PdiVersionOfSender = (byte)message[PdiVersionOfSenderOffset]; - return new ExternalLevelCrossingSystemPdiVersionCheckCommand(SenderIdentifier, ReceiverIdentifier, PdiVersionOfSender); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[PdiVersionOfSenderOffset] = (byte)PdiVersionOfSender; - return result; - } -} - - - - -public record AdjacentInterlockingSystemInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static AdjacentInterlockingSystemInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static TrainDetectionSystemInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static LightSignalInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static PointInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static RadioBlockCenterInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static LevelCrossingInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static CCInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static GenericIOInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemInitialisationRequestCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0021; - - public new static ExternalLevelCrossingSystemInitialisationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemInitialisationRequestCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static AdjacentInterlockingSystemStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static TrainDetectionSystemStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static LightSignalStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static PointStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static RadioBlockCenterStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static LevelCrossingStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static CCStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static GenericIOStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemStartInitialisationMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0022; - - public new static ExternalLevelCrossingSystemStartInitialisationMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemStartInitialisationMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static AdjacentInterlockingSystemStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static TrainDetectionSystemStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static LightSignalStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static PointStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static RadioBlockCenterStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static LevelCrossingStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static CCStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static GenericIOStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemStatusReportCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0026; - - public new static ExternalLevelCrossingSystemStatusReportCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemStatusReportCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static AdjacentInterlockingSystemInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static TrainDetectionSystemInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static LightSignalInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static PointInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static RadioBlockCenterInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static LevelCrossingInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static CCInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static GenericIOInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemInitialisationCompletedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0023; - - public new static ExternalLevelCrossingSystemInitialisationCompletedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemInitialisationCompletedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, AdjacentInterlockingSystemClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static AdjacentInterlockingSystemClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (AdjacentInterlockingSystemClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new AdjacentInterlockingSystemClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum AdjacentInterlockingSystemClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record TrainDetectionSystemClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static TrainDetectionSystemClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (TrainDetectionSystemClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new TrainDetectionSystemClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum TrainDetectionSystemClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record LightSignalClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, LightSignalClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static LightSignalClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (LightSignalClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new LightSignalClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum LightSignalClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record PointClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, PointClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static PointClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (PointClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new PointClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum PointClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record RadioBlockCenterClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, RadioBlockCenterClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static RadioBlockCenterClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (RadioBlockCenterClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new RadioBlockCenterClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum RadioBlockCenterClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record LevelCrossingClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, LevelCrossingClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static LevelCrossingClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (LevelCrossingClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new LevelCrossingClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum LevelCrossingClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record CCClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, CCClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static CCClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (CCClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new CCClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum CCClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record GenericIOClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, GenericIOClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static GenericIOClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (GenericIOClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new GenericIOClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum GenericIOClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record ExternalLevelCrossingSystemClosePdiCommand (string SenderIdentifier, string ReceiverIdentifier, ExternalLevelCrossingSystemClosePdiCommandCloseReason CloseReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CloseReasonOffset = 43; - public static readonly ushort MessageType = 0x0027; - - public new static ExternalLevelCrossingSystemClosePdiCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CloseReason = (ExternalLevelCrossingSystemClosePdiCommandCloseReason)message[CloseReasonOffset]; - return new ExternalLevelCrossingSystemClosePdiCommand(SenderIdentifier, ReceiverIdentifier, CloseReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CloseReasonOffset] = (byte)CloseReason; - return result; - } -} - -public enum ExternalLevelCrossingSystemClosePdiCommandCloseReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03, - NormalClose = 0x04, - OtherVersionRequired = 0x05, - Timeout = 0x06, - ChecksumMismatch = 0x07 -} - -public record AdjacentInterlockingSystemReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static AdjacentInterlockingSystemReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static TrainDetectionSystemReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static LightSignalReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static PointReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static RadioBlockCenterReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static LevelCrossingReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static CCReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static GenericIOReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0028; - - public new static ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static AdjacentInterlockingSystemPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static TrainDetectionSystemPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static LightSignalPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static PointPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static RadioBlockCenterPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static LevelCrossingPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static CCPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static GenericIOPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemPdiAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0029; - - public new static ExternalLevelCrossingSystemPdiAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemPdiAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static AdjacentInterlockingSystemPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new AdjacentInterlockingSystemPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static TrainDetectionSystemPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LightSignalPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static LightSignalPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LightSignalPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static PointPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record RadioBlockCenterPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static RadioBlockCenterPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new RadioBlockCenterPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record LevelCrossingPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static LevelCrossingPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record CCPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static CCPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new CCPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record GenericIOPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static GenericIOPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new GenericIOPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record ExternalLevelCrossingSystemPdiNotAvailableMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x002A; - - public new static ExternalLevelCrossingSystemPdiNotAvailableMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemPdiNotAvailableMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, AdjacentInterlockingSystemResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static AdjacentInterlockingSystemResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (AdjacentInterlockingSystemResetPdiMessageResetReason)message[ResetReasonOffset]; - return new AdjacentInterlockingSystemResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum AdjacentInterlockingSystemResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record TrainDetectionSystemResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static TrainDetectionSystemResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (TrainDetectionSystemResetPdiMessageResetReason)message[ResetReasonOffset]; - return new TrainDetectionSystemResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum TrainDetectionSystemResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record LightSignalResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, LightSignalResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static LightSignalResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (LightSignalResetPdiMessageResetReason)message[ResetReasonOffset]; - return new LightSignalResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum LightSignalResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record PointResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, PointResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static PointResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (PointResetPdiMessageResetReason)message[ResetReasonOffset]; - return new PointResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum PointResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record RadioBlockCenterResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, RadioBlockCenterResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static RadioBlockCenterResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (RadioBlockCenterResetPdiMessageResetReason)message[ResetReasonOffset]; - return new RadioBlockCenterResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.RadioBlockCenter; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum RadioBlockCenterResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record LevelCrossingResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, LevelCrossingResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static LevelCrossingResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (LevelCrossingResetPdiMessageResetReason)message[ResetReasonOffset]; - return new LevelCrossingResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum LevelCrossingResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record CCResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, CCResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static CCResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (CCResetPdiMessageResetReason)message[ResetReasonOffset]; - return new CCResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.CC; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum CCResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record GenericIOResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, GenericIOResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static GenericIOResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (GenericIOResetPdiMessageResetReason)message[ResetReasonOffset]; - return new GenericIOResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.GenericIO; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum GenericIOResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} - -public record ExternalLevelCrossingSystemResetPdiMessage (string SenderIdentifier, string ReceiverIdentifier, ExternalLevelCrossingSystemResetPdiMessageResetReason ResetReason) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ResetReasonOffset = 43; - public static readonly ushort MessageType = 0x002B; - - public new static ExternalLevelCrossingSystemResetPdiMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ResetReason = (ExternalLevelCrossingSystemResetPdiMessageResetReason)message[ResetReasonOffset]; - return new ExternalLevelCrossingSystemResetPdiMessage(SenderIdentifier, ReceiverIdentifier, ResetReason); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ResetReasonOffset] = (byte)ResetReason; - return result; - } -} - -public enum ExternalLevelCrossingSystemResetPdiMessageResetReason : byte { - ProtocolError = 0x01, - FormalTelegramError = 0x02, - ContentTelegramError = 0x03 -} diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs deleted file mode 100644 index af08c20..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciIls.cs +++ /dev/null @@ -1,872 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record AdjacentInterlockingSystemActivationZoneStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string ActivationZoneId, AdjacentInterlockingSystemActivationZoneStatusMessageActivationZoneStatus ActivationZoneStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int ActivationZoneIdOffset = 63; - private const int ActivationZoneStatusOffset = 83; - public static readonly ushort MessageType = 0x0001; - - public new static AdjacentInterlockingSystemActivationZoneStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var ActivationZoneId = Encoding.Latin1.GetString(message, ActivationZoneIdOffset, 20); - var ActivationZoneStatus = (AdjacentInterlockingSystemActivationZoneStatusMessageActivationZoneStatus)message[ActivationZoneStatusOffset]; - return new AdjacentInterlockingSystemActivationZoneStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, ActivationZoneId, ActivationZoneStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[84]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(ActivationZoneId.PadRight(20, '_')).CopyTo(result, ActivationZoneIdOffset); - result[ActivationZoneStatusOffset] = (byte)ActivationZoneStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemActivationZoneStatusMessageActivationZoneStatus : byte { - Active = 0x01, - NotActive = 0x02 -} - -public record AdjacentInterlockingSystemApproachZoneStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string ApproachZoneId, AdjacentInterlockingSystemApproachZoneStatusMessageApproachZoneStatus ApproachZoneStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int ApproachZoneIdOffset = 63; - private const int ApproachZoneStatusOffset = 83; - public static readonly ushort MessageType = 0x0002; - - public new static AdjacentInterlockingSystemApproachZoneStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var ApproachZoneId = Encoding.Latin1.GetString(message, ApproachZoneIdOffset, 20); - var ApproachZoneStatus = (AdjacentInterlockingSystemApproachZoneStatusMessageApproachZoneStatus)message[ApproachZoneStatusOffset]; - return new AdjacentInterlockingSystemApproachZoneStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, ApproachZoneId, ApproachZoneStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[84]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(ApproachZoneId.PadRight(20, '_')).CopyTo(result, ApproachZoneIdOffset); - result[ApproachZoneStatusOffset] = (byte)ApproachZoneStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemApproachZoneStatusMessageApproachZoneStatus : byte { - Active = 0x01, - NotActive = 0x02 -} - -public record AdjacentInterlockingSystemAccessRestrictionRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemAccessRestrictionRequestCommandAccessRestrictionType AccessRestrictionType) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int AccessRestrictionTypeOffset = 63; - public static readonly ushort MessageType = 0x0003; - - public new static AdjacentInterlockingSystemAccessRestrictionRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var AccessRestrictionType = (AdjacentInterlockingSystemAccessRestrictionRequestCommandAccessRestrictionType)message[AccessRestrictionTypeOffset]; - return new AdjacentInterlockingSystemAccessRestrictionRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, AccessRestrictionType); - } - - public override byte[] ToByteArray() { - var result = new byte[64]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[AccessRestrictionTypeOffset] = (byte)AccessRestrictionType; - return result; - } -} - -public enum AdjacentInterlockingSystemAccessRestrictionRequestCommandAccessRestrictionType : byte { - NoAccess = 0x01, - WorkTrack = 0x02, - TrackOutOfService = 0x03, - EmergencyTrain = 0x04, - SecondaryVehicle = 0x05, - WorkTeam = 0x06, - LevelCrossingInDegradedOperation = 0x07, - ClearanceCheckRequired = 0x08, - SectionCheckRequired = 0x09, - NoElectricTrains = 0x10, - ExtraordinaryTransport = 0x11, - CatenaryOffPantographDown = 0x12, - WrittenOrderRequired = 0x13, - AccessRestrictionTypeNotApplicable = 0xFF -} - -public record AdjacentInterlockingSystemAccessRestrictionStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionActivationStatus AccessRestrictionActivationStatus, AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionType AccessRestrictionType) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int AccessRestrictionActivationStatusOffset = 63; - private const int AccessRestrictionTypeOffset = 64; - public static readonly ushort MessageType = 0x0012; - - public new static AdjacentInterlockingSystemAccessRestrictionStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var AccessRestrictionActivationStatus = (AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionActivationStatus)message[AccessRestrictionActivationStatusOffset]; - var AccessRestrictionType = (AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionType)message[AccessRestrictionTypeOffset]; - return new AdjacentInterlockingSystemAccessRestrictionStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, AccessRestrictionActivationStatus, AccessRestrictionType); - } - - public override byte[] ToByteArray() { - var result = new byte[65]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[AccessRestrictionActivationStatusOffset] = (byte)AccessRestrictionActivationStatus; - result[AccessRestrictionTypeOffset] = (byte)AccessRestrictionType; - return result; - } -} - -public enum AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionActivationStatus : byte { - Active = 0x01, - NotActive = 0x02 -} - -public enum AdjacentInterlockingSystemAccessRestrictionStatusMessageAccessRestrictionType : byte { - NoAccess = 0x01, - WorkTrack = 0x02, - TrackOutOfService = 0x03, - EmergencyTrain = 0x04, - SecondaryVehicle = 0x05, - WorkTeam = 0x06, - LevelCrossingInDegradedOperation = 0x07, - ClearanceCheckRequired = 0x08, - SectionCheckRequired = 0x09, - NoElectricTrains = 0x10, - ExtraordinaryTransport = 0x11, - CatenaryOffPantographDown = 0x12, - WrittenOrderRequired = 0x13, - ManualRouteCondition = 0x14, - DoNotUseOppositeDirection = 0x15, - UseOppositeDirection = 0x16, - NoLxRemoteSupervision = 0x17, - LxRemoteSupervisionTimeout = 0x18, - AccessRestrictionTypeNotApplicable = 0xFF -} - -public record AdjacentInterlockingSystemLineStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemLineStatusMessageLineStatus LineStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int LineStatusOffset = 63; - public static readonly ushort MessageType = 0x0004; - - public new static AdjacentInterlockingSystemLineStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var LineStatus = (AdjacentInterlockingSystemLineStatusMessageLineStatus)message[LineStatusOffset]; - return new AdjacentInterlockingSystemLineStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, LineStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[64]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[LineStatusOffset] = (byte)LineStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemLineStatusMessageLineStatus : byte { - Vacant = 0x01, - Occupied = 0x02, - RequestForLineBlockReset = 0x03 -} - -public record AdjacentInterlockingSystemFlankProtectionRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemFlankProtectionRequestCommandFlankProtectionRequestType FlankProtectionRequestType) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int FlankProtectionRequestTypeOffset = 63; - public static readonly ushort MessageType = 0x0005; - - public new static AdjacentInterlockingSystemFlankProtectionRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var FlankProtectionRequestType = (AdjacentInterlockingSystemFlankProtectionRequestCommandFlankProtectionRequestType)message[FlankProtectionRequestTypeOffset]; - return new AdjacentInterlockingSystemFlankProtectionRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, FlankProtectionRequestType); - } - - public override byte[] ToByteArray() { - var result = new byte[64]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[FlankProtectionRequestTypeOffset] = (byte)FlankProtectionRequestType; - return result; - } -} - -public enum AdjacentInterlockingSystemFlankProtectionRequestCommandFlankProtectionRequestType : byte { - Provision = 0x01, - Cancellation = 0x02 -} - -public record AdjacentInterlockingSystemFlankProtectionStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemFlankProtectionStatusMessageFlankProtectionStatus FlankProtectionStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int FlankProtectionStatusOffset = 63; - public static readonly ushort MessageType = 0x0013; - - public new static AdjacentInterlockingSystemFlankProtectionStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var FlankProtectionStatus = (AdjacentInterlockingSystemFlankProtectionStatusMessageFlankProtectionStatus)message[FlankProtectionStatusOffset]; - return new AdjacentInterlockingSystemFlankProtectionStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, FlankProtectionStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[64]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[FlankProtectionStatusOffset] = (byte)FlankProtectionStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemFlankProtectionStatusMessageFlankProtectionStatus : byte { - Provided = 0x01, - NotProvided = 0x02 -} - -public record AdjacentInterlockingSystemRouteRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRouteRequestCommandRouteType RouteType) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - private const int RouteTypeOffset = 83; - public static readonly ushort MessageType = 0x0007; - - public new static AdjacentInterlockingSystemRouteRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - var RouteType = (AdjacentInterlockingSystemRouteRequestCommandRouteType)message[RouteTypeOffset]; - return new AdjacentInterlockingSystemRouteRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType); - } - - public override byte[] ToByteArray() { - var result = new byte[84]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - result[RouteTypeOffset] = (byte)RouteType; - return result; - } -} - -public enum AdjacentInterlockingSystemRouteRequestCommandRouteType : byte { - MainRoute = 0x01, - ShuntingRoute = 0x02, - OnSightRoute = 0x03, - SrTrainRoute = 0x04, - SpecialTrainRoute = 0x05, - TemporaryShuntingArea = 0x06 -} - -public record AdjacentInterlockingSystemRouteStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRouteStatusMessageRouteType RouteType, AdjacentInterlockingSystemRouteStatusMessageRouteStatus RouteStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - private const int RouteTypeOffset = 83; - private const int RouteStatusOffset = 84; - public static readonly ushort MessageType = 0x0008; - - public new static AdjacentInterlockingSystemRouteStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - var RouteType = (AdjacentInterlockingSystemRouteStatusMessageRouteType)message[RouteTypeOffset]; - var RouteStatus = (AdjacentInterlockingSystemRouteStatusMessageRouteStatus)message[RouteStatusOffset]; - return new AdjacentInterlockingSystemRouteStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType, RouteStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[85]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - result[RouteTypeOffset] = (byte)RouteType; - result[RouteStatusOffset] = (byte)RouteStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemRouteStatusMessageRouteType : byte { - MainRoute = 0x01, - ShuntingRoute = 0x02, - OnSightRoute = 0x03, - SrTrainRoute = 0x04, - SpecialTrainRoute = 0x05, - TemporaryShuntingArea = 0x06 -} - -public enum AdjacentInterlockingSystemRouteStatusMessageRouteStatus : byte { - Initiated = 0x01, - Locked = 0x02, - NoRoute = 0x03, - Cancelling = 0x04 -} - -public record AdjacentInterlockingSystemRouteMonitoringStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteType RouteType, string OverlapId, AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteMonitoring RouteMonitoring, AdjacentInterlockingSystemRouteMonitoringStatusMessageOccupancyMonitoring OccupancyMonitoring, AdjacentInterlockingSystemRouteMonitoringStatusMessageLevelCrossingMonitoring LevelCrossingMonitoring, byte EntranceSpeed, byte TargetSpeed, AdjacentInterlockingSystemRouteMonitoringStatusMessageDynamicOrStaticTargetSpeed DynamicOrStaticTargetSpeed) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - private const int RouteTypeOffset = 83; - private const int OverlapIdOffset = 84; - private const int RouteMonitoringOffset = 104; - private const int OccupancyMonitoringOffset = 105; - private const int LevelCrossingMonitoringOffset = 106; - private const int EntranceSpeedOffset = 107; - private const int TargetSpeedOffset = 108; - private const int DynamicOrStaticTargetSpeedOffset = 109; - public static readonly ushort MessageType = 0x0009; - - public new static AdjacentInterlockingSystemRouteMonitoringStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - var RouteType = (AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteType)message[RouteTypeOffset]; - var OverlapId = Encoding.Latin1.GetString(message, OverlapIdOffset, 20); - var RouteMonitoring = (AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteMonitoring)message[RouteMonitoringOffset]; - var OccupancyMonitoring = (AdjacentInterlockingSystemRouteMonitoringStatusMessageOccupancyMonitoring)message[OccupancyMonitoringOffset]; - var LevelCrossingMonitoring = (AdjacentInterlockingSystemRouteMonitoringStatusMessageLevelCrossingMonitoring)message[LevelCrossingMonitoringOffset]; - var EntranceSpeed = (byte)message[EntranceSpeedOffset]; - var TargetSpeed = (byte)message[TargetSpeedOffset]; - var DynamicOrStaticTargetSpeed = (AdjacentInterlockingSystemRouteMonitoringStatusMessageDynamicOrStaticTargetSpeed)message[DynamicOrStaticTargetSpeedOffset]; - return new AdjacentInterlockingSystemRouteMonitoringStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType, OverlapId, RouteMonitoring, OccupancyMonitoring, LevelCrossingMonitoring, EntranceSpeed, TargetSpeed, DynamicOrStaticTargetSpeed); - } - - public override byte[] ToByteArray() { - var result = new byte[110]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - result[RouteTypeOffset] = (byte)RouteType; - Encoding.Latin1.GetBytes(OverlapId.PadRight(20, '_')).CopyTo(result, OverlapIdOffset); - result[RouteMonitoringOffset] = (byte)RouteMonitoring; - result[OccupancyMonitoringOffset] = (byte)OccupancyMonitoring; - result[LevelCrossingMonitoringOffset] = (byte)LevelCrossingMonitoring; - result[EntranceSpeedOffset] = (byte)EntranceSpeed; - result[TargetSpeedOffset] = (byte)TargetSpeed; - result[DynamicOrStaticTargetSpeedOffset] = (byte)DynamicOrStaticTargetSpeed; - return result; - } -} - -public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteType : byte { - MainRoute = 0x01, - ShuntingRoute = 0x02, - OnSightRoute = 0x03, - SrTrainRoute = 0x04, - SpecialTrainRoute = 0x05, - TemporaryShuntingArea = 0x06 -} - -public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageRouteMonitoring : byte { - RouteMonitoringConditionsOfSecondaryRoutePresent = 0x01, - RouteMonitoringConditionsOfSecondaryRouteNotPresent = 0x02, - RouteMonitoringConditionsOfSecondaryRoutePresentUpToNextBlockIndicator = 0x03, - ShuntingRouteMonitoringConditionsOfSecondaryRoutePresent = 0x04 -} - -public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageOccupancyMonitoring : byte { - Occupation = 0x01, - NoOccupation = 0x02, - OccupancyMonitoringNotApplicable = 0xFF -} - -public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageLevelCrossingMonitoring : byte { - LevelCrossingMonitoringConditionsOfSecondaryRoutePresent = 0x01, - LevelCrossingMonitoringConditionsOfSecondaryRouteNotPresent = 0x02, - LevelCrossingMonitoringConditionsPresentUpToNextBlockIndicator = 0x03, - LevelCrossingMonitoringNotApplicable = 0xFF -} - -public enum AdjacentInterlockingSystemRouteMonitoringStatusMessageDynamicOrStaticTargetSpeed : byte { - Dynamic = 0x01, - Static = 0x02, - DynamicOrStaticTargetSpeedNotApplicable = 0xFF -} - -public record AdjacentInterlockingSystemRouteCancellationRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - public static readonly ushort MessageType = 0x000A; - - public new static AdjacentInterlockingSystemRouteCancellationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - return new AdjacentInterlockingSystemRouteCancellationRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId); - } - - public override byte[] ToByteArray() { - var result = new byte[83]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessageTrainOperatedRouteReleaseStatus TrainOperatedRouteReleaseStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int TrainOperatedRouteReleaseStatusOffset = 63; - public static readonly ushort MessageType = 0x000B; - - public new static AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var TrainOperatedRouteReleaseStatus = (AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessageTrainOperatedRouteReleaseStatus)message[TrainOperatedRouteReleaseStatusOffset]; - return new AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, TrainOperatedRouteReleaseStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[64]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[TrainOperatedRouteReleaseStatusOffset] = (byte)TrainOperatedRouteReleaseStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessageTrainOperatedRouteReleaseStatus : byte { - TvpsAdjacentToTheBoundaryIsInACorrectOccupancySequence = 0x01, - TvpsAdjacentToTheBoundaryIsReleasedByTrain = 0x02, - TvpsAdjacentToTheBoundaryIsNotInACorrectOccupancySequenceAndNotReleasedByTrain = 0x03 -} - -public record AdjacentInterlockingSystemSignalStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, byte AspectLampCombinations, byte AspectExtensionLampCombinations, byte SpeedIndicator, byte SpeedIndicatorAnnouncement, byte DirectionIndicator, byte DirectionIndicatorAnnouncement, AdjacentInterlockingSystemSignalStatusMessageIntentionallyDark IntentionallyDark) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int AspectLampCombinationsOffset = 63; - private const int AspectExtensionLampCombinationsOffset = 64; - private const int SpeedIndicatorOffset = 65; - private const int SpeedIndicatorAnnouncementOffset = 66; - private const int DirectionIndicatorOffset = 67; - private const int DirectionIndicatorAnnouncementOffset = 68; - private const int IntentionallyDarkOffset = 69; - public static readonly ushort MessageType = 0x000C; - - public new static AdjacentInterlockingSystemSignalStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var AspectLampCombinations = (byte)message[AspectLampCombinationsOffset]; - var AspectExtensionLampCombinations = (byte)message[AspectExtensionLampCombinationsOffset]; - var SpeedIndicator = (byte)message[SpeedIndicatorOffset]; - var SpeedIndicatorAnnouncement = (byte)message[SpeedIndicatorAnnouncementOffset]; - var DirectionIndicator = (byte)message[DirectionIndicatorOffset]; - var DirectionIndicatorAnnouncement = (byte)message[DirectionIndicatorAnnouncementOffset]; - var IntentionallyDark = (AdjacentInterlockingSystemSignalStatusMessageIntentionallyDark)message[IntentionallyDarkOffset]; - return new AdjacentInterlockingSystemSignalStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, AspectLampCombinations, AspectExtensionLampCombinations, SpeedIndicator, SpeedIndicatorAnnouncement, DirectionIndicator, DirectionIndicatorAnnouncement, IntentionallyDark); - } - - public override byte[] ToByteArray() { - var result = new byte[70]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[AspectLampCombinationsOffset] = (byte)AspectLampCombinations; - result[AspectExtensionLampCombinationsOffset] = (byte)AspectExtensionLampCombinations; - result[SpeedIndicatorOffset] = (byte)SpeedIndicator; - result[SpeedIndicatorAnnouncementOffset] = (byte)SpeedIndicatorAnnouncement; - result[DirectionIndicatorOffset] = (byte)DirectionIndicator; - result[DirectionIndicatorAnnouncementOffset] = (byte)DirectionIndicatorAnnouncement; - result[IntentionallyDarkOffset] = (byte)IntentionallyDark; - return result; - } -} - -public enum AdjacentInterlockingSystemSignalStatusMessageIntentionallyDark : byte { - TheCommandedSignalAspectIsIndicatedInTheSetLuminosity = 0x01, - TheCommandedSignalAspectIsIndicatedDark = 0x0F, - IntentionallyDarkNotApplicable = 0xFF -} - -public record AdjacentInterlockingSystemTvpsStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemTvpsStatusMessageOccupancyStatus OccupancyStatus, AdjacentInterlockingSystemTvpsStatusMessageFoulingStatus FoulingStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int OccupancyStatusOffset = 63; - private const int FoulingStatusOffset = 64; - public static readonly ushort MessageType = 0x000D; - - public new static AdjacentInterlockingSystemTvpsStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var OccupancyStatus = (AdjacentInterlockingSystemTvpsStatusMessageOccupancyStatus)message[OccupancyStatusOffset]; - var FoulingStatus = (AdjacentInterlockingSystemTvpsStatusMessageFoulingStatus)message[FoulingStatusOffset]; - return new AdjacentInterlockingSystemTvpsStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, OccupancyStatus, FoulingStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[65]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[OccupancyStatusOffset] = (byte)OccupancyStatus; - result[FoulingStatusOffset] = (byte)FoulingStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemTvpsStatusMessageOccupancyStatus : byte { - Vacant = 0x01, - Occupied = 0x02, - Disturbed = 0x03 -} - -public enum AdjacentInterlockingSystemTvpsStatusMessageFoulingStatus : byte { - Fouling = 0x01, - NotFouling = 0x02, - FoulingStatusNotApplicable = 0xFF -} - -public record AdjacentInterlockingSystemOppositeMainSignalStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - public static readonly ushort MessageType = 0x000E; - - public new static AdjacentInterlockingSystemOppositeMainSignalStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - return new AdjacentInterlockingSystemOppositeMainSignalStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId); - } - - public override byte[] ToByteArray() { - var result = new byte[63]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemRoutePretestRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRoutePretestRequestCommandRouteType RouteType) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - private const int RouteTypeOffset = 83; - public static readonly ushort MessageType = 0x000F; - - public new static AdjacentInterlockingSystemRoutePretestRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - var RouteType = (AdjacentInterlockingSystemRoutePretestRequestCommandRouteType)message[RouteTypeOffset]; - return new AdjacentInterlockingSystemRoutePretestRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType); - } - - public override byte[] ToByteArray() { - var result = new byte[84]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - result[RouteTypeOffset] = (byte)RouteType; - return result; - } -} - -public enum AdjacentInterlockingSystemRoutePretestRequestCommandRouteType : byte { - MainRoute = 0x01, - ShuntingRoute = 0x02, - OnSightRoute = 0x03, - SrTrainRoute = 0x04, - SpecialTrainRoute = 0x05, - TemporaryShuntingArea = 0x06 -} - -public record AdjacentInterlockingSystemRoutePretestStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId, AdjacentInterlockingSystemRoutePretestStatusMessageRouteType RouteType, AdjacentInterlockingSystemRoutePretestStatusMessageRouteStatus RouteStatus, AdjacentInterlockingSystemRoutePretestStatusMessagePretestResponse PretestResponse) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - private const int RouteTypeOffset = 83; - private const int RouteStatusOffset = 84; - private const int PretestResponseOffset = 85; - public static readonly ushort MessageType = 0x0010; - - public new static AdjacentInterlockingSystemRoutePretestStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - var RouteType = (AdjacentInterlockingSystemRoutePretestStatusMessageRouteType)message[RouteTypeOffset]; - var RouteStatus = (AdjacentInterlockingSystemRoutePretestStatusMessageRouteStatus)message[RouteStatusOffset]; - var PretestResponse = (AdjacentInterlockingSystemRoutePretestStatusMessagePretestResponse)message[PretestResponseOffset]; - return new AdjacentInterlockingSystemRoutePretestStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId, RouteType, RouteStatus, PretestResponse); - } - - public override byte[] ToByteArray() { - var result = new byte[86]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - result[RouteTypeOffset] = (byte)RouteType; - result[RouteStatusOffset] = (byte)RouteStatus; - result[PretestResponseOffset] = (byte)PretestResponse; - return result; - } -} - -public enum AdjacentInterlockingSystemRoutePretestStatusMessageRouteType : byte { - MainRoute = 0x01, - ShuntingRoute = 0x02, - OnSightRoute = 0x03, - SrTrainRoute = 0x04, - SpecialTrainRoute = 0x05, - TemporaryShuntingArea = 0x06 -} - -public enum AdjacentInterlockingSystemRoutePretestStatusMessageRouteStatus : byte { - Initiated = 0x01, - Locked = 0x02, - NoRoute = 0x03 -} - -public enum AdjacentInterlockingSystemRoutePretestStatusMessagePretestResponse : byte { - PossibleAndVacant = 0x01, - PossibleAndOccupied = 0x02, - Queue = 0x03, - Rejected = 0x04 -} - -public record AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - public static readonly ushort MessageType = 0x0011; - - public new static AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - return new AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId); - } - - public override byte[] ToByteArray() { - var result = new byte[63]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - return result; - } -} - - - -public record AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessageRouteReleaseInhibitionStatus RouteReleaseInhibitionStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteReleaseInhibitionStatusOffset = 63; - public static readonly ushort MessageType = 0x0014; - - public new static AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteReleaseInhibitionStatus = (AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessageRouteReleaseInhibitionStatus)message[RouteReleaseInhibitionStatusOffset]; - return new AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteReleaseInhibitionStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[64]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - result[RouteReleaseInhibitionStatusOffset] = (byte)RouteReleaseInhibitionStatus; - return result; - } -} - -public enum AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessageRouteReleaseInhibitionStatus : byte { - Activated = 0x01, - Deactivated = 0x02 -} - -public record AdjacentInterlockingSystemAbortRouteCancellationRequestCommand (string SenderIdentifier, string ReceiverIdentifier, string BoundaryId, string RouteId) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int BoundaryIdOffset = 43; - private const int RouteIdOffset = 63; - public static readonly ushort MessageType = 0x0016; - - public new static AdjacentInterlockingSystemAbortRouteCancellationRequestCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var BoundaryId = Encoding.Latin1.GetString(message, BoundaryIdOffset, 20); - var RouteId = Encoding.Latin1.GetString(message, RouteIdOffset, 20); - return new AdjacentInterlockingSystemAbortRouteCancellationRequestCommand(SenderIdentifier, ReceiverIdentifier, BoundaryId, RouteId); - } - - public override byte[] ToByteArray() { - var result = new byte[83]; - result[0] = (byte)ProtocolType.AdjacentInterlockingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - Encoding.Latin1.GetBytes(BoundaryId.PadRight(20, '_')).CopyTo(result, BoundaryIdOffset); - Encoding.Latin1.GetBytes(RouteId.PadRight(20, '_')).CopyTo(result, RouteIdOffset); - return result; - } -} - - diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs deleted file mode 100644 index 088e721..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciIo.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs deleted file mode 100644 index 2aa1490..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciLc.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record LevelCrossingDeactivationCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0002; - - public new static LevelCrossingDeactivationCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new LevelCrossingDeactivationCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.LevelCrossing; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs deleted file mode 100644 index 03030b6..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciLs.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record LightSignalSetLuminosityCommand (string SenderIdentifier, string ReceiverIdentifier, LightSignalSetLuminosityCommandByteNr43:Luminosity ByteNr43:Luminosity) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ByteNr43:LuminosityOffset = 43; - public static readonly ushort MessageType = 0x0002; - - public new static LightSignalSetLuminosityCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ByteNr43:Luminosity = (LightSignalSetLuminosityCommandByteNr43:Luminosity)message[ByteNr43:LuminosityOffset]; - return new LightSignalSetLuminosityCommand(SenderIdentifier, ReceiverIdentifier, ByteNr43:Luminosity); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ByteNr43:LuminosityOffset] = (byte)ByteNr43:Luminosity; - return result; - } -} - -public enum LightSignalSetLuminosityCommandByteNr43:Luminosity : byte { - LuminosityForDay = 0x01, - LuminosityForNight = 0x02, - IntentionallyDeleted = 0xFE -} - -public record LightSignalSetLuminosityMessage (string SenderIdentifier, string ReceiverIdentifier, LightSignalSetLuminosityMessageByteNr43:Luminosity ByteNr43:Luminosity) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ByteNr43:LuminosityOffset = 43; - public static readonly ushort MessageType = 0x0004; - - public new static LightSignalSetLuminosityMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ByteNr43:Luminosity = (LightSignalSetLuminosityMessageByteNr43:Luminosity)message[ByteNr43:LuminosityOffset]; - return new LightSignalSetLuminosityMessage(SenderIdentifier, ReceiverIdentifier, ByteNr43:Luminosity); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.LightSignal; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ByteNr43:LuminosityOffset] = (byte)ByteNr43:Luminosity; - return result; - } -} - -public enum LightSignalSetLuminosityMessageByteNr43:Luminosity : byte { - LuminosityForDay = 0x01, - LuminosityForNight = 0x02, - IntentionallyDeleted = 0xFE -} diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs deleted file mode 100644 index e012594..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciLx.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record ExternalLevelCrossingSystemCrossingClearCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0007; - - public new static ExternalLevelCrossingSystemCrossingClearCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new ExternalLevelCrossingSystemCrossingClearCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.ExternalLevelCrossingSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs deleted file mode 100644 index 9196806..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciP.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record PointMovePointCommand (string SenderIdentifier, string ReceiverIdentifier, PointMovePointCommandCommandedPointPosition CommandedPointPosition) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int CommandedPointPositionOffset = 43; - public static readonly ushort MessageType = 0x0001; - - public new static PointMovePointCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var CommandedPointPosition = (PointMovePointCommandCommandedPointPosition)message[CommandedPointPositionOffset]; - return new PointMovePointCommand(SenderIdentifier, ReceiverIdentifier, CommandedPointPosition); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[CommandedPointPositionOffset] = (byte)CommandedPointPosition; - return result; - } -} - -public enum PointMovePointCommandCommandedPointPosition : byte { - SubsystemElectronicInterlockingRequestsARightHandPointMoving = 0x01, - SubsystemElectronicInterlockingRequestsALeftHandPointMoving = 0x02 -} - -public record PointPointPositionMessage (string SenderIdentifier, string ReceiverIdentifier, PointPointPositionMessageReportedPointPosition ReportedPointPosition, PointPointPositionMessageReportedDegradedPointPosition ReportedDegradedPointPosition) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ReportedPointPositionOffset = 43; - private const int ReportedDegradedPointPositionOffset = 44; - public static readonly ushort MessageType = 0x000B; - - public new static PointPointPositionMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ReportedPointPosition = (PointPointPositionMessageReportedPointPosition)message[ReportedPointPositionOffset]; - var ReportedDegradedPointPosition = (PointPointPositionMessageReportedDegradedPointPosition)message[ReportedDegradedPointPositionOffset]; - return new PointPointPositionMessage(SenderIdentifier, ReceiverIdentifier, ReportedPointPosition, ReportedDegradedPointPosition); - } - - public override byte[] ToByteArray() { - var result = new byte[45]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ReportedPointPositionOffset] = (byte)ReportedPointPosition; - result[ReportedDegradedPointPositionOffset] = (byte)ReportedDegradedPointPosition; - return result; - } -} - -public enum PointPointPositionMessageReportedPointPosition : byte { - PointIsInARightHandPositionDefinedEndPosition = 0x01, - PointIsInALeftHandPositionDefinedEndPosition = 0x02, - PointIsInNoEndPosition = 0x03, - PointIsInUnintendedPosition = 0x04 -} - -public enum PointPointPositionMessageReportedDegradedPointPosition : byte { - PointIsInADegradedRightHandPosition = 0x01, - PointIsInADegradedLeftHandPosition = 0x02, - PointIsNotInADegradedPosition = 0x03, - DegradedPointPositionIsNotApplicable = 0xFF -} - -public record PointMovementFailedMessage (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x000C; - - public new static PointMovementFailedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new PointMovementFailedMessage(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record PointAbilityToMovePointMessage (string SenderIdentifier, string ReceiverIdentifier, PointAbilityToMovePointMessageReportedAbilityToMovePointStatus ReportedAbilityToMovePointStatus) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ReportedAbilityToMovePointStatusOffset = 43; - public static readonly ushort MessageType = 0x000D; - - public new static PointAbilityToMovePointMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ReportedAbilityToMovePointStatus = (PointAbilityToMovePointMessageReportedAbilityToMovePointStatus)message[ReportedAbilityToMovePointStatusOffset]; - return new PointAbilityToMovePointMessage(SenderIdentifier, ReceiverIdentifier, ReportedAbilityToMovePointStatus); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.Point; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ReportedAbilityToMovePointStatusOffset] = (byte)ReportedAbilityToMovePointStatus; - return result; - } -} - -public enum PointAbilityToMovePointMessageReportedAbilityToMovePointStatus : byte { - PointIsAbleToMove = 0x01, - PointIsUnableToMove = 0x02 -} diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs deleted file mode 100644 index 088e721..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciRbc.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - diff --git a/src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs b/src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs deleted file mode 100644 index f80550b..0000000 --- a/src/Messages/Baseline4R2/InterfaceSpecificationSciTds.cs +++ /dev/null @@ -1,311 +0,0 @@ -using System; -using System.Text; -using System.Linq; - -namespace EulynxLive.Messages.Baseline4R2; - -public record TrainDetectionSystemUpdateFillingLevelCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0002; - - public new static TrainDetectionSystemUpdateFillingLevelCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemUpdateFillingLevelCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemCancelCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0008; - - public new static TrainDetectionSystemCancelCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemCancelCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand (string SenderIdentifier, string ReceiverIdentifier) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - public static readonly ushort MessageType = 0x0003; - - public new static TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - return new TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand(SenderIdentifier, ReceiverIdentifier); - } - - public override byte[] ToByteArray() { - var result = new byte[43]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - return result; - } -} - - - -public record TrainDetectionSystemTvpsOccupancyStatusMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTvpsOccupancyStatusMessageOccupancyStatus OccupancyStatus, TrainDetectionSystemTvpsOccupancyStatusMessageAbilityToBeForcedToClear AbilityToBeForcedToClear, ushort FillingLevel, TrainDetectionSystemTvpsOccupancyStatusMessagePomStatus PomStatus, TrainDetectionSystemTvpsOccupancyStatusMessageDisturbanceStatus DisturbanceStatus, TrainDetectionSystemTvpsOccupancyStatusMessageChangeTrigger ChangeTrigger) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int OccupancyStatusOffset = 43; - private const int AbilityToBeForcedToClearOffset = 44; - private const int FillingLevelOffset = 45; - private const int PomStatusOffset = 47; - private const int DisturbanceStatusOffset = 48; - private const int ChangeTriggerOffset = 49; - public static readonly ushort MessageType = 0x0007; - - public new static TrainDetectionSystemTvpsOccupancyStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var OccupancyStatus = (TrainDetectionSystemTvpsOccupancyStatusMessageOccupancyStatus)message[OccupancyStatusOffset]; - var AbilityToBeForcedToClear = (TrainDetectionSystemTvpsOccupancyStatusMessageAbilityToBeForcedToClear)message[AbilityToBeForcedToClearOffset]; - var FillingLevelBytes = new byte[] { message[FillingLevelOffset], message[FillingLevelOffset + 1] }; - if (!BitConverter.IsLittleEndian) Array.Reverse(FillingLevelBytes); - var FillingLevel = BitConverter.ToUInt16(FillingLevelBytes); - var PomStatus = (TrainDetectionSystemTvpsOccupancyStatusMessagePomStatus)message[PomStatusOffset]; - var DisturbanceStatus = (TrainDetectionSystemTvpsOccupancyStatusMessageDisturbanceStatus)message[DisturbanceStatusOffset]; - var ChangeTrigger = (TrainDetectionSystemTvpsOccupancyStatusMessageChangeTrigger)message[ChangeTriggerOffset]; - return new TrainDetectionSystemTvpsOccupancyStatusMessage(SenderIdentifier, ReceiverIdentifier, OccupancyStatus, AbilityToBeForcedToClear, FillingLevel, PomStatus, DisturbanceStatus, ChangeTrigger); - } - - public override byte[] ToByteArray() { - var result = new byte[50]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[OccupancyStatusOffset] = (byte)OccupancyStatus; - result[AbilityToBeForcedToClearOffset] = (byte)AbilityToBeForcedToClear; - var FillingLevelBytes = BitConverter.GetBytes(FillingLevel); - if (!BitConverter.IsLittleEndian) Array.Reverse(FillingLevelBytes); - FillingLevelBytes.Take(2).ToArray().CopyTo(result, FillingLevelOffset); - result[PomStatusOffset] = (byte)PomStatus; - result[DisturbanceStatusOffset] = (byte)DisturbanceStatus; - result[ChangeTriggerOffset] = (byte)ChangeTrigger; - return result; - } -} - -public enum TrainDetectionSystemTvpsOccupancyStatusMessageOccupancyStatus : byte { - TvpsIsInStateVacant = 0x01, - TvpsIsInStateOccupied = 0x02, - TvpsIsInStateDisturbed = 0x03, - TvpsIsInStateWaitingForASweepingTrainAfterFcPAOrFcPCommand = 0x04, - TvpsIsInStateWaitingForAnAcknowledgmentAfterFcPACommand = 0x05, - TvpsIsInStateSweepingTrainDetected = 0x06 -} - -public enum TrainDetectionSystemTvpsOccupancyStatusMessageAbilityToBeForcedToClear : byte { - TvpsIsNotAbleToBeForcedToClear = 0x01, - TvpsIsAbleToBeForcedToClear = 0x02 -} - -public enum TrainDetectionSystemTvpsOccupancyStatusMessagePomStatus : byte { - PowerSupplyOk = 0x01, - PowerSupplyNok = 0x02, - PomStatusIsNotApplicable = 0xFF -} - -public enum TrainDetectionSystemTvpsOccupancyStatusMessageDisturbanceStatus : byte { - DisturbanceIsOperational = 0x01, - DisturbanceIsTechnical = 0x02, - DisturbanceStatusIsNotApplicable = 0xFF -} - -public enum TrainDetectionSystemTvpsOccupancyStatusMessageChangeTrigger : byte { - PassingDetected = 0x01, - CommandFromEilAccepted = 0x02, - CommandFromMaintainerAccepted = 0x03, - TechnicalFailure = 0x04, - InitialSectionState = 0x05, - InternalTrigger = 0x06, - ChangeTriggerIsNotApplicable = 0xFF -} - -public record TrainDetectionSystemCommandRejectedMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemCommandRejectedMessageReasonForRejection ReasonForRejection) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ReasonForRejectionOffset = 43; - public static readonly ushort MessageType = 0x0006; - - public new static TrainDetectionSystemCommandRejectedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ReasonForRejection = (TrainDetectionSystemCommandRejectedMessageReasonForRejection)message[ReasonForRejectionOffset]; - return new TrainDetectionSystemCommandRejectedMessage(SenderIdentifier, ReceiverIdentifier, ReasonForRejection); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ReasonForRejectionOffset] = (byte)ReasonForRejection; - return result; - } -} - -public enum TrainDetectionSystemCommandRejectedMessageReasonForRejection : byte { - OperationalRejected = 0x01, - TechnicalRejected = 0x02 -} - -public record TrainDetectionSystemTvpsFcPFailedMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTvpsFcPFailedMessageReasonForFailure ReasonForFailure) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ReasonForFailureOffset = 43; - public static readonly ushort MessageType = 0x0010; - - public new static TrainDetectionSystemTvpsFcPFailedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ReasonForFailure = (TrainDetectionSystemTvpsFcPFailedMessageReasonForFailure)message[ReasonForFailureOffset]; - return new TrainDetectionSystemTvpsFcPFailedMessage(SenderIdentifier, ReceiverIdentifier, ReasonForFailure); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ReasonForFailureOffset] = (byte)ReasonForFailure; - return result; - } -} - -public enum TrainDetectionSystemTvpsFcPFailedMessageReasonForFailure : byte { - IncorrectCountOfTheSweepingTrain = 0x01, - ExpirationOfTimerConTmaxResponseTimeFcP = 0x02, - BoundingDetectionPointIsConfiguredAsNotPermittedForFcP = 0x03, - IntentionallyDeleted = 0x04, - OutgoingAxleDetectedBeforeExpirationOfMinimumTimer = 0x05, - ProcessCancelled = 0x06 -} - -public record TrainDetectionSystemTvpsFcPAFailedMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTvpsFcPAFailedMessageReasonForFailure ReasonForFailure) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int ReasonForFailureOffset = 43; - public static readonly ushort MessageType = 0x0011; - - public new static TrainDetectionSystemTvpsFcPAFailedMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var ReasonForFailure = (TrainDetectionSystemTvpsFcPAFailedMessageReasonForFailure)message[ReasonForFailureOffset]; - return new TrainDetectionSystemTvpsFcPAFailedMessage(SenderIdentifier, ReceiverIdentifier, ReasonForFailure); - } - - public override byte[] ToByteArray() { - var result = new byte[44]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[ReasonForFailureOffset] = (byte)ReasonForFailure; - return result; - } -} - -public enum TrainDetectionSystemTvpsFcPAFailedMessageReasonForFailure : byte { - IncorrectCountOfTheSweepingTrain = 0x01, - ExpirationOfTimerConTmaxResponseTimeFcPA = 0x02, - BoundingDetectionPointIsConfiguredAsNotPermittedForFcPA = 0x03, - IntentionallyDeleted = 0x04, - OutgoingAxleDetectedBeforeExpirationOfMinimumTimer = 0x05, - ProcessCancelled = 0x06 -} - -public record TrainDetectionSystemTdpStatusMessage (string SenderIdentifier, string ReceiverIdentifier, TrainDetectionSystemTdpStatusMessageStateOfPassing StateOfPassing, TrainDetectionSystemTdpStatusMessageDirectionOfPassing DirectionOfPassing) : Message(SenderIdentifier, ReceiverIdentifier) { - private const int MessageTypeOffset = 1; - private const int SenderIdentifierOffset = 3; - private const int ReceiverIdentifierOffset = 23; - private const int StateOfPassingOffset = 43; - private const int DirectionOfPassingOffset = 44; - public static readonly ushort MessageType = 0x000B; - - public new static TrainDetectionSystemTdpStatusMessage FromBytes(byte[] message) { - var SenderIdentifier = Encoding.Latin1.GetString(message, SenderIdentifierOffset, 20); - var ReceiverIdentifier = Encoding.Latin1.GetString(message, ReceiverIdentifierOffset, 20); - var StateOfPassing = (TrainDetectionSystemTdpStatusMessageStateOfPassing)message[StateOfPassingOffset]; - var DirectionOfPassing = (TrainDetectionSystemTdpStatusMessageDirectionOfPassing)message[DirectionOfPassingOffset]; - return new TrainDetectionSystemTdpStatusMessage(SenderIdentifier, ReceiverIdentifier, StateOfPassing, DirectionOfPassing); - } - - public override byte[] ToByteArray() { - var result = new byte[45]; - result[0] = (byte)ProtocolType.TrainDetectionSystem; - var MessageTypeBytes = BitConverter.GetBytes(MessageType); - if (!BitConverter.IsLittleEndian) Array.Reverse(MessageTypeBytes); - MessageTypeBytes.Take(2).ToArray().CopyTo(result, MessageTypeOffset); - Encoding.Latin1.GetBytes(SenderIdentifier.PadRight(20, '_')).CopyTo(result, SenderIdentifierOffset); - Encoding.Latin1.GetBytes(ReceiverIdentifier.PadRight(20, '_')).CopyTo(result, ReceiverIdentifierOffset); - result[StateOfPassingOffset] = (byte)StateOfPassing; - result[DirectionOfPassingOffset] = (byte)DirectionOfPassing; - return result; - } -} - -public enum TrainDetectionSystemTdpStatusMessageStateOfPassing : byte { - NotPassed = 0x01, - Passed = 0x02, - Disturbed = 0x03 -} - -public enum TrainDetectionSystemTdpStatusMessageDirectionOfPassing : byte { - ReferenceDirection = 0x01, - AgainstReferenceDirection = 0x02, - WithoutIndicatedDirection = 0x03 -} diff --git a/src/Messages/Baseline4R2/Message.cs b/src/Messages/Baseline4R2/Message.cs deleted file mode 100644 index 1c6dc40..0000000 --- a/src/Messages/Baseline4R2/Message.cs +++ /dev/null @@ -1,178 +0,0 @@ -using System; - -namespace EulynxLive.Messages.Baseline4R2; - -public abstract record Message(string SenderIdentifier, string ReceiverIdentifier) { - - public abstract byte[] ToByteArray(); - - public static Message FromBytes(byte[] message) { - var protocolType = (ProtocolType)message[0]; - var messageType = BitConverter.ToUInt16(new byte[2] { message[1], message[2] }); - return protocolType switch { - ProtocolType.AdjacentInterlockingSystem => messageType switch { - 0x0001 => AdjacentInterlockingSystemActivationZoneStatusMessage.FromBytes(message), - 0x0002 => AdjacentInterlockingSystemApproachZoneStatusMessage.FromBytes(message), - 0x0003 => AdjacentInterlockingSystemAccessRestrictionRequestCommand.FromBytes(message), - 0x0012 => AdjacentInterlockingSystemAccessRestrictionStatusMessage.FromBytes(message), - 0x0004 => AdjacentInterlockingSystemLineStatusMessage.FromBytes(message), - 0x0005 => AdjacentInterlockingSystemFlankProtectionRequestCommand.FromBytes(message), - 0x0013 => AdjacentInterlockingSystemFlankProtectionStatusMessage.FromBytes(message), - 0x0007 => AdjacentInterlockingSystemRouteRequestCommand.FromBytes(message), - 0x0008 => AdjacentInterlockingSystemRouteStatusMessage.FromBytes(message), - 0x0009 => AdjacentInterlockingSystemRouteMonitoringStatusMessage.FromBytes(message), - 0x000A => AdjacentInterlockingSystemRouteCancellationRequestCommand.FromBytes(message), - 0x000B => AdjacentInterlockingSystemTrainOperatedRouteReleaseStatusMessage.FromBytes(message), - 0x000C => AdjacentInterlockingSystemSignalStatusMessage.FromBytes(message), - 0x000D => AdjacentInterlockingSystemTvpsStatusMessage.FromBytes(message), - 0x000E => AdjacentInterlockingSystemOppositeMainSignalStatusMessage.FromBytes(message), - 0x000F => AdjacentInterlockingSystemRoutePretestRequestCommand.FromBytes(message), - 0x0010 => AdjacentInterlockingSystemRoutePretestStatusMessage.FromBytes(message), - 0x0011 => AdjacentInterlockingSystemRouteReleaseInhibitionActivationRequestCommand.FromBytes(message), - 0x0014 => AdjacentInterlockingSystemRouteReleaseInhibitionStatusMessage.FromBytes(message), - 0x0016 => AdjacentInterlockingSystemAbortRouteCancellationRequestCommand.FromBytes(message), - 0x0024 => AdjacentInterlockingSystemPdiVersionCheckCommand.FromBytes(message), - 0x0025 => AdjacentInterlockingSystemPdiVersionCheckMessage.FromBytes(message), - 0x0021 => AdjacentInterlockingSystemInitialisationRequestCommand.FromBytes(message), - 0x0022 => AdjacentInterlockingSystemStartInitialisationMessage.FromBytes(message), - 0x0026 => AdjacentInterlockingSystemStatusReportCompletedMessage.FromBytes(message), - 0x0023 => AdjacentInterlockingSystemInitialisationCompletedMessage.FromBytes(message), - 0x0027 => AdjacentInterlockingSystemClosePdiCommand.FromBytes(message), - 0x0028 => AdjacentInterlockingSystemReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => AdjacentInterlockingSystemPdiAvailableMessage.FromBytes(message), - 0x002A => AdjacentInterlockingSystemPdiNotAvailableMessage.FromBytes(message), - 0x002B => AdjacentInterlockingSystemResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.TrainDetectionSystem => messageType switch { - 0x0002 => TrainDetectionSystemUpdateFillingLevelCommand.FromBytes(message), - 0x0008 => TrainDetectionSystemCancelCommand.FromBytes(message), - 0x0003 => TrainDetectionSystemDisableTheRestrictionToForceSectionStatusToClearCommand.FromBytes(message), - 0x0007 => TrainDetectionSystemTvpsOccupancyStatusMessage.FromBytes(message), - 0x0006 => TrainDetectionSystemCommandRejectedMessage.FromBytes(message), - 0x0010 => TrainDetectionSystemTvpsFcPFailedMessage.FromBytes(message), - 0x0011 => TrainDetectionSystemTvpsFcPAFailedMessage.FromBytes(message), - 0x000B => TrainDetectionSystemTdpStatusMessage.FromBytes(message), - 0x0024 => TrainDetectionSystemPdiVersionCheckCommand.FromBytes(message), - 0x0025 => TrainDetectionSystemPdiVersionCheckMessage.FromBytes(message), - 0x0021 => TrainDetectionSystemInitialisationRequestCommand.FromBytes(message), - 0x0022 => TrainDetectionSystemStartInitialisationMessage.FromBytes(message), - 0x0026 => TrainDetectionSystemStatusReportCompletedMessage.FromBytes(message), - 0x0023 => TrainDetectionSystemInitialisationCompletedMessage.FromBytes(message), - 0x0027 => TrainDetectionSystemClosePdiCommand.FromBytes(message), - 0x0028 => TrainDetectionSystemReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => TrainDetectionSystemPdiAvailableMessage.FromBytes(message), - 0x002A => TrainDetectionSystemPdiNotAvailableMessage.FromBytes(message), - 0x002B => TrainDetectionSystemResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.LightSignal => messageType switch { - 0x0002 => LightSignalSetLuminosityCommand.FromBytes(message), - 0x0004 => LightSignalSetLuminosityMessage.FromBytes(message), - 0x0024 => LightSignalPdiVersionCheckCommand.FromBytes(message), - 0x0025 => LightSignalPdiVersionCheckMessage.FromBytes(message), - 0x0021 => LightSignalInitialisationRequestCommand.FromBytes(message), - 0x0022 => LightSignalStartInitialisationMessage.FromBytes(message), - 0x0026 => LightSignalStatusReportCompletedMessage.FromBytes(message), - 0x0023 => LightSignalInitialisationCompletedMessage.FromBytes(message), - 0x0027 => LightSignalClosePdiCommand.FromBytes(message), - 0x0028 => LightSignalReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => LightSignalPdiAvailableMessage.FromBytes(message), - 0x002A => LightSignalPdiNotAvailableMessage.FromBytes(message), - 0x002B => LightSignalResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.Point => messageType switch { - 0x0001 => PointMovePointCommand.FromBytes(message), - 0x000B => PointPointPositionMessage.FromBytes(message), - 0x000C => PointMovementFailedMessage.FromBytes(message), - 0x000D => PointAbilityToMovePointMessage.FromBytes(message), - 0x0024 => PointPdiVersionCheckCommand.FromBytes(message), - 0x0025 => PointPdiVersionCheckMessage.FromBytes(message), - 0x0021 => PointInitialisationRequestCommand.FromBytes(message), - 0x0022 => PointStartInitialisationMessage.FromBytes(message), - 0x0026 => PointStatusReportCompletedMessage.FromBytes(message), - 0x0023 => PointInitialisationCompletedMessage.FromBytes(message), - 0x0027 => PointClosePdiCommand.FromBytes(message), - 0x0028 => PointReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => PointPdiAvailableMessage.FromBytes(message), - 0x002A => PointPdiNotAvailableMessage.FromBytes(message), - 0x002B => PointResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.RadioBlockCenter => messageType switch { - 0x0024 => RadioBlockCenterPdiVersionCheckCommand.FromBytes(message), - 0x0025 => RadioBlockCenterPdiVersionCheckMessage.FromBytes(message), - 0x0021 => RadioBlockCenterInitialisationRequestCommand.FromBytes(message), - 0x0022 => RadioBlockCenterStartInitialisationMessage.FromBytes(message), - 0x0026 => RadioBlockCenterStatusReportCompletedMessage.FromBytes(message), - 0x0023 => RadioBlockCenterInitialisationCompletedMessage.FromBytes(message), - 0x0027 => RadioBlockCenterClosePdiCommand.FromBytes(message), - 0x0028 => RadioBlockCenterReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => RadioBlockCenterPdiAvailableMessage.FromBytes(message), - 0x002A => RadioBlockCenterPdiNotAvailableMessage.FromBytes(message), - 0x002B => RadioBlockCenterResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.LevelCrossing => messageType switch { - 0x0002 => LevelCrossingDeactivationCommand.FromBytes(message), - 0x0024 => LevelCrossingPdiVersionCheckCommand.FromBytes(message), - 0x0025 => LevelCrossingPdiVersionCheckMessage.FromBytes(message), - 0x0021 => LevelCrossingInitialisationRequestCommand.FromBytes(message), - 0x0022 => LevelCrossingStartInitialisationMessage.FromBytes(message), - 0x0026 => LevelCrossingStatusReportCompletedMessage.FromBytes(message), - 0x0023 => LevelCrossingInitialisationCompletedMessage.FromBytes(message), - 0x0027 => LevelCrossingClosePdiCommand.FromBytes(message), - 0x0028 => LevelCrossingReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => LevelCrossingPdiAvailableMessage.FromBytes(message), - 0x002A => LevelCrossingPdiNotAvailableMessage.FromBytes(message), - 0x002B => LevelCrossingResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.CC => messageType switch { - 0x0024 => CCPdiVersionCheckCommand.FromBytes(message), - 0x0025 => CCPdiVersionCheckMessage.FromBytes(message), - 0x0021 => CCInitialisationRequestCommand.FromBytes(message), - 0x0022 => CCStartInitialisationMessage.FromBytes(message), - 0x0026 => CCStatusReportCompletedMessage.FromBytes(message), - 0x0023 => CCInitialisationCompletedMessage.FromBytes(message), - 0x0027 => CCClosePdiCommand.FromBytes(message), - 0x0028 => CCReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => CCPdiAvailableMessage.FromBytes(message), - 0x002A => CCPdiNotAvailableMessage.FromBytes(message), - 0x002B => CCResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.GenericIO => messageType switch { - 0x0024 => GenericIOPdiVersionCheckCommand.FromBytes(message), - 0x0025 => GenericIOPdiVersionCheckMessage.FromBytes(message), - 0x0021 => GenericIOInitialisationRequestCommand.FromBytes(message), - 0x0022 => GenericIOStartInitialisationMessage.FromBytes(message), - 0x0026 => GenericIOStatusReportCompletedMessage.FromBytes(message), - 0x0023 => GenericIOInitialisationCompletedMessage.FromBytes(message), - 0x0027 => GenericIOClosePdiCommand.FromBytes(message), - 0x0028 => GenericIOReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => GenericIOPdiAvailableMessage.FromBytes(message), - 0x002A => GenericIOPdiNotAvailableMessage.FromBytes(message), - 0x002B => GenericIOResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - ProtocolType.ExternalLevelCrossingSystem => messageType switch { - 0x0007 => ExternalLevelCrossingSystemCrossingClearCommand.FromBytes(message), - 0x0024 => ExternalLevelCrossingSystemPdiVersionCheckCommand.FromBytes(message), - 0x0025 => ExternalLevelCrossingSystemPdiVersionCheckMessage.FromBytes(message), - 0x0021 => ExternalLevelCrossingSystemInitialisationRequestCommand.FromBytes(message), - 0x0022 => ExternalLevelCrossingSystemStartInitialisationMessage.FromBytes(message), - 0x0026 => ExternalLevelCrossingSystemStatusReportCompletedMessage.FromBytes(message), - 0x0023 => ExternalLevelCrossingSystemInitialisationCompletedMessage.FromBytes(message), - 0x0027 => ExternalLevelCrossingSystemClosePdiCommand.FromBytes(message), - 0x0028 => ExternalLevelCrossingSystemReleasePdiForMaintenanceCommand.FromBytes(message), - 0x0029 => ExternalLevelCrossingSystemPdiAvailableMessage.FromBytes(message), - 0x002A => ExternalLevelCrossingSystemPdiNotAvailableMessage.FromBytes(message), - 0x002B => ExternalLevelCrossingSystemResetPdiMessage.FromBytes(message), - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }, - _ => throw new Exception($"Unknown protocol and message type {protocolType} / {messageType}") - }; - } -} From 19e52cd3682830f6dd6740c0fdce23f2b44d21c8 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Fri, 24 Nov 2023 10:28:47 +0100 Subject: [PATCH 10/22] fix config error --- src/Point/Point.cs | 13 ++++++++++--- src/Point/PointToInterlockingConnectionB4R1Impl.cs | 7 ------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 93bb929..820d155 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -20,7 +20,6 @@ public class Point : BackgroundService public bool AllPointMachinesCrucial { get; } private readonly ILogger _logger; - private readonly IConfiguration _configuration; private readonly List _webSockets; private IPointToInterlockingConnection _connection; private readonly Random _random; @@ -32,6 +31,16 @@ public class Point : BackgroundService public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) { + _logger = logger; + + var config = configuration.GetSection("PointSettings").Get() ?? throw new Exception("No configuration provided"); + if (config.AllPointMachinesCrucial == null) + { + _logger.LogInformation("Assuming all point machines are crucial."); + } + _simulateRandomTimeouts = config.SimulateRandomTimeouts ?? false; + AllPointMachinesCrucial = config.AllPointMachinesCrucial ?? false; + _webSockets = new List(); _pointState = new PointState() { @@ -39,8 +48,6 @@ public Point(ILogger logger, IConfiguration configuration, IPointToInterl DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED }; _random = new Random(); - _logger = logger; - _configuration = configuration; _connection = connection; } diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index 1801443..d90fb56 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -11,7 +11,6 @@ public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConnection { - public bool AllPointMachinesCrucial { get; } private readonly ILogger _logger; private readonly string _localId; private readonly string _localRastaId; @@ -28,12 +27,6 @@ public PointToInterlockingConnectionB4R1Impl( _currentConnection = null; var config = configuration.GetSection("PointSettings").Get() ?? throw new Exception("No configuration provided"); - if (config.AllPointMachinesCrucial == null) - { - _logger.LogInformation("Assuming all point machines are crucial."); - } - - AllPointMachinesCrucial = config.AllPointMachinesCrucial ?? false; _localId = config.LocalId; _localRastaId = config.LocalRastaId.ToString(); _remoteId = config.RemoteId; From 86f02f1d192f9eda4c9bb549abc37bae56cdf3c4 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Fri, 24 Nov 2023 10:37:15 +0100 Subject: [PATCH 11/22] cleanup --- src/Point/Point.cs | 2 +- .../PointToInterlockingConnectionMockImpl.cs | 56 ------------------- src/Point/Services/PointService.cs | 6 -- 3 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 src/Point/PointToInterlockingConnectionMockImpl.cs diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 820d155..d45f7d2 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -255,7 +255,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } } } - catch (RpcException ex) + catch (RpcException) { _logger.LogWarning("Could not communicate with remote endpoint."); } diff --git a/src/Point/PointToInterlockingConnectionMockImpl.cs b/src/Point/PointToInterlockingConnectionMockImpl.cs deleted file mode 100644 index 91c22ec..0000000 --- a/src/Point/PointToInterlockingConnectionMockImpl.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Diagnostics; -using EulynxLive.Point.Proto; -using EulynxLive.Messages.IPointToInterlockingConnection; -using PointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition; - -class PointToInterlockingConnectionMockImpl : IPointToInterlockingConnection -{ - private readonly ILogger _logger; - int _timeoutS = 3; - Stopwatch _sw = new Stopwatch(); - PointPosition commandedPosition = PointPosition.RIGHT; - - public PointToInterlockingConnectionMockImpl(ILogger logger) - { - _logger = logger; - } - - public void Connect() { } - - public void Dispose() { } - - async public Task InitializeConnection(IPointToInterlockingConnection.PointState state) - { - _sw = Stopwatch.StartNew(); - await Task.Delay(1000); - return true; - } - - async public Task ReceivePointPosition() - { - await Task.Delay(1000); - if (_sw.Elapsed.TotalSeconds >= _timeoutS) - { - _sw = Stopwatch.StartNew(); - commandedPosition = commandedPosition switch - { - PointPosition.RIGHT => PointPosition.LEFT, - PointPosition.LEFT => PointPosition.RIGHT, - PointPosition.NO_ENDPOSITION => throw new NotImplementedException(), - PointPosition.TRAILED => throw new NotImplementedException(), - }; - return commandedPosition; - } - return null; - } - - async public Task SendPointPosition(IPointToInterlockingConnection.PointState state) - { - await Task.Delay(1000); - } - - async public Task SendTimeoutMessage() - { - await Task.Delay(1000); - } -} diff --git a/src/Point/Services/PointService.cs b/src/Point/Services/PointService.cs index af75c35..98afc32 100644 --- a/src/Point/Services/PointService.cs +++ b/src/Point/Services/PointService.cs @@ -52,10 +52,7 @@ public override Task EstablishPointMachineState(PointMachineStateMessage throw new InvalidOperationException("Point has only crucial point machines"); } - // _point.PointState.AbilityToMove = request.AbilityToMove; - // _point.PointState.LastPointPosition = request.LastPointPosition; _point.PointState.PointPosition = request.PointPosition.ConvertToReportedPointPosition(); - // _point.PointState.Target = request.Target; return Task.FromResult(new Empty()); } @@ -64,11 +61,8 @@ public override Task GetPointMachineState(Empty reques { return Task.FromResult(new PointMachineStateMessage() { - // AbilityToMove = _point.PointState.AbilityToMove, Crucial = _point.AllPointMachinesCrucial ? PointMachineStateMessage.Types.Crucial.Crucial : PointMachineStateMessage.Types.Crucial.NonCrucial, - // LastPointPosition = _point.PointState.LastPointPosition, PointPosition = _point.PointState.PointPosition.ConvertToProtoMessage(), - // Target = _point.PointState.Target, }); } } From 1b171265452f4552ffc7e1bdeee15152d3b3474e Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Fri, 24 Nov 2023 11:44:23 +0100 Subject: [PATCH 12/22] refactor --- src/Point/Point.cs | 16 ++--- .../PointToInterlockingConnectionB4R1Impl.cs | 63 ++++++++++--------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/Point/Point.cs b/src/Point/Point.cs index d45f7d2..0ef1131 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -1,17 +1,13 @@ -using System.Net.WebSockets; -using System.Text.Json; -using Google.Protobuf; -using Grpc.Core; -using Sci; +using DegradedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.DegradedPointPosition; using EulynxLive.Messages.IPointToInterlockingConnection; +using EulynxLive.Point.Proto; +using Grpc.Core; using PointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition; -using DegradedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.DegradedPointPosition; using PointState = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointState; -using static Sci.Rasta; +using Sci; +using System.Net.WebSockets; using System.Text; -using Grpc.Net.Client; -using EulynxLive.Point.Components; -using EulynxLive.Point.Proto; +using System.Text.Json; namespace EulynxLive.Point { diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index d90fb56..326916b 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -1,4 +1,3 @@ -using System.Net.WebSockets; using EulynxLive.Messages.Baseline4R1; using EulynxLive.Point; using Google.Protobuf; @@ -48,32 +47,30 @@ public void Connect() public async Task InitializeConnection(PointState state) { _logger.LogTrace("Connected. Waiting for request..."); - if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) - || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointPdiVersionCheckCommand) + if (await ReceiveMessage() == null) { _logger.LogError("Unexpected message."); return false; } var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(versionCheckResponse.ToByteArray()) }); + await SendMessage(versionCheckResponse); - if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token) - || Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()) is not PointInitialisationRequestCommand) + if (await ReceiveMessage() == null) { _logger.LogError("Unexpected message."); return false; } var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(startInitialization.ToByteArray()) }); + await SendMessage(startInitialization); var pointState = new B4R1PointStateImpl(state); var initialPosition = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(initialPosition.ToByteArray()) }); + await SendMessage(initialPosition); var completeInitialization = new PointInitialisationCompletedMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(completeInitialization.ToByteArray()) }); + await SendMessage(completeInitialization); return true; } @@ -81,41 +78,50 @@ public async Task SendPointPosition(PointState state) { var pointState = new B4R1PointStateImpl(state); var response = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); + await SendMessage(response); } async public Task SendTimeoutMessage() { var response = new PointTimeoutMessage(_localId, _remoteId); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(response.ToByteArray()) }); + await SendMessage(response); } public async Task ReceivePointPosition() { + var message = await ReceiveMessage(); - if (!await _currentConnection.ResponseStream.MoveNext()) + return (message != null)? message.CommandedPointPosition switch { - return null; - } - var message = Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()); - - if (message is PointMovePointCommand movePointCommand) - { - return movePointCommand.CommandedPointPosition switch - { - PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving => PointPosition.RIGHT, - PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.LEFT, - }; - } - - _logger.LogInformation("Received unknown message {}", message.GetType()); - return null; + PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving => PointPosition.RIGHT, + PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.LEFT, + } : null; } public void Dispose() { _currentConnection?.Dispose(); } + + private async Task SendMessage(Message message) + { + if (_currentConnection == null) throw new NullReferenceException("Connection is null. Did you call Connect()?"); + await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(message.ToByteArray()) }); + } + + private async Task ReceiveMessage() where T : Message + { + if (_currentConnection == null) throw new NullReferenceException("Connection is null. Did you call Connect()?"); + if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token)) return null; + + var message = Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()); + if (message is not T) + { + _logger.LogError("Unexpected message: {}", message); + return null; + } + return message as T; + } } public class B4R1PointStateImpl @@ -124,7 +130,8 @@ public class B4R1PointStateImpl public PointPointPositionMessageReportedPointPosition PointPosition { get => map(_state.PointPosition); } public PointPointPositionMessageReportedDegradedPointPosition DegradedPointPosition { get => map(_state.DegradedPointPosition); } - public B4R1PointStateImpl(PointState state){ + public B4R1PointStateImpl(PointState state) + { _state = state; } From 23e65f5e8bd49bfbbcb276eba8025ff71c606daa Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 28 Nov 2023 14:15:27 +0100 Subject: [PATCH 13/22] resolve comments --- .../IPointToInterlockingConnection.cs | 16 +++--- src/Point/Point.cs | 54 +++++++++---------- src/Point/PointStateBaseline4R1.cs | 32 +++++++++++ .../PointToInterlockingConnectionB4R1Impl.cs | 48 ++++------------- .../ReportedPointPositionProtoConversion.cs | 16 +++--- src/Point/Startup.cs | 3 +- 6 files changed, 88 insertions(+), 81 deletions(-) create mode 100644 src/Point/PointStateBaseline4R1.cs diff --git a/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs b/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs index 0b543cb..cae25bb 100644 --- a/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs +++ b/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs @@ -17,17 +17,17 @@ public record PointState public enum PointPosition { - LEFT, - RIGHT, - TRAILED, - NO_ENDPOSITION + Left, + Right, + UnintendetPosition, + NoEndposition } public enum DegradedPointPosition { - DEGRADED_LEFT, - DEGRADED_RIGHT, - NOT_DEGRADED, - NOT_APPLICABLE + DegradedLeft, + DegradedRight, + NotDegraded, + NotApplicable } } diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 0ef1131..2b23394 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -40,8 +40,8 @@ public Point(ILogger logger, IConfiguration configuration, IPointToInterl _webSockets = new List(); _pointState = new PointState() { - PointPosition = PointPosition.NO_ENDPOSITION, - DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED + PointPosition = PointPosition.NoEndposition, + DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.NotApplicable : DegradedPointPosition.NotDegraded }; _random = new Random(); _connection = connection; @@ -74,7 +74,7 @@ public async Task HandleWebSocket(WebSocket webSocket) public async Task SimulateUnintendedPosition() { - _pointState.PointPosition = PointPosition.TRAILED; + _pointState.PointPosition = PointPosition.UnintendetPosition; if (_currentConnection != null) @@ -88,21 +88,21 @@ public async Task SimulateUnintendedPosition() private static DegradedPointPosition? GetDegradedPointPosition(PointPosition previousReportedPosition) => previousReportedPosition switch { - PointPosition.RIGHT - => DegradedPointPosition.DEGRADED_RIGHT, - PointPosition.LEFT - => DegradedPointPosition.DEGRADED_LEFT, - PointPosition.TRAILED + PointPosition.Right + => DegradedPointPosition.DegradedRight, + PointPosition.Left + => DegradedPointPosition.DegradedLeft, + PointPosition.UnintendetPosition => null, - PointPosition.NO_ENDPOSITION + PointPosition.NoEndposition => null, _ => null, }; private static PointPosition? GetPointPositionDegraded(Proto.PointPosition pointPosition) => pointPosition switch { - Proto.PointPosition.NoEndPosition => PointPosition.NO_ENDPOSITION, - Proto.PointPosition.UnintendedPosition => PointPosition.TRAILED, + Proto.PointPosition.NoEndPosition => PointPosition.NoEndposition, + Proto.PointPosition.UnintendedPosition => PointPosition.UnintendetPosition, _ => null, }; @@ -124,12 +124,12 @@ private void UpdatePointState(PointPosition pointPosition, DegradedPointPosition /// public async Task SetDegraded(PointDegradedMessage message) { - _pointState.PointPosition = PointPosition.NO_ENDPOSITION; + _pointState.PointPosition = PointPosition.NoEndposition; if (_currentConnection != null) { var degradedPointPosition = AllPointMachinesCrucial ? - DegradedPointPosition.NOT_APPLICABLE : GetDegradedPointPosition(_pointState.PointPosition); + DegradedPointPosition.NotApplicable : GetDegradedPointPosition(_pointState.PointPosition); if (degradedPointPosition != null) { @@ -154,18 +154,18 @@ public async Task PutInEndPosition() if (_currentConnection != null) { - if (_pointState.PointPosition != PointPosition.RIGHT && - _pointState.PointPosition != PointPosition.LEFT) + if (_pointState.PointPosition != PointPosition.Right && + _pointState.PointPosition != PointPosition.Left) { var reportedDegradedPointPosition = AllPointMachinesCrucial ? - DegradedPointPosition.NOT_APPLICABLE : DegradedPointPosition.NOT_DEGRADED; + DegradedPointPosition.NotApplicable : DegradedPointPosition.NotDegraded; PointPosition? finalPosition = _pointState.DegradedPointPosition switch { - DegradedPointPosition.DEGRADED_RIGHT => PointPosition.RIGHT, - DegradedPointPosition.DEGRADED_LEFT => PointPosition.LEFT, - DegradedPointPosition.NOT_DEGRADED => null, - DegradedPointPosition.NOT_APPLICABLE => null, + DegradedPointPosition.DegradedRight => PointPosition.Right, + DegradedPointPosition.DegradedLeft => PointPosition.Left, + DegradedPointPosition.NotDegraded => null, + DegradedPointPosition.NotApplicable => null, _ => null, }; if (finalPosition != null) @@ -202,14 +202,14 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) break; } - if ((commandedPointPosition == PointPosition.LEFT && _pointState.PointPosition == PointPosition.LEFT) - || (commandedPointPosition == PointPosition.RIGHT && _pointState.PointPosition == PointPosition.RIGHT)) + if ((commandedPointPosition == PointPosition.Left && _pointState.PointPosition == PointPosition.Left) + || (commandedPointPosition == PointPosition.Right && _pointState.PointPosition == PointPosition.Right)) { _connection.SendPointPosition(PointState); continue; } - UpdatePointState(PointPosition.NO_ENDPOSITION, DegradedPointPosition.NOT_APPLICABLE); + UpdatePointState(PointPosition.NoEndposition, DegradedPointPosition.NotApplicable); await UpdateConnectedWebClients(); @@ -289,10 +289,10 @@ private async Task UpdateConnectedWebClients() private async Task UpdateWebClient(WebSocket webSocket) { var positions = new Dictionary { - {PointPosition.RIGHT, "right"}, - {PointPosition.LEFT, "left"}, - {PointPosition.NO_ENDPOSITION, "noEndPosition"}, - {PointPosition.TRAILED, "trailed"}, + {PointPosition.Right, "right"}, + {PointPosition.Left, "left"}, + {PointPosition.NoEndposition, "noEndPosition"}, + {PointPosition.UnintendetPosition, "trailed"}, }; var options = new JsonSerializerOptions { WriteIndented = true }; var serializedState = JsonSerializer.Serialize(new diff --git a/src/Point/PointStateBaseline4R1.cs b/src/Point/PointStateBaseline4R1.cs new file mode 100644 index 0000000..69e16a3 --- /dev/null +++ b/src/Point/PointStateBaseline4R1.cs @@ -0,0 +1,32 @@ + +using EulynxLive.Messages.Baseline4R1; +using EulynxLive.Messages.IPointToInterlockingConnection; +using static EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection; + +public record PointStateBaseline4R1 +{ + private PointState _state; + public PointPointPositionMessageReportedPointPosition PointPosition { get => MapInterfacePointPositionToConcrete(_state.PointPosition); } + public PointPointPositionMessageReportedDegradedPointPosition DegradedPointPosition { get => MapInterfaceDegradedPointPositionToConcrete(_state.DegradedPointPosition); } + + public PointStateBaseline4R1(PointState state) + { + _state = state; + } + + private PointPointPositionMessageReportedPointPosition MapInterfacePointPositionToConcrete(PointPosition value) => value switch + { + IPointToInterlockingConnection.PointPosition.Left => PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, + IPointToInterlockingConnection.PointPosition.Right => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, + IPointToInterlockingConnection.PointPosition.UnintendetPosition => PointPointPositionMessageReportedPointPosition.PointIsTrailed, + IPointToInterlockingConnection.PointPosition.NoEndposition => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, + }; + + private PointPointPositionMessageReportedDegradedPointPosition MapInterfaceDegradedPointPositionToConcrete(DegradedPointPosition value) => value switch + { + IPointToInterlockingConnection.DegradedPointPosition.DegradedLeft => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, + IPointToInterlockingConnection.DegradedPointPosition.DegradedRight => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, + IPointToInterlockingConnection.DegradedPointPosition.NotDegraded => PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition, + IPointToInterlockingConnection.DegradedPointPosition.NotApplicable => PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable, + }; +} diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/PointToInterlockingConnectionB4R1Impl.cs index 326916b..d3de42c 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/PointToInterlockingConnectionB4R1Impl.cs @@ -8,7 +8,9 @@ using static EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection; using static Sci.Rasta; -public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConnection +namespace EulynxLive.Point.EulynxBaseline4R1; + +public class PointToInterlockingConnection : IPointToInterlockingConnection { private readonly ILogger _logger; private readonly string _localId; @@ -18,8 +20,8 @@ public class PointToInterlockingConnectionB4R1Impl : IPointToInterlockingConnect AsyncDuplexStreamingCall? _currentConnection; private CancellationTokenSource _timeout; - public PointToInterlockingConnectionB4R1Impl( - ILogger logger, + public PointToInterlockingConnection( + ILogger logger, IConfiguration configuration) { _logger = logger; @@ -65,7 +67,7 @@ public async Task InitializeConnection(PointState state) var startInitialization = new PointStartInitialisationMessage(_localId, _remoteId); await SendMessage(startInitialization); - var pointState = new B4R1PointStateImpl(state); + var pointState = new PointStateBaseline4R1(state); var initialPosition = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); await SendMessage(initialPosition); @@ -76,7 +78,7 @@ public async Task InitializeConnection(PointState state) public async Task SendPointPosition(PointState state) { - var pointState = new B4R1PointStateImpl(state); + var pointState = new PointStateBaseline4R1(state); var response = new PointPointPositionMessage(_localId, _remoteId, pointState.PointPosition, pointState.DegradedPointPosition); await SendMessage(response); } @@ -93,8 +95,8 @@ async public Task SendTimeoutMessage() return (message != null)? message.CommandedPointPosition switch { - PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving => PointPosition.RIGHT, - PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.LEFT, + PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving => PointPosition.Right, + PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.Left, } : null; } @@ -105,13 +107,13 @@ public void Dispose() private async Task SendMessage(Message message) { - if (_currentConnection == null) throw new NullReferenceException("Connection is null. Did you call Connect()?"); + if (_currentConnection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?"); await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(message.ToByteArray()) }); } private async Task ReceiveMessage() where T : Message { - if (_currentConnection == null) throw new NullReferenceException("Connection is null. Did you call Connect()?"); + if (_currentConnection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?"); if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token)) return null; var message = Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()); @@ -123,31 +125,3 @@ private async Task SendMessage(Message message) return message as T; } } - -public class B4R1PointStateImpl -{ - private PointState _state; - public PointPointPositionMessageReportedPointPosition PointPosition { get => map(_state.PointPosition); } - public PointPointPositionMessageReportedDegradedPointPosition DegradedPointPosition { get => map(_state.DegradedPointPosition); } - - public B4R1PointStateImpl(PointState state) - { - _state = state; - } - - private PointPointPositionMessageReportedPointPosition map(PointPosition value) => value switch - { - IPointToInterlockingConnection.PointPosition.LEFT => PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, - IPointToInterlockingConnection.PointPosition.RIGHT => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, - IPointToInterlockingConnection.PointPosition.TRAILED => PointPointPositionMessageReportedPointPosition.PointIsTrailed, - IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, - }; - - private PointPointPositionMessageReportedDegradedPointPosition map(DegradedPointPosition value) => value switch - { - IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_LEFT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedLeftHandPosition, - IPointToInterlockingConnection.DegradedPointPosition.DEGRADED_RIGHT => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, - IPointToInterlockingConnection.DegradedPointPosition.NOT_DEGRADED => PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition, - IPointToInterlockingConnection.DegradedPointPosition.NOT_APPLICABLE => PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable, - }; -} diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index f4f1e36..fef9b23 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -10,19 +10,19 @@ public static class ReportedPointPositionProtoConversion { public static PointPosition ConvertToProtoMessage(this ReportedPointPosition reportedPointPosition) => reportedPointPosition switch { - ReportedPointPosition.RIGHT => PointPosition.Right, - ReportedPointPosition.LEFT => PointPosition.Left, - ReportedPointPosition.NO_ENDPOSITION => PointPosition.NoEndPosition, - ReportedPointPosition.TRAILED => PointPosition.UnintendedPosition, + ReportedPointPosition.Right => PointPosition.Right, + ReportedPointPosition.Left => PointPosition.Left, + ReportedPointPosition.NoEndposition => PointPosition.NoEndPosition, + ReportedPointPosition.UnintendetPosition => PointPosition.UnintendedPosition, _ => throw new InvalidCastException($"Unable to convert reported point position {reportedPointPosition} to proto enum") }; public static ReportedPointPosition ConvertToReportedPointPosition(this PointPosition pointPositionMessage) => pointPositionMessage switch { - PointPosition.Right => ReportedPointPosition.RIGHT, - PointPosition.Left => ReportedPointPosition.LEFT, - PointPosition.NoEndPosition => ReportedPointPosition.NO_ENDPOSITION, - PointPosition.UnintendedPosition => ReportedPointPosition.TRAILED, + PointPosition.Right => ReportedPointPosition.Right, + PointPosition.Left => ReportedPointPosition.Left, + PointPosition.NoEndPosition => ReportedPointPosition.NoEndposition, + PointPosition.UnintendedPosition => ReportedPointPosition.UnintendetPosition, _ => throw new InvalidCastException($"Unable to convert point position message {pointPositionMessage} to reported point position.") }; } diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index 72d1383..ff9c513 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer; using EulynxLive.Point.Services; using EulynxLive.Messages.IPointToInterlockingConnection; +using EulynxLive.Point.EulynxBaseline4R1; namespace EulynxLive.Point { @@ -20,7 +21,7 @@ public void ConfigureServices(IServiceCollection services) services.AddGrpc(); services.AddGrpcReflection(); - services.AddSingleton(); + services.AddSingleton(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => From a43e3eb45447e9e818d3974d9127c7d6f9c4f6dd Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 28 Nov 2023 16:14:46 +0100 Subject: [PATCH 14/22] resolve comments --- .../PointToInterlockingConnection.cs} | 39 +++++++++------- src/Point/Connections/GrpcConnection.cs | 45 +++++++++++++++++++ .../PointStateBaseline4R1.cs | 2 + src/Point/Interfaces/IConnection.cs | 8 ++++ src/Point/Point.cs | 11 +++-- src/Point/Startup.cs | 12 +++-- 6 files changed, 91 insertions(+), 26 deletions(-) rename src/Point/{PointToInterlockingConnectionB4R1Impl.cs => Connections/Baseline4R1/PointToInterlockingConnection.cs} (82%) create mode 100644 src/Point/Connections/GrpcConnection.cs rename src/Point/{ => Connections}/PointStateBaseline4R1.cs (95%) create mode 100644 src/Point/Interfaces/IConnection.cs diff --git a/src/Point/PointToInterlockingConnectionB4R1Impl.cs b/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs similarity index 82% rename from src/Point/PointToInterlockingConnectionB4R1Impl.cs rename to src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs index d3de42c..d43018e 100644 --- a/src/Point/PointToInterlockingConnectionB4R1Impl.cs +++ b/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs @@ -1,12 +1,8 @@ using EulynxLive.Messages.Baseline4R1; -using EulynxLive.Point; -using Google.Protobuf; using Grpc.Core; -using Grpc.Net.Client; -using Sci; -using EulynxLive.Messages.IPointToInterlockingConnection; using static EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection; -using static Sci.Rasta; +using EulynxLive.Point.Interfaces; +using EulynxLive.Messages.IPointToInterlockingConnection; namespace EulynxLive.Point.EulynxBaseline4R1; @@ -17,13 +13,19 @@ public class PointToInterlockingConnection : IPointToInterlockingConnection private readonly string _localRastaId; private readonly string _remoteId; private readonly string _remoteEndpoint; - AsyncDuplexStreamingCall? _currentConnection; + IConnection? _currentConnection; private CancellationTokenSource _timeout; + private int _timeoutDuration; + private CancellationToken _stoppingToken; public PointToInterlockingConnection( ILogger logger, - IConfiguration configuration) + IConfiguration configuration, + CancellationToken stoppingToken, int timeoutDuration = 10000) { + _timeoutDuration = timeoutDuration; + _stoppingToken = stoppingToken; + _timeout = new CancellationTokenSource(); _logger = logger; _currentConnection = null; @@ -32,18 +34,14 @@ public PointToInterlockingConnection( _localRastaId = config.LocalRastaId.ToString(); _remoteId = config.RemoteId; _remoteEndpoint = config.RemoteEndpoint; - _timeout = new CancellationTokenSource(); } public void Connect() { - var channel = GrpcChannel.ForAddress(_remoteEndpoint); - var client = new RastaClient(channel); + ResetTimeout(); _logger.LogTrace("Connecting..."); - _timeout = new CancellationTokenSource(); - _timeout.CancelAfter(10000); var metadata = new Metadata { { "rasta-id", _localRastaId } }; - _currentConnection = client.Stream(metadata, cancellationToken: _timeout.Token); + _currentConnection = new GrpcConnection(metadata, _remoteEndpoint, _timeout.Token); } public async Task InitializeConnection(PointState state) @@ -97,6 +95,7 @@ async public Task SendTimeoutMessage() { PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsARightHandPointMoving => PointPosition.Right, PointMovePointCommandCommandedPointPosition.SubsystemElectronicInterlockingRequestsALeftHandPointMoving => PointPosition.Left, + _ => throw new global::System.NotImplementedException(), } : null; } @@ -108,15 +107,15 @@ public void Dispose() private async Task SendMessage(Message message) { if (_currentConnection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?"); - await _currentConnection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(message.ToByteArray()) }); + await _currentConnection.SendAsync(message.ToByteArray()); } private async Task ReceiveMessage() where T : Message { if (_currentConnection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?"); - if (!await _currentConnection.ResponseStream.MoveNext(_timeout.Token)) return null; + ResetTimeout(); - var message = Message.FromBytes(_currentConnection.ResponseStream.Current.Message.ToByteArray()); + var message = Message.FromBytes(await _currentConnection.ReceiveAsync(_timeout.Token)); if (message is not T) { _logger.LogError("Unexpected message: {}", message); @@ -124,4 +123,10 @@ private async Task SendMessage(Message message) } return message as T; } + + private void ResetTimeout() + { + _timeout = CancellationTokenSource.CreateLinkedTokenSource(_stoppingToken); + _timeout.CancelAfter(_timeoutDuration); + } } diff --git a/src/Point/Connections/GrpcConnection.cs b/src/Point/Connections/GrpcConnection.cs new file mode 100644 index 0000000..e7f71a0 --- /dev/null +++ b/src/Point/Connections/GrpcConnection.cs @@ -0,0 +1,45 @@ +using EulynxLive.Point.Interfaces; +using Google.Protobuf; +using Grpc.Core; +using Grpc.Net.Client; +using Sci; +using static Sci.Rasta; + +namespace EulynxLive.Point; + +class GrpcConnection : IConnection +{ + class GrpcConnectionException : Exception + { + public GrpcConnectionException(string message) : base(message) { } + } + + AsyncDuplexStreamingCall? _connection; + private CancellationToken _stoppingToken; + + public GrpcConnection(Metadata? metadata, string remoteEndpoint, CancellationToken stoppingToken) + { + _stoppingToken = stoppingToken; + + var channel = GrpcChannel.ForAddress(remoteEndpoint); + var client = new RastaClient(channel); + _connection = client.Stream(metadata, cancellationToken: stoppingToken); + } + public void Dispose() + { + _connection?.Dispose(); + } + + public async Task ReceiveAsync(CancellationToken cancellationToken) + { + if (_connection == null) throw new InvalidOperationException("Grpc connection not connected."); + if (!await _connection.ResponseStream.MoveNext(cancellationToken)) throw new GrpcConnectionException("Could not receive grpc message."); + return _connection.ResponseStream.Current.Message.ToByteArray(); + } + + public async Task SendAsync(byte[] bytes) + { + if (_connection == null) throw new InvalidOperationException("Grpc connection not connected."); + await _connection.RequestStream.WriteAsync(new SciPacket() { Message = ByteString.CopyFrom(bytes) }); + } +} diff --git a/src/Point/PointStateBaseline4R1.cs b/src/Point/Connections/PointStateBaseline4R1.cs similarity index 95% rename from src/Point/PointStateBaseline4R1.cs rename to src/Point/Connections/PointStateBaseline4R1.cs index 69e16a3..3599b9a 100644 --- a/src/Point/PointStateBaseline4R1.cs +++ b/src/Point/Connections/PointStateBaseline4R1.cs @@ -20,6 +20,7 @@ public PointStateBaseline4R1(PointState state) IPointToInterlockingConnection.PointPosition.Right => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, IPointToInterlockingConnection.PointPosition.UnintendetPosition => PointPointPositionMessageReportedPointPosition.PointIsTrailed, IPointToInterlockingConnection.PointPosition.NoEndposition => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, + _ => throw new NotImplementedException(), }; private PointPointPositionMessageReportedDegradedPointPosition MapInterfaceDegradedPointPositionToConcrete(DegradedPointPosition value) => value switch @@ -28,5 +29,6 @@ public PointStateBaseline4R1(PointState state) IPointToInterlockingConnection.DegradedPointPosition.DegradedRight => PointPointPositionMessageReportedDegradedPointPosition.PointIsInADegradedRightHandPosition, IPointToInterlockingConnection.DegradedPointPosition.NotDegraded => PointPointPositionMessageReportedDegradedPointPosition.PointIsNotInADegradedPosition, IPointToInterlockingConnection.DegradedPointPosition.NotApplicable => PointPointPositionMessageReportedDegradedPointPosition.DegradedPointPositionIsNotApplicable, + _ => throw new NotImplementedException(), }; } diff --git a/src/Point/Interfaces/IConnection.cs b/src/Point/Interfaces/IConnection.cs new file mode 100644 index 0000000..9b68e95 --- /dev/null +++ b/src/Point/Interfaces/IConnection.cs @@ -0,0 +1,8 @@ +namespace EulynxLive.Point.Interfaces +{ + interface IConnection : IDisposable + { + Task ReceiveAsync(CancellationToken cancellationToken); + Task SendAsync(byte[] bytes); + } +} diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 2b23394..3ed48b4 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -21,7 +21,6 @@ public class Point : BackgroundService private readonly Random _random; private readonly bool _simulateRandomTimeouts; private bool _initialized; - AsyncDuplexStreamingCall? _currentConnection; private readonly PointState _pointState; public PointState PointState { get { return _pointState; } } @@ -77,7 +76,7 @@ public async Task SimulateUnintendedPosition() _pointState.PointPosition = PointPosition.UnintendetPosition; - if (_currentConnection != null) + if (_connection != null) { await _connection.SendPointPosition(PointState); } @@ -126,7 +125,7 @@ public async Task SetDegraded(PointDegradedMessage message) { _pointState.PointPosition = PointPosition.NoEndposition; - if (_currentConnection != null) + if (_connection != null) { var degradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.NotApplicable : GetDegradedPointPosition(_pointState.PointPosition); @@ -152,7 +151,7 @@ public async Task SetDegraded(PointDegradedMessage message) public async Task PutInEndPosition() { - if (_currentConnection != null) + if (_connection != null) { if (_pointState.PointPosition != PointPosition.Right && _pointState.PointPosition != PointPosition.Left) @@ -171,7 +170,7 @@ public async Task PutInEndPosition() if (finalPosition != null) { UpdatePointState((PointPosition)finalPosition, reportedDegradedPointPosition); - _connection.SendPointPosition(PointState); + await _connection.SendPointPosition(PointState); } } } @@ -205,7 +204,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) if ((commandedPointPosition == PointPosition.Left && _pointState.PointPosition == PointPosition.Left) || (commandedPointPosition == PointPosition.Right && _pointState.PointPosition == PointPosition.Right)) { - _connection.SendPointPosition(PointState); + await _connection.SendPointPosition(PointState); continue; } diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index ff9c513..4e67cf7 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -21,7 +21,10 @@ public void ConfigureServices(IServiceCollection services) services.AddGrpc(); services.AddGrpcReflection(); - services.AddSingleton(); + services.AddSingleton(x => + { + return new PointToInterlockingConnection(x.GetRequiredService>(), x.GetRequiredService(), CancellationToken.None); + }); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => @@ -29,9 +32,12 @@ public void ConfigureServices(IServiceCollection services) configuration.RootPath = "rasta-point-web/build"; }); - try { + try + { services.AddSingleton(); - } catch (Exception e) { + } + catch (Exception e) + { Console.WriteLine($"Usage: --PointSettings:LocalId=<> --PointSettings:LocalRastaId=<> --PointSettings:RemoteId=<> --PointSettings:RemoteEndpoint=<>. {e.Message}"); Environment.Exit(1); } From 9136014c150c4eb4371539f4cdccdc700769768b Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Fri, 24 Nov 2023 15:18:08 +0100 Subject: [PATCH 15/22] Test turnover --- .../Point/PointTest.cs | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index 44e4448..512ae49 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -9,24 +9,73 @@ namespace FieldElementSubsystems.Test; public class PointTest { - [Fact] - public void PointShouldParseConfiguration() - { - var testSettings = new Dictionary { + private IDictionary _testSettings = new Dictionary { {"PointSettings:LocalId", "99W1" }, {"PointSettings:LocalRastaId", "100" }, {"PointSettings:RemoteId", "INTERLOCKING" }, {"PointSettings:RemoteEndpoint", "http://localhost:50051" }, {"PointSettings:AllPointMachinesCrucial", "true" }, - {"PointSettings:SimulateRandomTimeouts", "true" }, + {"PointSettings:SimulateRandomTimeouts", "false" }, }; + [Fact] + public void PointShouldParseConfiguration() + { var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(testSettings) + .AddInMemoryCollection(_testSettings) .Build(); var point = new EulynxLive.Point.Point(Mock.Of>(), configuration, Mock.Of()); Assert.True(point.AllPointMachinesCrucial); } + + [Fact] + public async void Test_Turnover() + { + + // Arrange + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(_testSettings) + .Build(); + + var logger = Mock.Of>(); + + var point = new EulynxLive.Point.Point(logger, configuration, Mock.Of()); + var mockConnection = new Mock(); + mockConnection + .Setup(m => m.SendPointPosition( + It.IsAny())) + .Returns(Task.FromResult(0)); + mockConnection + .Setup(m => m.InitializeConnection( + It.IsAny())) + .Returns(Task.FromResult(true)); + + var finished = false; + mockConnection + .SetupSequence(m => m.ReceivePointPosition()) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) + .Returns(Task.FromResult(null)) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) + .Returns(() => + { + finished = true; + return Task.FromResult(null); + }); + + point = new EulynxLive.Point.Point(logger, configuration, mockConnection.Object); + + // Act + await point.StartAsync(CancellationToken.None); + + while (!finished) + { + await Task.Delay(1000); + } + + // Assert + mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); + Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); + } } From 15d64434be7d1322c130c7fa70bd4c505a0188f4 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Mon, 27 Nov 2023 09:00:53 +0100 Subject: [PATCH 16/22] add more tests --- .../Point/PointTest.cs | 121 ++++++++++++++---- src/Point/Point.cs | 4 +- 2 files changed, 98 insertions(+), 27 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index 512ae49..e955da0 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -1,7 +1,6 @@ -using Castle.Core.Logging; using EulynxLive.Messages.Baseline4R1; using EulynxLive.Messages.IPointToInterlockingConnection; -using EulynxLive.Point; +using Point = EulynxLive.Point.Point; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Moq; @@ -9,7 +8,23 @@ namespace FieldElementSubsystems.Test; public class PointTest { - private IDictionary _testSettings = new Dictionary { + private EulynxLive.Point.Point CreateDefaultPoint(IPointToInterlockingConnection? connection = null) => + new EulynxLive.Point.Point(_logger, _configuration, connection ?? Mock.Of()); + + private Mock CreateDefaultMockConnection() { + var mockConnection = new Mock(); + mockConnection + .Setup(m => m.SendPointPosition( + It.IsAny())) + .Returns(Task.FromResult(0)); + mockConnection + .Setup(m => m.InitializeConnection( + It.IsAny())) + .Returns(Task.FromResult(true)); + return mockConnection; + } + + private static IDictionary _testSettings = new Dictionary { {"PointSettings:LocalId", "99W1" }, {"PointSettings:LocalRastaId", "100" }, {"PointSettings:RemoteId", "INTERLOCKING" }, @@ -17,40 +32,96 @@ public class PointTest {"PointSettings:AllPointMachinesCrucial", "true" }, {"PointSettings:SimulateRandomTimeouts", "false" }, }; - - [Fact] - public void PointShouldParseConfiguration() - { - var configuration = new ConfigurationBuilder() + private IConfiguration _configuration = new ConfigurationBuilder() .AddInMemoryCollection(_testSettings) .Build(); + private ILogger _logger = Mock.Of>(); - var point = new EulynxLive.Point.Point(Mock.Of>(), configuration, Mock.Of()); + [Fact] + public void Test_Parse_Configuration() + { + var point = CreateDefaultPoint(); Assert.True(point.AllPointMachinesCrucial); } [Fact] - public async void Test_Turnover() + public async void Test_Default_Position() { - - // Arrange - var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(_testSettings) - .Build(); + var point = CreateDefaultPoint(); + await point.StartAsync(CancellationToken.None); - var logger = Mock.Of>(); + Assert.Equal(IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION, point.PointState.PointPosition); + } - var point = new EulynxLive.Point.Point(logger, configuration, Mock.Of()); - var mockConnection = new Mock(); + [Fact] + public async void Test_Turn_Left() + { + // Arrange + var point = CreateDefaultPoint(); + var mockConnection = CreateDefaultMockConnection(); + + var finished = false; mockConnection - .Setup(m => m.SendPointPosition( - It.IsAny())) - .Returns(Task.FromResult(0)); + .SetupSequence(m => m.ReceivePointPosition()) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) + .Returns(() => + { + finished = true; + return Task.FromResult(null); + }); + + point = CreateDefaultPoint(mockConnection.Object); + + // Act + await point.StartAsync(CancellationToken.None); + while (!finished) + { + await Task.Delay(1000); + } + + // Assert + mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); + Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); + } + + [Fact] + public async void Test_Turn_Right() + { + // Arrange + var point = CreateDefaultPoint(); + var mockConnection = CreateDefaultMockConnection(); + + var finished = false; mockConnection - .Setup(m => m.InitializeConnection( - It.IsAny())) - .Returns(Task.FromResult(true)); + .SetupSequence(m => m.ReceivePointPosition()) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) + .Returns(() => + { + finished = true; + return Task.FromResult(null); + }); + + point = CreateDefaultPoint(mockConnection.Object); + + // Act + await point.StartAsync(CancellationToken.None); + while (!finished) + { + await Task.Delay(1000); + } + + // Assert + mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); + Assert.Equal(IPointToInterlockingConnection.PointPosition.RIGHT, point.PointState.PointPosition); + } + + [Fact] + public async void Test_Turnover() + { + // Arrange + var point = CreateDefaultPoint(); + var mockConnection = CreateDefaultMockConnection(); var finished = false; mockConnection @@ -64,7 +135,7 @@ public async void Test_Turnover() return Task.FromResult(null); }); - point = new EulynxLive.Point.Point(logger, configuration, mockConnection.Object); + point = CreateDefaultPoint(mockConnection.Object); // Act await point.StartAsync(CancellationToken.None); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index 3ed48b4..ee2f270 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -15,7 +15,7 @@ public class Point : BackgroundService { public bool AllPointMachinesCrucial { get; } - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly List _webSockets; private IPointToInterlockingConnection _connection; private readonly Random _random; @@ -24,7 +24,7 @@ public class Point : BackgroundService private readonly PointState _pointState; public PointState PointState { get { return _pointState; } } - public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) + public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) { _logger = logger; From 5576afb529dc95ccfed961a0041f19ae96ab8a28 Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Tue, 28 Nov 2023 14:07:02 +0100 Subject: [PATCH 17/22] Cancellation --- .../Point/PointTest.cs | 156 +++++++++--------- .../IPointToInterlockingConnection.cs | 5 +- .../PointToInterlockingConnection.cs | 12 +- src/Point/Point.cs | 14 +- 4 files changed, 94 insertions(+), 93 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index e955da0..203872e 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -1,6 +1,4 @@ -using EulynxLive.Messages.Baseline4R1; using EulynxLive.Messages.IPointToInterlockingConnection; -using Point = EulynxLive.Point.Point; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Moq; @@ -19,7 +17,7 @@ private Mock CreateDefaultMockConnection() { .Returns(Task.FromResult(0)); mockConnection .Setup(m => m.InitializeConnection( - It.IsAny())) + It.IsAny(), It.IsAny())) .Returns(Task.FromResult(true)); return mockConnection; } @@ -46,7 +44,7 @@ public void Test_Parse_Configuration() } [Fact] - public async void Test_Default_Position() + public async Task Test_Default_Position() { var point = CreateDefaultPoint(); await point.StartAsync(CancellationToken.None); @@ -55,98 +53,96 @@ public async void Test_Default_Position() } [Fact] - public async void Test_Turn_Left() - { + public async Task Test_Turn_Left() + { // Arrange var point = CreateDefaultPoint(); var mockConnection = CreateDefaultMockConnection(); + var cancel = new CancellationTokenSource(); - var finished = false; mockConnection - .SetupSequence(m => m.ReceivePointPosition()) + .SetupSequence(m => m.ReceivePointPosition(It.IsAny())) .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) .Returns(() => { - finished = true; - return Task.FromResult(null); + cancel.Cancel(); + return new TaskCompletionSource().Task; }); point = CreateDefaultPoint(mockConnection.Object); // Act - await point.StartAsync(CancellationToken.None); - while (!finished) - { - await Task.Delay(1000); - } + await point.StartAsync(cancel.Token); // Assert - mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); + mockConnection.Verify(v => v.InitializeConnection(It.IsAny(), It.IsAny())); Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); } - [Fact] - public async void Test_Turn_Right() - { - // Arrange - var point = CreateDefaultPoint(); - var mockConnection = CreateDefaultMockConnection(); - - var finished = false; - mockConnection - .SetupSequence(m => m.ReceivePointPosition()) - .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) - .Returns(() => - { - finished = true; - return Task.FromResult(null); - }); - - point = CreateDefaultPoint(mockConnection.Object); - - // Act - await point.StartAsync(CancellationToken.None); - while (!finished) - { - await Task.Delay(1000); - } - - // Assert - mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); - Assert.Equal(IPointToInterlockingConnection.PointPosition.RIGHT, point.PointState.PointPosition); - } - - [Fact] - public async void Test_Turnover() - { - // Arrange - var point = CreateDefaultPoint(); - var mockConnection = CreateDefaultMockConnection(); - - var finished = false; - mockConnection - .SetupSequence(m => m.ReceivePointPosition()) - .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) - .Returns(Task.FromResult(null)) - .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) - .Returns(() => - { - finished = true; - return Task.FromResult(null); - }); - - point = CreateDefaultPoint(mockConnection.Object); - - // Act - await point.StartAsync(CancellationToken.None); - - while (!finished) - { - await Task.Delay(1000); - } - - // Assert - mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); - Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); - } + // [Fact] + // public async Task Test_Turn_Right() + // { + // var cancel = new CancellationTokenSource(); + // // Arrange + // var point = CreateDefaultPoint(); + // var mockConnection = CreateDefaultMockConnection(); + + // var finished = false; + // mockConnection + // .SetupSequence(m => m.ReceivePointPosition()) + // .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) + // .Returns(() => + // { + // finished = true; + // return Task.FromResult(null); + // }); + + // point = CreateDefaultPoint(mockConnection.Object); + + // // Act + // await point.StartAsync(CancellationToken.None); + // while (!finished) + // { + // await Task.Delay(1000); + // } + + // // Assert + // mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); + // Assert.Equal(IPointToInterlockingConnection.PointPosition.RIGHT, point.PointState.PointPosition); + // } + + // [Fact] + // public async Task Test_Turnover() + // { + // var cancel = new CancellationTokenSource(); + // // Arrange + // var point = CreateDefaultPoint(); + // var mockConnection = CreateDefaultMockConnection(); + + // var finished = false; + // mockConnection + // .SetupSequence(m => m.ReceivePointPosition()) + // .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) + // .Returns(Task.FromResult(null)) + // .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) + // .Returns(() => + // { + // finished = true; + // return Task.FromResult(null); + // }); + + // point = CreateDefaultPoint(mockConnection.Object); + + // // Act + // await point.StartAsync(CancellationToken.None); + + // while (!finished) + // { + // await Task.Delay(1000); + // } + + // // Assert + // mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); + // Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); + // } } diff --git a/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs b/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs index cae25bb..9822cbf 100644 --- a/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs +++ b/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs @@ -1,3 +1,4 @@ +using System.Threading; using System.Threading.Tasks; namespace EulynxLive.Messages.IPointToInterlockingConnection; @@ -6,8 +7,8 @@ public interface IPointToInterlockingConnection: System.IDisposable { Task SendPointPosition(PointState state); Task SendTimeoutMessage(); void Connect(); - Task InitializeConnection(PointState state); - public Task ReceivePointPosition(); + Task InitializeConnection(PointState state, CancellationToken cancellationToken); + public Task ReceivePointPosition(CancellationToken stoppingToken); public record PointState { diff --git a/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs b/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs index d43018e..074ae59 100644 --- a/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs +++ b/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs @@ -44,10 +44,10 @@ public void Connect() _currentConnection = new GrpcConnection(metadata, _remoteEndpoint, _timeout.Token); } - public async Task InitializeConnection(PointState state) + public async Task InitializeConnection(PointState state, CancellationToken cancellationToken) { _logger.LogTrace("Connected. Waiting for request..."); - if (await ReceiveMessage() == null) + if (await ReceiveMessage(cancellationToken) == null) { _logger.LogError("Unexpected message."); return false; @@ -56,7 +56,7 @@ public async Task InitializeConnection(PointState state) var versionCheckResponse = new PointPdiVersionCheckMessage(_localId, _remoteId, PointPdiVersionCheckMessageResultPdiVersionCheck.PDIVersionsFromReceiverAndSenderDoMatch, /* TODO */ 0, 0, new byte[] { }); await SendMessage(versionCheckResponse); - if (await ReceiveMessage() == null) + if (await ReceiveMessage(cancellationToken) == null) { _logger.LogError("Unexpected message."); return false; @@ -87,9 +87,9 @@ async public Task SendTimeoutMessage() await SendMessage(response); } - public async Task ReceivePointPosition() + public async Task ReceivePointPosition(CancellationToken cancellationToken) { - var message = await ReceiveMessage(); + var message = await ReceiveMessage(cancellationToken); return (message != null)? message.CommandedPointPosition switch { @@ -110,7 +110,7 @@ private async Task SendMessage(Message message) await _currentConnection.SendAsync(message.ToByteArray()); } - private async Task ReceiveMessage() where T : Message + private async Task ReceiveMessage(CancellationToken cancellationToken) where T : Message { if (_currentConnection == null) throw new InvalidOperationException("Connection is null. Did you call Connect()?"); ResetTimeout(); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index ee2f270..b13d42c 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -186,7 +186,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await Reset(); try { - var success = await _connection.InitializeConnection(PointState); + var success = await _connection.InitializeConnection(PointState, stoppingToken); if (!success) { continue; @@ -195,7 +195,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) while (true) { - var commandedPointPosition = await _connection.ReceivePointPosition(); + var commandedPointPosition = await _connection.ReceivePointPosition(stoppingToken); if (commandedPointPosition == null) { break; @@ -253,13 +253,17 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) catch (RpcException) { _logger.LogWarning("Could not communicate with remote endpoint."); + await Reset(); + await Task.Delay(1000, stoppingToken); } - catch (Exception ex) + catch (OperationCanceledException) { - _logger.LogWarning(ex, "Exception during simulation."); + await Reset(); + return; } - finally + catch (Exception ex) { + _logger.LogWarning(ex, "Exception during simulation."); await Reset(); await Task.Delay(1000, stoppingToken); } From 7359cde1a0945ae3e28dbbb0e6582a1e5e8502b1 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Tue, 28 Nov 2023 16:31:09 +0100 Subject: [PATCH 18/22] minor fixes --- .../Point/PointTest.cs | 129 ++++++++---------- src/Point/Point.cs | 4 +- 2 files changed, 61 insertions(+), 72 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index 203872e..9d6565e 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -33,7 +33,7 @@ private Mock CreateDefaultMockConnection() { private IConfiguration _configuration = new ConfigurationBuilder() .AddInMemoryCollection(_testSettings) .Build(); - private ILogger _logger = Mock.Of>(); + private ILogger _logger = Mock.Of>(); [Fact] public void Test_Parse_Configuration() @@ -49,7 +49,7 @@ public async Task Test_Default_Position() var point = CreateDefaultPoint(); await point.StartAsync(CancellationToken.None); - Assert.Equal(IPointToInterlockingConnection.PointPosition.NO_ENDPOSITION, point.PointState.PointPosition); + Assert.Equal(IPointToInterlockingConnection.PointPosition.NoEndposition, point.PointState.PointPosition); } [Fact] @@ -62,7 +62,7 @@ public async Task Test_Turn_Left() mockConnection .SetupSequence(m => m.ReceivePointPosition(It.IsAny())) - .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.Left)) .Returns(() => { cancel.Cancel(); @@ -76,73 +76,62 @@ public async Task Test_Turn_Left() // Assert mockConnection.Verify(v => v.InitializeConnection(It.IsAny(), It.IsAny())); - Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); + Assert.Equal(IPointToInterlockingConnection.PointPosition.Left, point.PointState.PointPosition); } - // [Fact] - // public async Task Test_Turn_Right() - // { - // var cancel = new CancellationTokenSource(); - // // Arrange - // var point = CreateDefaultPoint(); - // var mockConnection = CreateDefaultMockConnection(); - - // var finished = false; - // mockConnection - // .SetupSequence(m => m.ReceivePointPosition()) - // .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) - // .Returns(() => - // { - // finished = true; - // return Task.FromResult(null); - // }); - - // point = CreateDefaultPoint(mockConnection.Object); - - // // Act - // await point.StartAsync(CancellationToken.None); - // while (!finished) - // { - // await Task.Delay(1000); - // } - - // // Assert - // mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); - // Assert.Equal(IPointToInterlockingConnection.PointPosition.RIGHT, point.PointState.PointPosition); - // } - - // [Fact] - // public async Task Test_Turnover() - // { - // var cancel = new CancellationTokenSource(); - // // Arrange - // var point = CreateDefaultPoint(); - // var mockConnection = CreateDefaultMockConnection(); - - // var finished = false; - // mockConnection - // .SetupSequence(m => m.ReceivePointPosition()) - // .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.RIGHT)) - // .Returns(Task.FromResult(null)) - // .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.LEFT)) - // .Returns(() => - // { - // finished = true; - // return Task.FromResult(null); - // }); - - // point = CreateDefaultPoint(mockConnection.Object); - - // // Act - // await point.StartAsync(CancellationToken.None); - - // while (!finished) - // { - // await Task.Delay(1000); - // } - - // // Assert - // mockConnection.Verify(v => v.InitializeConnection(It.IsAny())); - // Assert.Equal(IPointToInterlockingConnection.PointPosition.LEFT, point.PointState.PointPosition); - // } + [Fact] + public async Task Test_Turn_Right() + { + var cancel = new CancellationTokenSource(); + // Arrange + var point = CreateDefaultPoint(); + var mockConnection = CreateDefaultMockConnection(); + + mockConnection + .SetupSequence(m => m.ReceivePointPosition(It.IsAny())) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.Right)) + .Returns(() => + { + cancel.Cancel(); + return new TaskCompletionSource().Task; + }); + + point = CreateDefaultPoint(mockConnection.Object); + + // Act + await point.StartAsync(CancellationToken.None); + + // Assert + mockConnection.Verify(v => v.InitializeConnection(It.IsAny(), It.IsAny())); + Assert.Equal(IPointToInterlockingConnection.PointPosition.Right, point.PointState.PointPosition); + } + + [Fact] + public async Task Test_Turnover() + { + var cancel = new CancellationTokenSource(); + // Arrange + var point = CreateDefaultPoint(); + var mockConnection = CreateDefaultMockConnection(); + + mockConnection + .SetupSequence(m => m.ReceivePointPosition(It.IsAny())) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.Right)) + .Returns(Task.FromResult(null)) + .Returns(Task.FromResult(IPointToInterlockingConnection.PointPosition.Left)) + .Returns(() => + { + cancel.Cancel(); + return new TaskCompletionSource().Task; + }); + + point = CreateDefaultPoint(mockConnection.Object); + + // Act + await point.StartAsync(CancellationToken.None); + + // Assert + mockConnection.Verify(v => v.InitializeConnection(It.IsAny(), It.IsAny())); + Assert.Equal(IPointToInterlockingConnection.PointPosition.Left, point.PointState.PointPosition); + } } diff --git a/src/Point/Point.cs b/src/Point/Point.cs index b13d42c..c10b993 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -15,7 +15,7 @@ public class Point : BackgroundService { public bool AllPointMachinesCrucial { get; } - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly List _webSockets; private IPointToInterlockingConnection _connection; private readonly Random _random; @@ -24,7 +24,7 @@ public class Point : BackgroundService private readonly PointState _pointState; public PointState PointState { get { return _pointState; } } - public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) + public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) { _logger = logger; From 39e15460fb17ae41e72843a5bf8b66c446be7ded Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 29 Nov 2023 10:11:12 +0100 Subject: [PATCH 19/22] resolve comment --- src/FieldElementSubsystems.Test/Point/PointTest.cs | 2 +- .../Baseline4R1/PointToInterlockingConnection.cs | 6 ++++-- src/Point/Connections/PointStateBaseline4R1.cs | 6 ++++-- .../Interfaces}/IPointToInterlockingConnection.cs | 7 ++----- src/Point/Point.cs | 11 +++++------ .../ReportedPointPositionProtoConversion.cs | 4 +--- src/Point/Startup.cs | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) rename src/{Messages/IPointToInterlockingConnection => Point/Interfaces}/IPointToInterlockingConnection.cs (79%) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index 9d6565e..bd75540 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -1,4 +1,4 @@ -using EulynxLive.Messages.IPointToInterlockingConnection; +using IPointToInterlockingConnection = EulynxLive.Point.Interfaces.IPointToInterlockingConnection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Moq; diff --git a/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs b/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs index 074ae59..5d11b0e 100644 --- a/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs +++ b/src/Point/Connections/Baseline4R1/PointToInterlockingConnection.cs @@ -1,8 +1,10 @@ using EulynxLive.Messages.Baseline4R1; using Grpc.Core; -using static EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection; +using IPointToInterlockingConnection = EulynxLive.Point.Interfaces.IPointToInterlockingConnection; +using PointState = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointState; +using PointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointPosition; using EulynxLive.Point.Interfaces; -using EulynxLive.Messages.IPointToInterlockingConnection; + namespace EulynxLive.Point.EulynxBaseline4R1; diff --git a/src/Point/Connections/PointStateBaseline4R1.cs b/src/Point/Connections/PointStateBaseline4R1.cs index 3599b9a..3a69877 100644 --- a/src/Point/Connections/PointStateBaseline4R1.cs +++ b/src/Point/Connections/PointStateBaseline4R1.cs @@ -1,7 +1,9 @@ using EulynxLive.Messages.Baseline4R1; -using EulynxLive.Messages.IPointToInterlockingConnection; -using static EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection; +using IPointToInterlockingConnection = EulynxLive.Point.Interfaces.IPointToInterlockingConnection; +using PointState = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointState; +using PointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointPosition; +using DegradedPointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.DegradedPointPosition; public record PointStateBaseline4R1 { diff --git a/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs b/src/Point/Interfaces/IPointToInterlockingConnection.cs similarity index 79% rename from src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs rename to src/Point/Interfaces/IPointToInterlockingConnection.cs index 9822cbf..3329e74 100644 --- a/src/Messages/IPointToInterlockingConnection/IPointToInterlockingConnection.cs +++ b/src/Point/Interfaces/IPointToInterlockingConnection.cs @@ -1,9 +1,6 @@ -using System.Threading; -using System.Threading.Tasks; +namespace EulynxLive.Point.Interfaces; -namespace EulynxLive.Messages.IPointToInterlockingConnection; - -public interface IPointToInterlockingConnection: System.IDisposable { +public interface IPointToInterlockingConnection: IDisposable { Task SendPointPosition(PointState state); Task SendTimeoutMessage(); void Connect(); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index c10b993..acd229b 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -1,10 +1,9 @@ -using DegradedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.DegradedPointPosition; -using EulynxLive.Messages.IPointToInterlockingConnection; -using EulynxLive.Point.Proto; +using EulynxLive.Point.Proto; using Grpc.Core; -using PointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition; -using PointState = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointState; -using Sci; +using IPointToInterlockingConnection = EulynxLive.Point.Interfaces.IPointToInterlockingConnection; +using PointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointPosition; +using PointState = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointState; +using DegradedPointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.DegradedPointPosition; using System.Net.WebSockets; using System.Text; using System.Text.Json; diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index fef9b23..2ae254d 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -1,8 +1,6 @@ -using System; using EulynxLive.Point.Proto; -using ReportedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.PointPosition ; -using DegradedPointPosition = EulynxLive.Messages.IPointToInterlockingConnection.IPointToInterlockingConnection.DegradedPointPosition; +using ReportedPointPosition = EulynxLive.Point.Interfaces.IPointToInterlockingConnection.PointPosition ; namespace Point.Services.Extensions { diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index 4e67cf7..d37e9dc 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer; using EulynxLive.Point.Services; -using EulynxLive.Messages.IPointToInterlockingConnection; +using IPointToInterlockingConnection =EulynxLive.Point.Interfaces.IPointToInterlockingConnection; using EulynxLive.Point.EulynxBaseline4R1; namespace EulynxLive.Point From 09a429cb4543e79012c6deff1ef6eda56ba35697 Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Thu, 30 Nov 2023 08:07:33 +0100 Subject: [PATCH 20/22] refactor timeout simulation --- src/FieldElementSubsystems.Test/Point/PointTest.cs | 2 +- src/Point/Point.cs | 6 ++++-- src/Point/Startup.cs | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index bd75540..ca6e4f9 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -7,7 +7,7 @@ namespace FieldElementSubsystems.Test; public class PointTest { private EulynxLive.Point.Point CreateDefaultPoint(IPointToInterlockingConnection? connection = null) => - new EulynxLive.Point.Point(_logger, _configuration, connection ?? Mock.Of()); + new EulynxLive.Point.Point(_logger, _configuration, connection ?? Mock.Of(), async () => {}); private Mock CreateDefaultMockConnection() { var mockConnection = new Mock(); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index acd229b..d395207 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -15,6 +15,7 @@ public class Point : BackgroundService public bool AllPointMachinesCrucial { get; } private readonly ILogger _logger; + private readonly Func _simulateTimeout; private readonly List _webSockets; private IPointToInterlockingConnection _connection; private readonly Random _random; @@ -23,9 +24,10 @@ public class Point : BackgroundService private readonly PointState _pointState; public PointState PointState { get { return _pointState; } } - public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection) + public Point(ILogger logger, IConfiguration configuration, IPointToInterlockingConnection connection, Func simulateTimeout) { _logger = logger; + _simulateTimeout = simulateTimeout; var config = configuration.GetSection("PointSettings").Get() ?? throw new Exception("No configuration provided"); if (config.AllPointMachinesCrucial == null) @@ -239,7 +241,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } else { - await transitioningTask; + await _simulateTimeout(); UpdatePointState(commandedPointPosition.Value); await UpdateConnectedWebClients(); diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index d37e9dc..f72e87c 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -34,7 +34,11 @@ public void ConfigureServices(IServiceCollection services) try { - services.AddSingleton(); + services.AddSingleton(x => + { + Func simulateTimout = async () => await Task.Delay(new Random().Next(1, 5) * 1000); + return new Point(x.GetRequiredService>(), x.GetRequiredService(), x.GetRequiredService(), simulateTimout); + }); } catch (Exception e) { From f570596e03b0c7ceeb47c39410125ba734f507be Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Sun, 3 Dec 2023 12:57:24 +0100 Subject: [PATCH 21/22] Fix typo --- .../Point/PointTest.cs | 2 +- .../Connections/PointStateBaseline4R1.cs | 4 ++-- .../IPointToInterlockingConnection.cs | 4 ++-- src/Point/Point.cs | 20 +++++++++---------- .../ReportedPointPositionProtoConversion.cs | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index ca6e4f9..7b3fca4 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -49,7 +49,7 @@ public async Task Test_Default_Position() var point = CreateDefaultPoint(); await point.StartAsync(CancellationToken.None); - Assert.Equal(IPointToInterlockingConnection.PointPosition.NoEndposition, point.PointState.PointPosition); + Assert.Equal(IPointToInterlockingConnection.PointPosition.NoEndPosition, point.PointState.PointPosition); } [Fact] diff --git a/src/Point/Connections/PointStateBaseline4R1.cs b/src/Point/Connections/PointStateBaseline4R1.cs index 3a69877..ef4349e 100644 --- a/src/Point/Connections/PointStateBaseline4R1.cs +++ b/src/Point/Connections/PointStateBaseline4R1.cs @@ -20,8 +20,8 @@ public PointStateBaseline4R1(PointState state) { IPointToInterlockingConnection.PointPosition.Left => PointPointPositionMessageReportedPointPosition.PointIsInALeftHandPositionDefinedEndPosition, IPointToInterlockingConnection.PointPosition.Right => PointPointPositionMessageReportedPointPosition.PointIsInARightHandPositionDefinedEndPosition, - IPointToInterlockingConnection.PointPosition.UnintendetPosition => PointPointPositionMessageReportedPointPosition.PointIsTrailed, - IPointToInterlockingConnection.PointPosition.NoEndposition => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, + IPointToInterlockingConnection.PointPosition.UnintendedPosition => PointPointPositionMessageReportedPointPosition.PointIsTrailed, + IPointToInterlockingConnection.PointPosition.NoEndPosition => PointPointPositionMessageReportedPointPosition.PointIsInNoEndPosition, _ => throw new NotImplementedException(), }; diff --git a/src/Point/Interfaces/IPointToInterlockingConnection.cs b/src/Point/Interfaces/IPointToInterlockingConnection.cs index 3329e74..9b9b7af 100644 --- a/src/Point/Interfaces/IPointToInterlockingConnection.cs +++ b/src/Point/Interfaces/IPointToInterlockingConnection.cs @@ -17,8 +17,8 @@ public enum PointPosition { Left, Right, - UnintendetPosition, - NoEndposition + UnintendedPosition, + NoEndPosition } public enum DegradedPointPosition diff --git a/src/Point/Point.cs b/src/Point/Point.cs index d395207..bb04384 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -40,7 +40,7 @@ public Point(ILogger logger, IConfiguration configuration, IPointToInterl _webSockets = new List(); _pointState = new PointState() { - PointPosition = PointPosition.NoEndposition, + PointPosition = PointPosition.NoEndPosition, DegradedPointPosition = AllPointMachinesCrucial ? DegradedPointPosition.NotApplicable : DegradedPointPosition.NotDegraded }; _random = new Random(); @@ -74,7 +74,7 @@ public async Task HandleWebSocket(WebSocket webSocket) public async Task SimulateUnintendedPosition() { - _pointState.PointPosition = PointPosition.UnintendetPosition; + _pointState.PointPosition = PointPosition.UnintendedPosition; if (_connection != null) @@ -92,17 +92,17 @@ public async Task SimulateUnintendedPosition() => DegradedPointPosition.DegradedRight, PointPosition.Left => DegradedPointPosition.DegradedLeft, - PointPosition.UnintendetPosition + PointPosition.UnintendedPosition => null, - PointPosition.NoEndposition + PointPosition.NoEndPosition => null, _ => null, }; private static PointPosition? GetPointPositionDegraded(Proto.PointPosition pointPosition) => pointPosition switch { - Proto.PointPosition.NoEndPosition => PointPosition.NoEndposition, - Proto.PointPosition.UnintendedPosition => PointPosition.UnintendetPosition, + Proto.PointPosition.NoEndPosition => PointPosition.NoEndPosition, + Proto.PointPosition.UnintendedPosition => PointPosition.UnintendedPosition, _ => null, }; @@ -124,7 +124,7 @@ private void UpdatePointState(PointPosition pointPosition, DegradedPointPosition /// public async Task SetDegraded(PointDegradedMessage message) { - _pointState.PointPosition = PointPosition.NoEndposition; + _pointState.PointPosition = PointPosition.NoEndPosition; if (_connection != null) { @@ -209,7 +209,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) continue; } - UpdatePointState(PointPosition.NoEndposition, DegradedPointPosition.NotApplicable); + UpdatePointState(PointPosition.NoEndPosition, DegradedPointPosition.NotApplicable); await UpdateConnectedWebClients(); @@ -295,8 +295,8 @@ private async Task UpdateWebClient(WebSocket webSocket) var positions = new Dictionary { {PointPosition.Right, "right"}, {PointPosition.Left, "left"}, - {PointPosition.NoEndposition, "noEndPosition"}, - {PointPosition.UnintendetPosition, "trailed"}, + {PointPosition.NoEndPosition, "noEndPosition"}, + {PointPosition.UnintendedPosition, "trailed"}, }; var options = new JsonSerializerOptions { WriteIndented = true }; var serializedState = JsonSerializer.Serialize(new diff --git a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs index 2ae254d..91189fc 100644 --- a/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs +++ b/src/Point/Services/Extensions/ReportedPointPositionProtoConversion.cs @@ -10,8 +10,8 @@ public static class ReportedPointPositionProtoConversion { ReportedPointPosition.Right => PointPosition.Right, ReportedPointPosition.Left => PointPosition.Left, - ReportedPointPosition.NoEndposition => PointPosition.NoEndPosition, - ReportedPointPosition.UnintendetPosition => PointPosition.UnintendedPosition, + ReportedPointPosition.NoEndPosition => PointPosition.NoEndPosition, + ReportedPointPosition.UnintendedPosition => PointPosition.UnintendedPosition, _ => throw new InvalidCastException($"Unable to convert reported point position {reportedPointPosition} to proto enum") }; @@ -19,8 +19,8 @@ public static class ReportedPointPositionProtoConversion { PointPosition.Right => ReportedPointPosition.Right, PointPosition.Left => ReportedPointPosition.Left, - PointPosition.NoEndPosition => ReportedPointPosition.NoEndposition, - PointPosition.UnintendedPosition => ReportedPointPosition.UnintendetPosition, + PointPosition.NoEndPosition => ReportedPointPosition.NoEndPosition, + PointPosition.UnintendedPosition => ReportedPointPosition.UnintendedPosition, _ => throw new InvalidCastException($"Unable to convert point position message {pointPositionMessage} to reported point position.") }; } From e5848ad3621014b35c052d9de1982c6765140abf Mon Sep 17 00:00:00 2001 From: Robert Schmid Date: Sun, 3 Dec 2023 13:13:35 +0100 Subject: [PATCH 22/22] Fix tests --- .../Point/PointTest.cs | 34 +++++++++---------- .../IPointToInterlockingConnection.cs | 2 +- src/Point/Point.cs | 8 ++--- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index 7b3fca4..6bc4cda 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -7,7 +7,7 @@ namespace FieldElementSubsystems.Test; public class PointTest { private EulynxLive.Point.Point CreateDefaultPoint(IPointToInterlockingConnection? connection = null) => - new EulynxLive.Point.Point(_logger, _configuration, connection ?? Mock.Of(), async () => {}); + new(_logger, _configuration, connection ?? Mock.Of(), () => Task.CompletedTask); private Mock CreateDefaultMockConnection() { var mockConnection = new Mock(); @@ -22,18 +22,18 @@ private Mock CreateDefaultMockConnection() { return mockConnection; } - private static IDictionary _testSettings = new Dictionary { - {"PointSettings:LocalId", "99W1" }, - {"PointSettings:LocalRastaId", "100" }, - {"PointSettings:RemoteId", "INTERLOCKING" }, - {"PointSettings:RemoteEndpoint", "http://localhost:50051" }, - {"PointSettings:AllPointMachinesCrucial", "true" }, - {"PointSettings:SimulateRandomTimeouts", "false" }, - }; - private IConfiguration _configuration = new ConfigurationBuilder() + private static readonly IDictionary _testSettings = new Dictionary { + {"PointSettings:LocalId", "99W1" }, + {"PointSettings:LocalRastaId", "100" }, + {"PointSettings:RemoteId", "INTERLOCKING" }, + {"PointSettings:RemoteEndpoint", "http://localhost:50051" }, + {"PointSettings:AllPointMachinesCrucial", "true" }, + {"PointSettings:SimulateRandomTimeouts", "false" }, + }; + private readonly IConfiguration _configuration = new ConfigurationBuilder() .AddInMemoryCollection(_testSettings) .Build(); - private ILogger _logger = Mock.Of>(); + private readonly ILogger _logger = Mock.Of>(); [Fact] public void Test_Parse_Configuration() @@ -44,11 +44,9 @@ public void Test_Parse_Configuration() } [Fact] - public async Task Test_Default_Position() + public void Test_Default_Position() { var point = CreateDefaultPoint(); - await point.StartAsync(CancellationToken.None); - Assert.Equal(IPointToInterlockingConnection.PointPosition.NoEndPosition, point.PointState.PointPosition); } @@ -82,10 +80,10 @@ public async Task Test_Turn_Left() [Fact] public async Task Test_Turn_Right() { - var cancel = new CancellationTokenSource(); // Arrange var point = CreateDefaultPoint(); var mockConnection = CreateDefaultMockConnection(); + var cancel = new CancellationTokenSource(); mockConnection .SetupSequence(m => m.ReceivePointPosition(It.IsAny())) @@ -99,7 +97,7 @@ public async Task Test_Turn_Right() point = CreateDefaultPoint(mockConnection.Object); // Act - await point.StartAsync(CancellationToken.None); + await point.StartAsync(cancel.Token); // Assert mockConnection.Verify(v => v.InitializeConnection(It.IsAny(), It.IsAny())); @@ -109,10 +107,10 @@ public async Task Test_Turn_Right() [Fact] public async Task Test_Turnover() { - var cancel = new CancellationTokenSource(); // Arrange var point = CreateDefaultPoint(); var mockConnection = CreateDefaultMockConnection(); + var cancel = new CancellationTokenSource(); mockConnection .SetupSequence(m => m.ReceivePointPosition(It.IsAny())) @@ -128,7 +126,7 @@ public async Task Test_Turnover() point = CreateDefaultPoint(mockConnection.Object); // Act - await point.StartAsync(CancellationToken.None); + await point.StartAsync(cancel.Token); // Assert mockConnection.Verify(v => v.InitializeConnection(It.IsAny(), It.IsAny())); diff --git a/src/Point/Interfaces/IPointToInterlockingConnection.cs b/src/Point/Interfaces/IPointToInterlockingConnection.cs index 9b9b7af..04eccf0 100644 --- a/src/Point/Interfaces/IPointToInterlockingConnection.cs +++ b/src/Point/Interfaces/IPointToInterlockingConnection.cs @@ -1,6 +1,6 @@ namespace EulynxLive.Point.Interfaces; -public interface IPointToInterlockingConnection: IDisposable { +public interface IPointToInterlockingConnection : IDisposable { Task SendPointPosition(PointState state); Task SendTimeoutMessage(); void Connect(); diff --git a/src/Point/Point.cs b/src/Point/Point.cs index bb04384..4a5fe7a 100644 --- a/src/Point/Point.cs +++ b/src/Point/Point.cs @@ -17,7 +17,7 @@ public class Point : BackgroundService private readonly ILogger _logger; private readonly Func _simulateTimeout; private readonly List _webSockets; - private IPointToInterlockingConnection _connection; + private readonly IPointToInterlockingConnection _connection; private readonly Random _random; private readonly bool _simulateRandomTimeouts; private bool _initialized; @@ -190,7 +190,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) var success = await _connection.InitializeConnection(PointState, stoppingToken); if (!success) { - continue; + throw new Exception("Unable to initialize connection"); } await UpdateConnectedWebClients(); @@ -215,14 +215,14 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) // Simulate point movement var transitioningTime = _random.Next(1, 5); - var transitioningTask = Task.Delay(transitioningTime * 1000); + var transitioningTask = Task.Delay(transitioningTime * 1000, CancellationToken.None); var pointMovementTimeout = 3 * 1000; _logger.LogDebug("Moving to {}.", commandedPointPosition); if (_simulateRandomTimeouts) { - if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout)) == transitioningTask) + if (await Task.WhenAny(transitioningTask, Task.Delay(pointMovementTimeout, CancellationToken.None)) == transitioningTask) { // transition completed within timeout UpdatePointState(commandedPointPosition.Value);