X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=b5cd540fb9135d26a1685a47f3c20406e87a41d8;hb=3f9b82aa7229403771e0b5d33087e75084631891;hp=08f69cd7b1674cc994f37c0468c16bbdd49b6b23;hpb=7ea0d55841195dc1f0397d3b77405b8f55fdde3f;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 08f69cd..b5cd540 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -88,7 +88,7 @@ void *CCECProcessor::Process(void) m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); cec_command command; - cec_adapter_message msg; + CCECAdapterMessage msg; while (!IsStopped()) { @@ -147,17 +147,6 @@ void CCECProcessor::LogOutput(const cec_command &data) 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; @@ -187,26 +176,21 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable) 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 @@ -240,8 +224,7 @@ bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout 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)) { @@ -315,7 +298,7 @@ bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout return bTransmitSucceeded && !*bError; } -bool CCECProcessor::ParseMessage(cec_adapter_message &msg) +bool CCECProcessor::ParseMessage(CCECAdapterMessage &msg) { bool bEom = false;