Ejemplo n.º 1
0
        /// <summary>
        /// Constructor that builds a packet from a byte sequence.
        /// </summary>
        /// <param name="source">Array of bytes to build the command from.</param>
        public GaiaPacketBLE(byte[] source)
        {
            int payloadLength = source.Length - PACKET_INFORMATION_LENGTH;

            if (payloadLength < 0)
            {
                throw new GaiaException(GaiaException.Type.PACKET_PAYLOAD_INVALID_PARAMETER);
            }

            VendorId  = GaiaUtils.ExtractIntFromByteArray(source, OFFSET_VENDOR_ID, LENGTH_VENDOR_ID, false);
            CommandId = GaiaUtils.ExtractIntFromByteArray(source, OFFSET_COMMAND_ID, LENGTH_COMMAND_ID, false);

            if (payloadLength > 0)
            {
                Payload = new byte[payloadLength];
                Array.Copy(source, OFFSET_PAYLOAD, Payload, 0, payloadLength);
            }

            Bytes = source;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor that builds a command from a byte sequence.
        /// </summary>
        /// <param name="_source">Array of bytes to build the command from.</param>
        public GaiaPacketBREDR(byte[] _source)
        {
            int flags         = _source[OFFSET_FLAGS];
            int payloadLength = _source.Length - OFFSET_PAYLOAD;

            if ((flags & FLAG_CHECK_MASK) != 0)
            {
                --payloadLength;
            }

            VendorId  = GaiaUtils.ExtractIntFromByteArray(_source, OFFSET_VENDOR_ID, LENGTH_VENDOR_ID, false);
            CommandId = GaiaUtils.ExtractIntFromByteArray(_source, OFFSET_COMMAND_ID, LENGTH_COMMAND_ID, false);

            if (payloadLength > 0)
            {
                Payload = new byte[payloadLength];
                Array.Copy(_source, OFFSET_PAYLOAD, Payload, 0, payloadLength);
            }

            Bytes = _source;
        }