From: Lars Op den Kamp Date: Mon, 19 Mar 2012 12:05:06 +0000 (+0100) Subject: cec: wait for MSGEND when data was received when opening the connection. bugzid: 536 X-Git-Tag: upstream/2.2.0~1^2~31^2~67 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=053ecec4dcdb808bcd39f45ed246ad38a4df37bb;p=deb_libcec.git cec: wait for MSGEND when data was received when opening the connection. bugzid: 536 --- 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); } }