From 053ecec4dcdb808bcd39f45ed246ad38a4df37bb Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 19 Mar 2012 13:05:06 +0100 Subject: [PATCH] cec: wait for MSGEND when data was received when opening the connection. bugzid: 536 --- src/lib/adapter/USBCECAdapterCommunication.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 64212cb..28b5fee 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -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); } } -- 2.34.1