From: Lars Op den Kamp Date: Sun, 30 Oct 2011 13:07:55 +0000 (+0100) Subject: cec: added GetDeviceVendorId()/cec_get_device_vendor_id() X-Git-Tag: upstream/2.2.0~1^2~169 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=44c74256f77e455f9ef241351ecde43fd53d5c35;p=deb_libcec.git cec: added GetDeviceVendorId()/cec_get_device_vendor_id() --- diff --git a/include/cec.h b/include/cec.h index 9be8d21..4389d7b 100644 --- a/include/cec.h +++ b/include/cec.h @@ -149,6 +149,11 @@ namespace CEC * @see cec_get_device_menu_language */ virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) = 0; + + /*! + * @see cec_get_device_vendor_id + */ + virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index a76ac0f..0c9d57c 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -241,8 +241,20 @@ extern DECLSPEC cec_version cec_get_device_cec_version(cec_logical_address iLogi #ifdef __cplusplus extern DECLSPEC int cec_get_device_menu_language(CEC::cec_logical_address iLogicalAddress, CEC::cec_menu_language *language); #else -extern DECLSPEC cec_version cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_language *language); +extern DECLSPEC int cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_language *language); #endif + +/*! + * @brief Get the vendor ID of the device with the given logical address. + * @param iLogicalAddress The device to get the vendor id for. + * @return The vendor ID or 0 if it wasn't found. + */ +#ifdef __cplusplus +extern DECLSPEC uint64_t cec_get_device_vendor_id(CEC::cec_logical_address iLogicalAddress); +#else +extern DECLSPEC uint64_t cec_get_device_vendor_id(cec_logical_address iLogicalAddress); +#endif + #ifdef __cplusplus }; #endif diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 279c79f..eea66ee 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -213,6 +213,11 @@ bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu return (strcmp(language->language, "???")); } +uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) +{ + return m_busDevices[iAddress]->GetVendorId(); +} + bool CCECProcessor::Transmit(const cec_command &data) { bool bReturn(false); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 94c796c..025d6dd 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -63,6 +63,7 @@ namespace CEC virtual bool SwitchMonitoring(bool bEnable); virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); + virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress); virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; } virtual uint16_t GetPhysicalAddress(void) const; diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 6790c3c..d7d7d60 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -218,6 +218,14 @@ bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_langu return false; } +uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress) +{ + if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) + return m_cec->GetDeviceVendorId(iAddress); + return 0; +} + + void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { if (m_cec) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 1862a6e..286e47e 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -75,6 +75,7 @@ namespace CEC virtual bool SwitchMonitoring(bool bEnable); virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); + virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress); //@} virtual void AddLog(cec_log_level level, const std::string &strMessage); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 2e9f31d..ad663b7 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -201,4 +201,11 @@ int cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_l return -1; } +uint64_t cec_get_device_vendor_id(cec_logical_address iLogicalAddress) +{ + if (cec_parser) + return cec_parser->GetDeviceVendorId(iLogicalAddress); + return 0; +} + //@} diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 8aa5e4b..f26e7c3 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -173,6 +173,22 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) return true; } +uint64_t CCECBusDevice::GetVendorId(void) +{ + if (m_iVendorId == CEC_VENDOR_UNKNOWN) + { + AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID"); + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), GetLogicalAddress(), CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); + CLockObject lock(&m_mutex); + + if (m_processor->Transmit(command)) + m_condition.Wait(&m_mutex, 1000); + } + + return m_iVendorId; +} + void CCECBusDevice::PollVendorId(void) { CLockObject lock(&m_mutex); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 67a816f..81d5796 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -46,22 +46,27 @@ namespace CEC CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0); virtual ~CCECBusDevice(void); + virtual cec_logical_address GetMyLogicalAddress(void) const; + virtual uint16_t GetMyPhysicalAddress(void) const; + virtual const char * GetVendorName(void) const { return CECVendorIdToString(m_iVendorId); } + virtual uint64_t GetVendorId(void); + virtual uint8_t GetVendorClass(void) const { return m_iVendorClass; } + virtual uint64_t GetLastActive(void) const { return m_iLastActive; } virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; } - virtual uint16_t GetPhysicalAddress(void) const { return m_iPhysicalAddress; } - virtual void SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddress = 0); + virtual uint16_t GetPhysicalAddress(void) const { return m_iPhysicalAddress; } + virtual cec_version GetCecVersion(void); + virtual cec_menu_language & GetMenuLanguage(void); - virtual cec_logical_address GetMyLogicalAddress(void) const; - virtual uint16_t GetMyPhysicalAddress(void) const; + virtual bool PowerOn(void); + virtual bool Standby(void); + virtual bool SetOSDString(cec_display_control duration, const char *strMessage); + virtual void PollVendorId(void); + virtual void SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddress = 0); virtual void SetCecVersion(cec_version newVersion); virtual void SetMenuLanguage(const cec_menu_language &menuLanguage); virtual void SetVendorId(const cec_datapacket &data); virtual void SetVendorId(uint64_t iVendorId, uint8_t iVendorClass = 0); - virtual const char *GetVendorName(void) const { return CECVendorIdToString(m_iVendorId); } - virtual uint64_t GetVendorId(void) const { return m_iVendorId; } - virtual uint8_t GetVendorClass(void) const { return m_iVendorClass; } - - virtual uint64_t GetLastActive(void) const { return m_iLastActive; } virtual bool HandleCommand(const cec_command &command); @@ -69,12 +74,6 @@ namespace CEC virtual CCECProcessor *GetProcessor() const { return m_processor; } virtual CCECCommandHandler *GetHandler(void) const { return m_handler; }; - virtual cec_version GetCecVersion(void); - virtual cec_menu_language &GetMenuLanguage(void); - virtual void PollVendorId(void); - virtual bool PowerOn(void); - virtual bool Standby(void); - virtual bool SetOSDString(cec_display_control duration, const char *strMessage); virtual bool ReportCECVersion(void); virtual bool ReportDeckStatus(void); virtual bool ReportMenuState(bool bActive = true); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 9952a8c..38f6b5b 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -221,7 +221,10 @@ void show_console_help(void) "ver {addr} get the CEC version of the specified device." << endl << "[ver 0] get the CEC version of the TV" << endl << endl << - "lang {addr get the menu language of the specified device." << endl << + "ven {addr} get the vendor ID of the specified device." << endl << + "[ven 0] get the vendor ID of the TV" << endl << + endl << + "lang {addr} get the menu language of the specified device." << endl << "[lang 0] get the menu language of the TV" << endl << endl << "[mon] {1|0} enable or disable CEC bus monitoring." << endl << @@ -517,6 +520,21 @@ int main (int argc, char *argv[]) } } } + else if (command == "ven") + { + CStdString strDev; + if (GetWord(input, strDev)) + { + int iDev = atoi(strDev); + if (iDev >= 0 && iDev < 15) + { + uint64_t iVendor = parser->GetDeviceVendorId((cec_logical_address) iDev); + CStdString strLog; + strLog.Format("vendor id: %06x", iVendor); + cout << strLog.c_str() << endl; + } + } + } else if (command == "ver") { CStdString strDev;