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 "platform/timeutils.h"
42 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
) :
43 m_iPhysicalAddress(iPhysicalAddress
),
44 m_iLogicalAddress(iLogicalAddress
),
45 m_processor(processor
),
47 m_iVendorClass(CEC_VENDOR_UNKNOWN
),
50 m_handler
= new CCECCommandHandler(this);
53 CCECBusDevice::~CCECBusDevice(void)
58 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
60 return m_processor
->GetLogicalAddress();
63 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
65 return m_processor
->GetPhysicalAddress();
68 void CCECBusDevice::AddLog(cec_log_level level
, const CStdString
&strMessage
)
70 m_processor
->AddLog(level
, strMessage
);
73 void CCECBusDevice::SetVendorId(uint64_t iVendorId
, uint8_t iVendorClass
/* = 0 */)
75 m_iVendorId
= iVendorId
;
76 m_iVendorClass
= iVendorClass
;
80 case CEC_VENDOR_SAMSUNG
:
81 if (m_handler
->GetVendorId() != CEC_VENDOR_SAMSUNG
)
84 m_handler
= new CANCommandHandler(this);
88 if (m_handler
->GetVendorId() != CEC_VENDOR_LG
)
91 m_handler
= new CSLCommandHandler(this);
95 if (m_handler
->GetVendorId() != CEC_VENDOR_UNKNOWN
)
98 m_handler
= new CCECCommandHandler(this);
104 strLog
.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress
, GetVendorName(), GetVendorId(), GetVendorClass());
105 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
108 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
110 CLockObject
lock(&m_mutex
);
111 m_iLastActive
= GetTimeMs();
112 m_handler
->HandleCommand(command
);
116 void CCECBusDevice::PollVendorId(void)
118 CLockObject
lock(&m_mutex
);
119 if (m_iLastActive
> 0 && m_iVendorId
== CEC_VENDOR_UNKNOWN
&&
120 GetTimeMs() - m_iLastActive
> 5000)
122 m_iLastActive
= GetTimeMs();
125 cec_command::format(command
, GetMyLogicalAddress(), GetLogicalAddress(), CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
126 m_processor
->Transmit(command
, false);
130 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
133 strLog
.Format(">> %i changed physical address from %04x to %04x", GetLogicalAddress(), m_iPhysicalAddress
, iNewAddress
);
134 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
136 m_iPhysicalAddress
= iNewAddress
;
139 const char *CCECBusDevice::CECVendorIdToString(const uint64_t iVendorId
)
143 case CEC_VENDOR_SAMSUNG
: