public static bool TryParse(byte[] bytes, out InterfaceResponseMessage message)
        {
            message = default(InterfaceResponseMessage);

            if (bytes.Length != PacketLengths.InterfaceResponse + 1)
            {
                return(false);
            }

            var packetLength = bytes[0];

            if (packetLength != PacketLengths.InterfaceResponse)
            {
                return(false);
            }

            PacketType packetType;

            if (!PacketType.TryParse(bytes[1], out packetType) && packetType != PacketType.InterfaceMessage)
            {
                return(false);
            }

            InterfaceResponseSubType subType;

            if (!InterfaceResponseSubType.TryParse(bytes[2], out subType))
            {
                return(false);
            }

            var sequenceNumber = bytes[3];

            InterfaceControlCommand command;

            if (!InterfaceControlCommand.TryParse(bytes[4], out command))
            {
                return(false);
            }

            TransceiverType message1;

            if (!TransceiverType.TryParse(bytes[5], out message1))
            {
                return(false);
            }

            var message2 = bytes[6];
            var message3 = bytes[7];
            var message4 = bytes[8];
            var message5 = bytes[9];

            var enabledProtocols1 = Protocol.ListEnabled(message3).Where(x => x.MessageNumber == 3);
            var enabledProtocols2 = Protocol.ListEnabled(message4).Where(x => x.MessageNumber == 4);
            var enabledProtocols3 = Protocol.ListEnabled(message5).Where(x => x.MessageNumber == 5);
            var enabledProtocols  = enabledProtocols1.Concat(enabledProtocols2).Concat(enabledProtocols3).ToArray();

            message = new InterfaceResponseMessage(packetLength, packetType, subType, sequenceNumber, command, message1, message2, enabledProtocols);

            return(true);
        }
 public InterfaceResponseMessage(byte packetLength, PacketType packetType, InterfaceResponseSubType subType, byte sequenceNumber, InterfaceControlCommand controlCommand, TransceiverType transceiverType, byte version, Protocol[] protocols)
 {
     PacketLength    = packetLength;
     PacketType      = packetType;
     SubType         = subType;
     SequenceNumber  = sequenceNumber;
     ControlCommand  = controlCommand;
     TransceiverType = transceiverType;
     Version         = version;
     Protocols       = protocols;
 }
Example #3
0
        public InterfaceControlMessage(byte sequenceNumber, InterfaceControlCommand controlCommand, byte[] messages)
        {
            if (messages.Length != 9)
            {
                throw new ArgumentException("Must be an array of 9 bytes", "messages");
            }

            PacketLength   = PacketLengths.InterfaceControl;
            PacketType     = PacketType.InterfaceCommand;
            SubType        = InterfaceControlSubType.ModeCommand;
            SequenceNumber = sequenceNumber;
            ControlCommand = controlCommand;
            Messages       = messages;
        }
Example #4
0
 public InterfaceControlMessage(InterfaceControlCommand controlCommand)
     : this(0, controlCommand, Buffer.Empty(9))
 {
 }
Example #5
0
 public InterfaceControlMessage(InterfaceControlCommand controlCommand, byte[] messages) : this(0, controlCommand, messages)
 {
 }