cec: added GetDeviceVendorId()/cec_get_device_vendor_id()
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 13:07:55 +0000 (14:07 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 13:07:55 +0000 (14:07 +0100)
include/cec.h
include/cecc.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/testclient/main.cpp

index 9be8d21980e77306605abf32669a97f4bf925d82..4389d7bfa849101c86250265952b1b74f94202bb 100644 (file)
@@ -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;
   };
 };
 
index a76ac0f05a43e16648ded6acd924313d70be1963..0c9d57ce2769a5fa3ebe2f90b74d4e6a5ce91298 100644 (file)
@@ -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
index 279c79ff5dbc9535ad038fa3facf31c65cb19e2f..eea66ee1e638d268e0ec682a5f2a6df70deb2e26 100644 (file)
@@ -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);
index 94c796c73681bee0a87113d910c79109a806c8da..025d6dd26c7871b7814ac4ffbe7c4b3fbbdc08de 100644 (file)
@@ -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;
index 6790c3c1d1184775a86666c936ad2ccf852f344c..d7d7d60655b35108a9c4a4502bed163582e19fdb 100644 (file)
@@ -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)
index 1862a6e707eb359fc942c0a999ea431648016f4f..286e47e0569f480980e1a248c0b4f7302d8b3831 100644 (file)
@@ -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);
index 2e9f31df51b3421f1272bf922c32a987a5522d37..ad663b7623fcf104e528f0fa5bab7c5b3a054c74 100644 (file)
@@ -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;
+}
+
 //@}
index 8aa5e4bf908f2465bf70b570b92fd6efa4f12aa0..f26e7c3c456765f40ef3786b952e6caa14f4f127 100644 (file)
@@ -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);
index 67a816f0e6c3468ca34f991113747c6856075c93..81d5796604515233e9f31ec084d9dbfa8bf8c22d 100644 (file)
@@ -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);
index 9952a8c77e514c59cbc27d017ef61ee458017045..38f6b5bd8eaaba8832890680da9e27d7325a827f 100644 (file)
@@ -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;