- CLockObject lock(m_mutex);
- for (size_t iPtr = 0; iPtr < iLen; iPtr++)
- {
- if (!m_bGotStart)
- {
- if (data[iPtr] == MSGSTART)
- m_bGotStart = true;
- }
- else if (data[iPtr] == MSGSTART) //we found a msgstart before msgend, this is not right, remove
- {
- if (m_currentAdapterMessage.Size() > 0)
- CLibCEC::AddLog(CEC_LOG_WARNING, "received MSGSTART before MSGEND, removing previous buffer contents");
- m_currentAdapterMessage.Clear();
- m_bGotStart = true;
- }
- else if (data[iPtr] == MSGEND)
- {
- CCECAdapterMessage *newMessage = new CCECAdapterMessage;
- newMessage->packet = m_currentAdapterMessage.packet;
- m_inBuffer.Push(newMessage);
- m_currentAdapterMessage.Clear();
- m_bGotStart = false;
- m_bNextIsEscaped = false;
- m_rcvCondition.Signal();
- }
- else if (m_bNextIsEscaped)
- {
- m_currentAdapterMessage.PushBack(data[iPtr] + (uint8_t)ESCOFFSET);
- m_bNextIsEscaped = false;
- }
- else if (data[iPtr] == MSGESC)
- {
- m_bNextIsEscaped = true;
- }
- else
- {
- m_currentAdapterMessage.PushBack(data[iPtr]);
- }
- }