コード例 #1
0
        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);
        }
コード例 #2
0
        public async static Task SetMode(this ITransceiver transceiver, TransceiverType transceiverType, params Protocol[] protocols)
        {
            var messages = Buffer.Empty(9);

            messages[0] = transceiverType;
            messages[2] = (byte)protocols.Where(protocol => protocol.MessageNumber == 3).Sum(protocol => protocol.Value);
            messages[3] = (byte)protocols.Where(protocol => protocol.MessageNumber == 4).Sum(protocol => protocol.Value);
            messages[4] = (byte)protocols.Where(protocol => protocol.MessageNumber == 5).Sum(protocol => protocol.Value);

            await transceiver.Send(new InterfaceControlMessage(InterfaceControlCommand.SetMode, messages));
        }
コード例 #3
0
 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;
 }