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),
55 m_iLastCommandSent(0),
57 m_cecVersion(CEC_VERSION_UNKNOWN
),
58 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN
),
59 m_iTransmitTimeout(1000)
61 m_handler
= new CCECCommandHandler(this);
63 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
64 m_menuLanguage
.language
[iPtr
] = '?';
65 m_menuLanguage
.language
[3] = 0;
66 m_menuLanguage
.device
= iLogicalAddress
;
68 m_strDeviceName
= ToString(m_iLogicalAddress
);
71 CCECBusDevice::~CCECBusDevice(void)
73 m_condition
.Broadcast();
77 void CCECBusDevice::AddLog(cec_log_level level
, const CStdString
&strMessage
)
79 m_processor
->AddLog(level
, strMessage
);
82 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
84 CLockObject
lock(&m_transmitMutex
);
85 m_iLastActive
= GetTimeMs();
86 m_handler
->HandleCommand(command
);
87 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
89 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
92 strLog
.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
93 AddLog(CEC_LOG_DEBUG
, strLog
);
95 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
101 bool CCECBusDevice::PowerOn(void)
104 strLog
.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
105 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
108 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_IMAGE_VIEW_ON
, m_iTransmitTimeout
);
109 if (m_processor
->Transmit(command
))
112 CLockObject
lock(&m_mutex
);
113 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
115 cec_power_status status
= GetPowerStatus();
116 if (status
== CEC_POWER_STATUS_STANDBY
|| status
== CEC_POWER_STATUS_UNKNOWN
)
118 SendKeypress(CEC_USER_CONTROL_CODE_POWER
, true);
119 return SendKeyRelease(false);
127 bool CCECBusDevice::Standby(void)
130 strLog
.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
131 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
134 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_STANDBY
, m_iTransmitTimeout
);
136 return m_processor
->Transmit(command
);
141 cec_version
CCECBusDevice::GetCecVersion(void)
143 CLockObject
lock(&m_mutex
);
144 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
145 m_cecVersion
== CEC_VERSION_UNKNOWN
)
151 bool CCECBusDevice::RequestCecVersion(void)
154 if (!MyLogicalAddressContains(m_iLogicalAddress
))
157 strLog
.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
158 AddLog(CEC_LOG_NOTICE
, strLog
);
160 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GET_CEC_VERSION
, m_iTransmitTimeout
);
161 CLockObject
lock(&m_transmitMutex
);
162 if (m_processor
->Transmit(command
))
163 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
168 uint64_t CCECBusDevice::GetLastCommandSent(void) const
170 return GetTimeMs() - m_iLastCommandSent
;
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 (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
182 !strcmp(m_menuLanguage
.language
, "???"))
183 RequestMenuLanguage();
185 return m_menuLanguage
;
188 bool CCECBusDevice::RequestMenuLanguage(void)
191 if (!MyLogicalAddressContains(m_iLogicalAddress
))
194 strLog
.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
195 AddLog(CEC_LOG_NOTICE
, strLog
);
197 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GET_MENU_LANGUAGE
, m_iTransmitTimeout
);
198 CLockObject
lock(&m_transmitMutex
);
199 if (m_processor
->Transmit(command
))
200 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
205 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
207 return m_processor
->GetLogicalAddress();
210 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
212 return m_processor
->GetPhysicalAddress();
215 CStdString
CCECBusDevice::GetOSDName(void)
217 CLockObject
lock(&m_mutex
);
218 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
219 m_strDeviceName
.Equals(ToString(m_iLogicalAddress
)) &&
220 m_type
!= CEC_DEVICE_TYPE_TV
)
223 return m_strDeviceName
;
226 bool CCECBusDevice::RequestOSDName(void)
229 if (!MyLogicalAddressContains(m_iLogicalAddress
))
232 strLog
.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
233 AddLog(CEC_LOG_NOTICE
, strLog
);
235 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_OSD_NAME
, m_iTransmitTimeout
);
236 CLockObject
lock(&m_transmitMutex
);
237 if (m_processor
->Transmit(command
))
238 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
243 uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh
/* = true */)
245 CLockObject
lock(&m_mutex
);
246 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
247 (m_iPhysicalAddress
== 0xFFFF || bRefresh
))
249 if (!RequestPhysicalAddress())
250 AddLog(CEC_LOG_ERROR
, "failed to request the physical address");
253 return m_iPhysicalAddress
;
256 bool CCECBusDevice::RequestPhysicalAddress(void)
259 if (!MyLogicalAddressContains(m_iLogicalAddress
))
262 strLog
.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
263 AddLog(CEC_LOG_NOTICE
, strLog
);
265 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
, m_iTransmitTimeout
);
266 CLockObject
lock(&m_transmitMutex
);
267 if (m_processor
->Transmit(command
))
268 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
273 cec_power_status
CCECBusDevice::GetPowerStatus(void)
275 CLockObject
lock(&m_mutex
);
276 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
277 m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
)
278 RequestPowerStatus();
280 return m_powerStatus
;
283 bool CCECBusDevice::RequestPowerStatus(void)
286 if (!MyLogicalAddressContains(m_iLogicalAddress
))
289 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
290 AddLog(CEC_LOG_NOTICE
, strLog
);
292 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
, m_iTransmitTimeout
);
293 CLockObject
lock(&m_transmitMutex
);
294 if (m_processor
->Transmit(command
))
295 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
300 cec_vendor_id
CCECBusDevice::GetVendorId(void)
302 CLockObject
lock(&m_mutex
);
303 if (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
304 m_vendor
== CEC_VENDOR_UNKNOWN
)
310 bool CCECBusDevice::RequestVendorId(void)
313 if (!MyLogicalAddressContains(m_iLogicalAddress
))
316 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
317 AddLog(CEC_LOG_NOTICE
, strLog
);
319 cec_command::Format(command
, GetMyLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
, m_iTransmitTimeout
);
321 CLockObject
lock(&m_transmitMutex
);
322 if (m_processor
->Transmit(command
))
323 bReturn
= m_condition
.Wait(&m_transmitMutex
, 1000);
328 const char *CCECBusDevice::GetVendorName(void)
330 return ToString(GetVendorId());
333 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
335 return m_processor
->HasLogicalAddress(address
);
338 bool CCECBusDevice::NeedsPoll(void)
340 bool bSendPoll(false);
341 switch (m_iLogicalAddress
)
343 case CECDEVICE_PLAYBACKDEVICE3
:
344 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
347 case CECDEVICE_PLAYBACKDEVICE2
:
348 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
351 case CECDEVICE_RECORDINGDEVICE3
:
352 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
355 case CECDEVICE_RECORDINGDEVICE2
:
356 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
359 case CECDEVICE_TUNER4
:
360 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
363 case CECDEVICE_TUNER3
:
364 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
367 case CECDEVICE_TUNER2
:
368 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
371 case CECDEVICE_AUDIOSYSTEM
:
372 case CECDEVICE_PLAYBACKDEVICE1
:
373 case CECDEVICE_RECORDINGDEVICE1
:
374 case CECDEVICE_TUNER1
:
385 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
387 CLockObject
lock(&m_writeMutex
);
388 if (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
)
391 bool bPollAcked(false);
392 if (bForcePoll
|| NeedsPoll())
393 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
396 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
399 return m_deviceStatus
;
406 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
408 m_cecVersion
= newVersion
;
411 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
412 AddLog(CEC_LOG_DEBUG
, strLog
);
415 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
417 CLockObject
lock(&m_writeMutex
);
418 if (language
.device
== m_iLogicalAddress
)
421 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
422 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
423 m_menuLanguage
= language
;
427 void CCECBusDevice::SetOSDName(CStdString strName
)
429 CLockObject
lock(&m_writeMutex
);
430 if (m_strDeviceName
!= strName
)
433 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
434 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
435 m_strDeviceName
= strName
;
439 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
441 CLockObject
lock(&m_writeMutex
);
442 if (m_menuState
!= state
)
445 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
446 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
451 void CCECBusDevice::SetInactiveDevice(void)
453 CLockObject
lock(&m_writeMutex
);
454 m_bActiveSource
= false;
457 void CCECBusDevice::SetActiveDevice(void)
459 CLockObject
lock(&m_writeMutex
);
461 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
462 if (iPtr
!= m_iLogicalAddress
)
463 m_processor
->m_busDevices
[iPtr
]->SetInactiveDevice();
465 m_bActiveSource
= true;
466 m_powerStatus
= CEC_POWER_STATUS_ON
;
469 bool CCECBusDevice::TryLogicalAddress(void)
472 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
473 AddLog(CEC_LOG_DEBUG
, strLog
);
475 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
476 if (!TransmitPoll(m_iLogicalAddress
))
478 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
479 AddLog(CEC_LOG_NOTICE
, strLog
);
480 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
485 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
486 AddLog(CEC_LOG_DEBUG
, strLog
);
487 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
491 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
493 CLockObject
lock(&m_writeMutex
);
496 case CEC_DEVICE_STATUS_UNKNOWN
:
498 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
499 m_vendor
= CEC_VENDOR_UNKNOWN
;
500 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
501 m_bActiveSource
= false;
502 m_iLastCommandSent
= 0;
504 m_cecVersion
= CEC_VERSION_UNKNOWN
;
505 m_deviceStatus
= newStatus
;
507 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
509 m_powerStatus
= CEC_POWER_STATUS_ON
;
510 m_vendor
= CEC_VENDOR_UNKNOWN
;
511 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
512 m_bActiveSource
= false;
513 m_iLastCommandSent
= 0;
515 m_cecVersion
= CEC_VERSION_1_3A
;
516 m_deviceStatus
= newStatus
;
518 case CEC_DEVICE_STATUS_PRESENT
:
519 case CEC_DEVICE_STATUS_NOT_PRESENT
:
520 m_deviceStatus
= newStatus
;
525 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
527 CLockObject
lock(&m_writeMutex
);
528 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
531 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
532 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
534 m_iPhysicalAddress
= iNewAddress
;
538 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
540 CLockObject
lock(&m_writeMutex
);
544 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
545 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
547 m_iStreamPath
= iNewAddress
;
552 SetPowerStatus(CEC_POWER_STATUS_ON
);
557 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
559 CLockObject
lock(&m_writeMutex
);
560 if (m_powerStatus
!= powerStatus
)
563 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
564 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
565 m_powerStatus
= powerStatus
;
569 void CCECBusDevice::SetVendorId(uint64_t iVendorId
)
572 CLockObject
lock(&m_writeMutex
);
573 m_vendor
= (cec_vendor_id
)iVendorId
;
577 case CEC_VENDOR_SAMSUNG
:
578 if (m_handler
->GetVendorId() != CEC_VENDOR_SAMSUNG
)
581 m_handler
= new CANCommandHandler(this);
585 if (m_handler
->GetVendorId() != CEC_VENDOR_LG
)
588 m_handler
= new CSLCommandHandler(this);
591 case CEC_VENDOR_PANASONIC
:
592 if (m_handler
->GetVendorId() != CEC_VENDOR_PANASONIC
)
595 m_handler
= new CVLCommandHandler(this);
599 if (m_handler
->GetVendorId() != CEC_VENDOR_UNKNOWN
)
602 m_handler
= new CCECCommandHandler(this);
608 m_handler
->InitHandler();
611 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
612 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
616 /** @name Transmit methods */
618 bool CCECBusDevice::TransmitActiveSource(void)
620 CLockObject
lock(&m_writeMutex
);
621 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
624 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
625 AddLog(CEC_LOG_DEBUG
, strLog
);
627 else if (m_bActiveSource
)
630 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
631 AddLog(CEC_LOG_NOTICE
, strLog
);
634 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_ACTIVE_SOURCE
, m_iTransmitTimeout
);
635 command
.parameters
.PushBack((uint8_t) ((m_iPhysicalAddress
>> 8) & 0xFF));
636 command
.parameters
.PushBack((uint8_t) (m_iPhysicalAddress
& 0xFF));
639 return m_processor
->Transmit(command
);
644 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
645 AddLog(CEC_LOG_DEBUG
, strLog
);
651 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
653 CLockObject
lock(&m_writeMutex
);
655 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
656 AddLog(CEC_LOG_NOTICE
, strLog
);
659 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_CEC_VERSION
, m_iTransmitTimeout
);
660 command
.parameters
.PushBack((uint8_t)m_cecVersion
);
663 return m_processor
->Transmit(command
);
666 bool CCECBusDevice::TransmitInactiveSource(void)
669 strLog
.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
670 AddLog(CEC_LOG_NOTICE
, strLog
);
673 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_TV
, CEC_OPCODE_INACTIVE_SOURCE
, m_iTransmitTimeout
);
674 command
.parameters
.PushBack((m_iPhysicalAddress
>> 8) & 0xFF);
675 command
.parameters
.PushBack(m_iPhysicalAddress
& 0xFF);
677 return m_processor
->Transmit(command
);
680 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
683 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
684 AddLog(CEC_LOG_NOTICE
, strLog
);
687 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_MENU_STATUS
, m_iTransmitTimeout
);
688 command
.parameters
.PushBack((uint8_t)m_menuState
);
690 return m_processor
->Transmit(command
);
693 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
695 CLockObject
lock(&m_writeMutex
);
697 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
698 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
701 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_SET_OSD_NAME
, m_iTransmitTimeout
);
702 for (unsigned int iPtr
= 0; iPtr
< m_strDeviceName
.length(); iPtr
++)
703 command
.parameters
.PushBack(m_strDeviceName
.at(iPtr
));
706 return m_processor
->Transmit(command
);
709 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
711 CLockObject
lock(&m_writeMutex
);
713 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
714 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
717 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_SET_OSD_STRING
, m_iTransmitTimeout
);
718 command
.parameters
.PushBack((uint8_t)duration
);
720 unsigned int iLen
= strlen(strMessage
);
721 if (iLen
> 13) iLen
= 13;
723 for (unsigned int iPtr
= 0; iPtr
< iLen
; iPtr
++)
724 command
.parameters
.PushBack(strMessage
[iPtr
]);
727 return m_processor
->Transmit(command
);
730 bool CCECBusDevice::TransmitPhysicalAddress(void)
732 CLockObject
lock(&m_writeMutex
);
734 if (m_iPhysicalAddress
= 0xffff)
738 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
739 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
742 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
, m_iTransmitTimeout
);
743 command
.parameters
.PushBack((uint8_t) ((m_iPhysicalAddress
>> 8) & 0xFF));
744 command
.parameters
.PushBack((uint8_t) (m_iPhysicalAddress
& 0xFF));
745 command
.parameters
.PushBack((uint8_t) (m_type
));
748 return m_processor
->Transmit(command
);
751 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
754 if (dest
== CECDEVICE_UNKNOWN
)
755 dest
= m_iLogicalAddress
;
757 CLockObject
lock(&m_writeMutex
);
760 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
761 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
764 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_NONE
, m_iTransmitTimeout
);
768 CLockObject
lock(&m_transmitMutex
);
769 bReturn
= m_processor
->Transmit(command
);
772 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
774 m_iLastActive
= GetTimeMs();
779 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
781 CLockObject
lock(&m_writeMutex
);
783 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
784 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
787 cec_command::Format(command
, m_iLogicalAddress
, dest
, CEC_OPCODE_REPORT_POWER_STATUS
, m_iTransmitTimeout
);
788 command
.parameters
.PushBack((uint8_t) m_powerStatus
);
791 return m_processor
->Transmit(command
);
794 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
)
796 CLockObject
lock(&m_writeMutex
);
797 if (m_vendor
== CEC_VENDOR_UNKNOWN
)
800 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
801 AddLog(CEC_LOG_NOTICE
, strLog
);
804 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
810 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_vendor
), (uint64_t)m_vendor
);
811 AddLog(CEC_LOG_NOTICE
, strLog
);
814 cec_command::Format(command
, m_iLogicalAddress
, CECDEVICE_BROADCAST
, CEC_OPCODE_DEVICE_VENDOR_ID
, m_iTransmitTimeout
);
816 command
.parameters
.PushBack((uint8_t) (((uint64_t)m_vendor
>> 16) & 0xFF));
817 command
.parameters
.PushBack((uint8_t) (((uint64_t)m_vendor
>> 8) & 0xFF));
818 command
.parameters
.PushBack((uint8_t) ((uint64_t)m_vendor
& 0xFF));
821 return m_processor
->Transmit(command
);
825 bool CCECBusDevice::SendKeypress(cec_user_control_code key
, bool bWait
/* = false */)
827 CLockObject
lock(&m_transmitMutex
);
829 cec_command::Format(command
, m_processor
->GetLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_USER_CONTROL_PRESSED
, m_iTransmitTimeout
);
830 command
.parameters
.PushBack((uint8_t)key
);
834 if (m_processor
->Transmit(command
))
835 return m_condition
.Wait(&m_transmitMutex
, 1000);
839 return m_processor
->Transmit(command
);
842 bool CCECBusDevice::SendKeyRelease(bool bWait
/* = false */)
844 CLockObject
lock(&m_transmitMutex
);
846 cec_command::Format(command
, m_processor
->GetLogicalAddress(), m_iLogicalAddress
, CEC_OPCODE_USER_CONTROL_RELEASE
, m_iTransmitTimeout
);
850 if (m_processor
->Transmit(command
))
851 return m_condition
.Wait(&m_transmitMutex
, 1000);
856 return m_processor
->Transmit(command
);