cec: improved logging. fixed GetVendorId()
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
index 7c2f6bf5705f89c501f1ce2ab2b9ea6d9f0c6335..c2595c3927aff0a07619d8921c9d191ebd6b5a86 100644 (file)
@@ -42,13 +42,14 @@ using namespace CEC;
 
 CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
   m_iPhysicalAddress(iPhysicalAddress),
+  m_iStreamPath(0),
   m_iLogicalAddress(iLogicalAddress),
   m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
   m_processor(processor),
   m_bMenuActive(true),
   m_iVendorClass(CEC_VENDOR_UNKNOWN),
   m_iLastActive(0),
-  m_cecVersion(CEC_VERSION_1_3A)
+  m_cecVersion(CEC_VERSION_UNKNOWN)
 {
   m_handler = new CCECCommandHandler(this);
 
@@ -87,8 +88,12 @@ void CCECBusDevice::PollVendorId(void)
   CLockObject lock(&m_mutex);
   if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST &&
       m_vendor.vendor == CEC_VENDOR_UNKNOWN &&
-      GetTimeMs() - m_iLastActive > 5000)
+      GetTimeMs() - m_iLastActive > 5000 &&
+      !m_processor->IsMonitoring())
   {
+    CStdString strLog;
+    strLog.Format("<< requesting vendor ID of device %x", m_iLogicalAddress);
+    AddLog(CEC_LOG_NOTICE, strLog);
     m_iLastActive = GetTimeMs();
 
     cec_command command;
@@ -130,7 +135,9 @@ cec_version CCECBusDevice::GetCecVersion(void)
   {
     if (!MyLogicalAddressContains(m_iLogicalAddress))
     {
-      AddLog(CEC_LOG_NOTICE, "<< requesting CEC version");
+      CStdString strLog;
+      strLog.Format("<< requesting CEC version of device %x", m_iLogicalAddress);
+      AddLog(CEC_LOG_NOTICE, strLog);
       cec_command command;
       cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION);
       CLockObject lock(&m_mutex);
@@ -148,7 +155,9 @@ cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
   {
     if (!MyLogicalAddressContains(m_iLogicalAddress))
     {
-      AddLog(CEC_LOG_NOTICE, "<< requesting menu language");
+      CStdString strLog;
+      strLog.Format("<< requesting menu language of device %x", m_iLogicalAddress);
+      AddLog(CEC_LOG_NOTICE, strLog);
       cec_command command;
       cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE);
       CLockObject lock(&m_mutex);
@@ -176,7 +185,9 @@ cec_power_status CCECBusDevice::GetPowerStatus(void)
   {
     if (!MyLogicalAddressContains(m_iLogicalAddress))
     {
-      AddLog(CEC_LOG_NOTICE, "<< requesting power status");
+      CStdString strLog;
+      strLog.Format("<< requesting power status of device %x", m_iLogicalAddress);
+      AddLog(CEC_LOG_NOTICE, strLog);
       cec_command command;
       cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
       CLockObject lock(&m_mutex);
@@ -194,7 +205,9 @@ const cec_vendor &CCECBusDevice::GetVendor(void)
   {
     if (!MyLogicalAddressContains(m_iLogicalAddress))
     {
-      AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID");
+      CStdString strLog;
+      strLog.Format("<< requesting vendor ID of device %x", m_iLogicalAddress);
+      AddLog(CEC_LOG_NOTICE, strLog);
       cec_command command;
       cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
       CLockObject lock(&m_mutex);
@@ -224,19 +237,19 @@ void CCECBusDevice::SetCecVersion(const cec_version newVersion)
   switch (newVersion)
   {
   case CEC_VERSION_1_2:
-    strLog.Format("device %d reports CEC version 1.2", m_iLogicalAddress);
+    strLog.Format("device %d: CEC version 1.2", m_iLogicalAddress);
     break;
   case CEC_VERSION_1_2A:
-    strLog.Format("device %d reports CEC version 1.2a", m_iLogicalAddress);
+    strLog.Format("device %d: CEC version 1.2a", m_iLogicalAddress);
     break;
   case CEC_VERSION_1_3:
-    strLog.Format("device %d reports CEC version 1.3", m_iLogicalAddress);
+    strLog.Format("device %d: CEC version 1.3", m_iLogicalAddress);
     break;
   case CEC_VERSION_1_3A:
-    strLog.Format("device %d reports CEC version 1.3a", m_iLogicalAddress);
+    strLog.Format("device %d: CEC version 1.3a", m_iLogicalAddress);
     break;
   default:
-    strLog.Format("device %d reports an unknown CEC version", m_iLogicalAddress);
+    strLog.Format("device %d: unknown CEC version", m_iLogicalAddress);
     m_cecVersion = CEC_VERSION_UNKNOWN;
     break;
   }
@@ -254,7 +267,7 @@ void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
   }
 }
 
-void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
+void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
 {
   if (iNewAddress > 0)
   {
@@ -266,30 +279,27 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress, uint16_t iOldAddres
   }
 }
 
-void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
+void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
 {
-  if (m_powerStatus != powerStatus)
+  if (iNewAddress > 0)
   {
     CStdString strLog;
-    strLog.Format("device %d power status changed from %2x to %2x", m_iLogicalAddress, m_powerStatus, powerStatus);
-    m_processor->AddLog(CEC_LOG_DEBUG, strLog);
-    m_powerStatus = powerStatus;
+    strLog.Format(">> %i stream path from %04x to %04x", m_iLogicalAddress, iOldAddress, iNewAddress);
+    AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+    m_iStreamPath = iNewAddress;
   }
 }
 
-void CCECBusDevice::SetVendorId(const cec_datapacket &data)
+void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
 {
-  if (data.size < 3)
+  if (m_powerStatus != powerStatus)
   {
-    AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
-    return;
+    CStdString strLog;
+    strLog.Format("device %d power status changed from %2x to %2x", m_iLogicalAddress, m_powerStatus, powerStatus);
+    m_processor->AddLog(CEC_LOG_DEBUG, strLog);
+    m_powerStatus = powerStatus;
   }
-
-  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 */)
@@ -340,7 +350,7 @@ void CCECBusDevice::SetVendorId(uint64_t iVendorId, uint8_t iVendorClass /* = 0
 bool CCECBusDevice::TransmitActiveSource(void)
 {
   CStdString strLog;
-  strLog.Format("<< %x -> broadcast: active source", m_iLogicalAddress);
+  strLog.Format("<< %x -> broadcast: active source (%4x)", m_iLogicalAddress, m_iPhysicalAddress);
   AddLog(CEC_LOG_NOTICE, strLog);
 
   cec_command command;
@@ -354,7 +364,7 @@ bool CCECBusDevice::TransmitActiveSource(void)
 bool CCECBusDevice::TransmitActiveView(void)
 {
   CStdString strLog;
-  strLog.Format("<< %x -> broadcast: active view", m_iLogicalAddress);
+  strLog.Format("<< %x -> broadcast: active view (%4x)", m_iLogicalAddress, m_iPhysicalAddress);
   AddLog(CEC_LOG_NOTICE, strLog);
 
   cec_command command;
@@ -481,7 +491,7 @@ bool CCECBusDevice::TransmitPhysicalAddress(void)
   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));
+  command.parameters.push_back((uint8_t) (m_type));
 
   return m_processor->Transmit(command);
 }