X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FCECCommandHandler.cpp;h=d1a4855c793364ac65981cf7913d6906f3dfac02;hb=2c56dd5189b47478350c84917c420670598ca06b;hp=f0a2e64ae6ae2bcdf1134e2374a679bb0ff6db5b;hpb=03ae897d74d37f6fdb35e2bb937e851cee61793b;p=deb_libcec.git diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index f0a2e64..d1a4855 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -42,6 +42,7 @@ using namespace std; CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) { m_busDevice = busDevice; + m_processor = m_busDevice->GetProcessor(); } bool CCECCommandHandler::HandleCommand(const cec_command &command) @@ -49,9 +50,11 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) bool bHandled(true); CStdString strLog; - strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", m_busDevice->GetProcessor()->ToString(command.initiator), command.initiator, m_busDevice->GetProcessor()->ToString(command.destination), command.destination, m_busDevice->GetProcessor()->ToString(command.opcode), command.opcode); + strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", m_processor->ToString(command.initiator), command.initiator, m_processor->ToString(command.destination), command.destination, m_processor->ToString(command.opcode), command.opcode); m_busDevice->AddLog(CEC_LOG_NOTICE, strLog); + m_processor->AddCommand(command); + switch(command.opcode) { case CEC_OPCODE_REPORT_POWER_STATUS: @@ -106,7 +109,16 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) HandleGiveSystemAudioModeStatus(command); break; case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - HandleSetSystemAudioModeRequest(command); + HandleSystemAudioModeRequest(command); + break; + case CEC_OPCODE_REPORT_AUDIO_STATUS: + HandleReportAudioStatus(command); + break; + case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: + HandleSystemAudioModeStatus(command); + break; + case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: + HandleSetSystemAudioMode(command); break; case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: HandleRequestActiveSource(command); @@ -129,12 +141,6 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: HandleReportPhysicalAddress(command); break; - case CEC_OPCODE_REPORT_AUDIO_STATUS: - HandleReportAudioStatus(command); - break; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: - HandleSystemAudioStatus(command); - break; case CEC_OPCODE_SET_OSD_NAME: HandleSetOSDName(command); break; @@ -150,7 +156,6 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) break; } - m_busDevice->GetProcessor()->AddCommand(command); return bHandled; } @@ -159,7 +164,7 @@ bool CCECCommandHandler::HandleActiveSource(const cec_command &command) if (command.parameters.size == 2) { uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); - return m_busDevice->GetProcessor()->SetStreamPath(iAddress); + return m_processor->SetStreamPath(iAddress); } return true; @@ -192,7 +197,7 @@ bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) { if (m_busDevice->MyLogicalAddressContains(command.destination)) - m_busDevice->GetProcessor()->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); + m_processor->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); return true; } @@ -301,7 +306,7 @@ bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &comm bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) { - m_busDevice->GetProcessor()->SetActiveSource(command.initiator); + m_processor->SetActiveSource(command.initiator); return true; } @@ -387,7 +392,7 @@ bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) if (command.parameters.size == 2) { uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); - m_busDevice->GetProcessor()->SetStreamPath(iNewAddress); + m_processor->SetStreamPath(iNewAddress); } return false; @@ -442,7 +447,7 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - if (m_busDevice->GetProcessor()->SetStreamPath(iStreamAddress)) + if (m_processor->SetStreamPath(iStreamAddress)) { CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); if (device) @@ -455,13 +460,29 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) return false; } -bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command) +bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) { - if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1) + if (m_busDevice->MyLogicalAddressContains(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) - return ((CCECAudioSystem *) device)->SetSystemAudioMode(command); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + { + if (command.parameters.size >= 2) + { + device->SetPowerStatus(CEC_POWER_STATUS_ON); + ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); + uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); + CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); + if (newActiveDevice) + m_processor->SetActiveSource(newActiveDevice->GetLogicalAddress()); + return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); + } + else + { + ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); + return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); + } + } } return false; } @@ -475,13 +496,31 @@ bool CCECCommandHandler::HandleStandby(const cec_command &command) return true; } -bool CCECCommandHandler::HandleSystemAudioStatus(const cec_command &command) +bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + if (command.parameters.size == 1) { - ((CCECAudioSystem *)device)->SetSystemAudioMode(command); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + { + ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); + return true; + } + } + + return false; +} + +bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) +{ + if (command.parameters.size == 1) + { + CCECBusDevice *device = GetDevice(command.initiator); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + { + ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); + return true; + } } return false; @@ -489,7 +528,7 @@ bool CCECCommandHandler::HandleSystemAudioStatus(const cec_command &command) bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) { - m_busDevice->GetProcessor()->SetActiveSource(command.initiator); + m_processor->SetActiveSource(command.initiator); return true; } @@ -497,7 +536,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) { if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0) { - m_busDevice->GetProcessor()->AddKey(); + m_processor->AddKey(); if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) { @@ -513,7 +552,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) device->SetPowerStatus(CEC_POWER_STATUS_ON); } - m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]); + m_processor->SetCurrentButton((cec_user_control_code) command.parameters[0]); return true; } } @@ -523,7 +562,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) { if (m_busDevice->MyLogicalAddressContains(command.destination)) - m_busDevice->GetProcessor()->AddKey(); + m_processor->AddKey(); return true; } @@ -539,7 +578,7 @@ unsigned int CCECCommandHandler::GetMyDevices(vector &devices) { unsigned int iReturn(0); - cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses(); + cec_logical_addresses addresses = m_processor->GetLogicalAddresses(); for (uint8_t iPtr = 0; iPtr < 16; iPtr++) { if (addresses[iPtr]) @@ -557,19 +596,19 @@ CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress CCECBusDevice *device = NULL; if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST) - device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress]; + device = m_processor->m_busDevices[iLogicalAddress]; return device; } CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const { - return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress); + return m_processor->GetDeviceByPhysicalAddress(iPhysicalAddress); } CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const { - return m_busDevice->GetProcessor()->GetDeviceByType(type); + return m_processor->GetDeviceByType(type); } void CCECCommandHandler::SetVendorId(const cec_command &command) @@ -593,14 +632,27 @@ void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16 { if (!m_busDevice->MyLogicalAddressContains(iAddress)) { - bool bOurAddress(m_busDevice->GetProcessor()->GetPhysicalAddress() == iNewAddress); + bool bOurAddress(m_processor->GetPhysicalAddress() == iNewAddress); GetDevice(iAddress)->SetPhysicalAddress(iNewAddress); if (bOurAddress) { /* another device reported the same physical address as ours * since we don't have physical address detection yet, we'll just use the * given address, increased by 0x100 for now */ - m_busDevice->GetProcessor()->SetPhysicalAddress(iNewAddress + 0x100); + m_processor->SetPhysicalAddress(iNewAddress + 0x100); } } } + +void CCECCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) +{ + CStdString strLog; + strLog.Format("<< POLL: %s (%x) -> %s (%x)", m_processor->ToString(iInitiator), iInitiator, m_processor->ToString(iDestination), iDestination); + m_processor->AddLog(CEC_LOG_DEBUG, strLog); +} + +bool CCECCommandHandler::HandleReceiveFailed(void) +{ + /* default = error */ + return true; +}