X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=8c808ae8b390cb20e4461e466d20038d9944a1e3;hb=102120cb9d6b3c723ed44b22ae1c97cb160e0bcc;hp=7ece12ae1412293297f3ba12859a5e38afab94a0;hpb=c3c2d822d2e5f385e9a23682e553c1c7bf1f23f3;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 7ece12a..8c808ae 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -145,21 +145,43 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint return bReturn; } + uint64_t iNow = GetTimeMs(); + uint64_t iTarget = iTimeoutMs > 0 ? iNow + iTimeoutMs : iNow + CEC_DEFAULT_TRANSMIT_WAIT; + /* open a new connection */ if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false) CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection"); /* try to ping the adapter */ - if ((bReturn = m_communication->PingAdapter()) == false) - CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter does not respond correctly"); - - if (bReturn) + bool bPingOk(false); + unsigned iPingTry(0), iFwVersionTry(0); + uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN); + while ((!bPingOk || iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) && iTarget > iNow) { - uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion(); - if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "the adapter is running an unknown firmware version"); + if (!bPingOk) + { + if ((bPingOk = m_communication->PingAdapter()) == false) + { + CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to a ping (try %d)", ++iPingTry); + Sleep(500); + } + } + + if (bPingOk) + { + if ((iFirmwareVersion = m_communication->GetFirmwareVersion()) == CEC_FW_VERSION_UNKNOWN) + { + CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond with a correct firmware version (try %d)", ++iFwVersionTry); + Sleep(500); + } + else + { + CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion); + bReturn = true; + } + } - CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion); + iNow = GetTimeMs(); } return bReturn;