From 2d4183227b9bec3e95ca90f427687426ec155bc6 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Fri, 10 Aug 2012 10:55:48 +0200 Subject: [PATCH] added the type of adapter to libcec_configuration, and display the type in cec-client -l. fixed missing cec_version updates in libcec_configuration --- include/cec.h | 4 +++- include/cectypes.h | 20 +++++++++++++++--- src/lib/CECClient.cpp | 16 ++++++++++++++ src/lib/CECProcessor.cpp | 2 ++ src/lib/CECTypeUtils.h | 19 +++++++++++++++++ src/lib/LibCEC.cpp | 5 +++++ src/lib/LibCEC.h | 1 + src/lib/adapter/AdapterCommunication.h | 5 +++++ .../Pulse-Eight/USBCECAdapterCommands.cpp | 16 +++++++++++++- .../Pulse-Eight/USBCECAdapterCommands.h | 12 +++++++++++ .../USBCECAdapterCommunication.cpp | 21 +++++++++++++++++-- .../Pulse-Eight/USBCECAdapterCommunication.h | 1 + .../Pulse-Eight/USBCECAdapterMessage.cpp | 2 ++ .../Pulse-Eight/USBCECAdapterMessage.h | 8 +++++++ .../adapter/RPi/RPiCECAdapterCommunication.h | 1 + src/testclient/main.cpp | 9 ++++++-- 16 files changed, 133 insertions(+), 9 deletions(-) diff --git a/include/cec.h b/include/cec.h index bd56fff..12f35b2 100644 --- a/include/cec.h +++ b/include/cec.h @@ -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; }; }; diff --git a/include/cectypes.h b/include/cectypes.h index f0ccd67..515c552 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -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(); diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index e7ac955..c9525af 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -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); diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 88795e9..e22d13f 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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); diff --git a/src/lib/CECTypeUtils.h b/src/lib/CECTypeUtils.h index 7a50d9e..ac9e7d6 100644 --- a/src/lib/CECTypeUtils.h +++ b/src/lib/CECTypeUtils.h @@ -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"; + } + } }; } diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index ad4ce66..252e1dc 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -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)) {} diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 76d2919..fa4e632 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -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; diff --git a/src/lib/adapter/AdapterCommunication.h b/src/lib/adapter/AdapterCommunication.h index 03880b6..02dda4d 100644 --- a/src/lib/adapter/AdapterCommunication.h +++ b/src/lib/adapter/AdapterCommunication.h @@ -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; }; }; diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp index 457889c..ab0fa39 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp @@ -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) diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h index 13e2249..fa7f543 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h @@ -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; }; } diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp index 70e45ac..80f7714 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp @@ -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); diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h index ae7fa1c..2192456 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h @@ -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); diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp index 08e6c35..64efd06 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp @@ -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; } diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h index 74980bb..f8ae413 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h @@ -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: diff --git a/src/lib/adapter/RPi/RPiCECAdapterCommunication.h b/src/lib/adapter/RPi/RPiCECAdapterCommunication.h index 530aec1..01dbb5e 100644 --- a/src/lib/adapter/RPi/RPiCECAdapterCommunication.h +++ b/src/lib/adapter/RPi/RPiCECAdapterCommunication.h @@ -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); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index e594eaf..2192643 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -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 @@ -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"); -- 2.34.1