/// <summary> /// Writes the Frame Address 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 WriteFrameAddress(MemoryStream buffer) { Debug.Assert(buffer != null); // The first 8 bytes contain the 6-byte Target MAC Address, right padded with 2 zeros. // byte[] targetAddress = Target.Bytes; Debug.Assert(targetAddress.Length == 6); buffer.Write(targetAddress, 0, 6); buffer.WriteZeros(2); // The next 6 bytes are unusued and marked "Reserved". // buffer.WriteZeros(6); // The next byte contains bitflags about the message where byte: // [0]: res_required // [1]: ack_required // byte flags = 0; if (ResponseRequired) { flags |= (1 << 0); } if (AckRequired) { flags |= (1 << 1); } buffer.LittleEndianWriteByte(flags); // The last byte is the Message's sequence number. // buffer.LittleEndianWriteByte(SequenceNumber); }
/// <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); }