cec: wait for MSGEND when data was received when opening the connection. bugzid: 536
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 19 Mar 2012 12:05:06 +0000 (13:05 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 19 Mar 2012 12:05:06 +0000 (13:05 +0100)
src/lib/adapter/USBCECAdapterCommunication.cpp

index 64212cb18a99cb01823c0326d5fd42e88ee8250d..28b5fee1588e31a1040d47de7bfe83af5b00603a 100644 (file)
@@ -181,9 +181,20 @@ bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32
     {
       //clear any input bytes
       uint8_t buff[1024];
-      while (m_port->Read(buff, 1024, 100) > 0)
+      ssize_t iBytesRead(0);
+      bool bGotMsgStart(false), bGotMsgEnd(false);
+      while ((iBytesRead = m_port->Read(buff, 1024, 100)) > 0 || (bGotMsgStart && !bGotMsgEnd))
       {
-        CLibCEC::AddLog(CEC_LOG_DEBUG, "data received, clearing it");
+        if (!bGotMsgStart)
+          CLibCEC::AddLog(CEC_LOG_DEBUG, "data received, clearing it");
+        // if something was received, wait for MSGEND
+        for (ssize_t iPtr = 0; iPtr < iBytesRead; iPtr++)
+        {
+          if (buff[iPtr] == MSGSTART)
+            bGotMsgStart = true;
+          else if (buff[iPtr] == MSGEND)
+            bGotMsgEnd = true;
+        }
         Sleep(250);
       }
     }