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) CCECCommandHandler::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),
55 m_iLastCommandSent(0),
57 m_cecVersion(CEC_VERSION_UNKNOWN
),
58 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN
)
60 m_handler
= new CCECCommandHandler(this);
62 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
63 m_menuLanguage
.language
[iPtr
] = '?';
64 m_menuLanguage
.language
[3] = 0;
65 m_menuLanguage
.device
= iLogicalAddress
;
67 m_strDeviceName
= ToString(m_iLogicalAddress
);
70 CCECBusDevice::~CCECBusDevice(void)
72 m_condition
.Broadcast();
76 void CCECBusDevice::AddLog(cec_log_level level
, const CStdString
&strMessage
)
78 m_processor
->AddLog(level
, strMessage
);
81 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
83 CLockObject
lock(&m_transmitMutex
);
84 m_iLastActive
= GetTimeMs();
85 m_handler
->HandleCommand(command
);
86 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
87 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
92 void CCECBusDevice::PollVendorId(void)
94 CLockObject
lock(&m_transmitMutex
);
95 if (m_iLastActive
> 0 && m_iLogicalAddress
!= CECDEVICE_BROADCAST
&&
96 m_vendor
== CEC_VENDOR_UNKNOWN
&&
97 GetTimeMs() - m_iLastCommandSent
> 5000 &&
98 !m_processor
->IsMonitoring())
101 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
102 AddLog(CEC_LOG_NOTICE
, strLog
);
103 m_iLastCommandSent
= GetTimeMs();
106 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
107 if (m_processor
->Transmit(command
))
108 m_condition
.Wait(&m_transmitMutex
, 1000);
112 bool CCECBusDevice::PowerOn(void)
115 strLog
.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
116 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
119 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_IMAGE_VIEW_ON
);
120 if (m_processor
->Transmit(command
))
129 bool CCECBusDevice::Standby(void)
132 strLog
.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
133 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
136 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_STANDBY
);
138 return m_processor
->Transmit(command
);
143 cec_version
CCECBusDevice::GetCecVersion(void)
145 CLockObject
lock(&m_mutex
);
146 if (m_cecVersion
== CEC_VERSION_UNKNOWN
)
156 bool CCECBusDevice::RequestCecVersion(void)
159 if (!MyLogicalAddressContains(m_iLogicalAddress
))
162 strLog
.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
163 AddLog(CEC_LOG_NOTICE
, strLog
);
165 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GET_CEC_VERSION
);
166 CLockObject
lock(&m_transmitMutex
);
167 if (m_processor
->Transmit(command
))
168 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
173 const char* CCECBusDevice::GetLogicalAddressName(void) const
175 return ToString(m_iLogicalAddress
);
178 cec_menu_language
&CCECBusDevice::GetMenuLanguage(void)
180 CLockObject
lock(&m_mutex
);
181 if (!strcmp(m_menuLanguage
.language
, "???"))
184 RequestMenuLanguage();
187 return m_menuLanguage
;
190 bool CCECBusDevice::RequestMenuLanguage(void)
193 if (!MyLogicalAddressContains(m_iLogicalAddress
))
196 strLog
.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
197 AddLog(CEC_LOG_NOTICE
, strLog
);
199 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GET_MENU_LANGUAGE
);
200 CLockObject
lock(&m_transmitMutex
);
201 if (m_processor
->Transmit(command
))
202 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
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(void)
219 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
221 CLockObject
lock(&m_mutex
);
222 if (m_strDeviceName
.Equals(ToString(m_iLogicalAddress
)))
230 CLockObject
lock(&m_mutex
);
231 return m_strDeviceName
;
234 bool CCECBusDevice::RequestOSDName(void)
237 if (!MyLogicalAddressContains(m_iLogicalAddress
))
240 strLog
.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
241 AddLog(CEC_LOG_NOTICE
, strLog
);
243 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_OSD_NAME
);
244 CLockObject
lock(&m_transmitMutex
);
245 if (m_processor
->Transmit(command
))
246 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
251 uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh
/* = true */)
253 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
255 CLockObject
lock(&m_mutex
);
256 if (m_iPhysicalAddress
== 0xFFFF || bRefresh
)
259 if (!RequestPhysicalAddress())
260 AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
265 CLockObject
lock(&m_mutex
);
266 return m_iPhysicalAddress
;
269 bool CCECBusDevice::RequestPhysicalAddress(void)
272 if (!MyLogicalAddressContains(m_iLogicalAddress
))
275 strLog
.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
276 AddLog(CEC_LOG_NOTICE
, strLog
);
278 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
);
279 CLockObject
lock(&m_transmitMutex
);
280 if (m_processor
->Transmit(command
))
281 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
286 cec_power_status
CCECBusDevice::GetPowerStatus(void)
288 CLockObject
lock(&m_mutex
);
289 if (m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
)
292 RequestPowerStatus();
295 return m_powerStatus
;
298 bool CCECBusDevice::RequestPowerStatus(void)
301 if (!MyLogicalAddressContains(m_iLogicalAddress
))
304 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
305 AddLog(CEC_LOG_NOTICE
, strLog
);
307 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
);
308 CLockObject
lock(&m_transmitMutex
);
309 if (m_processor
->Transmit(command
))
310 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
315 cec_vendor_id
CCECBusDevice::GetVendorId(void)
317 CLockObject
lock(&m_mutex
);
318 if (m_vendor
== CEC_VENDOR_UNKNOWN
)
327 bool CCECBusDevice::RequestVendorId(void)
330 if (!MyLogicalAddressContains(m_iLogicalAddress
))
333 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
334 AddLog(CEC_LOG_NOTICE
, strLog
);
336 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
338 CLockObject
lock(&m_transmitMutex
);
339 if (m_processor
->Transmit(command
))
340 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
345 const char *CCECBusDevice::GetVendorName(void)
347 return ToString(GetVendorId());
350 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
352 return m_processor
->HasLogicalAddress(address
);
355 bool CCECBusDevice::NeedsPoll(void)
357 bool bSendPoll(false);
358 switch (m_iLogicalAddress
)
360 case CECDEVICE_PLAYBACKDEVICE3
:
361 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
364 case CECDEVICE_PLAYBACKDEVICE2
:
365 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
368 case CECDEVICE_RECORDINGDEVICE3
:
369 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
372 case CECDEVICE_RECORDINGDEVICE2
:
373 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
376 case CECDEVICE_TUNER4
:
377 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
380 case CECDEVICE_TUNER3
:
381 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
384 case CECDEVICE_TUNER2
:
385 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
388 case CECDEVICE_AUDIOSYSTEM
:
389 case CECDEVICE_PLAYBACKDEVICE1
:
390 case CECDEVICE_RECORDINGDEVICE1
:
391 case CECDEVICE_TUNER1
:
402 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
404 CLockObject
lock(&m_mutex
);
405 if (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
)
408 bool bPollAcked(false);
409 if (bForcePoll
|| NeedsPoll())
410 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
413 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
416 return m_deviceStatus
;
423 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
425 m_cecVersion
= newVersion
;
428 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
429 AddLog(CEC_LOG_DEBUG
, strLog
);
432 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
434 CLockObject
lock(&m_mutex
);
435 if (language
.device
== m_iLogicalAddress
)
438 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
439 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
440 m_menuLanguage
= language
;
444 void CCECBusDevice::SetOSDName(CStdString strName
)
446 CLockObject
lock(&m_mutex
);
447 if (m_strDeviceName
!= strName
)
450 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
451 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
452 m_strDeviceName
= strName
;
456 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
458 CLockObject
lock(&m_mutex
);
459 if (m_menuState
!= state
)
462 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
463 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
468 void CCECBusDevice::SetInactiveDevice(void)
470 CLockObject
lock(&m_mutex
);
471 m_bActiveSource
= false;
474 void CCECBusDevice::SetActiveDevice(void)
476 CLockObject
lock(&m_mutex
);
478 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
479 if (iPtr
!= m_iLogicalAddress
)
480 m_processor
->m_busDevices
[iPtr
]->SetInactiveDevice();
482 m_bActiveSource
= true;
483 m_powerStatus
= CEC_POWER_STATUS_ON
;
486 bool CCECBusDevice::TryLogicalAddress(void)
489 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
490 AddLog(CEC_LOG_DEBUG
, strLog
);
492 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
493 if (!TransmitPoll(m_iLogicalAddress
))
495 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
496 AddLog(CEC_LOG_NOTICE
, strLog
);
497 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
502 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
503 AddLog(CEC_LOG_DEBUG
, strLog
);
504 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
508 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
510 CLockObject
lock(&m_mutex
);
513 case CEC_DEVICE_STATUS_UNKNOWN
:
515 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
516 m_vendor
= CEC_VENDOR_UNKNOWN
;
517 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
518 m_bActiveSource
= false;
519 m_iLastCommandSent
= 0;
521 m_cecVersion
= CEC_VERSION_UNKNOWN
;
522 m_deviceStatus
= newStatus
;
524 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
526 m_powerStatus
= CEC_POWER_STATUS_ON
;
527 m_vendor
= CEC_VENDOR_UNKNOWN
;
528 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
529 m_bActiveSource
= false;
530 m_iLastCommandSent
= 0;
532 m_cecVersion
= CEC_VERSION_1_3A
;
533 m_deviceStatus
= newStatus
;
535 case CEC_DEVICE_STATUS_PRESENT
:
536 case CEC_DEVICE_STATUS_NOT_PRESENT
:
537 m_deviceStatus
= newStatus
;
542 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
544 CLockObject
lock(&m_mutex
);
545 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
548 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
549 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
551 m_iPhysicalAddress
= iNewAddress
;
555 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
557 CLockObject
lock(&m_mutex
);
561 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
562 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
564 m_iStreamPath
= iNewAddress
;
569 SetPowerStatus(CEC_POWER_STATUS_ON
);
574 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
576 CLockObject
lock(&m_mutex
);
577 if (m_powerStatus
!= powerStatus
)
580 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
581 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
582 m_powerStatus
= powerStatus
;
586 void CCECBusDevice::SetVendorId(uint64_t iVendorId
)
589 CLockObject
lock(&m_mutex
);
590 m_vendor
= (cec_vendor_id
)iVendorId
;
594 case CEC_VENDOR_SAMSUNG
:
595 if (m_handler
->GetVendorId() != CEC_VENDOR_SAMSUNG
)
598 m_handler
= new CANCommandHandler(this);
602 if (m_handler
->GetVendorId() != CEC_VENDOR_LG
)
605 m_handler
= new CSLCommandHandler(this);
608 case CEC_VENDOR_PANASONIC
:
609 if (m_handler
->GetVendorId() != CEC_VENDOR_PANASONIC
)
612 m_handler
= new CVLCommandHandler(this);
616 if (m_handler
->GetVendorId() != CEC_VENDOR_UNKNOWN
)
619 m_handler
= new CCECCommandHandler(this);
626 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, GetVendorName(), m_vendor
);
627 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
631 /** @name Transmit methods */
633 bool CCECBusDevice::TransmitActiveSource(void)
635 CLockObject
lock(&m_mutex
);
636 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
639 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
640 AddLog(CEC_LOG_DEBUG
, strLog
);
642 else if (m_bActiveSource
)
645 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
646 AddLog(CEC_LOG_NOTICE
, strLog
);
649 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_ACTIVE_SOURCE
);
650 command
.parameters
.PushBack((uint8_t) ((m_iPhysicalAddress
>> 8) & 0xFF));
651 command
.parameters
.PushBack((uint8_t) (m_iPhysicalAddress
& 0xFF));
654 return m_processor
->Transmit(command
);
659 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
660 AddLog(CEC_LOG_DEBUG
, strLog
);
666 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
668 CLockObject
lock(&m_mutex
);
670 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
671 AddLog(CEC_LOG_NOTICE
, strLog
);
674 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_CEC_VERSION
);
675 command
.parameters
.PushBack((uint8_t)m_cecVersion
);
678 return m_processor
->Transmit(command
);
681 bool CCECBusDevice::TransmitInactiveSource(void)
684 strLog
.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
685 AddLog(CEC_LOG_NOTICE
, strLog
);
688 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_TV
, CEC_OPCODE_INACTIVE_SOURCE
);
689 command
.parameters
.PushBack((m_iPhysicalAddress
>> 8) & 0xFF);
690 command
.parameters
.PushBack(m_iPhysicalAddress
& 0xFF);
692 return m_processor
->Transmit(command
);
695 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
698 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
699 AddLog(CEC_LOG_NOTICE
, strLog
);
702 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_MENU_STATUS
);
703 command
.parameters
.PushBack((uint8_t)m_menuState
);
705 return m_processor
->Transmit(command
);
708 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
710 CLockObject
lock(&m_mutex
);
712 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
713 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
716 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_SET_OSD_NAME
);
717 for (unsigned int iPtr
= 0; iPtr
< m_strDeviceName
.length(); iPtr
++)
718 command
.parameters
.PushBack(m_strDeviceName
.at(iPtr
));
721 return m_processor
->Transmit(command
);
724 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
726 CLockObject
lock(&m_mutex
);
728 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
729 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
732 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_SET_OSD_STRING
);
733 command
.parameters
.PushBack((uint8_t)duration
);
735 unsigned int iLen
= strlen(strMessage
);
736 if (iLen
> 13) iLen
= 13;
738 for (unsigned int iPtr
= 0; iPtr
< iLen
; iPtr
++)
739 command
.parameters
.PushBack(strMessage
[iPtr
]);
742 return m_processor
->Transmit(command
);
745 bool CCECBusDevice::TransmitPhysicalAddress(void)
747 CLockObject
lock(&m_mutex
);
749 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
750 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
753 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
);
754 command
.parameters
.PushBack((uint8_t) ((m_iPhysicalAddress
>> 8) & 0xFF));
755 command
.parameters
.PushBack((uint8_t) (m_iPhysicalAddress
& 0xFF));
756 command
.parameters
.PushBack((uint8_t) (m_type
));
759 return m_processor
->Transmit(command
);
762 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
765 if (dest
== CECDEVICE_UNKNOWN
)
766 dest
= m_iLogicalAddress
;
769 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
770 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
773 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_NONE
);
776 CLockObject
lock(&m_transmitMutex
);
777 bReturn
= m_processor
->Transmit(command
);
780 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
784 CLockObject
lock(&m_mutex
);
785 m_iLastActive
= GetTimeMs();
791 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
793 CLockObject
lock(&m_mutex
);
795 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
796 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
799 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_REPORT_POWER_STATUS
);
800 command
.parameters
.PushBack((uint8_t) m_powerStatus
);
803 return m_processor
->Transmit(command
);
806 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
)
808 CLockObject
lock(&m_mutex
);
809 if (m_vendor
== CEC_VENDOR_UNKNOWN
)
812 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
813 AddLog(CEC_LOG_NOTICE
, strLog
);
816 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
822 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_vendor
), (uint64_t)m_vendor
);
823 AddLog(CEC_LOG_NOTICE
, strLog
);
826 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_DEVICE_VENDOR_ID
);
828 command
.parameters
.PushBack((uint8_t) (((uint64_t)m_vendor
>> 16) & 0xFF));
829 command
.parameters
.PushBack((uint8_t) (((uint64_t)m_vendor
>> 8) & 0xFF));
830 command
.parameters
.PushBack((uint8_t) ((uint64_t)m_vendor
& 0xFF));
833 return m_processor
->Transmit(command
);
837 bool CCECBusDevice::SendKeypress(cec_user_control_code key
, bool bWait
/* = false */)
840 CLockObject
lock(&m_transmitMutex
);
842 cec_command::Format(command
, m_processor
->GetLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_USER_CONTROL_PRESSED
);
843 command
.parameters
.PushBack((uint8_t)key
);
847 if (m_processor
->Transmit(command
))
848 return m_condition
.Wait(&m_transmitMutex
, 1000);
852 return m_processor
->Transmit(command
);
856 bool CCECBusDevice::SendKeyRelease(bool bWait
/* = false */)
859 CLockObject
lock(&m_transmitMutex
);
861 cec_command::Format(command
, m_processor
->GetLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_USER_CONTROL_RELEASE
);
865 if (m_processor
->Transmit(command
))
866 return m_condition
.Wait(&m_transmitMutex
, 1000);
871 return m_processor
->Transmit(command
);