2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
33 #include "CECProcessor.h"
35 #include "AdapterCommunication.h"
36 #include "devices/CECBusDevice.h"
37 #include "devices/CECAudioSystem.h"
38 #include "devices/CECPlaybackDevice.h"
39 #include "devices/CECRecordingDevice.h"
40 #include "devices/CECTuner.h"
41 #include "devices/CECTV.h"
42 #include "implementations/CECCommandHandler.h"
44 #include "util/StdString.h"
45 #include "platform/timeutils.h"
50 CCECProcessor::CCECProcessor(CLibCEC
*controller
, CAdapterCommunication
*serComm
, const char *strDeviceName
, cec_logical_address iLogicalAddress
/* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
52 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
53 m_strDeviceName(strDeviceName
),
54 m_communication(serComm
),
55 m_controller(controller
),
58 m_logicalAddresses
.Clear();
59 m_logicalAddresses
.Set(iLogicalAddress
);
61 for (int iPtr
= 0; iPtr
<= 16; iPtr
++)
62 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, iPtr
== iLogicalAddress
? iPhysicalAddress
: 0);
65 CCECProcessor::CCECProcessor(CLibCEC
*controller
, CAdapterCommunication
*serComm
, const char *strDeviceName
, const cec_device_type_list
&types
) :
67 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
68 m_strDeviceName(strDeviceName
),
70 m_communication(serComm
),
71 m_controller(controller
),
74 m_logicalAddresses
.Clear();
75 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
79 case CECDEVICE_AUDIOSYSTEM
:
80 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
82 case CECDEVICE_PLAYBACKDEVICE1
:
83 case CECDEVICE_PLAYBACKDEVICE2
:
84 case CECDEVICE_PLAYBACKDEVICE3
:
85 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
87 case CECDEVICE_RECORDINGDEVICE1
:
88 case CECDEVICE_RECORDINGDEVICE2
:
89 case CECDEVICE_RECORDINGDEVICE3
:
90 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
92 case CECDEVICE_TUNER1
:
93 case CECDEVICE_TUNER2
:
94 case CECDEVICE_TUNER3
:
95 case CECDEVICE_TUNER4
:
96 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
99 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
102 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
108 CCECProcessor::~CCECProcessor(void)
110 m_startCondition
.Broadcast();
112 m_communication
= NULL
;
114 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
115 delete m_busDevices
[iPtr
];
118 bool CCECProcessor::Start(void)
120 CLockObject
lock(&m_mutex
);
121 if (!m_communication
|| !m_communication
->IsOpen())
123 m_controller
->AddLog(CEC_LOG_ERROR
, "connection is closed");
129 if (!m_startCondition
.Wait(&m_mutex
) || !m_bStarted
)
131 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
136 if (SetAckMask(m_logicalAddresses
.AckMask()) &&
137 SetHDMIPort(m_iHDMIPort
, true))
144 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
149 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
151 if (m_busDevices
[address
]->TryLogicalAddress())
153 /* only set our OSD name and active source for the primary device */
154 if (m_logicalAddresses
.IsEmpty())
156 m_busDevices
[address
]->m_strDeviceName
= m_strDeviceName
;
157 m_busDevices
[address
]->m_bActiveSource
= true;
159 m_logicalAddresses
.Set(address
);
166 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
168 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
169 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
170 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
171 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
174 bool CCECProcessor::FindLogicalAddressTuner(void)
176 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
177 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
178 TryLogicalAddress(CECDEVICE_TUNER2
) ||
179 TryLogicalAddress(CECDEVICE_TUNER3
) ||
180 TryLogicalAddress(CECDEVICE_TUNER4
);
183 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
185 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
186 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
187 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
188 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
191 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
193 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
194 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
197 bool CCECProcessor::FindLogicalAddresses(void)
200 m_logicalAddresses
.Clear();
203 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
205 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
208 strLog
.Format("%s - device %d: type %d", __FUNCTION__
, iPtr
, m_types
.types
[iPtr
]);
209 AddLog(CEC_LOG_DEBUG
, strLog
);
211 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
212 bReturn
&= FindLogicalAddressRecordingDevice();
213 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
214 bReturn
&= FindLogicalAddressTuner();
215 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
216 bReturn
&= FindLogicalAddressPlaybackDevice();
217 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
218 bReturn
&= FindLogicalAddressAudioSystem();
224 void *CCECProcessor::Process(void)
226 bool bParseFrame(false);
228 CCECAdapterMessage msg
;
230 if (m_logicalAddresses
.IsEmpty() && !FindLogicalAddresses())
232 CLockObject
lock(&m_mutex
);
233 m_controller
->AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
234 m_startCondition
.Signal();
239 CLockObject
lock(&m_mutex
);
241 m_controller
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
242 m_startCondition
.Signal();
251 CLockObject
lock(&m_mutex
);
252 if (m_commandBuffer
.Pop(command
))
256 else if (m_communication
->IsOpen() && m_communication
->Read(msg
, 50))
258 m_controller
->AddLog(msg
.is_error() ? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
259 if ((bParseFrame
= (ParseMessage(msg
) && !IsStopped())) == true)
260 command
= m_currentframe
;
265 ParseCommand(command
);
270 m_controller
->CheckKeypressTimeout();
272 for (uint8_t iDevicePtr
= 0; iDevicePtr
< 16; iDevicePtr
++)
274 if (!m_logicalAddresses
[iDevicePtr
])
275 m_busDevices
[iDevicePtr
]->PollVendorId();
284 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
291 cec_logical_address addr
= m_logicalAddresses
.primary
;
293 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
295 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
297 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
299 addr
= (cec_logical_address
) iPtr
;
305 return SetStreamPath(m_busDevices
[addr
]->GetPhysicalAddress(false)) &&
306 m_busDevices
[addr
]->TransmitActiveSource();
309 bool CCECProcessor::SetActiveSource(cec_logical_address iAddress
)
311 return SetStreamPath(m_busDevices
[iAddress
]->GetPhysicalAddress(false));
314 bool CCECProcessor::SetActiveView(void)
316 return SetActiveSource(m_types
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_types
[0]);
319 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
323 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
326 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
328 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
335 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
339 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
342 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
344 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
351 bool CCECProcessor::SetHDMIPort(uint8_t iPort
, bool bForce
/* = false */)
356 strLog
.Format("setting HDMI port to %d", iPort
);
357 AddLog(CEC_LOG_DEBUG
, strLog
);
360 if (!m_bStarted
&& !bForce
)
363 uint16_t iPhysicalAddress(0);
365 while(!bReturn
&& iPos
>= 0)
367 iPhysicalAddress
+= ((uint16_t)iPort
* (0x1 << iPos
*4));
368 strLog
.Format("checking physical address %4x", iPhysicalAddress
);
369 AddLog(CEC_LOG_DEBUG
, strLog
);
370 if (CheckPhysicalAddress(iPhysicalAddress
))
372 strLog
.Format("physical address %4x is in use", iPhysicalAddress
);
373 AddLog(CEC_LOG_DEBUG
, strLog
);
378 SetPhysicalAddress(iPhysicalAddress
);
386 void CCECProcessor::ScanCECBus(void)
388 CCECBusDevice
*device(NULL
);
389 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
391 device
= m_busDevices
[iPtr
];
392 if (device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
394 device
->GetPhysicalAddress();
395 device
->GetCecVersion();
396 device
->GetVendorId();
401 bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress
)
403 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
405 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
411 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath
)
415 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
418 device
->SetActiveDevice();
425 bool CCECProcessor::SetInactiveView(void)
430 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
431 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveView();
435 void CCECProcessor::LogOutput(const cec_command
&data
)
438 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
440 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
442 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
443 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
444 m_controller
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
447 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
449 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
452 strLog
.Format("<< setting primary logical address to %1x", iLogicalAddress
);
453 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
454 m_logicalAddresses
.primary
= iLogicalAddress
;
455 m_logicalAddresses
.Set(iLogicalAddress
);
456 return SetAckMask(m_logicalAddresses
.AckMask());
462 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
464 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
466 if (m_logicalAddresses
[iPtr
])
467 m_busDevices
[iPtr
]->SetMenuState(state
);
471 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
476 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
)
478 if (!m_logicalAddresses
.IsEmpty())
480 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
481 if (m_logicalAddresses
[iPtr
])
482 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
483 return SetActiveView();
488 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
491 strLog
.Format("== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
492 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
494 m_bMonitor
= bEnable
;
496 return SetAckMask(0);
498 return SetAckMask(m_logicalAddresses
.AckMask());
501 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
503 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
505 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
506 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
507 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
512 uint8_t CCECProcessor::VolumeUp(bool bWait
/* = true */)
515 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
516 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bWait
);
521 uint8_t CCECProcessor::VolumeDown(bool bWait
/* = true */)
524 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
525 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bWait
);
530 uint8_t CCECProcessor::MuteAudio(bool bWait
/* = true */)
533 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
534 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bWait
);
539 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
541 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
542 return m_busDevices
[m_logicalAddresses
.primary
];
544 CCECBusDevice
*device
= NULL
;
545 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
547 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
549 device
= m_busDevices
[iPtr
];
557 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
559 CCECBusDevice
*device
= NULL
;
561 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
563 if (m_busDevices
[iPtr
]->m_type
== type
)
565 device
= m_busDevices
[iPtr
];
573 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
575 return m_busDevices
[iAddress
]->GetCecVersion();
578 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
580 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
583 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
584 retVal
.device
= iAddress
;
589 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
591 if (m_busDevices
[iAddress
])
593 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
594 return (strcmp(language
->language
, "???") != 0);
599 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
601 if (m_busDevices
[iAddress
])
602 return m_busDevices
[iAddress
]->GetVendorId();
606 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
608 if (m_busDevices
[iAddress
])
609 return m_busDevices
[iAddress
]->GetPowerStatus();
610 return CEC_POWER_STATUS_UNKNOWN
;
613 bool CCECProcessor::Transmit(const cec_command
&data
)
618 CCECAdapterMessage
*output
= new CCECAdapterMessage(data
);
619 bReturn
= Transmit(output
);
625 bool CCECProcessor::Transmit(CCECAdapterMessage
*output
)
628 CLockObject
lock(&m_mutex
);
630 CLockObject
msgLock(&output
->mutex
);
631 if (!m_communication
|| !m_communication
->Write(output
))
635 output
->condition
.Wait(&output
->mutex
);
636 if (output
->state
!= ADAPTER_MESSAGE_STATE_SENT
)
638 m_controller
->AddLog(CEC_LOG_ERROR
, "command was not sent");
643 if (output
->transmit_timeout
> 0)
645 if ((bReturn
= WaitForTransmitSucceeded(output
->size(), output
->transmit_timeout
)) == false)
646 m_controller
->AddLog(CEC_LOG_DEBUG
, "did not receive ack");
655 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
657 m_controller
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
661 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
662 command
.parameters
.PushBack((uint8_t)opcode
);
663 command
.parameters
.PushBack((uint8_t)reason
);
668 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength
, uint32_t iTimeout
/* = 1000 */)
671 bool bTransmitSucceeded(false);
672 uint8_t iPacketsLeft(iLength
/ 4);
674 int64_t iNow
= GetTimeMs();
675 int64_t iTargetTime
= iNow
+ (uint64_t) iTimeout
;
677 while (!bTransmitSucceeded
&& !bError
&& (iTimeout
== 0 || iNow
< iTargetTime
))
679 CCECAdapterMessage msg
;
681 if (!m_communication
->Read(msg
, iTimeout
> 0 ? (int32_t)(iTargetTime
- iNow
) : 1000))
687 if ((bError
= msg
.is_error()) == false)
689 m_controller
->AddLog(bError
? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
691 switch(msg
.message())
693 case MSGCODE_COMMAND_ACCEPTED
:
694 if (iPacketsLeft
> 0)
697 case MSGCODE_TRANSMIT_SUCCEEDED
:
698 bTransmitSucceeded
= (iPacketsLeft
== 0);
699 bError
= !bTransmitSucceeded
;
702 if (ParseMessage(msg
))
703 m_commandBuffer
.Push(m_currentframe
);
710 return bTransmitSucceeded
&& !bError
;
713 bool CCECProcessor::ParseMessage(const CCECAdapterMessage
&msg
)
720 switch(msg
.message())
722 case MSGCODE_FRAME_START
:
724 m_currentframe
.Clear();
727 m_currentframe
.initiator
= msg
.initiator();
728 m_currentframe
.destination
= msg
.destination();
729 m_currentframe
.ack
= msg
.ack();
730 m_currentframe
.eom
= msg
.eom();
734 case MSGCODE_FRAME_DATA
:
738 m_currentframe
.PushBack(msg
[1]);
739 m_currentframe
.eom
= msg
.eom();
751 void CCECProcessor::ParseCommand(cec_command
&command
)
754 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
755 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
756 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
757 m_controller
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
759 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
760 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
763 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
765 cec_logical_addresses addresses
;
767 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
769 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
770 addresses
.Set((cec_logical_address
) iPtr
);
775 bool CCECProcessor::IsActiveDevice(cec_logical_address address
)
777 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
780 bool CCECProcessor::IsActiveDeviceType(cec_device_type type
)
782 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
784 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
791 uint16_t CCECProcessor::GetPhysicalAddress(void) const
793 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
794 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
798 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode
)
800 m_controller
->SetCurrentButton(iButtonCode
);
803 void CCECProcessor::AddCommand(const cec_command
&command
)
805 m_controller
->AddCommand(command
);
808 void CCECProcessor::AddKey(cec_keypress
&key
)
810 m_controller
->AddKey(key
);
813 void CCECProcessor::AddKey(void)
815 m_controller
->AddKey();
818 void CCECProcessor::AddLog(cec_log_level level
, const CStdString
&strMessage
)
820 m_controller
->AddLog(level
, strMessage
);
823 bool CCECProcessor::SetAckMask(uint16_t iMask
)
827 strLog
.Format("setting ackmask to %2x", iMask
);
828 m_controller
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
830 CCECAdapterMessage
*output
= new CCECAdapterMessage
;
832 output
->push_back(MSGSTART
);
833 output
->push_escaped(MSGCODE_SET_ACK_MASK
);
834 output
->push_escaped(iMask
>> 8);
835 output
->push_escaped((uint8_t)iMask
);
836 output
->push_back(MSGEND
);
838 if ((bReturn
= Transmit(output
)) == false)
839 m_controller
->AddLog(CEC_LOG_ERROR
, "could not set the ackmask");
846 bool CCECProcessor::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = false */)
848 return m_busDevices
[iDestination
]->SendKeypress(key
, bWait
);
851 bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = false */)
853 return m_busDevices
[iDestination
]->SendKeyRelease(bWait
);