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 "CECBusDevice.h"
34 #include "../CECProcessor.h"
35 #include "../implementations/ANCommandHandler.h"
36 #include "../implementations/CECCommandHandler.h"
37 #include "../implementations/SLCommandHandler.h"
38 #include "../implementations/VLCommandHandler.h"
39 #include "../platform/timeutils.h"
43 #define ToString(p) m_processor->ToString(p)
45 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
) :
46 m_type(CEC_DEVICE_TYPE_RESERVED
),
47 m_iPhysicalAddress(iPhysicalAddress
),
49 m_iLogicalAddress(iLogicalAddress
),
50 m_powerStatus(CEC_POWER_STATUS_UNKNOWN
),
51 m_processor(processor
),
52 m_vendor(CEC_VENDOR_UNKNOWN
),
53 m_menuState(CEC_MENU_STATE_ACTIVATED
),
54 m_bActiveSource(false),
56 m_cecVersion(CEC_VERSION_UNKNOWN
),
57 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN
)
59 m_handler
= new CCECCommandHandler(this);
61 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
62 m_menuLanguage
.language
[iPtr
] = '?';
63 m_menuLanguage
.language
[3] = 0;
64 m_menuLanguage
.device
= iLogicalAddress
;
66 m_strDeviceName
= ToString(m_iLogicalAddress
);
69 CCECBusDevice::~CCECBusDevice(void)
74 void CCECBusDevice::AddLog(cec_log_level level
, const CStdString
&strMessage
)
76 m_processor
->AddLog(level
, strMessage
);
79 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
83 /* update "last active" */
85 CLockObject
lock(&m_writeMutex
);
86 m_iLastActive
= GetTimeMs();
88 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
89 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
92 /* handle the command */
93 bHandled
= m_handler
->HandleCommand(command
);
95 /* change status to present */
98 CLockObject
lock(&m_writeMutex
);
99 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
101 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
104 strLog
.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
105 AddLog(CEC_LOG_DEBUG
, strLog
);
107 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
114 bool CCECBusDevice::PowerOn(void)
117 strLog
.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
118 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
120 if (m_handler
->TransmitPowerOn(GetMyLogicalAddress(), m_iLogicalAddress
))
123 CLockObject
lock(&m_mutex
);
124 // m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
125 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
127 // cec_power_status status = GetPowerStatus();
128 // if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
130 // /* sending the normal power on command appears to have failed */
131 // CStdString strLog;
132 // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
133 // AddLog(CEC_LOG_DEBUG, strLog.c_str());
135 // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
136 // return TransmitKeyRelease();
144 bool CCECBusDevice::Standby(void)
147 strLog
.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
148 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
150 return m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
155 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
157 CLockObject
lock(&m_mutex
);
158 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
159 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
))
165 bool CCECBusDevice::RequestCecVersion(void)
168 if (!MyLogicalAddressContains(m_iLogicalAddress
))
171 strLog
.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
172 AddLog(CEC_LOG_NOTICE
, strLog
);
174 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
179 const char* CCECBusDevice::GetLogicalAddressName(void) const
181 return ToString(m_iLogicalAddress
);
184 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
186 CLockObject
lock(&m_mutex
);
187 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
188 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")))
189 RequestMenuLanguage();
191 return m_menuLanguage
;
194 bool CCECBusDevice::RequestMenuLanguage(void)
197 if (!MyLogicalAddressContains(m_iLogicalAddress
))
200 strLog
.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
201 AddLog(CEC_LOG_NOTICE
, strLog
);
202 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
207 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
209 return m_processor
->GetLogicalAddress();
212 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
214 return m_processor
->GetPhysicalAddress();
217 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
219 CLockObject
lock(&m_mutex
);
220 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
221 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
222 m_type
!= CEC_DEVICE_TYPE_TV
)
225 return m_strDeviceName
;
228 bool CCECBusDevice::RequestOSDName(void)
231 if (!MyLogicalAddressContains(m_iLogicalAddress
))
234 strLog
.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
235 AddLog(CEC_LOG_NOTICE
, strLog
);
236 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
241 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
243 CLockObject
lock(&m_mutex
);
244 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
245 (m_iPhysicalAddress
== 0xFFFF || bUpdate
))
247 if (!RequestPhysicalAddress())
248 AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
251 return m_iPhysicalAddress
;
254 bool CCECBusDevice::RequestPhysicalAddress(void)
257 if (!MyLogicalAddressContains(m_iLogicalAddress
))
260 strLog
.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
261 AddLog(CEC_LOG_NOTICE
, strLog
);
262 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
267 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
269 CLockObject
lock(&m_mutex
);
270 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
271 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
))
272 RequestPowerStatus();
274 return m_powerStatus
;
277 bool CCECBusDevice::RequestPowerStatus(void)
280 if (!MyLogicalAddressContains(m_iLogicalAddress
))
283 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
284 AddLog(CEC_LOG_NOTICE
, strLog
);
285 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
290 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
292 CLockObject
lock(&m_mutex
);
293 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
294 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
))
300 bool CCECBusDevice::RequestVendorId(void)
303 if (!MyLogicalAddressContains(m_iLogicalAddress
))
306 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
307 AddLog(CEC_LOG_NOTICE
, strLog
);
308 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
313 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
315 return ToString(GetVendorId(bUpdate
));
318 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
320 return m_processor
->HasLogicalAddress(address
);
323 bool CCECBusDevice::NeedsPoll(void)
325 bool bSendPoll(false);
326 switch (m_iLogicalAddress
)
328 case CECDEVICE_PLAYBACKDEVICE3
:
329 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
332 case CECDEVICE_PLAYBACKDEVICE2
:
333 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
336 case CECDEVICE_RECORDINGDEVICE3
:
337 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
340 case CECDEVICE_RECORDINGDEVICE2
:
341 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
344 case CECDEVICE_TUNER4
:
345 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
348 case CECDEVICE_TUNER3
:
349 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
352 case CECDEVICE_TUNER2
:
353 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
356 case CECDEVICE_AUDIOSYSTEM
:
357 case CECDEVICE_PLAYBACKDEVICE1
:
358 case CECDEVICE_RECORDINGDEVICE1
:
359 case CECDEVICE_TUNER1
:
370 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
372 CLockObject
lock(&m_writeMutex
);
373 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
374 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
377 bool bPollAcked(false);
378 if (bForcePoll
|| NeedsPoll())
379 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
382 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
385 return m_deviceStatus
;
392 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
394 m_cecVersion
= newVersion
;
397 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
398 AddLog(CEC_LOG_DEBUG
, strLog
);
401 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
403 CLockObject
lock(&m_writeMutex
);
404 if (language
.device
== m_iLogicalAddress
)
407 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
408 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
409 m_menuLanguage
= language
;
413 void CCECBusDevice::SetOSDName(CStdString strName
)
415 CLockObject
lock(&m_writeMutex
);
416 if (m_strDeviceName
!= strName
)
419 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
420 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
421 m_strDeviceName
= strName
;
425 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
427 CLockObject
lock(&m_writeMutex
);
428 if (m_menuState
!= state
)
431 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
432 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
437 void CCECBusDevice::SetInactiveDevice(void)
439 CLockObject
lock(&m_writeMutex
);
440 m_bActiveSource
= false;
443 void CCECBusDevice::SetActiveDevice(void)
445 CLockObject
lock(&m_writeMutex
);
447 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
448 if (iPtr
!= m_iLogicalAddress
)
449 m_processor
->m_busDevices
[iPtr
]->SetInactiveDevice();
451 m_bActiveSource
= true;
452 m_powerStatus
= CEC_POWER_STATUS_ON
;
455 bool CCECBusDevice::TryLogicalAddress(void)
458 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
459 AddLog(CEC_LOG_DEBUG
, strLog
);
461 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
462 if (!TransmitPoll(m_iLogicalAddress
))
464 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
465 AddLog(CEC_LOG_NOTICE
, strLog
);
466 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
471 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
472 AddLog(CEC_LOG_DEBUG
, strLog
);
473 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
477 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
479 CLockObject
lock(&m_writeMutex
);
482 case CEC_DEVICE_STATUS_UNKNOWN
:
484 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
485 m_vendor
= CEC_VENDOR_UNKNOWN
;
486 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
487 m_bActiveSource
= false;
489 m_cecVersion
= CEC_VERSION_UNKNOWN
;
490 m_deviceStatus
= newStatus
;
492 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
494 m_powerStatus
= CEC_POWER_STATUS_ON
;
495 m_vendor
= CEC_VENDOR_UNKNOWN
;
496 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
497 m_bActiveSource
= false;
499 m_cecVersion
= CEC_VERSION_1_3A
;
500 m_deviceStatus
= newStatus
;
502 case CEC_DEVICE_STATUS_PRESENT
:
503 case CEC_DEVICE_STATUS_NOT_PRESENT
:
504 m_deviceStatus
= newStatus
;
509 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
511 CLockObject
lock(&m_writeMutex
);
512 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
515 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
516 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
518 m_iPhysicalAddress
= iNewAddress
;
522 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
524 CLockObject
lock(&m_writeMutex
);
528 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
529 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
531 m_iStreamPath
= iNewAddress
;
536 SetPowerStatus(CEC_POWER_STATUS_ON
);
541 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
543 CLockObject
lock(&m_writeMutex
);
544 if (m_powerStatus
!= powerStatus
)
547 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
548 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
549 m_powerStatus
= powerStatus
;
553 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
, bool bInitHandler
/* = true */)
555 bool bVendorChanged(false);
558 CLockObject
lock(&m_writeMutex
);
559 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
560 m_vendor
= (cec_vendor_id
)iVendorId
;
567 case CEC_VENDOR_SAMSUNG
:
569 m_handler
= new CANCommandHandler(this);
573 m_handler
= new CSLCommandHandler(this);
575 case CEC_VENDOR_PANASONIC
:
577 m_handler
= new CVLCommandHandler(this);
581 m_handler
= new CCECCommandHandler(this);
586 if (bVendorChanged
&& bInitHandler
)
587 m_handler
->InitHandler();
590 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
591 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
593 return bVendorChanged
;
597 /** @name Transmit methods */
599 bool CCECBusDevice::TransmitActiveSource(void)
601 bool bSendActiveSource(false);
604 CLockObject
lock(&m_writeMutex
);
605 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
608 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
609 AddLog(CEC_LOG_DEBUG
, strLog
);
611 else if (m_bActiveSource
)
614 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
615 AddLog(CEC_LOG_NOTICE
, strLog
);
616 bSendActiveSource
= true;
621 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
622 AddLog(CEC_LOG_DEBUG
, strLog
);
626 return bSendActiveSource
? m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
) : false;
629 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
633 CLockObject
lock(&m_writeMutex
);
635 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
636 AddLog(CEC_LOG_NOTICE
, strLog
);
637 version
= m_cecVersion
;
640 return m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
643 bool CCECBusDevice::TransmitInactiveSource(void)
645 uint16_t iPhysicalAddress
;
647 CLockObject
lock(&m_writeMutex
);
649 strLog
.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
650 AddLog(CEC_LOG_NOTICE
, strLog
);
651 iPhysicalAddress
= m_iPhysicalAddress
;
654 return m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
657 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
659 cec_menu_state menuState
;
661 CLockObject
lock(&m_writeMutex
);
663 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
664 AddLog(CEC_LOG_NOTICE
, strLog
);
665 menuState
= m_menuState
;
668 return m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
671 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
673 CStdString strDeviceName
;
675 CLockObject
lock(&m_writeMutex
);
677 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
678 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
679 strDeviceName
= m_strDeviceName
;
682 return m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
685 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
688 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
689 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
691 return m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
694 bool CCECBusDevice::TransmitPhysicalAddress(void)
696 uint16_t iPhysicalAddress
;
697 cec_device_type type
;
699 CLockObject
lock(&m_writeMutex
);
700 if (m_iPhysicalAddress
== 0xffff)
704 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
705 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
707 iPhysicalAddress
= m_iPhysicalAddress
;
711 return m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
714 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
717 if (dest
== CECDEVICE_UNKNOWN
)
718 dest
= m_iLogicalAddress
;
720 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
721 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
725 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
726 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
727 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
728 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
730 CLockObject
lock(&m_writeMutex
);
733 m_iLastActive
= GetTimeMs();
734 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
737 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
742 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
744 cec_power_status state
;
746 CLockObject
lock(&m_writeMutex
);
748 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
749 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
750 state
= m_powerStatus
;
753 return m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
756 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
760 CLockObject
lock(&m_writeMutex
);
761 iVendorId
= (uint64_t)m_vendor
;
764 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
769 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
770 AddLog(CEC_LOG_NOTICE
, strLog
);
772 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
779 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString((cec_vendor_id
)iVendorId
), iVendorId
);
780 AddLog(CEC_LOG_NOTICE
, strLog
);
782 return m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
786 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
)
788 return m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
);
791 bool CCECBusDevice::TransmitKeyRelease(void)
793 return m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
);