From 0f23c85cf92ff0ff061b5c965f771d9a4b3afe56 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Fri, 28 Oct 2011 11:16:57 +0200 Subject: [PATCH] cec: moved device specific logic from CCECProcessor to CCECBusDevice --- src/lib/CECProcessor.cpp | 182 ++---------------- src/lib/CECProcessor.h | 18 +- src/lib/LibCEC.cpp | 7 +- src/lib/devices/CECBusDevice.cpp | 180 ++++++++++++++++- src/lib/devices/CECBusDevice.h | 15 ++ src/lib/implementations/CECCommandHandler.cpp | 81 +++++--- src/lib/implementations/CECCommandHandler.h | 1 + 7 files changed, 271 insertions(+), 213 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index e9ae43e..bb20751 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -42,7 +42,6 @@ using namespace CEC; using namespace std; CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : - m_iPhysicalAddress(iPhysicalAddress), m_iLogicalAddress(iLogicalAddress), m_strDeviceName(strDeviceName), m_communication(serComm), @@ -51,6 +50,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm { for (unsigned int iPtr = 0; iPtr < 16; iPtr++) m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0); + + m_busDevices[m_iLogicalAddress]->SetPhysicalAddress(iPhysicalAddress); } CCECProcessor::~CCECProcessor(void) @@ -124,49 +125,12 @@ void *CCECProcessor::Process(void) return NULL; } -bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) -{ - if (!IsRunning()) - return false; - - CStdString strLog; - strLog.Format("<< powering on device with logical address %d", (int8_t)address); - m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_IMAGE_VIEW_ON); - - return Transmit(command); -} - -bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) -{ - if (!IsRunning()) - return false; - - CStdString strLog; - strLog.Format("<< putting device with logical address %d in standby mode", (int8_t)address); - m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_STANDBY); - - return Transmit(command); -} - bool CCECProcessor::SetActiveView(void) { if (!IsRunning()) return false; - m_controller->AddLog(CEC_LOG_DEBUG, "<< setting active view"); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); - command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); - command.parameters.push_back(m_iPhysicalAddress & 0xFF); - - return Transmit(command); + return m_busDevices[m_iLogicalAddress]->BroadcastActiveView(); } bool CCECProcessor::SetInactiveView(void) @@ -174,14 +138,7 @@ bool CCECProcessor::SetInactiveView(void) if (!IsRunning()) return false; - m_controller->AddLog(CEC_LOG_DEBUG, "<< setting inactive view"); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE); - command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); - command.parameters.push_back(m_iPhysicalAddress & 0xFF); - - return Transmit(command); + return m_busDevices[m_iLogicalAddress]->BroadcastInactiveView(); } void CCECProcessor::LogOutput(const cec_command &data) @@ -217,28 +174,8 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) { - CStdString strLog; - strLog.Format("<< setting physical address to %2x", iPhysicalAddress); - m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - m_iPhysicalAddress = iPhysicalAddress; - return SetActiveView(); -} - -bool CCECProcessor::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) -{ - CStdString strLog; - strLog.Format("<< display message '%s'", strMessage); - m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, iLogicalAddress, CEC_OPCODE_SET_OSD_STRING); - command.parameters.push_back((uint8_t)duration); - - for (unsigned int iPtr = 0; iPtr < strlen(strMessage); iPtr++) - command.parameters.push_back(strMessage[iPtr]); - - return Transmit(command); + m_busDevices[m_iLogicalAddress]->SetPhysicalAddress(iPhysicalAddress); + return m_busDevices[m_iLogicalAddress]->BroadcastActiveView(); } bool CCECProcessor::SwitchMonitoring(bool bEnable) @@ -296,93 +233,6 @@ void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode Transmit(command); } -void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_TV */) -{ - m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting CEC version as 1.3a"); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_CEC_VERSION); - command.parameters.push_back(CEC_VERSION_1_3A); - - Transmit(command); -} - -void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_TV */, bool bOn /* = true */) -{ - if (bOn) - m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting \"On\" power status"); - else - m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting \"Off\" power status"); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_REPORT_POWER_STATUS); - command.parameters.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY); - - Transmit(command); -} - -void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_TV */, bool bActive /* = true */) -{ - if (bActive) - m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting menu state as active"); - else - m_controller->AddLog(CEC_LOG_NOTICE, "<< reporting menu state as inactive"); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_MENU_STATUS); - command.parameters.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); - - Transmit(command); -} - -void CCECProcessor::ReportVendorID(cec_logical_address address /* = CECDEVICE_TV */) -{ - m_controller->AddLog(CEC_LOG_NOTICE, "<< vendor ID requested, feature abort"); - TransmitAbort(address, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); -} - -void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV */) -{ - const char *osdname = m_strDeviceName.c_str(); - CStdString strLog; - strLog.Format("<< reporting OSD name as %s", osdname); - m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, address, CEC_OPCODE_SET_OSD_NAME); - for (unsigned int iPtr = 0; iPtr < strlen(osdname); iPtr++) - command.parameters.push_back(osdname[iPtr]); - - Transmit(command); -} - -void CCECProcessor::ReportPhysicalAddress(void) -{ - CStdString strLog; - strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress); - m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); - command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); - command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); - command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE)); - - Transmit(command); -} - -void CCECProcessor::BroadcastActiveSource(void) -{ - m_controller->AddLog(CEC_LOG_NOTICE, "<< broadcasting active source"); - - cec_command command; - cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); - command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); - command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); - - Transmit(command); -} - bool CCECProcessor::WaitForAck(bool *bError, uint32_t iTimeout /* = 1000 */) { bool bTransmitSucceeded = false, bEom = false; @@ -524,21 +374,6 @@ void CCECProcessor::ParseMessage(cec_adapter_message &msg, bool *bError, bool *b } } -void CCECProcessor::ParseVendorId(cec_logical_address device, const cec_datapacket &data) -{ - if (data.size < 3) - { - m_controller->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); - return; - } - - uint64_t iVendorId = ((uint64_t)data[0] << 3) + - ((uint64_t)data[1] << 2) + - (uint64_t)data[2]; - - m_busDevices[(uint8_t)device]->SetVendorId(iVendorId, data.size >= 4 ? data[3] : 0); -} - void CCECProcessor::ParseCommand(cec_command &command) { CStdString dataStr; @@ -551,6 +386,11 @@ void CCECProcessor::ParseCommand(cec_command &command) m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); } +uint16_t CCECProcessor::GetPhysicalAddress(void) const +{ + return m_busDevices[m_iLogicalAddress]->GetPhysicalAddress(); +} + void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode) { m_controller->SetCurrentButton(iButtonCode); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index c9028a8..24d1e31 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -54,18 +54,16 @@ namespace CEC virtual bool Start(void); void *Process(void); - virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV); - virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST); virtual bool SetActiveView(void); virtual bool SetInactiveView(void); virtual bool Transmit(const cec_command &data, bool bWaitForAck = true); virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); - virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage); virtual bool SwitchMonitoring(bool bEnable); virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; } - virtual uint16_t GetPhysicalAddress(void) const { return m_iPhysicalAddress; } + virtual uint16_t GetPhysicalAddress(void) const; + virtual const std::string &GetDeviceName(void) { return m_strDeviceName; } virtual void SetCurrentButton(cec_user_control_code iButtonCode); virtual void AddCommand(const cec_command &command); @@ -74,14 +72,8 @@ namespace CEC virtual bool TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck = true); virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); - virtual void ReportCECVersion(cec_logical_address address = CECDEVICE_TV); - virtual void ReportPowerState(cec_logical_address address = CECDEVICE_TV, bool bOn = true); - virtual void ReportMenuState(cec_logical_address address = CECDEVICE_TV, bool bActive = true); - virtual void ReportVendorID(cec_logical_address address = CECDEVICE_TV); - virtual void ReportOSDName(cec_logical_address address = CECDEVICE_TV); - virtual void ReportPhysicalAddress(void); - virtual void BroadcastActiveSource(void); - virtual void ParseVendorId(cec_logical_address device, const cec_datapacket &data); + + CCECBusDevice *m_busDevices[16]; private: void LogOutput(const cec_command &data); @@ -90,14 +82,12 @@ namespace CEC void ParseCommand(cec_command &command); cec_command m_currentframe; - uint16_t m_iPhysicalAddress; cec_logical_address m_iLogicalAddress; CecBuffer m_frameBuffer; std::string m_strDeviceName; CMutex m_mutex; CAdapterCommunication *m_communication; CLibCEC *m_controller; - CCECBusDevice *m_busDevices[16]; bool m_bMonitor; }; }; diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index ecbc55a..ab25290 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -35,6 +35,7 @@ #include "AdapterCommunication.h" #include "AdapterDetection.h" #include "CECProcessor.h" +#include "devices/CECBusDevice.h" #include "util/StdString.h" #include "platform/timeutils.h" @@ -175,12 +176,12 @@ bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress) bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) { - return m_cec ? m_cec->PowerOnDevices(address) : false; + return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->PowerOn() : false; } bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) { - return m_cec ? m_cec->StandbyDevices(address) : false; + return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->Standby() : false; } bool CLibCEC::SetActiveView(void) @@ -195,7 +196,7 @@ bool CLibCEC::SetInactiveView(void) bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) { - return m_cec ? m_cec->SetOSDString(iLogicalAddress, duration, strMessage) : false; + return m_cec && iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)iLogicalAddress]->SetOSDString(duration, strMessage) : false; } bool CLibCEC::SwitchMonitoring(bool bEnable) diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index f89d730..c26d1bc 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -70,6 +70,21 @@ void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage) m_processor->AddLog(level, strMessage); } +void CCECBusDevice::SetVendorId(const cec_datapacket &data) +{ + if (data.size < 3) + { + AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); + return; + } + + uint64_t iVendorId = ((uint64_t)data[0] << 3) + + ((uint64_t)data[1] << 2) + + (uint64_t)data[2]; + + SetVendorId(iVendorId, data.size >= 4 ? data[3] : 0); +} + void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0 */) { m_iVendorId = iVendorId; @@ -101,7 +116,7 @@ void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0 } CStdString strLog; - strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass()); + strLog.Format("device %d: vendor = %s (%06x) class = %2x", m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass()); m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); } @@ -116,7 +131,8 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) void CCECBusDevice::PollVendorId(void) { CLockObject lock(&m_mutex); - if (m_iLastActive > 0 && m_iVendorId == CEC_VENDOR_UNKNOWN && + if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST && + m_iVendorId == CEC_VENDOR_UNKNOWN && GetTimeMs() - m_iLastActive > 5000) { m_iLastActive = GetTimeMs(); @@ -136,6 +152,166 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddres m_iPhysicalAddress = iNewAddress; } +bool CCECBusDevice::PowerOn(void) +{ + CStdString strLog; + strLog.Format("<< powering on device with logical address %d", (int8_t)m_iLogicalAddress); + AddLog(CEC_LOG_DEBUG, strLog.c_str()); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::Standby(void) +{ + CStdString strLog; + strLog.Format("<< putting device with logical address %d in standby mode", (int8_t)m_iLogicalAddress); + AddLog(CEC_LOG_DEBUG, strLog.c_str()); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::SetOSDString(cec_display_control duration, const char *strMessage) +{ + CStdString strLog; + strLog.Format("<< display message '%s'", strMessage); + AddLog(CEC_LOG_NOTICE, strLog.c_str()); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_SET_OSD_STRING); + command.parameters.push_back((uint8_t)duration); + + for (unsigned int iPtr = 0; iPtr < strlen(strMessage); iPtr++) + command.parameters.push_back(strMessage[iPtr]); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::ReportCECVersion(void) +{ + AddLog(CEC_LOG_NOTICE, "<< reporting CEC version as 1.3a"); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_CEC_VERSION); + command.parameters.push_back(CEC_VERSION_1_3A); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::ReportDeckStatus(void) +{ + // need to support opcodes play and deck control before doing anything with this + AddLog(CEC_LOG_NOTICE, "<< deck status requested, feature abort"); + m_processor->TransmitAbort(m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); + return false; +} + +bool CCECBusDevice::ReportMenuState(bool bActive /* = true */) +{ + if (bActive) + AddLog(CEC_LOG_NOTICE, "<< reporting menu state as active"); + else + AddLog(CEC_LOG_NOTICE, "<< reporting menu state as inactive"); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_MENU_STATUS); + command.parameters.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::ReportOSDName(void) +{ + const char *osdname = m_processor->GetDeviceName().c_str(); + CStdString strLog; + strLog.Format("<< reporting OSD name as %s", osdname); + AddLog(CEC_LOG_NOTICE, strLog.c_str()); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_SET_OSD_NAME); + for (unsigned int iPtr = 0; iPtr < strlen(osdname); iPtr++) + command.parameters.push_back(osdname[iPtr]); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::ReportPowerState(bool bOn /* = true */) +{ + if (bOn) + AddLog(CEC_LOG_NOTICE, "<< reporting \"On\" power status"); + else + AddLog(CEC_LOG_NOTICE, "<< reporting \"Off\" power status"); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_REPORT_POWER_STATUS); + command.parameters.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::ReportVendorID(void) +{ + AddLog(CEC_LOG_NOTICE, "<< vendor ID requested, feature abort"); + m_processor->TransmitAbort(m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); + return false; +} + +bool CCECBusDevice::BroadcastActiveView(void) +{ + AddLog(CEC_LOG_DEBUG, "<< setting active view"); + + cec_command command; + cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); + command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); + command.parameters.push_back(m_iPhysicalAddress & 0xFF); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::BroadcastInactiveView(void) +{ + AddLog(CEC_LOG_DEBUG, "<< setting inactive view"); + + cec_command command; + cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE); + command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); + command.parameters.push_back(m_iPhysicalAddress & 0xFF); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::BroadcastPhysicalAddress(void) +{ + CStdString strLog; + strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress); + AddLog(CEC_LOG_NOTICE, strLog.c_str()); + + cec_command command; + cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); + command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); + command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); + command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE)); + + return m_processor->Transmit(command); +} + +bool CCECBusDevice::BroadcastActiveSource(void) +{ + AddLog(CEC_LOG_NOTICE, "<< broadcasting active source"); + + cec_command command; + cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); + command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); + command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); + + return m_processor->Transmit(command); +} + const char *CCECBusDevice::CECVendorIdToString(const uint64_t iVendorId) { switch (iVendorId) diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index a115346..227f14d 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -53,6 +53,7 @@ namespace CEC virtual cec_logical_address GetMyLogicalAddress(void) const; virtual uint16_t GetMyPhysicalAddress(void) const; + 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; } @@ -67,6 +68,20 @@ namespace CEC virtual CCECCommandHandler *GetHandler(void) const { return m_handler; }; 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); + virtual bool ReportOSDName(void); + virtual bool ReportPowerState(bool bOn = true); + virtual bool ReportVendorID(void); + + virtual bool BroadcastActiveView(void); + virtual bool BroadcastInactiveView(void); + virtual bool BroadcastPhysicalAddress(void); + virtual bool BroadcastActiveSource(void); static const char *CECVendorIdToString(const uint64_t iVendorId); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 35a5704..df685bc 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -127,58 +127,81 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) { - m_busDevice->GetProcessor()->ParseVendorId(command.initiator, command.parameters); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + device->SetVendorId(command.parameters); + + return false; } bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) { - m_busDevice->GetProcessor()->ParseVendorId(command.initiator, command.parameters); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + device->SetVendorId(command.parameters); + + return false; } bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) { - m_busDevice->GetProcessor()->ReportCECVersion(command.initiator); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + return device->ReportCECVersion(); + + return false; } bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) { - // need to support opcodes play and deck control before doing anything with this - m_busDevice->GetProcessor()->TransmitAbort(command.initiator, CEC_OPCODE_GIVE_DECK_STATUS); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + return device->ReportDeckStatus(); + + return false; } bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) { - m_busDevice->GetProcessor()->ReportPowerState(command.initiator); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + return device->ReportPowerState(); + + return false; } bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) { - m_busDevice->GetProcessor()->ReportVendorID(command.initiator); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + return device->ReportVendorID(); + + return false; } bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) { - m_busDevice->GetProcessor()->ReportOSDName(command.initiator); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + return device->ReportOSDName(); + + return false; } bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) { - m_busDevice->GetProcessor()->ReportPhysicalAddress(); - return true; + return m_busDevice->BroadcastPhysicalAddress(); } bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) { if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY) - m_busDevice->GetProcessor()->ReportMenuState(command.initiator); - return true; + { + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + return device->ReportMenuState(); + } + return false; } bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) @@ -186,7 +209,7 @@ bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) CStdString strLog; strLog.Format(">> %i requests active source", (uint8_t) command.initiator); m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - m_busDevice->GetProcessor()->BroadcastActiveSource(); + m_busDevice->BroadcastActiveSource(); return true; } @@ -197,7 +220,9 @@ bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); - m_busDevice->SetPhysicalAddress(iNewAddress, iOldAddress); + CCECBusDevice *device = GetDevice(command.initiator); + if (device) + device->SetPhysicalAddress(iNewAddress, iOldAddress); } return true; } @@ -211,7 +236,7 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) strLog.Format(">> %i requests stream path from physical address %04x", command.initiator, streamaddr); m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); if (streamaddr == m_busDevice->GetMyPhysicalAddress()) - m_busDevice->GetProcessor()->BroadcastActiveSource(); + m_busDevice->BroadcastActiveSource(); } return true; } @@ -242,5 +267,15 @@ bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) void CCECCommandHandler::UnhandledCommand(const cec_command &command) { - m_busDevice->GetProcessor()->AddCommand(command);; + m_busDevice->GetProcessor()->AddCommand(command); +} + +CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const +{ + CCECBusDevice *device = NULL; + + if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST) + device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress]; + + return device; } diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 7bb0fc2..70c86eb 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -63,6 +63,7 @@ namespace CEC bool HandleUserControlRelease(const cec_command &command); void UnhandledCommand(const cec_command &command); + CCECBusDevice *GetDevice(cec_logical_address iLogicalAddress) const; CCECBusDevice *m_busDevice; }; }; -- 2.34.1