Example #1
0
        /// <summary>
        /// Writes the Frame portion of the message header to the buffer.
        /// See http://lan.developer.lifx.com/docs/header-description for more details.
        /// </summary>
        /// <param name="buffer">The buffer to write to.</param>
        private void WriteFrame(MemoryStream buffer)
        {
            Debug.Assert(buffer != null);

            // Write the message size (2B)
            //
            buffer.LitteEndianWriteUInt16(MessageSizeInBytes);

            // The next 2 bytes contain:
            //   - The Origin field (2 bits, always set to 0)
            //   - The Tagged flag (1 bit - 1 if Target is specific device, 0 if all devices)
            //   - The Addressable flag (1 bit, always set to 1)
            //   - The protocol number (12 bits, always set to 1024)
            //
            const UInt16 TaggedFlag = 0x2000;
            const UInt16 AddressableFlag = 0x1000;

            UInt16 flagsAndProtocol = AddressableFlag | Constants.LifXProtocolNumber;

            if (Target == MacAddress.Empty)
            {
                flagsAndProtocol |= TaggedFlag;
            }

            buffer.LitteEndianWriteUInt16(flagsAndProtocol);

            // The last 4 bytes are the message Source.
            //
            buffer.LitteEndianWriteUInt32(Source);
        }
Example #2
0
        /// <summary>
        /// Writes the Protocol Header portion of the message header to the buffer.
        /// See http://lan.developer.lifx.com/docs/header-description for more details.
        /// </summary>
        /// <param name="buffer">The buffer to write to.</param>
        private void WriteProtocolHeader(MemoryStream buffer)
        {
            Debug.Assert(buffer != null);

            // The first 8 bytes are unusued and marked "Reserved".
            //
            buffer.WriteZeros(8);

            // The next 2 bytes are the MessageType.
            //
            buffer.LitteEndianWriteUInt16((UInt16)MessageType);

            // The last 2 bytes are also unusued and marked "Reserved".
            //
            buffer.WriteZeros(2);
        }