cec: retry the ping adapter command when starting libCEC. set the default transmit...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jan 2012 19:13:52 +0000 (20:13 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jan 2012 19:13:52 +0000 (20:13 +0100)
include/cectypes.h
src/lib/CECProcessor.cpp
src/lib/adapter/AdapterMessage.h

index 86be2a258e2969fe80e7ff788933e7810a2a8f72..e602ac9921ae51f65979307367c0475791d6396f 100644 (file)
@@ -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
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)
index 784ed2a648af2db300b2df426c5998f11882f46a..ad81878ece635fb178957bfae38c93bde196ff54 100644 (file)
@@ -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;