private void DetermineQueryLength(int retries) { SendMsg(NEW_QUERY_MSG); var response = ReadMsg(2); if (response.Length == 2) { m_queryLen = 14; return; } SendMsg(OLD_QUERY_MSG); response = ReadMsg(2); if (response.Length >= 2) { if (response[1] == 0x1) { m_protocol = LedProtocolType.kLedNet_Original; m_useChecksum = false; m_queryLen = 11; return; } else { m_useChecksum = true; } } if (retries > 0) { DetermineQueryLength(retries - 1); return; } throw new UnknownProtocolException("Unable to determine protocol."); }
public void UpdateState(int retries = 2) { if (!m_socket.Connected) { Connect(); } byte[] state = QueryState(retries); // typical response: // pos 0 1 2 3 4 5 6 7 8 9 10 // 66 01 24 39 21 0a ff 00 00 01 99 // | | | | | | | | | | | // | | | | | | | | | | checksum // | | | | | | | | | warmwhite // | | | | | | | | blue // | | | | | | | green // | | | | | | red // | | | | | speed: 0f = highest f0 is lowest // | | | | <don't know yet> // | | | preset pattern // | | off(23)/on(24) // | type // msg head // // response from a 5-channel LEDENET controller: // pos 0 1 2 3 4 5 6 7 8 9 10 11 12 13 // 81 25 23 61 21 06 38 05 06 f9 01 00 0f 9d // | | | | | | | | | | | | | | // | | | | | | | | | | | | | checksum // | | | | | | | | | | | | color mode (f0 colors were set, 0f whites, 00 all were set) // | | | | | | | | | | | cold-white // | | | | | | | | | | <don't know yet> // | | | | | | | | | warmwhite // | | | | | | | | blue // | | | | | | | green // | | | | | | red // | | | | | speed: 0f = highest f0 is lowest // | | | | <don't know yet> // | | | preset pattern // | | off(23)/on(24) // | type // msg head // // Devices that don't require a separate rgb/w bit if (state[1] == 0x04 || state[1] == 0x33 || state[1] == 0x81) { m_rgbwprotocol = true; } //Devices that actually support rgbw if (state[1] == 0x04 || state[1] == 0x25 || state[1] == 0x33 || state[1] == 0x81) { RGBWCapable = true; } //Devices that use an 8-byte protocol if (state[1] == 0x25 || state[1] == 0x27 || state[1] == 0x35) { m_protocol = LedProtocolType.kLedNet_9byte; } //Devices that use the original LEDENET protocol if (state[1] == 0x01) { m_protocol = LedProtocolType.kLedNet_Original; m_useChecksum = false; } byte pattern = state[3]; byte ww_level = state[9]; m_mode = DetermineMode(ww_level, pattern); if (m_mode == LedMode.kUnknown) { if (retries < 1) { throw new UnknownModeException(); } UpdateState(retries - 1); return; } byte power_state = state[2]; if (power_state == 0x23) { IsOn = true; } else if (power_state == 0x24) { IsOn = false; } m_rawState = state; }