added the type of adapter to libcec_configuration, and display the type in cec-client...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 10 Aug 2012 08:55:48 +0000 (10:55 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 10 Aug 2012 09:05:47 +0000 (11:05 +0200)
16 files changed:
include/cec.h
include/cectypes.h
src/lib/CECClient.cpp
src/lib/CECProcessor.cpp
src/lib/CECTypeUtils.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/adapter/AdapterCommunication.h
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h
src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h
src/lib/adapter/RPi/RPiCECAdapterCommunication.h
src/testclient/main.cpp

index bd56fff29161739ff9a4ada0efb44e1c6a647cd9..12f35b29b50719efde664792ffa8258541ebae2b 100644 (file)
@@ -36,7 +36,7 @@
 
 #include "cectypes.h"
 
-#define LIBCEC_VERSION_CURRENT CEC_SERVER_VERSION_1_8_1
+#define LIBCEC_VERSION_CURRENT CEC_SERVER_VERSION_1_8_2
 
 namespace CEC
 {
@@ -500,6 +500,8 @@ namespace CEC
      * Should be called as first call to libCEC, directly after CECInitialise() and before using Open()
      */
     virtual void InitVideoStandalone(void) = 0;
+
+    virtual const char *ToString(const cec_adapter_type type) = 0;
   };
 };
 
index f0ccd6777ed73624bfce6ec3e0dcd79730d6aa88..515c5524439904e36366970aec9458231fab400e 100644 (file)
@@ -647,6 +647,14 @@ typedef enum cec_vendor_id
   CEC_VENDOR_UNKNOWN   = 0
 } cec_vendor_id;
 
+typedef enum cec_adapter_type
+{
+  ADAPTERTYPE_UNKNOWN          = 0,
+  ADAPTERTYPE_P8_EXTERNAL      = 0x1,
+  ADAPTERTYPE_P8_DAUGHTERBOARD = 0x2,
+  ADAPTERTYPE_RPI              = 0x100
+} cec_adapter_type;
+
 typedef struct cec_menu_language
 {
   char                language[4]; /**< the iso language code. @bug the language code is only 3 chars long, not 4. will be changed in v2.0, because changing it now would break backwards compat */
@@ -1185,7 +1193,8 @@ typedef enum cec_client_version
   CEC_CLIENT_VERSION_1_7_1   = 0x1701,
   CEC_CLIENT_VERSION_1_7_2   = 0x1702,
   CEC_CLIENT_VERSION_1_8_0   = 0x1800,
-  CEC_CLIENT_VERSION_1_8_1   = 0x1801
+  CEC_CLIENT_VERSION_1_8_1   = 0x1801,
+  CEC_CLIENT_VERSION_1_8_2   = 0x1802
 } cec_client_version;
 
 typedef enum cec_server_version
@@ -1203,7 +1212,8 @@ typedef enum cec_server_version
   CEC_SERVER_VERSION_1_7_1   = 0x1701,
   CEC_SERVER_VERSION_1_7_2   = 0x1702,
   CEC_SERVER_VERSION_1_8_0   = 0x1800,
-  CEC_SERVER_VERSION_1_8_1   = 0x1801
+  CEC_SERVER_VERSION_1_8_1   = 0x1801,
+  CEC_SERVER_VERSION_1_8_2   = 0x1802
 } cec_server_version;
 
 typedef struct libcec_configuration
@@ -1240,6 +1250,7 @@ typedef struct libcec_configuration
   uint32_t              iFirmwareBuildDate;   /*!< (read-only) the build date of the firmware, in seconds since epoch. if not available, this value will be set to 0. added in 1.6.2 */
   uint8_t               bMonitorOnly;         /*!< won't allocate a CCECClient when starting the connection when set (same as monitor mode). added in 1.6.3 */
   cec_version           cecVersion;           /*!< CEC spec version to use by libCEC. defaults to v1.4. added in 1.8.0 */
+  cec_adapter_type      adapterType;          /*!< type of the CEC adapter that we're connected to. added in 1.8.2 */
 
 #ifdef __cplusplus
   // @todo re-add in v2.0 (breaks ABI)
@@ -1277,7 +1288,9 @@ typedef struct libcec_configuration
         /* libcec 1.6.3+ */
         (other.clientVersion < CEC_CLIENT_VERSION_1_6_3 || bMonitorOnly              == other.bMonitorOnly) &&
         /* libcec 1.8.0+ */
-        (other.clientVersion < CEC_CLIENT_VERSION_1_8_0 || cecVersion                == other.cecVersion));
+        (other.clientVersion < CEC_CLIENT_VERSION_1_8_0 || cecVersion                == other.cecVersion) &&
+        /* libcec 1.8.2+ */
+        (other.clientVersion < CEC_CLIENT_VERSION_1_8_2 || adapterType               == other.adapterType));
   }
 
   bool operator!=(const libcec_configuration &other) const
@@ -1310,6 +1323,7 @@ typedef struct libcec_configuration
     iFirmwareBuildDate =              CEC_FW_BUILD_UNKNOWN;
     bMonitorOnly =                    0;
     cecVersion =         (cec_version)CEC_DEFAULT_SETTING_CEC_VERSION;
+    adapterType =                     ADAPTERTYPE_UNKNOWN;
 
     memset(strDeviceName, 0, 13);
     deviceTypes.clear();
index e7ac9556349601af73230fbc73904c918ed8777d..c9525af15ace48fd132a3c78771d65873fdf79ee 100644 (file)
@@ -802,6 +802,14 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration)
     configuration.bMonitorOnly            = m_configuration.bMonitorOnly;
   }
 
+  // client version 1.8.0
+  if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_8_0)
+    configuration.cecVersion              = m_configuration.cecVersion;
+
+  // client version 1.8.2
+  if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_8_2)
+    configuration.adapterType             = m_configuration.adapterType;
+
   return true;
 }
 
@@ -859,6 +867,14 @@ bool CCECClient::SetConfiguration(const libcec_configuration &configuration)
       m_configuration.bMonitorOnly = configuration.bMonitorOnly;
     }
 
+    // client version 1.8.0
+    if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_8_0)
+      m_configuration.cecVersion   = configuration.cecVersion;
+
+    // client version 1.8.2
+    if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_8_2)
+      m_configuration.adapterType  = configuration.adapterType;
+
     // ensure that there is at least 1 device type set
     if (m_configuration.deviceTypes.IsEmpty())
       m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
index 88795e92b9dde65123abe66f6b4de546371b9759..e22d13fd969b77d20bd1572f0b8d4f2615671a8e 100644 (file)
@@ -604,6 +604,7 @@ bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configurati
   config->iFirmwareVersion   = m_communication->GetFirmwareVersion();
   config->iPhysicalAddress   = m_communication->GetPhysicalAddress();
   config->iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
+  config->adapterType        = m_communication->GetAdapterType();
 
   return true;
 }
@@ -731,6 +732,7 @@ bool CCECProcessor::RegisterClient(CCECClient *client)
   configuration.serverVersion      = LIBCEC_VERSION_CURRENT;
   configuration.iFirmwareVersion   = m_communication->GetFirmwareVersion();
   configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
+  configuration.adapterType        = m_communication->GetAdapterType();
 
   // mark the client as registered
   client->SetRegistered(true);
index 7a50d9e743fc0fcb43b30403b773054bee457add..ac9e7d6dc699ce5b0caa66c3ac322917bd690230 100644 (file)
@@ -547,6 +547,8 @@ namespace CEC
         return "1.8.0";
       case CEC_CLIENT_VERSION_1_8_1:
         return "1.8.1";
+      case CEC_CLIENT_VERSION_1_8_2:
+        return "1.8.2";
       default:
         return "Unknown";
       }
@@ -584,6 +586,8 @@ namespace CEC
         return "1.8.0";
       case CEC_SERVER_VERSION_1_8_1:
         return "1.8.1";
+      case CEC_SERVER_VERSION_1_8_2:
+        return "1.8.2";
       default:
         return "Unknown";
       }
@@ -776,5 +780,20 @@ namespace CEC
         return "unknown";
       }
     }
+
+    static const char *ToString(const cec_adapter_type type)
+    {
+      switch (type)
+      {
+      case ADAPTERTYPE_P8_EXTERNAL:
+        return "Pulse-Eight USB-CEC Adapter";
+      case ADAPTERTYPE_P8_DAUGHTERBOARD:
+        return "Pulse-Eight USB-CEC Daughterboard";
+      case ADAPTERTYPE_RPI:
+        return "Raspberry Pi";
+      default:
+        return "unknown";
+      }
+    }
   };
 }
index ad4ce66625873f156c7f037b0d9445228c3e0e28..252e1dcfe9f48545f183b82698b87cb325d029a3 100644 (file)
@@ -649,6 +649,11 @@ void CLibCEC::InitVideoStandalone(void)
   CAdapterFactory::InitVideoStandalone();
 }
 
+const char *CLibCEC::ToString(const cec_adapter_type type)
+{
+  return CCECTypeUtils::ToString(type);
+}
+
 // no longer being used
 void CLibCEC::AddKey(const cec_keypress &UNUSED(key)) {}
 void CLibCEC::ConfigurationChanged(const libcec_configuration &UNUSED(config)) {}
index 76d29191e9619ee66555bd9fad2c81d5d048176d..fa4e6321bf92b9d1b347af2b9d40da3bf8d7036b 100644 (file)
@@ -149,6 +149,7 @@ namespace CEC
       const char *GetLibInfo(void);
       const char *ToString(const cec_user_control_code key);
       void InitVideoStandalone(void);
+      const char *ToString(const cec_adapter_type type);
 
       CCECProcessor *           m_cec;
 
index 03880b6ef921dafaa46657aa6069c2c56456c47b..02dda4dab1e4db1766403ed221236000fed5c49d 100644 (file)
@@ -200,6 +200,11 @@ namespace CEC
      */
     virtual bool SupportsSourceLogicalAddress(const cec_logical_address address) = 0;
 
+    /*!
+     * @return The type of adapter that this instance is connected to.
+     */
+    virtual cec_adapter_type GetAdapterType(void) = 0;
+
     IAdapterCommunicationCallback *m_callback;
   };
 };
index 457889cf3b555d9baffba9ed786ad2e813880ed0..ab0fa392e12633c54a0c237861bbae481b1fbfcb 100644 (file)
@@ -54,7 +54,8 @@ CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm
     m_iSettingLAMask(0),
     m_bNeedsWrite(false),
     m_iBuildDate(CEC_FW_BUILD_UNKNOWN),
-    m_bControlledMode(false)
+    m_bControlledMode(false),
+    m_adapterType(P8_ADAPTERTYPE_UNKNOWN)
 {
   m_persistedConfiguration.Clear();
 }
@@ -132,6 +133,19 @@ bool CUSBCECAdapterCommands::RequestSettingCECVersion(void)
   return false;
 }
 
+p8_cec_adapter_type CUSBCECAdapterCommands::RequestAdapterType(void)
+{
+  if (m_adapterType == P8_ADAPTERTYPE_UNKNOWN)
+  {
+    LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting adapter type");
+
+    cec_datapacket response = RequestSetting(MSGCODE_GET_ADAPTER_TYPE);
+    if (response.size == 1)
+      m_adapterType = (p8_cec_adapter_type)response[0];
+  }
+  return m_adapterType;
+}
+
 uint32_t CUSBCECAdapterCommands::RequestBuildDate(void)
 {
   if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN)
index 13e22494cad0041564708dad3c078e7f35d4d611..fa7f543261ef8e8c6aee8a9b0dc5c4c81f5fdad7 100644 (file)
@@ -114,6 +114,17 @@ namespace CEC
      */
     uint32_t GetPersistedBuildDate(void) const { return m_iBuildDate; };
 
+    /*!
+     * @brief Request the adapter type.
+     * @return The type
+     */
+    p8_cec_adapter_type RequestAdapterType(void);
+
+    /*!
+     * @return The persisted build date.
+     */
+    p8_cec_adapter_type GetPersistedAdapterType(void) const { return m_adapterType; };
+
     /*!
      * @brief Persist the current settings in the EEPROM
      * @return True when persisted, false otherwise.
@@ -234,6 +245,7 @@ namespace CEC
     libcec_configuration         m_persistedConfiguration; /**< the configuration that is persisted in the eeprom */
     uint32_t                     m_iBuildDate;             /**< the build date of the firmware */
     bool                         m_bControlledMode;        /**< current value of the controlled mode feature */
+    p8_cec_adapter_type          m_adapterType;            /**< the type of the adapter that we're connected to */
     PLATFORM::CMutex             m_mutex;
   };
 }
index 70e45ac6c30e00e06987cf9c001f67cf55c68028..80f7714a3af1f9651476d143257598ede46ca8c1 100644 (file)
@@ -482,8 +482,14 @@ bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs /* = CEC_DEFA
   else
     bReturn = true;
 
-  /* try to read the build date */
-  m_commands->RequestBuildDate();
+  if (m_commands->GetFirmwareVersion() >= 2)
+  {
+    /* try to read the build date */
+    m_commands->RequestBuildDate();
+
+    /* try to read the adapter type */
+    m_commands->RequestAdapterType();
+  }
 
   SetInitialised(bReturn);
   return bReturn;
@@ -570,6 +576,17 @@ uint32_t CUSBCECAdapterCommunication::GetFirmwareBuildDate(void)
   return iBuildDate;
 }
 
+cec_adapter_type CUSBCECAdapterCommunication::GetAdapterType(void)
+{
+  cec_adapter_type type(ADAPTERTYPE_UNKNOWN);
+  if (m_commands)
+    type = (cec_adapter_type)m_commands->GetPersistedAdapterType();
+  if (type == ADAPTERTYPE_UNKNOWN && IsOpen())
+    type = (cec_adapter_type)m_commands->RequestAdapterType();
+
+  return type;
+}
+
 bool CUSBCECAdapterCommunication::ProvidesExtendedResponse(void)
 {
   uint32_t iBuildDate(0);
index ae7fa1c634633c92794d05df01864e7dd59e8984..2192456010ca99c7dae30f42285a8ed387d79dd3 100644 (file)
@@ -87,6 +87,7 @@ namespace CEC
     bool SetControlledMode(bool controlled);
     cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; }
     bool SupportsSourceLogicalAddress(const cec_logical_address UNUSED(address)) { return true; }
+    cec_adapter_type GetAdapterType(void);
     ///}
 
     bool ProvidesExtendedResponse(void);
index 08e6c358243c70b6ecf2eb7ef8591c32692d297c..64efd062f5f58ab60a2666e4c6c82bab673cabb3 100644 (file)
@@ -229,6 +229,8 @@ const char *CCECAdapterMessage::ToString(cec_adapter_messagecode msgCode)
     return "SET_OSD_NAME";
   case MSGCODE_WRITE_EEPROM:
     return "WRITE_EEPROM";
+  case MSGCODE_GET_ADAPTER_TYPE:
+    return "GET_ADAPTER_TYPE";
   default:
     break;
   }
index 74980bba14acf60b3fc0914c0d919a8fdfe6d45a..f8ae4135362167378a5e4e61257484eeb1c87781 100644 (file)
@@ -77,10 +77,18 @@ namespace CEC
     MSGCODE_GET_OSD_NAME,
     MSGCODE_SET_OSD_NAME,
     MSGCODE_WRITE_EEPROM,
+    MSGCODE_GET_ADAPTER_TYPE,
     MSGCODE_FRAME_EOM = 0x80,
     MSGCODE_FRAME_ACK = 0x40,
   } cec_adapter_messagecode;
 
+  typedef enum p8_cec_adapter_type
+  {
+    P8_ADAPTERTYPE_UNKNOWN = 0,
+    P8_ADAPTERTYPE_EXTERNAL,
+    P8_ADAPTERTYPE_DAUGHTERBOARD,
+  } p8_cec_adapter_type;
+
   class CCECAdapterMessage
   {
   public:
index 530aec105b8a1923afd317891258c7b577443d24..01dbb5e51adbea0935fd5b538f458ada03aa5487 100644 (file)
@@ -78,6 +78,7 @@ namespace CEC
     bool SetControlledMode(bool UNUSED(controlled)) { return true; };
     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; };
     ///}
 
     bool IsInitialised(void);
index e594eaf16aa2b132e700ff4deceb92e87b8f2644..2192643e6dcaee688c76b0d21b2150ab8cfb5b39 100644 (file)
@@ -47,7 +47,7 @@ using namespace CEC;
 using namespace std;
 using namespace PLATFORM;
 
-#define CEC_CONFIG_VERSION CEC_CLIENT_VERSION_1_8_1;
+#define CEC_CONFIG_VERSION CEC_CLIENT_VERSION_1_8_2;
 
 #include <cecloader.h>
 
@@ -224,7 +224,12 @@ void ListDevices(ICECAdapter *parser)
           time_t buildTime = (time_t)config.iFirmwareBuildDate;
           strDeviceInfo.AppendFormat("firmware build date: %s", asctime(gmtime(&buildTime)));
           strDeviceInfo = strDeviceInfo.Left(strDeviceInfo.length() > 1 ? (unsigned)(strDeviceInfo.length() - 1) : 0); // strip \n added by asctime
-          strDeviceInfo.append(" +0000");
+          strDeviceInfo.append(" +0000\n");
+        }
+
+        if (config.adapterType != ADAPTERTYPE_UNKNOWN)
+        {
+          strDeviceInfo.AppendFormat("type:                %s\n", parser->ToString(config.adapterType));
         }
       }
       strDeviceInfo.append("\n");