private BroadlinkDevice CreateBroadlinkDevice(short deviceType) { BroadlinkDevice device; switch (deviceType) { case 0x2712: // RM2 case 0x2737: // RM Mini case 0x273d: // RM Pro Phicomm case 0x2783: // RM2 Home Plus case 0x277c: // RM2 Home Plus GDT case 0x272a: // RM2 Pro Plus case 0x2787: // RM2 Pro Plus2 case 0x278b: // RM2 Pro Plus BL case 0x278f: // RM Mini Shate device = new RMDevice(); break; default: device = new BroadlinkDevice(); break; } device.DeviceType = deviceType; return(device); }
public static byte[] GenerateAuthorizationPacket(BroadlinkDevice device) { var payload = GenerateAuthorizationPayload(); var command = (short)0x0065; var packet = GenerateCommandPacket(command, payload, device); return(packet); }
public static byte[] GenerateReadLearningModePacket(BroadlinkDevice device) { var payload = new byte[16]; payload[0x00] = 0x04; var command = (short)0x006a; var packet = GenerateCommandPacket(command, payload, device); return(packet); }
public static byte[] GenerateSendDataPacket(BroadlinkDevice device, byte[] data) { var payload = new byte[0x04 + data.Length]; payload[0x00] = 0x02; data.CopyTo(payload, 0x04); var command = (short)0x006a; var packet = GenerateCommandPacket(command, payload, device); return(packet); }
private static byte[] GenerateCommandPacket(short commandCode, byte[] payload, BroadlinkDevice device) { var header = new byte[56]; header[0x00] = 0x5a; header[0x01] = 0xa5; header[0x02] = 0xaa; header[0x03] = 0x55; header[0x04] = 0x5a; header[0x05] = 0xa5; header[0x06] = 0xaa; header[0x07] = 0x55; header[0x24] = 0x2a; header[0x25] = 0x27; commandCode.ToLittleEndianBytes().CopyTo(header, 0x26); device.PacketCount.ToLittleEndianBytes().CopyTo(header, 0x28); device.MacAddress.CopyTo(header, 0x2a); var deviceId = device.DeviceId; if (deviceId == null) { deviceId = new byte[4]; } deviceId.CopyTo(header, 0x30); GenerateChecksum(payload).CopyTo(header, 0x34); var encryptedPayload = payload.Encrypt(device.EncryptionKey); var packet = new byte[header.Length + encryptedPayload.Length]; header.CopyTo(packet, 0); encryptedPayload.CopyTo(packet, 0x38); GenerateChecksum(packet).CopyTo(packet, 0x20); return(packet); }