From: Lars Op den Kamp Date: Wed, 25 Jan 2012 10:41:26 +0000 (+0100) Subject: cec: check whether the adapter responds when connecting to it and report the firmware... X-Git-Tag: upstream/2.2.0~1^2~39^2~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1fc16cfd0bc42166ca6a184d42ee50d393c95a34;p=deb_libcec.git cec: check whether the adapter responds when connecting to it and report the firmware version of the adapter after connecting --- diff --git a/include/cectypes.h b/include/cectypes.h index ba21200..86be2a2 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -71,6 +71,7 @@ namespace CEC { #define ESCOFFSET 3 #define CEC_BUTTON_TIMEOUT 500 #define CEC_POWER_STATE_REFRESH_TIME 30000 +#define CEC_FW_VERSION_UNKNOWN 0xFFFF #define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000 #define CEC_DEFAULT_TRANSMIT_WAIT 2000 diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index cb4fe81..659eae3 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -149,6 +149,18 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false) m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection"); + /* try to ping the adapter */ + if ((bReturn = m_communication->PingAdapter()) == false) + m_controller->AddLog(CEC_LOG_ERROR, "the adapter does not respond correctly"); + + uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion(); + if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false) + m_controller->AddLog(CEC_LOG_ERROR, "the adapter is running an unknown firmware version"); + + CStdString strLog; + strLog.Format("CEC Adapter firmware version: %d", iFirmwareVersion); + m_controller->AddLog(CEC_LOG_NOTICE, strLog); + return bReturn; } diff --git a/src/lib/adapter/AdapterCommunication.cpp b/src/lib/adapter/AdapterCommunication.cpp index 44b24e1..cc8507f 100644 --- a/src/lib/adapter/AdapterCommunication.cpp +++ b/src/lib/adapter/AdapterCommunication.cpp @@ -43,7 +43,8 @@ using namespace PLATFORM; CAdapterCommunication::CAdapterCommunication(CCECProcessor *processor) : m_port(NULL), m_processor(processor), - m_iLineTimeout(0) + m_iLineTimeout(0), + m_iFirmwareVersion(CEC_FW_VERSION_UNKNOWN) { m_port = new PLATFORM::CSerialPort; } @@ -269,6 +270,39 @@ bool CAdapterCommunication::PingAdapter(void) return bReturn; } +uint16_t CAdapterCommunication::GetFirmwareVersion(void) +{ + uint16_t iReturn(m_iFirmwareVersion); + if (!IsRunning()) + return iReturn; + + if (iReturn == CEC_FW_VERSION_UNKNOWN) + { + m_processor->AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); + CCECAdapterMessage *output = new CCECAdapterMessage; + + output->PushBack(MSGSTART); + output->PushEscaped(MSGCODE_FIRMWARE_VERSION); + output->PushBack(MSGEND); + output->isTransmission = false; + output->expectControllerAck = false; + + SendMessageToAdapter(output); + delete output; + + CCECAdapterMessage input; + if (!Read(input, CEC_DEFAULT_TRANSMIT_WAIT) || input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3) + m_processor->AddLog(CEC_LOG_ERROR, "no or invalid firmware version"); + else + { + m_iFirmwareVersion = (input[1] << 8 | input[2]); + iReturn = m_iFirmwareVersion; + } + } + + return iReturn; +} + bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout) { bool bReturn(m_iLineTimeout != iTimeout); @@ -403,6 +437,7 @@ bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout) if (!m_port) return false; + CLockObject lock(m_mutex); iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout); if (iBytesRead < 0 || iBytesRead > 256) { @@ -419,6 +454,7 @@ bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout) void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg) { + CLockObject adapterLock(m_mutex); CLockObject lock(msg->mutex); if (m_port->Write(msg->packet.data, msg->Size()) != (int32_t) msg->Size()) { diff --git a/src/lib/adapter/AdapterCommunication.h b/src/lib/adapter/AdapterCommunication.h index bdc3de3..3d74546 100644 --- a/src/lib/adapter/AdapterCommunication.h +++ b/src/lib/adapter/AdapterCommunication.h @@ -53,7 +53,6 @@ namespace CEC bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000); bool Read(CCECAdapterMessage &msg, uint32_t iTimeout = 1000); bool Write(CCECAdapterMessage *data); - bool PingAdapter(void); void Close(void); bool IsOpen(void); std::string GetError(void) const; @@ -63,6 +62,8 @@ namespace CEC bool SetLineTimeout(uint8_t iTimeout); bool StartBootloader(void); bool SetAckMask(uint16_t iMask); + bool PingAdapter(void); + uint16_t GetFirmwareVersion(void); bool WaitForTransmitSucceeded(CCECAdapterMessage *message); @@ -79,5 +80,6 @@ namespace CEC PLATFORM::CMutex m_mutex; PLATFORM::CCondition m_rcvCondition; uint8_t m_iLineTimeout; + uint16_t m_iFirmwareVersion; }; };