Esempio n. 1
0
 public override int GetResponseLength()
 {
     return(base.GetResponseLength() +
            UniversalInputs.Length * sizeof(short) +
            CounterInput.Length * sizeof(short) +
            CounterValue.Length * sizeof(short) +
            CounterCommandId.Length * sizeof(short) +
            MotorCommandId.Length * sizeof(short) +
            sizeof(ushort) +
            ResponseExchangeDataIr.GetByteLength() * Ir.Length + 1);
 }
Esempio n. 2
0
        public override void FromByteArray(byte[] bytes)
        {
            if (bytes.Length < GetResponseLength())
            {
                throw new InvalidOperationException($"The byte array is to short to read. Length is {bytes.Length} bytes and 24 bytes are needed");
            }

            int bytesIndex = 0;

            var id = BitConverter.ToUInt32(bytes, bytesIndex);

            bytesIndex += 4;


            if (id != ResponseId)
            {
                throw new InvalidOperationException($"The byte array does not match the response id. Expected id is {ResponseId} and response id is {id}");
            }


            for (int i = 0; i < UniversalInputs.Length; i++)
            {
                UniversalInputs[i] = BitConverter.ToInt16(bytes, bytesIndex);

                bytesIndex += sizeof(short);
            }

            for (int i = 0; i < CounterInput.Length; i++)
            {
                CounterInput[i] = BitConverter.ToInt16(bytes, bytesIndex);

                bytesIndex += sizeof(short);
            }

            for (int i = 0; i < CounterValue.Length; i++)
            {
                CounterValue[i] = BitConverter.ToInt16(bytes, bytesIndex);

                bytesIndex += sizeof(short);
            }

            for (int i = 0; i < CounterCommandId.Length; i++)
            {
                CounterCommandId[i] = BitConverter.ToInt16(bytes, bytesIndex);

                bytesIndex += sizeof(short);
            }

            for (int i = 0; i < MotorCommandId.Length; i++)
            {
                MotorCommandId[i] = BitConverter.ToInt16(bytes, bytesIndex);

                bytesIndex += sizeof(short);
            }


            SoundCommandId = BitConverter.ToUInt16(bytes, bytesIndex);


            for (int i = 0; i < Ir.Length; i++)
            {
                Ir[i] = new ResponseExchangeDataIr();
                Ir[i].FromBytes(bytes, bytesIndex);

                bytesIndex += ResponseExchangeDataIr.GetByteLength();
            }
        }