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");
137 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
142 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
144 if (m_busDevices
[address
]->TryLogicalAddress())
146 /* only set our OSD name and active source for the primary device */
147 if (m_logicalAddresses
.IsEmpty())
149 m_busDevices
[address
]->m_strDeviceName
= m_strDeviceName
;
150 m_busDevices
[address
]->m_bActiveSource
= true;
152 m_logicalAddresses
.Set(address
);
159 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
161 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
162 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
163 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
164 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
167 bool CCECProcessor::FindLogicalAddressTuner(void)
169 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
170 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
171 TryLogicalAddress(CECDEVICE_TUNER2
) ||
172 TryLogicalAddress(CECDEVICE_TUNER3
) ||
173 TryLogicalAddress(CECDEVICE_TUNER4
);
176 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
178 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
179 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
180 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
181 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
184 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
186 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
187 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
190 bool CCECProcessor::FindLogicalAddresses(void)
193 m_logicalAddresses
.Clear();
196 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
198 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
201 strLog
.Format("%s - device %d: type %d", __FUNCTION__
, iPtr
, m_types
.types
[iPtr
]);
202 AddLog(CEC_LOG_DEBUG
, strLog
);
204 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
205 bReturn
&= FindLogicalAddressRecordingDevice();
206 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
207 bReturn
&= FindLogicalAddressTuner();
208 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
209 bReturn
&= FindLogicalAddressPlaybackDevice();
210 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
211 bReturn
&= FindLogicalAddressAudioSystem();
217 void *CCECProcessor::Process(void)
219 bool bParseFrame(false);
221 CCECAdapterMessage msg
;
224 if (m_logicalAddresses
.IsEmpty() && !FindLogicalAddresses())
226 CLockObject
lock(&m_mutex
);
227 m_controller
->AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
228 m_startCondition
.Signal();
232 SetAckMask(m_logicalAddresses
.AckMask());
237 CLockObject
lock(&m_mutex
);
241 SetHDMIPort(m_iHDMIPort
);
244 m_controller
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
245 m_startCondition
.Signal();
255 CLockObject
lock(&m_mutex
);
256 if (m_commandBuffer
.Pop(command
))
260 else if (m_communication
->IsOpen() && m_communication
->Read(msg
, 50))
262 m_controller
->AddLog(msg
.is_error() ? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
263 if ((bParseFrame
= (ParseMessage(msg
) && !IsStopped())) == true)
264 command
= m_currentframe
;
269 ParseCommand(command
);
274 m_controller
->CheckKeypressTimeout();
276 for (unsigned int iDevicePtr
= 0; iDevicePtr
< 16; iDevicePtr
++)
278 if (!m_logicalAddresses
[iDevicePtr
])
279 m_busDevices
[iDevicePtr
]->PollVendorId();
288 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
295 cec_logical_address addr
= m_logicalAddresses
.primary
;
297 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
299 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
301 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
303 addr
= (cec_logical_address
) iPtr
;
309 return SetStreamPath(m_busDevices
[addr
]->GetPhysicalAddress(false)) &&
310 m_busDevices
[addr
]->TransmitActiveSource();
313 bool CCECProcessor::SetActiveSource(cec_logical_address iAddress
)
315 return SetStreamPath(m_busDevices
[iAddress
]->GetPhysicalAddress(false));
318 bool CCECProcessor::SetActiveView(void)
320 return SetActiveSource(m_types
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_types
[0]);
323 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
327 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
330 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
332 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
339 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
343 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
346 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
348 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
355 bool CCECProcessor::SetHDMIPort(uint8_t iPort
)
360 strLog
.Format("setting HDMI port to %d", iPort
);
361 AddLog(CEC_LOG_DEBUG
, strLog
);
367 uint16_t iPhysicalAddress(0);
369 while(!bReturn
&& iPos
>= 0)
371 iPhysicalAddress
+= ((uint16_t)iPort
* (0x1 << iPos
*4));
372 strLog
.Format("checking physical address %4x", iPhysicalAddress
);
373 AddLog(CEC_LOG_DEBUG
, strLog
);
374 if (CheckPhysicalAddress(iPhysicalAddress
))
376 strLog
.Format("physical address %4x is in use", iPhysicalAddress
);
377 AddLog(CEC_LOG_DEBUG
, strLog
);
382 SetPhysicalAddress(iPhysicalAddress
);
390 void CCECProcessor::ScanCECBus(void)
392 CCECBusDevice
*device(NULL
);
393 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
395 device
= m_busDevices
[iPtr
];
396 if (device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
398 device
->GetPhysicalAddress();
399 device
->GetCecVersion();
400 device
->GetVendorId();
405 bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress
)
407 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
409 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
415 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath
)
419 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
422 device
->SetActiveDevice();
429 bool CCECProcessor::SetInactiveView(void)
434 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
435 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveView();
439 void CCECProcessor::LogOutput(const cec_command
&data
)
442 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
444 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
446 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
447 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
448 m_controller
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
451 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
453 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
456 strLog
.Format("<< setting primary logical address to %1x", iLogicalAddress
);
457 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
458 m_logicalAddresses
.primary
= iLogicalAddress
;
459 m_logicalAddresses
.Set(iLogicalAddress
);
460 return SetAckMask(m_logicalAddresses
.AckMask());
466 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
468 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
470 if (m_logicalAddresses
[iPtr
])
471 m_busDevices
[iPtr
]->SetMenuState(state
);
475 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
480 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
)
482 if (!m_logicalAddresses
.IsEmpty())
484 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
485 if (m_logicalAddresses
[iPtr
])
486 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
487 return SetActiveView();
492 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
495 strLog
.Format("== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
496 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
498 m_bMonitor
= bEnable
;
500 return SetAckMask(0);
502 return SetAckMask(m_logicalAddresses
.AckMask());
505 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
507 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
509 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
510 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
511 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
516 uint8_t CCECProcessor::VolumeUp(bool bWait
/* = true */)
519 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
520 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bWait
);
525 uint8_t CCECProcessor::VolumeDown(bool bWait
/* = true */)
528 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
529 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bWait
);
534 uint8_t CCECProcessor::MuteAudio(bool bWait
/* = true */)
537 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
538 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bWait
);
543 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
545 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
546 return m_busDevices
[m_logicalAddresses
.primary
];
548 CCECBusDevice
*device
= NULL
;
549 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
551 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
553 device
= m_busDevices
[iPtr
];
561 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
563 CCECBusDevice
*device
= NULL
;
565 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
567 if (m_busDevices
[iPtr
]->m_type
== type
)
569 device
= m_busDevices
[iPtr
];
577 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
579 return m_busDevices
[iAddress
]->GetCecVersion();
582 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
584 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
587 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
588 retVal
.device
= iAddress
;
593 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
595 if (m_busDevices
[iAddress
])
597 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
598 return (strcmp(language
->language
, "???") != 0);
603 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
605 if (m_busDevices
[iAddress
])
606 return m_busDevices
[iAddress
]->GetVendorId();
610 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
612 if (m_busDevices
[iAddress
])
613 return m_busDevices
[iAddress
]->GetPowerStatus();
614 return CEC_POWER_STATUS_UNKNOWN
;
617 bool CCECProcessor::Transmit(const cec_command
&data
)
622 CCECAdapterMessage
*output
= new CCECAdapterMessage(data
);
623 bReturn
= Transmit(output
);
629 bool CCECProcessor::Transmit(CCECAdapterMessage
*output
)
632 CLockObject
lock(&m_mutex
);
634 CLockObject
msgLock(&output
->mutex
);
635 if (!m_communication
|| !m_communication
->Write(output
))
639 output
->condition
.Wait(&output
->mutex
);
640 if (output
->state
!= ADAPTER_MESSAGE_STATE_SENT
)
642 m_controller
->AddLog(CEC_LOG_ERROR
, "command was not sent");
647 if (output
->transmit_timeout
> 0)
649 if ((bReturn
= WaitForTransmitSucceeded(output
->size(), output
->transmit_timeout
)) == false)
650 m_controller
->AddLog(CEC_LOG_DEBUG
, "did not receive ack");
659 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
661 m_controller
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
665 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
666 command
.parameters
.PushBack((uint8_t)opcode
);
667 command
.parameters
.PushBack((uint8_t)reason
);
672 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength
, uint32_t iTimeout
/* = 1000 */)
675 bool bTransmitSucceeded(false);
676 uint8_t iPacketsLeft(iLength
/ 4);
678 int64_t iNow
= GetTimeMs();
679 int64_t iTargetTime
= iNow
+ (uint64_t) iTimeout
;
681 while (!bTransmitSucceeded
&& !bError
&& (iTimeout
== 0 || iNow
< iTargetTime
))
683 CCECAdapterMessage msg
;
685 if (!m_communication
->Read(msg
, iTimeout
> 0 ? (int32_t)(iTargetTime
- iNow
) : 1000))
691 if ((bError
= msg
.is_error()) == false)
693 m_controller
->AddLog(bError
? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
695 switch(msg
.message())
697 case MSGCODE_COMMAND_ACCEPTED
:
698 if (iPacketsLeft
> 0)
701 case MSGCODE_TRANSMIT_SUCCEEDED
:
702 bTransmitSucceeded
= (iPacketsLeft
== 0);
703 bError
= !bTransmitSucceeded
;
706 if (ParseMessage(msg
))
707 m_commandBuffer
.Push(m_currentframe
);
714 return bTransmitSucceeded
&& !bError
;
717 bool CCECProcessor::ParseMessage(const CCECAdapterMessage
&msg
)
724 switch(msg
.message())
726 case MSGCODE_FRAME_START
:
728 m_currentframe
.Clear();
731 m_currentframe
.initiator
= msg
.initiator();
732 m_currentframe
.destination
= msg
.destination();
733 m_currentframe
.ack
= msg
.ack();
734 m_currentframe
.eom
= msg
.eom();
738 case MSGCODE_FRAME_DATA
:
742 m_currentframe
.PushBack(msg
[1]);
743 m_currentframe
.eom
= msg
.eom();
755 void CCECProcessor::ParseCommand(cec_command
&command
)
758 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
759 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
760 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
761 m_controller
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
763 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
764 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
767 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
769 cec_logical_addresses addresses
;
770 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
772 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
773 addresses
.Set((cec_logical_address
) iPtr
);
778 bool CCECProcessor::IsActiveDevice(cec_logical_address address
)
780 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
783 bool CCECProcessor::IsActiveDeviceType(cec_device_type type
)
785 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
787 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
794 uint16_t CCECProcessor::GetPhysicalAddress(void) const
796 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
797 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
801 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode
)
803 m_controller
->SetCurrentButton(iButtonCode
);
806 void CCECProcessor::AddCommand(const cec_command
&command
)
808 m_controller
->AddCommand(command
);
811 void CCECProcessor::AddKey(cec_keypress
&key
)
813 m_controller
->AddKey(key
);
816 void CCECProcessor::AddKey(void)
818 m_controller
->AddKey();
821 void CCECProcessor::AddLog(cec_log_level level
, const CStdString
&strMessage
)
823 m_controller
->AddLog(level
, strMessage
);
826 bool CCECProcessor::SetAckMask(uint16_t iMask
)
830 strLog
.Format("setting ackmask to %2x", iMask
);
831 m_controller
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
833 CCECAdapterMessage
*output
= new CCECAdapterMessage
;
835 output
->push_back(MSGSTART
);
836 output
->push_escaped(MSGCODE_SET_ACK_MASK
);
837 output
->push_escaped(iMask
>> 8);
838 output
->push_escaped((uint8_t)iMask
);
839 output
->push_back(MSGEND
);
841 if ((bReturn
= Transmit(output
)) == false)
842 m_controller
->AddLog(CEC_LOG_ERROR
, "could not set the ackmask");
849 bool CCECProcessor::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = false */)
851 return m_busDevices
[iDestination
]->SendKeypress(key
, bWait
);
854 bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = false */)
856 return m_busDevices
[iDestination
]->SendKeyRelease(bWait
);