From 6d858ba423e643bf169115c854ec298e60b5ef1e Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Fri, 25 Nov 2011 12:32:28 +0100 Subject: [PATCH] cec: added GetActiveDevices()/cec_get_active_devices(), IsActiveDevice()/cec_is_active_device(), IsActiveDeviceType()/cec_is_active_device_type(). --- include/cec.h | 19 +++++++++++++ include/cecc.h | 18 ++++++++++++ src/lib/CECProcessor.cpp | 25 +++++++++++++++++ src/lib/CECProcessor.h | 3 ++ src/lib/LibCEC.cpp | 22 +++++++++++++++ src/lib/LibCEC.h | 3 ++ src/lib/LibCECC.cpp | 24 +++++++++++++++- src/testclient/main.cpp | 60 +++++++++++++++++++++++++--------------- 8 files changed, 151 insertions(+), 23 deletions(-) diff --git a/include/cec.h b/include/cec.h index 7a306dd..2e47abd 100644 --- a/include/cec.h +++ b/include/cec.h @@ -243,6 +243,25 @@ namespace CEC * @return True if the POLL was acked, false otherwise. */ virtual bool PollDevice(cec_logical_address iAddress) = 0; + + /*! + * @return The devices that are active on the bus and not handled by libcec. + */ + virtual cec_logical_addresses GetActiveDevices(void) = 0; + + /*! + * @brief Check whether a device is active on the bus. + * @param iAddress The address to check. + * @return True when active, false otherwise. + */ + virtual bool IsActiveDevice(cec_logical_address iAddress) = 0; + + /*! + * @brief Check whether a device of the given type is active on the bus. + * @param type The type to check. + * @return True when active, false otherwise. + */ + virtual bool IsActiveDeviceType(cec_device_type type) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index 0b0f2fe..c644662 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -167,6 +167,24 @@ extern DECLSPEC int cec_poll_device(CEC::cec_logical_address iLogicalAddress); extern DECLSPEC int cec_poll_device(cec_logical_address iLogicalAddress); #endif +#ifdef __cplusplus +extern DECLSPEC CEC::cec_logical_addresses cec_get_active_devices(void); +#else +extern DECLSPEC cec_logical_addresses cec_get_active_devices(void); +#endif + +#ifdef __cplusplus +extern DECLSPEC int cec_is_active_device(CEC::cec_logical_address iAddress); +#else +extern DECLSPEC int cec_is_active_device(cec_logical_address iAddress); +#endif + +#ifdef __cplusplus +extern DECLSPEC int cec_is_active_device_type(CEC::cec_device_type type); +#else +extern DECLSPEC int cec_is_active_device_type(cec_device_type type); +#endif + #ifdef __cplusplus }; #endif diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index c7d4de2..dfd0cc1 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -647,6 +647,31 @@ void CCECProcessor::ParseCommand(cec_command &command) m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); } +cec_logical_addresses CCECProcessor::GetActiveDevices(void) +{ + cec_logical_addresses addresses; + for (unsigned int iPtr = 0; iPtr < 15; iPtr++) + { + if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) + addresses.Set((cec_logical_address) iPtr); + } + return addresses; +} + +bool CCECProcessor::IsActiveDevice(cec_logical_address address) +{ + return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT; +} + +bool CCECProcessor::IsActiveDeviceType(cec_device_type type) +{ + cec_logical_addresses activeDevices = GetActiveDevices(); + for (unsigned int iPtr = 0; iPtr < 15; iPtr++) + if (activeDevices.IsSet((cec_logical_address) iPtr) && m_busDevices[iPtr]->GetType() == type) + return true; + return false; +} + uint16_t CCECProcessor::GetPhysicalAddress(void) const { if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary]) diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index e7832d8..58bba6b 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -66,7 +66,10 @@ namespace CEC virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress); virtual cec_logical_address GetLogicalAddress(void) const { return m_logicalAddresses.primary; } virtual cec_logical_addresses GetLogicalAddresses(void) const { return m_logicalAddresses; } + virtual cec_logical_addresses GetActiveDevices(void); virtual bool HasLogicalAddress(cec_logical_address address) const { return m_logicalAddresses.IsSet(address); } + virtual bool IsActiveDevice(cec_logical_address address); + virtual bool IsActiveDeviceType(cec_device_type type); virtual uint16_t GetPhysicalAddress(void) const; virtual bool SetActiveView(void); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index c067562..3b47651 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -253,6 +253,28 @@ bool CLibCEC::PollDevice(cec_logical_address iAddress) return false; } +cec_logical_addresses CLibCEC::GetActiveDevices(void) +{ + cec_logical_addresses addresses; + if (m_cec) + addresses = m_cec->GetActiveDevices(); + return addresses; +} + +bool CLibCEC::IsActiveDevice(cec_logical_address iAddress) +{ + if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) + return m_cec->IsActiveDevice(iAddress); + return false; +} + +bool CLibCEC::IsActiveDeviceType(cec_device_type type) +{ + if (m_cec && type >= CEC_DEVICE_TYPE_TV && type <= CEC_DEVICE_TYPE_AUDIO_SYSTEM) + return m_cec->IsActiveDeviceType(type); + return false; +} + 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 7a69c96..b6948e4 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -84,6 +84,9 @@ namespace CEC virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress); virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress); virtual bool PollDevice(cec_logical_address iAddress); + virtual cec_logical_addresses GetActiveDevices(void); + virtual bool IsActiveDevice(cec_logical_address iAddress); + virtual bool IsActiveDeviceType(cec_device_type type); //@} virtual void AddLog(cec_log_level level, const std::string &strMessage); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index c95741c..ec703f2 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -238,7 +238,29 @@ cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress int cec_poll_device(cec_logical_address iLogicalAddress) { if (cec_parser) - return cec_parser->PollDevice(iLogicalAddress); + return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0; + return -1; +} + +cec_logical_addresses cec_get_active_devices(void) +{ + cec_logical_addresses addresses; + if (cec_parser) + addresses = cec_parser->GetActiveDevices(); + return addresses; +} + +int cec_is_active_device(cec_logical_address iAddress) +{ + if (cec_parser) + return cec_parser->IsActiveDevice(iAddress) ? 1 : 0; + return -1; +} + +int cec_is_active_device_type(cec_device_type type) +{ + if (cec_parser) + return cec_parser->IsActiveDeviceType(type) ? 1 : 0; return -1; } diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 73d6990..dbb62e7 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -223,38 +223,19 @@ void ShowHelpConsole(void) endl << "tx {bytes} transfer bytes over the CEC line." << endl << "txn {bytes} transfer bytes but don't wait for transmission ACK." << endl << - "[tx 40 00 FF 11 22 33] sends bytes 0x40 0x00 0xFF 0x11 0x22 0x33" << endl << - endl << "on {address} power on the device with the given logical address." << endl << - "[on 5] power on a connected audio system" << endl << - endl << "standby {address} put the device with the given address in standby mode." << endl << - "[standby 0] powers off the TV" << endl << - endl << "la {logical_address} change the logical address of the CEC adapter." << endl << - "[la 4] logical address 4" << endl << - endl << "pa {physical_address} change the physical address of the CEC adapter." << endl << - "[pa 10 00] physical address 1.0.0.0" << endl << - endl << "osd {addr} {string} set OSD message on the specified device." << endl << - "[osd 0 Test Message] displays 'Test Message' on the TV" << endl << - endl << "ver {addr} get the CEC version of the specified device." << endl << - "[ver 0] get the CEC version of the TV" << endl << - 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 << "pow {addr} get the power status of the specified device." << endl << - "[pow 0] get the power status of the TV" << endl << - endl << "poll {addr} poll the specified device." << endl << - "[poll 0] sends a poll message to the TV" << endl << - endl << + "lad lists active devices on the bus" << endl << + "ad {addr} checks whether the specified device is active." << endl << + "at {type} checks whether the specified device type is active." << endl << "[mon] {1|0} enable or disable CEC bus monitoring." << endl << "[log] {1 - 31} change the log level. see cectypes.h for values." << endl << "[ping] send a ping command to the CEC adapter." << endl << @@ -709,6 +690,41 @@ int main (int argc, char *argv[]) } } } + else if (command == "lad") + { + cout << "listing active devices:" << endl; + cec_logical_addresses addresses = parser->GetActiveDevices(); + for (unsigned iPtr = 0; iPtr < 16; iPtr++) + if (addresses[iPtr]) + cout << "logical address " << iPtr << endl; + } + else if (command == "ad") + { + CStdString strDev; + if (GetWord(input, strDev)) + { + int iDev = atoi(strDev); + if (iDev >= 0 && iDev < 15) + cout << "logical address " << iDev << " is " << (parser->IsActiveDevice((cec_logical_address)iDev) ? "active" : "not active") << endl; + } + } + else if (command == "at") + { + CStdString strType; + if (GetWord(input, strType)) + { + cec_device_type type = CEC_DEVICE_TYPE_TV; + if (strType.Equals("a")) + type = CEC_DEVICE_TYPE_AUDIO_SYSTEM; + else if (strType.Equals("p")) + type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE; + else if (strType.Equals("r")) + type = CEC_DEVICE_TYPE_RECORDING_DEVICE; + else if (strType.Equals("t")) + type = CEC_DEVICE_TYPE_TUNER; + cout << "device " << type << " is " << (parser->IsActiveDeviceType(type) ? "active" : "not active") << endl; + } + } else if (command == "r") { cout << "closing the connection" << endl; -- 2.34.1