added GetAdapterProductId()+GetAdapterVendorId()/cec_get_adapter_product_id()+cec_get...
authorLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 12:39:07 +0000 (14:39 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 15:54:48 +0000 (17:54 +0200)
16 files changed:
include/cec.h
include/cecc.h
src/LibCecSharp/LibCecSharp.cpp
src/LibCecTray/controller/CECController.cs
src/LibCecTray/controller/applications/internal/XBMCController.cs
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/lib/adapter/AdapterCommunication.h
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h
src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h
src/lib/adapter/RPi/RPiCECAdapterCommunication.h
src/lib/platform/windows/os-types.h

index 8d141640943ad0c28a32972a06f0aebd75717a9a..1b0019bea193a912c165fabaccb0a2d1229c3c3c 100644 (file)
@@ -397,6 +397,16 @@ namespace CEC
      */
     virtual void InitVideoStandalone(void) = 0;
 
+    /*!
+     * @return The (virtual) USB vendor id
+     */
+    virtual uint16_t GetAdapterVendorId(void) const = 0;
+
+    /*!
+     * @return The (virtual) USB product id
+     */
+    virtual uint16_t GetAdapterProductId(void) const = 0;
+
     virtual const char *ToString(const cec_menu_state state) = 0;
     virtual const char *ToString(const cec_version version) = 0;
     virtual const char *ToString(const cec_power_status status) = 0;
index 5241e7391cd2e6ebe49a2953a59876ac20703e74..a4892c48b045ab13d276e1e32ee69738503c0b06 100644 (file)
@@ -272,6 +272,10 @@ extern DECLSPEC const char * cec_get_lib_info(void);
 
 extern DECLSPEC void cec_init_video_standalone(void);
 
+extern DECLSPEC uint16_t cec_get_adapter_vendor_id(void);
+
+extern DECLSPEC uint16_t cec_get_adapter_product_id(void);
+
 #ifdef __cplusplus
 };
 #endif
index a008f2ee671cc3beae8b9ce979ff1b5624e1e11f..ff3c619f487694166c2ec37d23aa37763e446c67 100644 (file)
@@ -731,6 +731,24 @@ namespace CecSharp
       m_libCec->InitVideoStandalone();
     }
 
+    /// <summary>
+    /// Get the (virtual) USB vendor id
+    /// </summary>
+    /// <returns>The (virtual) USB vendor id</returns>
+    uint16_t GetAdapterVendorId()
+    {
+      return m_libCec->GetAdapterVendorId();
+    }
+
+    /// <summary>
+    /// Get the (virtual) USB product id
+    /// </summary>
+    /// <returns>The (virtual) USB product id</returns>
+    uint16_t GetAdapterProductId()
+    {
+      return m_libCec->GetAdapterProductId();
+    }
+
   private:
     !LibCecSharp(void)
     {
index 13d75201cbdd644a7e63c9834ff87f7488da40fc..f7a3a04fb37dec7777e6c2ce78cbc6d58247817c 100644 (file)
@@ -490,20 +490,6 @@ namespace LibCECTray.controller
       get { return Lib.ToString(Config.ClientVersion); }
     }
 
-    /// <summary>
-    /// Get the usb vid:prod descriptor
-    /// </summary>
-    public string USBDescriptor
-    {
-      get
-      {
-        DateTime checkDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
-        checkDate = checkDate.AddSeconds(0x5045dbf5);
-
-        return string.Format("2548:100{0}", ((DateTime)Config.FirmwareBuildDate >= checkDate ? "2" : "1"));
-      }
-    }
-
     /// <summary>
     /// libCEC
     /// </summary>
index 5ffe8f9ec88c15d3968d48bec1354d471dd4115b..9e4fb3a1973d717351d04993bb8cc145a4d4b212 100644 (file)
@@ -69,17 +69,17 @@ namespace LibCECTray.controller.applications.@internal
     }
 
     public bool LoadXMLConfiguration()
-    {
-      var xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
-      return LoadXMLConfiguration(xbmcDir + @"\usb_2548_1001.xml") || LoadXMLConfiguration(xbmcDir + @"\usb_2548_1002.xml");
-    }
-
-    public bool LoadXMLConfiguration(string filename)
     {
       bool gotConfig = false;
-      if (File.Exists(filename))
+      string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
+      string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+      string file = defaultDir + @"\usb_2548_1001.xml";
+      if (File.Exists(xbmcDir + @"\usb_2548_1001.xml"))
+        file = xbmcDir + @"\usb_2548_1001.xml";
+
+      if (File.Exists(file))
       {
-        XmlTextReader reader = new XmlTextReader(filename);
+        XmlTextReader reader = new XmlTextReader(file);
         while (reader.Read())
         {
           gotConfig = true;
@@ -203,23 +203,14 @@ namespace LibCECTray.controller.applications.@internal
     {
       Settings.Persist();
 
-      var xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
-      if (!Directory.Exists(xbmcDir))
-        Directory.CreateDirectory(xbmcDir);
-
-      if (!Directory.Exists(xbmcDir))
-      {
-        // couldn't create directory
-        MessageBox.Show(string.Format(Resources.could_not_create_directory, xbmcDir), Resources.error,
-                        MessageBoxButtons.OK, MessageBoxIcon.Error);
-        return;
-      }
+      string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
+      string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
       SaveFileDialog dialog = new SaveFileDialog
-      {
+                                {
         Title = Resources.store_settings_where,
-        InitialDirectory = xbmcDir,
-        FileName = string.Format("usb_{0}.xml", Program.Instance.Controller.USBDescriptor.Replace(':', '_')),
+        InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir,
+        FileName = "usb_2548_1001.xml",
         Filter = Resources.xml_file_filter,
         FilterIndex = 1
       };
index 409b30b1cdde68d6f4ff79304a9fecc32a7d1316..50bb95fce849bedf025ef8cb990749580db3c843 100644 (file)
@@ -944,6 +944,16 @@ void CCECProcessor::HandleLogicalAddressLost(cec_logical_address oldAddress)
   }
 }
 
+uint16_t CCECProcessor::GetAdapterVendorId(void) const
+{
+  return m_communication ? m_communication->GetAdapterVendorId() : 0;
+}
+
+uint16_t CCECProcessor::GetAdapterProductId(void) const
+{
+  return m_communication ? m_communication->GetAdapterProductId() : 0;
+}
+
 CCECAllocateLogicalAddress::CCECAllocateLogicalAddress(CCECProcessor* processor, CCECClient* client) :
     m_processor(processor),
     m_client(client) { }
index e1f6d68517eee2908cc7f1b6906e72db0f29240b..dff892e8b9ee2b1e5e588640705a451ff9977605 100644 (file)
@@ -143,6 +143,9 @@ namespace CEC
       void SwitchMonitoring(bool bSwitchTo);
 
       bool AllocateLogicalAddresses(CCECClient* client);
+
+      uint16_t GetAdapterVendorId(void) const;
+      uint16_t GetAdapterProductId(void) const;
     private:
       bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true);
       void SetCECInitialised(bool bSetTo = true);
index b74bc335d9d790d63d19041b5a610d7b1812f8d2..9ff5e146b6d06ff7c4607890b0eceb45ddf83f63 100644 (file)
@@ -529,3 +529,12 @@ void CLibCEC::InitVideoStandalone(void)
 {
   CAdapterFactory::InitVideoStandalone();
 }
+uint16_t CLibCEC::GetAdapterVendorId(void) const
+{
+  return m_cec && m_cec->IsRunning() ? m_cec->GetAdapterVendorId() : 0;
+}
+
+uint16_t CLibCEC::GetAdapterProductId(void) const
+{
+  return m_cec && m_cec->IsRunning() ? m_cec->GetAdapterProductId() : 0;
+}
index d4558615d2d3ce689e5443c783eb7f0404d1cce3..56a112bf52e9e42ee49c45eaf05838eb6719a1ab 100644 (file)
@@ -48,10 +48,6 @@ namespace CEC
       CLibCEC(void);
       virtual ~CLibCEC(void);
 
-    /*!
-     * ICECAdapter implementation
-     */
-    //@{
       bool Open(const char *strPort, uint32_t iTimeout = CEC_DEFAULT_CONNECT_TIMEOUT);
       void Close(void);
       bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
@@ -121,7 +117,6 @@ namespace CEC
       static uint16_t GetMaskForType(cec_device_type type);
 
       bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
-    //@}
 
       void AddLog(const cec_log_level level, const char *strFormat, ...);
       void AddCommand(const cec_command &command);
@@ -134,6 +129,8 @@ namespace CEC
       std::vector<CCECClient *> GetClients(void) { return m_clients; };
       const char *GetLibInfo(void);
       void InitVideoStandalone(void);
+      uint16_t GetAdapterVendorId(void) const;
+      uint16_t GetAdapterProductId(void) const;
 
       CCECProcessor *           m_cec;
 
index 9f501ccd8a7699e12684410187d87b5b7ffb08d6..6d9d8c50719457c103f2bee82becdfd52c793fc9 100644 (file)
@@ -378,4 +378,14 @@ void cec_init_video_standalone(void)
     cec_parser->InitVideoStandalone();
 }
 
+uint16_t cec_get_adapter_vendor_id(void)
+{
+  return cec_parser ? cec_parser->GetAdapterVendorId() : NULL;
+}
+
+uint16_t cec_get_adapter_product_id(void)
+{
+  return cec_parser ? cec_parser->GetAdapterProductId() : NULL;
+}
+
 //@}
index 07026713042a19e934bc84af18d4060de42788cb..7dd56b7fdbfebd22eb3a8c86867fbe916193f980 100644 (file)
@@ -211,6 +211,16 @@ namespace CEC
      */
     virtual cec_adapter_type GetAdapterType(void) = 0;
 
+    /*!
+     * @return The (virtual) USB vendor id
+     */
+    virtual uint16_t GetAdapterVendorId(void) const = 0;
+
+    /*!
+     * @return The (virtual) USB product id
+     */
+    virtual uint16_t GetAdapterProductId(void) const = 0;
+
     IAdapterCommunicationCallback *m_callback;
   };
 };
index 3d36497de409cd5c66c0f1591f1ebffc83a35089..7fa78f73638b96eff4e9ace948a258f57247affd 100644 (file)
@@ -36,6 +36,7 @@
 #include "USBCECAdapterCommands.h"
 #include "USBCECAdapterMessageQueue.h"
 #include "USBCECAdapterMessage.h"
+#include "USBCECAdapterDetection.h"
 #include "lib/platform/sockets/serialport.h"
 #include "lib/platform/util/timeutils.h"
 #include "lib/platform/util/util.h"
@@ -59,6 +60,7 @@ using namespace PLATFORM;
 #define CEC_LATEST_ADAPTER_FW_DATE    0x501a4b0c
 
 #define CEC_FW_DATE_EXTENDED_RESPONSE 0x501a4b0c
+#define CEC_FW_DATE_DESCRIPTOR2       0x5045dbf5
 
 #define LIB_CEC m_callback->GetLib()
 
@@ -611,6 +613,20 @@ bool CUSBCECAdapterCommunication::ProvidesExtendedResponse(void)
   return iBuildDate >= CEC_FW_DATE_EXTENDED_RESPONSE;
 }
 
+uint16_t CUSBCECAdapterCommunication::GetAdapterVendorId(void) const
+{
+  return CEC_VID;
+}
+
+uint16_t CUSBCECAdapterCommunication::GetAdapterProductId(void) const
+{
+  uint32_t iBuildDate(0);
+  if (m_commands)
+    iBuildDate = m_commands->GetPersistedBuildDate();
+
+  return iBuildDate >= CEC_FW_DATE_DESCRIPTOR2 ? CEC_PID2 : CEC_PID;
+}
+
 bool CUSBCECAdapterCommunication::IsRunningLatestFirmware(void)
 {
   return GetFirmwareBuildDate() >= CEC_LATEST_ADAPTER_FW_DATE &&
index 2192456010ca99c7dae30f42285a8ed387d79dd3..04199e2bc079b3a7371aa5455da23bc3f856f2bc 100644 (file)
@@ -88,6 +88,8 @@ namespace CEC
     cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; }
     bool SupportsSourceLogicalAddress(const cec_logical_address UNUSED(address)) { return true; }
     cec_adapter_type GetAdapterType(void);
+    uint16_t GetAdapterVendorId(void) const;
+    uint16_t GetAdapterProductId(void) const;
     ///}
 
     bool ProvidesExtendedResponse(void);
index dfccd65bb2c3bd61a603f0b0f652157e217ce9c2..37478b9632036770d6e480537c94252d074d9ad6 100644 (file)
 
 namespace CEC
 {
+  #define CEC_VID  0x2548
+  #define CEC_PID  0x1001
+  #define CEC_PID2 0x1002
+  
   class CUSBCECAdapterDetection
   {
   public:
index 7f815450c27b60a87e28cc4256d7b4ed80880acf..740091611b12277b02fd17ba46897b0949fe0560 100644 (file)
@@ -36,6 +36,9 @@
 #include "lib/adapter/AdapterCommunication.h"
 #include "lib/platform/threads/threads.h"
 
+#define RPI_ADAPTER_VID 0x2708
+#define RPI_ADAPTER_PID 0x1001
+
 extern "C" {
 #include <interface/vmcs_host/vc_cecservice.h>
 #include <interface/vchiq_arm/vchiq_if.h>
@@ -79,6 +82,8 @@ namespace CEC
     cec_vendor_id GetVendorId(void) { return CEC_VENDOR_BROADCOM; }
     bool SupportsSourceLogicalAddress(const cec_logical_address address) { return address > CECDEVICE_TV && address < CECDEVICE_BROADCAST; }
     cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_RPI; };
+    uint16_t GetAdapterVendorId(void) const { return RPI_ADAPTER_VID; }
+    uint16_t GetAdapterProductId(void) const { return RPI_ADAPTER_PID; }
     ///}
 
     bool IsInitialised(void);
index 2fc62690c407732b92bb263a34ac93c267595a6d..d47eb056d65a06df9684b8ce68f3cd078945fbdd 100644 (file)
@@ -65,6 +65,7 @@ typedef _W64 int   ssize_t;
 #endif
 
 #define snprintf _snprintf
+#define strdup _strdup
 
 #if defined(_MSC_VER)
 #pragma warning (push)