+bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int iIndex)
+{
+ const char *strLabel = CCECCommandHandler::ToString(address);
+ CStdString strLog;
+ strLog.Format("trying logical address '%s'", strLabel);
+ AddLog(CEC_LOG_DEBUG, strLog);
+
+ SetAckMask(0x1 << address);
+ if (!m_busDevices[address]->TransmitPoll(address))
+ {
+ strLog.Format("using logical address '%s'", strLabel);
+ AddLog(CEC_LOG_NOTICE, strLog);
+
+ /* only set our OSD name and active source for the primary device */
+ if (m_logicalAddresses.empty())
+ {
+ m_busDevices[address]->m_strDeviceName = m_strDeviceName;
+ m_busDevices[address]->m_bActiveSource = true;
+ }
+ m_busDevices[address]->m_powerStatus = (m_types[0] == m_busDevices[address]->m_type) ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY;
+ m_busDevices[address]->m_cecVersion = CEC_VERSION_1_3A;
+ m_logicalAddresses.set(address);
+
+ // TODO
+ m_busDevices[address]->SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS + (iIndex * 0x100));
+
+ return true;
+ }
+
+ strLog.Format("logical address '%s' already taken", strLabel);
+ AddLog(CEC_LOG_DEBUG, strLog);
+ return false;
+}
+
+bool CCECProcessor::FindLogicalAddressRecordingDevice(unsigned int iIndex)
+{
+ AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
+ return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1, iIndex) ||
+ TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2, iIndex) ||
+ TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3, iIndex);
+}
+
+bool CCECProcessor::FindLogicalAddressTuner(unsigned int iIndex)
+{
+ AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
+ return TryLogicalAddress(CECDEVICE_TUNER1, iIndex) ||
+ TryLogicalAddress(CECDEVICE_TUNER2, iIndex) ||
+ TryLogicalAddress(CECDEVICE_TUNER3, iIndex) ||
+ TryLogicalAddress(CECDEVICE_TUNER4, iIndex);
+}
+
+bool CCECProcessor::FindLogicalAddressPlaybackDevice(unsigned int iIndex)
+{
+ AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
+ return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1, iIndex) ||
+ TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2, iIndex) ||
+ TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3, iIndex);
+}
+
+bool CCECProcessor::FindLogicalAddressAudioSystem(unsigned int iIndex)
+{
+ AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
+ return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM, iIndex);
+}
+
+bool CCECProcessor::FindLogicalAddresses(void)
+{
+ bool bReturn(true);
+ m_logicalAddresses.clear();
+ CStdString strLog;
+
+ for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ {
+ if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
+ continue;
+
+ strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]);
+ AddLog(CEC_LOG_DEBUG, strLog);
+
+ if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
+ bReturn &= FindLogicalAddressRecordingDevice(iPtr);
+ if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
+ bReturn &= FindLogicalAddressTuner(iPtr);
+ if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
+ bReturn &= FindLogicalAddressPlaybackDevice(iPtr);
+ if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
+ bReturn &= FindLogicalAddressAudioSystem(iPtr);
+ }
+
+ return bReturn;
+}
+