From: Lars Op den Kamp Date: Fri, 27 Jan 2012 00:13:53 +0000 (+0100) Subject: cec: try to ping the device and grab the firmware version until the connect timeout... X-Git-Tag: upstream/2.2.0~1^2~37^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c520af4f3b579a249c517d7f73632e9763fe8ed0;p=deb_libcec.git cec: try to ping the device and grab the firmware version until the connect timeout runs out. fixes failed reconnect after standby, when the adapter is still being initialised --- diff --git a/include/cectypes.h b/include/cectypes.h index 5213b37..86be2a2 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -76,8 +76,6 @@ namespace CEC { #define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000 #define CEC_DEFAULT_TRANSMIT_WAIT 2000 #define CEC_DEFAULT_TRANSMIT_RETRIES 1 -#define CEC_PING_ADAPTER_TRIES 5 -#define CEC_FW_VERSION_TRIES 5 #define CEC_MIN_LIB_VERSION 1 #define CEC_LIB_VERSION_MAJOR 1 diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 12cea4f..8c808ae 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -145,45 +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 */ - int iPingTry(0); bool bPingOk(false); - while (!bPingOk && iPingTry++ < CEC_PING_ADAPTER_TRIES) + unsigned iPingTry(0), iFwVersionTry(0); + uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN); + while ((!bPingOk || iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) && iTarget > iNow) { - if ((bPingOk = m_communication->PingAdapter()) == false) + if (!bPingOk) { - CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to a ping (try %d of %d)", iPingTry, CEC_PING_ADAPTER_TRIES); - Sleep(500); + 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) - { - uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN); - int iFwVersionTry(0); - bool bFwVersionOk(false); - while (!bFwVersionOk && iFwVersionTry++ < CEC_FW_VERSION_TRIES) + 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 of %d)", iFwVersionTry, CEC_FW_VERSION_TRIES); + 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; + } } - if (iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) - { - bReturn = false; - } - else - { - bReturn = true; - CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion); - } + iNow = GetTimeMs(); } return bReturn;