From: Lars Op den Kamp Date: Sat, 3 Dec 2011 23:58:32 +0000 (+0100) Subject: cec: set line timeout when (re)transmitting. don't sleep after transmitting X-Git-Tag: upstream/2.2.0~1^2~44^2~57 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9902f4e81052ba0260c587a4b9309e1dd4c729db;p=deb_libcec.git cec: set line timeout when (re)transmitting. don't sleep after transmitting --- diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index c13000b..fc650f0 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -379,7 +379,6 @@ void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg) else { m_processor->AddLog(CEC_LOG_DEBUG, "command sent"); - CCondition::Sleep((uint32_t) msg->size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/); msg->state = ADAPTER_MESSAGE_STATE_SENT; } msg->condition.Signal(); diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 8fc71dc..f8ea3bc 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -55,7 +55,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec m_strDeviceName(strDeviceName), m_controller(controller), m_bMonitor(false), - m_busScan(NULL) + m_busScan(NULL), + m_iLineTimeout(0) { m_communication = new CAdapterCommunication(this); m_logicalAddresses.Clear(); @@ -72,7 +73,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con m_strDeviceName(strDeviceName), m_types(types), m_controller(controller), - m_bMonitor(false) + m_bMonitor(false), + m_iLineTimeout(0) { m_communication = new CAdapterCommunication(this); m_logicalAddresses.Clear(); @@ -242,17 +244,22 @@ bool CCECProcessor::FindLogicalAddresses(void) bool CCECProcessor::SetLineTimeout(uint8_t iTimeout) { - bool bReturn(false); - CCECAdapterMessage *output = new CCECAdapterMessage; + bool bReturn(m_iLineTimeout != iTimeout); - output->push_back(MSGSTART); - output->push_escaped(MSGCODE_TRANSMIT_IDLETIME); - output->push_escaped(iTimeout); - output->push_back(MSGEND); + if (!bReturn) + { + CCECAdapterMessage *output = new CCECAdapterMessage; + + output->push_back(MSGSTART); + output->push_escaped(MSGCODE_TRANSMIT_IDLETIME); + output->push_escaped(iTimeout); + output->push_back(MSGEND); + + if ((bReturn = Transmit(output)) == false) + m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime"); + delete output; + } - if ((bReturn = Transmit(output)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime"); - delete output; return bReturn; } @@ -674,8 +681,13 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) bool bReturn(false); CLockObject lock(&m_mutex); { + SetLineTimeout(3); + do { + if (output->tries > 0) + SetLineTimeout(5); + CLockObject msgLock(&output->mutex); if (!m_communication || !m_communication->Write(output)) return bReturn; @@ -699,6 +711,8 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries <= output->maxTries); } + SetLineTimeout(3); + return bReturn; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 309365b..82dc149 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -154,6 +154,7 @@ namespace CEC CecBuffer m_commandBuffer; cec_keypress m_previousKey; CThread * m_busScan; + uint8_t m_iLineTimeout; }; class CCECBusScan : public CThread diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index 62e70d8..c6affec 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -55,6 +55,29 @@ bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) return m_busDevice->GetProcessor()->Transmit(response); } + else if (command.parameters.size >= 1 && + command.parameters[0] == 0x04) + { + /* enable SL */ + cec_command response; + cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND); + response.PushBack(0x05); + response.PushBack(0x04); + + return m_busDevice->GetProcessor()->Transmit(response); + } + else if (command.parameters.size == 1 && + command.parameters[0] == 0xa0) + { + /* enable SL */ + cec_command response; + cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND); + response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 16) & 0xFF)); + response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 8) & 0xFF)); + response.parameters.PushBack((uint8_t) ((uint64_t)CEC_VENDOR_LG & 0xFF)); + + return m_busDevice->GetProcessor()->Transmit(response); + } return false; }