cec: retry the ping adapter command when starting libCEC. set the default transmit...
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 7ece12ae1412293297f3ba12859a5e38afab94a0..8e1c1017ff722e434447ff8a8247602530cf0b98 100644 (file)
@@ -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)