m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
cec_command command;
- cec_adapter_message msg;
+ CCECAdapterMessage msg;
while (!IsStopped())
{
m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
}
-bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true */)
-{
- LogOutput(data);
-
- cec_adapter_message output;
- output.clear();
- CAdapterCommunication::FormatAdapterMessage(data, output);
-
- return TransmitFormatted(output, bWaitForAck);
-}
-
bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
{
- CStdString strLog;
- strLog.Format("<< setting logical address to %1x", iLogicalAddress);
- m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
+ if (m_iLogicalAddress != iLogicalAddress)
+ {
+ CStdString strLog;
+ strLog.Format("<< setting logical address to %1x", iLogicalAddress);
+ m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
+
+ m_iLogicalAddress = iLogicalAddress;
+ return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
+ }
- m_iLogicalAddress = iLogicalAddress;
- return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
+ return true;
}
bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
}
-bool CCECProcessor::TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck /* = true */)
+bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true */)
{
bool bReturn(false);
+ LogOutput(data);
+
+ CCECAdapterMessage output(data);
+
CLockObject lock(&m_mutex);
- if (!m_communication || !m_communication->Write(data))
+ if (!m_communication || !m_communication->Write(output))
return bReturn;
if (bWaitForAck)
{
- uint64_t now = GetTimeMs();
- uint64_t target = now + 1000;
bool bError(false);
-
- while (!bReturn && now < target && !bError)
- {
- bReturn = WaitForAck(&bError, data.size(), (uint32_t) (target - now));
- now = GetTimeMs();
- }
-
- if (!bReturn)
+ if ((bReturn = WaitForAck(&bError, output.size(), 1000)) == false)
m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
}
else
while (!bTransmitSucceeded && !*bError && (iTimeout == 0 || iNow < iTargetTime))
{
- cec_adapter_message msg;
- msg.clear();
+ CCECAdapterMessage msg;
if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
{
return bTransmitSucceeded && !*bError;
}
-bool CCECProcessor::ParseMessage(cec_adapter_message &msg)
+bool CCECProcessor::ParseMessage(CCECAdapterMessage &msg)
{
bool bEom = false;