if (output->transmit_timeout > 0)
{
- if ((bReturn = WaitForTransmitSucceeded(output)) == false)
+ if ((bReturn = m_communication->WaitForTransmitSucceeded(output)) == false)
m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
}
else
Transmit(command);
}
-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.IsACK())
- {
- m_busDevices[msg.Initiator()]->GetHandler()->HandlePoll(msg.Initiator(), msg.Destination());
- m_lastInitiator = msg.Initiator();
- iNow = GetTimeMs();
- continue;
- }
-
- bError = msg.IsError();
- 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);
{
return m_communication->PingAdapter();
}
+
+void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination)
+{
+ m_busDevices[initiator]->GetHandler()->HandlePoll(initiator, destination);
+ m_lastInitiator = initiator;
+}
+
+bool CCECProcessor::HandleReceiveFailed(void)
+{
+ return m_lastInitiator != CECDEVICE_UNKNOWN &&
+ !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed();
+}
virtual bool StartBootloader(void);
virtual bool PingAdapter(void);
+ virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
+ virtual bool HandleReceiveFailed(void);
CCECBusDevice * m_busDevices[16];
PLATFORM::CMutex m_transmitMutex;
bool FindLogicalAddressAudioSystem(void);
void LogOutput(const cec_command &data);
- bool WaitForTransmitSucceeded(CCECAdapterMessage *message);
bool ParseMessage(const CCECAdapterMessage &msg);
void ParseCommand(cec_command &command);
return !IsStopped() && m_port->IsOpen() && IsRunning();
}
+bool CAdapterCommunication::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 (!Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
+ {
+ iNow = GetTimeMs();
+ continue;
+ }
+
+ if (msg.Message() == MSGCODE_FRAME_START && msg.IsACK())
+ {
+ m_processor->HandlePoll(msg.Initiator(), msg.Destination());
+ iNow = GetTimeMs();
+ continue;
+ }
+
+ if (msg.Message() == MSGCODE_RECEIVE_FAILED &&
+ m_processor->HandleReceiveFailed())
+ {
+ iNow = GetTimeMs();
+ continue;
+ }
+
+ bError = msg.IsError();
+ if (bError)
+ {
+ message->reply = msg.Message();
+ m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString());
+ }
+ else
+ {
+ switch(msg.Message())
+ {
+ case MSGCODE_COMMAND_ACCEPTED:
+ m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString());
+ if (iPacketsLeft > 0)
+ iPacketsLeft--;
+ break;
+ case MSGCODE_TRANSMIT_SUCCEEDED:
+ m_processor->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;
+}
+
void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
{
CLockObject lock(m_mutex);
bool SetLineTimeout(uint8_t iTimeout);
bool StartBootloader(void);
+ bool WaitForTransmitSucceeded(CCECAdapterMessage *message);
+
private:
void SendMessageToAdapter(CCECAdapterMessage *msg);
void WriteNextCommand(void);