X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fadapter%2FUSBCECAdapterCommunication.cpp;h=360eff5d1fde41257d339f9b58a9b046c4f18884;hb=d4db0c6f1121a5e43c98255af5202ebd33f2b800;hp=351fa28a6fae2ea5b3657e900fc4f26e381226b0;hpb=7a87e02ec121e65ea9039c5c54863c9a44c22de5;p=deb_libcec.git diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 351fa28..360eff5 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -452,31 +452,12 @@ uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void) { CLockObject lock(m_mutex); CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); - - CCECAdapterMessage params; - if (!SendCommand(MSGCODE_FIRMWARE_VERSION, params, false)) - { - CLibCEC::AddLog(CEC_LOG_ERROR, "could not request the firmware version"); - return iReturn; - } - - Sleep(250); // TODO ReadFromDevice() isn't waiting for the timeout to pass on win32 - ReadFromDevice(CEC_DEFAULT_TRANSMIT_WAIT, 5 /* start + msgcode + 2 bytes for fw version + end */); - CCECAdapterMessage input; - if (Read(input, 0)) + cec_datapacket response = GetSetting(MSGCODE_FIRMWARE_VERSION); + if (response.size == 2) { - if (input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3) - CLibCEC::AddLog(CEC_LOG_ERROR, "invalid firmware version (size = %d, message = %d)", input.Size(), input.Message()); - else - { - m_iFirmwareVersion = (input[1] << 8 | input[2]); - iReturn = m_iFirmwareVersion; - CLibCEC::AddLog(CEC_LOG_DEBUG, "firmware version %d", m_iFirmwareVersion); - } - } - else - { - CLibCEC::AddLog(CEC_LOG_ERROR, "no firmware version received"); + m_iFirmwareVersion = (response[0] << 8 | response[1]); + iReturn = m_iFirmwareVersion; + CLibCEC::AddLog(CEC_LOG_DEBUG, "firmware version %d", m_iFirmwareVersion); } } @@ -852,3 +833,36 @@ bool CUSBCECAdapterCommunication::SendCommand(cec_adapter_messagecode msgCode, C delete output; return true; } + +cec_datapacket CUSBCECAdapterCommunication::GetSetting(cec_adapter_messagecode msgCode) +{ + cec_datapacket retVal; + retVal.Clear(); + + CCECAdapterMessage params; + if (!SendCommand(msgCode, params, false)) + { + CLibCEC::AddLog(CEC_LOG_ERROR, "%s failed", CCECAdapterMessage::ToString(msgCode)); + return retVal; + } + + Sleep(250); // TODO ReadFromDevice() isn't waiting for the timeout to pass on win32 + ReadFromDevice(CEC_DEFAULT_TRANSMIT_WAIT, 5 /* start + msgcode + 2 bytes for fw version + end */); + CCECAdapterMessage input; + if (Read(input, 0)) + { + if (input.Message() != msgCode) + CLibCEC::AddLog(CEC_LOG_ERROR, "invalid response to %s received (%s)", CCECAdapterMessage::ToString(msgCode), CCECAdapterMessage::ToString(input.Message())); + else + { + for (uint8_t iPtr = 1; iPtr < input.Size(); iPtr++) + retVal.PushBack(input[iPtr]); + } + } + else + { + CLibCEC::AddLog(CEC_LOG_ERROR, "no response to %s received", CCECAdapterMessage::ToString(msgCode)); + } + + return retVal; +}