Beispiel #1
0
        public static string GetPacket(byte[] targetMacAddress, IPayload Payload)
        {
            // Mac address must be left-aligned and padded with zeroes to a length of 8...
            if (targetMacAddress.Length != 8)
            {
                throw new NotImplementedException();
            }

            // http://lan.developer.lifx.com/v2.0/docs/header-description#frame
            // Frame is 16+2+1+1+12+32=64 bits = 8 bytes

            byte[] sizelessHeader = GetSizelessHeader(targetMacAddress, Payload);
            byte[] payloadBytes   = Payload.GetPayload();

            var frameSizeInt = Convert.ToInt16(2 + sizelessHeader.Length + payloadBytes.Length);
            var frameSize    = BitConverter.GetBytes(frameSizeInt);

            var packet = frameSize.Concat(sizelessHeader)
                         .Concat(payloadBytes);

            var packetAsString = BitConverter.ToString(packet.ToArray()).Replace("-", "");

            return(packetAsString);// ;
        }
Beispiel #2
0
 public string GetPayload()
 {
     return(_payload.GetPayload());
 }