Пример #1
0
        public AcknowledgeResponse(ProdysSocketProxy socket)
        {
            var buffer = new byte[16];

            socket.Receive(buffer);

            Command         = (Command)ConvertHelper.DecodeUInt(buffer, 0);
            Length          = (int)ConvertHelper.DecodeUInt(buffer, 4);
            ReceivedCommand = (Command)ConvertHelper.DecodeUInt(buffer, 8);
            Acknowleged     = Convert.ToBoolean(ConvertHelper.DecodeUInt(buffer, 12));
        }
        protected static byte[] GetResponseBytes(ProdysSocketProxy socket, Command expectedCommand, int expectedResponseLength)
        {
            // Read fixed part of header
            var buffer = new byte[8];

            socket.Receive(buffer);
            var command = (Command)ConvertHelper.DecodeUInt(buffer, 0);
            var length  = (int)ConvertHelper.DecodeUInt(buffer, 4);

            // Read variable part of header
            var result = new byte[length];

            socket.Receive(result);

            if (command != expectedCommand || length != expectedResponseLength)
            {
                throw new Exception(string.Format(
                                        "Invalid response from codec. Command was {0} and length {1}. Expected {2} with length {3}",
                                        command, length, expectedCommand, expectedResponseLength));
            }

            return(result);
        }
        protected void ParseResponse(ProdysSocketProxy socket, Command expectedCommand)
        {
            var buffer = new byte[8];

            socket.Receive(buffer);
            var command = (Command)ConvertHelper.DecodeUInt(buffer, 0);
            var length  = (int)ConvertHelper.DecodeUInt(buffer, 4);

            // TODO: Verify that length has valid value.

            var payloadBytes = new byte[length];

            socket.Receive(payloadBytes);

            if (command != expectedCommand || length != 4)
            {
                // This is usually a sign that no GPIO exists for the requested gpio number
                Active = null;
                return;
            }

            Active = Convert.ToBoolean(ConvertHelper.DecodeUInt(payloadBytes, 0));
        }