From 578c3905a5d00d54611bbcd0da3f6cf8ad9263ac Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 23 Jan 2012 19:30:36 +0100 Subject: [PATCH] cec: fixed reconnect after standby --- src/lib/CECProcessor.cpp | 97 +++++++++++++++++++++++++--------------- src/lib/CECProcessor.h | 3 ++ 2 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 9ed9b23..c23cb93 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -128,26 +128,70 @@ CCECProcessor::~CCECProcessor(void) delete m_busDevices[iPtr]; } -bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */) +bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs) { bool bReturn(false); + CLockObject lock(m_mutex); + if (!m_communication) + { + m_controller->AddLog(CEC_LOG_ERROR, "no connection handler found"); + return bReturn; + } + /* check for an already opened connection */ + if (m_communication->IsOpen()) { - CLockObject lock(m_mutex); + m_controller->AddLog(CEC_LOG_ERROR, "connection already opened"); + return bReturn; + } - /* check for an already opened connection */ - if (!m_communication || m_communication->IsOpen()) - { - m_controller->AddLog(CEC_LOG_ERROR, "connection already opened"); - return bReturn; - } + /* open a new connection */ + if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false) + m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection"); - /* open a new connection */ - if (!m_communication->Open(strPort, iBaudRate, iTimeoutMs)) - { - m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection"); + return bReturn; +} + +bool CCECProcessor::Initialise(void) +{ + bool bReturn(false); + CLockObject lock(m_mutex); + if (!m_logicalAddresses.IsEmpty()) + m_logicalAddresses.Clear(); + + if (!FindLogicalAddresses()) + { + m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); + return bReturn; + } + + /* only set our OSD name for the primary device */ + m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_strDeviceName; + + /* get the vendor id from the TV, so we are using the correct handler */ + m_busDevices[CECDEVICE_TV]->RequestVendorId(); + ReplaceHandlers(); + + if ((bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true)) == false) + { + CStdString strLog; + strLog.Format("unable to set the correct HDMI port (HDMI %d on %s(%x)", m_iHDMIPort, ToString(m_iBaseDevice), (uint8_t)m_iBaseDevice); + m_controller->AddLog(CEC_LOG_ERROR, strLog); + } + else + m_bInitialised = true; + + return bReturn; +} + +bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */) +{ + bool bReturn(false); + + { + CLockObject lock(m_mutex); + if (!OpenConnection(strPort, iBaudRate, iTimeoutMs)) return bReturn; - } /* create the processor thread */ if (!CreateThread() || !m_startCondition.Wait(m_mutex) || !m_bStarted) @@ -157,33 +201,14 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, } } - /* find the logical address for the adapter */ - bReturn = m_logicalAddresses.IsEmpty() ? FindLogicalAddresses() : true; - if (!bReturn) - m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); - - /* set the physical address for the adapter */ - if (bReturn) - { - /* only set our OSD name for the primary device */ - m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_strDeviceName; - - /* get the vendor id from the TV, so we are using the correct handler */ - m_busDevices[CECDEVICE_TV]->RequestVendorId(); - ReplaceHandlers(); - - bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true); - } - - if (bReturn) + if ((bReturn = Initialise()) == false) { - m_bInitialised = true; - m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); + m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); + StopThread(true); } else { - m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); - StopThread(true); + m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); } return bReturn; diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 8e6fae9..2d6ca5e 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -134,6 +134,9 @@ namespace CEC PLATFORM::CMutex m_transmitMutex; private: + bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs); + bool Initialise(void); + void ReplaceHandlers(void); void ScanCECBus(void); bool PhysicalAddressInUse(uint16_t iPhysicalAddress); -- 2.34.1