-bool CCECProcessor::WaitForTransmitSucceeded(CCECAdapterMessage *message)
-{
- bool bError(false);
- bool bTransmitSucceeded(false);
- uint8_t iPacketsLeft(message->size() / 4);
-
- int64_t iNow = GetTimeMs();
- int64_t iTargetTime = iNow + message->transmit_timeout;
-
- while (!bTransmitSucceeded && !bError && (message->transmit_timeout == 0 || iNow < iTargetTime))
- {
- CCECAdapterMessage msg;
-
- if (!m_communication->Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
- {
- iNow = GetTimeMs();
- continue;
- }
-
- if (msg.message() == MSGCODE_FRAME_START && msg.ack())
- {
- m_busDevices[msg.initiator()]->GetHandler()->HandlePoll(msg.initiator(), msg.destination());
- m_lastInitiator = msg.initiator();
- iNow = GetTimeMs();
- continue;
- }
-
- bError = msg.is_error();
- if (msg.message() == MSGCODE_RECEIVE_FAILED &&
- m_lastInitiator != CECDEVICE_UNKNOWN &&
- !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed())
- {
- iNow = GetTimeMs();
- continue;
- }
-
- if (bError)
- {
- message->reply = msg.message();
- m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
- }
- else
- {
- switch(msg.message())
- {
- case MSGCODE_COMMAND_ACCEPTED:
- m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
- if (iPacketsLeft > 0)
- iPacketsLeft--;
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
- bTransmitSucceeded = (iPacketsLeft == 0);
- bError = !bTransmitSucceeded;
- message->reply = MSGCODE_TRANSMIT_SUCCEEDED;
- break;
- default:
- // ignore other data while waiting
- break;
- }
-
- iNow = GetTimeMs();
- }
- }
-
- return bTransmitSucceeded && !bError;
-}
-
-bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
-{
- bool bEom(false);
- bool bIsError(msg.is_error());
-
- if (msg.empty())
- return bEom;
-
- switch(msg.message())
- {
- case MSGCODE_FRAME_START:
- {
- m_currentframe.Clear();
- if (msg.size() >= 2)
- {
- m_currentframe.initiator = msg.initiator();
- m_currentframe.destination = msg.destination();
- m_currentframe.ack = msg.ack();
- m_currentframe.eom = msg.eom();
- }
- if (m_currentframe.ack == true)
- {
- m_lastInitiator = m_currentframe.initiator;
- m_busDevices[m_lastInitiator]->GetHandler()->HandlePoll(m_currentframe.initiator, m_currentframe.destination);
- }
- }
- break;
- case MSGCODE_RECEIVE_FAILED:
- {
- if (m_lastInitiator != CECDEVICE_UNKNOWN)
- bIsError = m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed();
- }
- break;
- case MSGCODE_FRAME_DATA:
- {
- if (msg.size() >= 2)
- {
- m_currentframe.PushBack(msg[1]);
- m_currentframe.eom = msg.eom();
- }
- bEom = msg.eom();
- }
- break;
- default:
- break;
- }
-
- m_controller->AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
- return bEom;
-}
-
-void CCECProcessor::ParseCommand(cec_command &command)