#include "CECAudioSystem.h"
#include "../CECProcessor.h"
+#include "../implementations/CECCommandHandler.h"
using namespace CEC;
m_systemAudioStatus(CEC_SYSTEM_AUDIO_STATUS_ON),
m_audioStatus(CEC_AUDIO_MUTE_STATUS_MASK)
{
- m_type = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
+ m_type = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
+}
+
+bool CCECAudioSystem::SetAudioStatus(const cec_audio_status status)
+{
+ if (m_audioStatus != status)
+ {
+ CStdString strLog;
+ strLog.Format(">> %s (%X): audio status changed from %s to %s", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(m_audioStatus), CCECCommandHandler::ToString(status));
+ AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+ m_audioStatus = status;
+ return true;
+ }
+
+ return false;
+}
+
+bool CCECAudioSystem::SetSystemAudioMode(const cec_system_audio_status mode)
+{
+ if (m_systemAudioStatus != mode)
+ {
+ CStdString strLog;
+ strLog.Format(">> %s (%X): system audio mode changed from %s to %s", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(m_systemAudioStatus), CCECCommandHandler::ToString(mode));
+ AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+ m_systemAudioStatus = mode;
+ return true;
+ }
+
+ return false;
}
bool CCECAudioSystem::SetSystemAudioMode(const cec_command &command)
{
- m_systemAudioStatus = (command.parameters.size == 0) ?
+ SetSystemAudioMode((command.parameters.size == 0) ?
CEC_SYSTEM_AUDIO_STATUS_OFF :
- CEC_SYSTEM_AUDIO_STATUS_ON;
+ CEC_SYSTEM_AUDIO_STATUS_ON);
return TransmitAudioStatus(command.initiator);
}
bool CCECAudioSystem::TransmitAudioStatus(cec_logical_address dest)
{
CStdString strLog;
- strLog.Format("<< %x -> %x: audio status '%2x'", m_iLogicalAddress, dest, m_audioStatus);
+ strLog.Format("<< %x -> %x: audio status '%2x'", m_iLogicalAddress, dest, CCECCommandHandler::ToString(m_audioStatus));
AddLog(CEC_LOG_NOTICE, strLog);
cec_command command;
bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest)
{
CStdString strLog;
- strLog.Format("<< %x -> %x: system audio mode '%2x'", m_iLogicalAddress, dest, m_systemAudioStatus);
+ strLog.Format("<< %x -> %x: system audio mode '%s'", m_iLogicalAddress, dest, CCECCommandHandler::ToString(m_systemAudioStatus));
AddLog(CEC_LOG_NOTICE, strLog);
cec_command command;
using namespace CEC;
+#define ToString(p) CCECCommandHandler::ToString(p)
+
CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
+ m_type(CEC_DEVICE_TYPE_RESERVED),
m_iPhysicalAddress(iPhysicalAddress),
m_iStreamPath(0),
m_iLogicalAddress(iLogicalAddress),
m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
m_processor(processor),
+ m_vendor(CEC_VENDOR_UNKNOWN),
m_bMenuActive(true),
m_bActiveSource(false),
- m_iVendorClass(CEC_VENDOR_UNKNOWN),
m_iLastCommandSent(0),
m_iLastActive(0),
m_cecVersion(CEC_VERSION_UNKNOWN)
m_menuLanguage.language[3] = 0;
m_menuLanguage.device = iLogicalAddress;
- m_vendor.vendor = CEC_VENDOR_UNKNOWN;
- m_type = CEC_DEVICE_TYPE_RESERVED;
- m_strDeviceName = CCECCommandHandler::ToString(m_iLogicalAddress);
+ m_strDeviceName = ToString(m_iLogicalAddress);
}
CCECBusDevice::~CCECBusDevice(void)
{
CLockObject lock(&m_mutex);
if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST &&
- m_vendor.vendor == CEC_VENDOR_UNKNOWN &&
+ m_vendor == CEC_VENDOR_UNKNOWN &&
GetTimeMs() - m_iLastCommandSent > 5000 &&
!m_processor->IsMonitoring())
{
const char* CCECBusDevice::GetLogicalAddressName(void) const
{
- return CCECCommandHandler::ToString(m_iLogicalAddress);
+ return ToString(m_iLogicalAddress);
}
cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
return m_powerStatus;
}
-const cec_vendor &CCECBusDevice::GetVendor(void)
+const cec_vendor_id CCECBusDevice::GetVendorId(void)
{
- if (m_vendor.vendor == CEC_VENDOR_UNKNOWN)
+ if (m_vendor == CEC_VENDOR_UNKNOWN)
{
if (!MyLogicalAddressContains(m_iLogicalAddress))
{
return m_vendor;
}
+const char *CCECBusDevice::GetVendorName(void)
+{
+ GetVendorId();
+ return ToString(m_vendor);
+}
+
bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
{
return m_processor->HasLogicalAddress(address);
m_cecVersion = newVersion;
CStdString strLog;
- strLog.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(newVersion));
+ strLog.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
AddLog(CEC_LOG_DEBUG, strLog);
}
if (m_powerStatus != powerStatus)
{
CStdString strLog;
- strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(m_powerStatus), CCECCommandHandler::ToString(powerStatus));
+ strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
m_processor->AddLog(CEC_LOG_DEBUG, strLog);
m_powerStatus = powerStatus;
}
}
-void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0 */)
+void CCECBusDevice::SetVendorId(uint64_t iVendorId)
{
- m_vendor.vendor = (cec_vendor_id)iVendorId;
- m_iVendorClass = iVendorClass;
+ m_vendor = (cec_vendor_id)iVendorId;
switch (iVendorId)
{
}
CStdString strLog;
- strLog.Format("%s (%X): vendor = %s (%06x) class = %2x", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass());
+ strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), GetVendorId());
m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
}
//@}
bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
{
CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, CCECCommandHandler::ToString(m_cecVersion));
+ strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion));
AddLog(CEC_LOG_NOTICE, strLog);
cec_command command;
bool CCECBusDevice::TransmitMenuState(cec_logical_address dest)
{
CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): ", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
+ strLog.Format("<< %s (%X) -> %s (%X): ", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
if (m_bMenuActive)
strLog.append("menu active");
else
bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
{
CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, m_strDeviceName.c_str());
+ strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str());
AddLog(CEC_LOG_NOTICE, strLog.c_str());
cec_command command;
bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
{
CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, strMessage);
+ strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage);
AddLog(CEC_LOG_NOTICE, strLog.c_str());
cec_command command;
dest = m_iLogicalAddress;
CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
+ strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
AddLog(CEC_LOG_NOTICE, strLog.c_str());
cec_command command;
bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
{
CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, CCECCommandHandler::ToString(m_powerStatus));
+ strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
AddLog(CEC_LOG_NOTICE, strLog.c_str());
cec_command command;
bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
{
- CStdString strLog;
- strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest);
- AddLog(CEC_LOG_NOTICE, strLog);
+ if (m_vendor == CEC_VENDOR_UNKNOWN)
+ {
+ CStdString strLog;
+ strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
+ AddLog(CEC_LOG_NOTICE, strLog);
- m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
- return false;
+ m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+ return false;
+ }
+ else
+ {
+ CStdString strLog;
+ strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_vendor), (uint64_t)m_vendor);
+ AddLog(CEC_LOG_NOTICE, strLog);
+
+ cec_command command;
+ cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+
+ command.parameters.push_back((uint8_t) (((uint64_t)m_vendor >> 16) & 0xFF));
+ command.parameters.push_back((uint8_t) (((uint64_t)m_vendor >> 8) & 0xFF));
+ command.parameters.push_back((uint8_t) ((uint64_t)m_vendor & 0xFF));
+
+ return m_processor->Transmit(command);
+ }
}
//@}