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 RequestPhysicalAddress();
264 CLockObject
lock(&m_mutex
);
265 return m_iPhysicalAddress
;
268 bool CCECBusDevice::RequestPhysicalAddress(void)
271 if (!MyLogicalAddressContains(m_iLogicalAddress
))
274 strLog
.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
275 AddLog(CEC_LOG_NOTICE
, strLog
);
277 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
);
278 CLockObject
lock(&m_transmitMutex
);
279 if (m_processor
->Transmit(command
))
280 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
285 cec_power_status
CCECBusDevice::GetPowerStatus(void)
287 CLockObject
lock(&m_mutex
);
288 if (m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
)
291 RequestPowerStatus();
294 return m_powerStatus
;
297 bool CCECBusDevice::RequestPowerStatus(void)
300 if (!MyLogicalAddressContains(m_iLogicalAddress
))
303 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
304 AddLog(CEC_LOG_NOTICE
, strLog
);
306 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
);
307 CLockObject
lock(&m_transmitMutex
);
308 if (m_processor
->Transmit(command
))
309 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
314 cec_vendor_id
CCECBusDevice::GetVendorId(void)
316 CLockObject
lock(&m_mutex
);
317 if (m_vendor
== CEC_VENDOR_UNKNOWN
)
326 bool CCECBusDevice::RequestVendorId(void)
329 if (!MyLogicalAddressContains(m_iLogicalAddress
))
332 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
333 AddLog(CEC_LOG_NOTICE
, strLog
);
335 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
337 CLockObject
lock(&m_transmitMutex
);
338 if (m_processor
->Transmit(command
))
339 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
344 const char *CCECBusDevice::GetVendorName(void)
346 return ToString(GetVendorId());
349 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
351 return m_processor
->HasLogicalAddress(address
);
354 cec_bus_device_status
CCECBusDevice::GetStatus(void)
356 CLockObject
lock(&m_mutex
);
357 if (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
)
360 bool bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
363 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
366 return m_deviceStatus
;
373 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
375 m_cecVersion
= newVersion
;
378 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
379 AddLog(CEC_LOG_DEBUG
, strLog
);
382 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
384 CLockObject
lock(&m_mutex
);
385 if (language
.device
== m_iLogicalAddress
)
388 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
389 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
390 m_menuLanguage
= language
;
394 void CCECBusDevice::SetOSDName(CStdString strName
)
396 CLockObject
lock(&m_mutex
);
397 if (m_strDeviceName
!= strName
)
400 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
401 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
402 m_strDeviceName
= strName
;
406 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
408 CLockObject
lock(&m_mutex
);
409 if (m_menuState
!= state
)
412 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
413 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
418 void CCECBusDevice::SetInactiveDevice(void)
420 CLockObject
lock(&m_mutex
);
421 m_bActiveSource
= false;
424 void CCECBusDevice::SetActiveDevice(void)
426 CLockObject
lock(&m_mutex
);
428 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
429 if (iPtr
!= m_iLogicalAddress
)
430 m_processor
->m_busDevices
[iPtr
]->SetInactiveDevice();
432 m_bActiveSource
= true;
433 m_powerStatus
= CEC_POWER_STATUS_ON
;
436 bool CCECBusDevice::TryLogicalAddress(void)
439 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
440 AddLog(CEC_LOG_DEBUG
, strLog
);
442 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
443 if (!TransmitPoll(m_iLogicalAddress
))
445 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
446 AddLog(CEC_LOG_NOTICE
, strLog
);
447 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
452 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
453 AddLog(CEC_LOG_DEBUG
, strLog
);
454 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
458 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
460 CLockObject
lock(&m_mutex
);
463 case CEC_DEVICE_STATUS_UNKNOWN
:
465 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
466 m_vendor
= CEC_VENDOR_UNKNOWN
;
467 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
468 m_bActiveSource
= false;
469 m_iLastCommandSent
= 0;
471 m_cecVersion
= CEC_VERSION_UNKNOWN
;
472 m_deviceStatus
= newStatus
;
474 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
476 m_powerStatus
= CEC_POWER_STATUS_ON
;
477 m_vendor
= CEC_VENDOR_UNKNOWN
;
478 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
479 m_bActiveSource
= false;
480 m_iLastCommandSent
= 0;
482 m_cecVersion
= CEC_VERSION_1_3A
;
483 m_deviceStatus
= newStatus
;
485 case CEC_DEVICE_STATUS_PRESENT
:
486 case CEC_DEVICE_STATUS_NOT_PRESENT
:
487 m_deviceStatus
= newStatus
;
492 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
494 CLockObject
lock(&m_mutex
);
495 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
498 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
499 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
501 m_iPhysicalAddress
= iNewAddress
;
505 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
507 CLockObject
lock(&m_mutex
);
511 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
512 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
514 m_iStreamPath
= iNewAddress
;
519 SetPowerStatus(CEC_POWER_STATUS_ON
);
524 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
526 CLockObject
lock(&m_mutex
);
527 if (m_powerStatus
!= powerStatus
)
530 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
531 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
532 m_powerStatus
= powerStatus
;
536 void CCECBusDevice::SetVendorId(uint64_t iVendorId
)
539 CLockObject
lock(&m_mutex
);
540 m_vendor
= (cec_vendor_id
)iVendorId
;
544 case CEC_VENDOR_SAMSUNG
:
545 if (m_handler
->GetVendorId() != CEC_VENDOR_SAMSUNG
)
548 m_handler
= new CANCommandHandler(this);
552 if (m_handler
->GetVendorId() != CEC_VENDOR_LG
)
555 m_handler
= new CSLCommandHandler(this);
558 case CEC_VENDOR_PANASONIC
:
559 if (m_handler
->GetVendorId() != CEC_VENDOR_PANASONIC
)
562 m_handler
= new CVLCommandHandler(this);
566 if (m_handler
->GetVendorId() != CEC_VENDOR_UNKNOWN
)
569 m_handler
= new CCECCommandHandler(this);
576 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, GetVendorName(), m_vendor
);
577 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
581 /** @name Transmit methods */
583 bool CCECBusDevice::TransmitActiveSource(void)
585 CLockObject
lock(&m_mutex
);
586 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
589 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
590 AddLog(CEC_LOG_DEBUG
, strLog
);
592 else if (m_bActiveSource
)
595 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
596 AddLog(CEC_LOG_NOTICE
, strLog
);
599 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_ACTIVE_SOURCE
);
600 command
.parameters
.PushBack((uint8_t) ((m_iPhysicalAddress
>> 8) & 0xFF));
601 command
.parameters
.PushBack((uint8_t) (m_iPhysicalAddress
& 0xFF));
604 return m_processor
->Transmit(command
);
609 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
610 AddLog(CEC_LOG_DEBUG
, strLog
);
616 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
618 CLockObject
lock(&m_mutex
);
620 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
621 AddLog(CEC_LOG_NOTICE
, strLog
);
624 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_CEC_VERSION
);
625 command
.parameters
.PushBack((uint8_t)m_cecVersion
);
628 return m_processor
->Transmit(command
);
631 bool CCECBusDevice::TransmitInactiveView(void)
634 strLog
.Format("<< %s (%X) -> broadcast (F): inactive view", GetLogicalAddressName(), m_iLogicalAddress
);
635 AddLog(CEC_LOG_NOTICE
, strLog
);
638 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_INACTIVE_SOURCE
);
639 command
.parameters
.PushBack((m_iPhysicalAddress
>> 8) & 0xFF);
640 command
.parameters
.PushBack(m_iPhysicalAddress
& 0xFF);
642 return m_processor
->Transmit(command
);
645 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
648 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
649 AddLog(CEC_LOG_NOTICE
, strLog
);
652 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_MENU_STATUS
);
653 command
.parameters
.PushBack((uint8_t)m_menuState
);
655 return m_processor
->Transmit(command
);
658 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
660 CLockObject
lock(&m_mutex
);
662 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
663 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
666 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_SET_OSD_NAME
);
667 for (unsigned int iPtr
= 0; iPtr
< m_strDeviceName
.length(); iPtr
++)
668 command
.parameters
.PushBack(m_strDeviceName
.at(iPtr
));
671 return m_processor
->Transmit(command
);
674 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
676 CLockObject
lock(&m_mutex
);
678 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
679 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
682 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_SET_OSD_STRING
);
683 command
.parameters
.PushBack((uint8_t)duration
);
685 unsigned int iLen
= strlen(strMessage
);
686 if (iLen
> 13) iLen
= 13;
688 for (unsigned int iPtr
= 0; iPtr
< iLen
; iPtr
++)
689 command
.parameters
.PushBack(strMessage
[iPtr
]);
692 return m_processor
->Transmit(command
);
695 bool CCECBusDevice::TransmitPhysicalAddress(void)
697 CLockObject
lock(&m_mutex
);
699 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
700 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
703 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
);
704 command
.parameters
.PushBack((uint8_t) ((m_iPhysicalAddress
>> 8) & 0xFF));
705 command
.parameters
.PushBack((uint8_t) (m_iPhysicalAddress
& 0xFF));
706 command
.parameters
.PushBack((uint8_t) (m_type
));
709 return m_processor
->Transmit(command
);
712 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
715 if (dest
== CECDEVICE_UNKNOWN
)
716 dest
= m_iLogicalAddress
;
719 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
720 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
723 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_NONE
);
726 CLockObject
lock(&m_transmitMutex
);
727 bReturn
= m_processor
->Transmit(command
);
730 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
734 CLockObject
lock(&m_mutex
);
735 m_iLastActive
= GetTimeMs();
741 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
743 CLockObject
lock(&m_mutex
);
745 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
746 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
749 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_REPORT_POWER_STATUS
);
750 command
.parameters
.PushBack((uint8_t) m_powerStatus
);
753 return m_processor
->Transmit(command
);
756 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
)
758 CLockObject
lock(&m_mutex
);
759 if (m_vendor
== CEC_VENDOR_UNKNOWN
)
762 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
763 AddLog(CEC_LOG_NOTICE
, strLog
);
766 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
772 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_vendor
), (uint64_t)m_vendor
);
773 AddLog(CEC_LOG_NOTICE
, strLog
);
776 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_DEVICE_VENDOR_ID
);
778 command
.parameters
.PushBack((uint8_t) (((uint64_t)m_vendor
>> 16) & 0xFF));
779 command
.parameters
.PushBack((uint8_t) (((uint64_t)m_vendor
>> 8) & 0xFF));
780 command
.parameters
.PushBack((uint8_t) ((uint64_t)m_vendor
& 0xFF));
783 return m_processor
->Transmit(command
);
787 bool CCECBusDevice::SendKeypress(cec_user_control_code key
, bool bWait
/* = false */)
790 CLockObject
lock(&m_transmitMutex
);
792 cec_command::Format(command
, m_processor
->GetLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_USER_CONTROL_PRESSED
);
793 command
.parameters
.PushBack((uint8_t)key
);
797 if (m_processor
->Transmit(command
))
798 return m_condition
.Wait(&m_transmitMutex
, 1000);
802 return m_processor
->Transmit(command
);
806 bool CCECBusDevice::SendKeyRelease(bool bWait
/* = false */)
809 CLockObject
lock(&m_transmitMutex
);
811 cec_command::Format(command
, m_processor
->GetLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_USER_CONTROL_RELEASE
);
815 if (m_processor
->Transmit(command
))
816 return m_condition
.Wait(&m_transmitMutex
, 1000);
821 return m_processor
->Transmit(command
);