From: Lars Op den Kamp Date: Wed, 25 Jan 2012 19:13:52 +0000 (+0100) Subject: cec: retry the ping adapter command when starting libCEC. set the default transmit... X-Git-Tag: upstream/2.2.0~1^2~39^2~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c71891a335d74d5f31dc96c2f5853384167a081b;p=deb_libcec.git cec: retry the ping adapter command when starting libCEC. set the default transmit timeout properly instead of using 0. fixes possible infinite loop in CAdapterCommunication::WaitForTransmitSucceeded() --- diff --git a/include/cectypes.h b/include/cectypes.h index 86be2a2..e602ac9 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -76,6 +76,7 @@ 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_MIN_LIB_VERSION 1 #define CEC_LIB_VERSION_MAJOR 1 diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 7ece12a..8e1c101 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -150,10 +150,18 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint 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"); + int iPingTry(0); + bool bPingOk(false); + while (!bPingOk && iPingTry++ < CEC_PING_ADAPTER_TRIES) + { + if ((bPingOk = m_communication->PingAdapter()) == false) + { + 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 (bReturn) + if (bPingOk) { uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion(); if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false) diff --git a/src/lib/adapter/AdapterMessage.h b/src/lib/adapter/AdapterMessage.h index 784ed2a..ad81878 100644 --- a/src/lib/adapter/AdapterMessage.h +++ b/src/lib/adapter/AdapterMessage.h @@ -256,7 +256,7 @@ namespace CEC void Clear(void) { state = ADAPTER_MESSAGE_STATE_UNKNOWN; - transmit_timeout = 0; + transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT; packet.Clear(); maxTries = CEC_DEFAULT_TRANSMIT_RETRIES + 1; tries = 0;