cec: store the status of a bus device: present, not present or handled by libcec
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
CommitLineData
e9de9629
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
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.
13 *
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.
18 *
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.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
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/
31 */
32
33#include "CECBusDevice.h"
eafa9d46
LOK
34#include "../CECProcessor.h"
35#include "../implementations/ANCommandHandler.h"
36#include "../implementations/CECCommandHandler.h"
37#include "../implementations/SLCommandHandler.h"
11621576 38#include "../implementations/VLCommandHandler.h"
eafa9d46 39#include "../platform/timeutils.h"
e9de9629
LOK
40
41using namespace CEC;
42
c4098482
LOK
43#define ToString(p) CCECCommandHandler::ToString(p)
44
e9de9629 45CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
c4098482 46 m_type(CEC_DEVICE_TYPE_RESERVED),
e9de9629 47 m_iPhysicalAddress(iPhysicalAddress),
9dc04b07 48 m_iStreamPath(0),
e9de9629 49 m_iLogicalAddress(iLogicalAddress),
e55f3f70 50 m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
e9de9629 51 m_processor(processor),
c4098482 52 m_vendor(CEC_VENDOR_UNKNOWN),
4abd6768 53 m_menuState(CEC_MENU_STATE_ACTIVATED),
8747dd4f 54 m_bActiveSource(false),
d54e8570 55 m_iLastCommandSent(0),
6a1c0009 56 m_iLastActive(0),
f8ae3295
LOK
57 m_cecVersion(CEC_VERSION_UNKNOWN),
58 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN)
e9de9629
LOK
59{
60 m_handler = new CCECCommandHandler(this);
51b2a094 61
a3269a0a
LOK
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;
1fcf5a3f 66
c4098482 67 m_strDeviceName = ToString(m_iLogicalAddress);
e9de9629
LOK
68}
69
70CCECBusDevice::~CCECBusDevice(void)
71{
6a1c0009 72 m_condition.Broadcast();
e9de9629
LOK
73 delete m_handler;
74}
75
93729720 76void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage)
e9de9629 77{
93729720 78 m_processor->AddLog(level, strMessage);
e9de9629
LOK
79}
80
93729720 81bool CCECBusDevice::HandleCommand(const cec_command &command)
f8513317 82{
81a1e39d 83 CLockObject lock(&m_transmitMutex);
93729720
LOK
84 m_iLastActive = GetTimeMs();
85 m_handler->HandleCommand(command);
86 m_condition.Signal();
87 return true;
88}
89
90void CCECBusDevice::PollVendorId(void)
91{
81a1e39d 92 CLockObject lock(&m_transmitMutex);
93729720 93 if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST &&
c4098482 94 m_vendor == CEC_VENDOR_UNKNOWN &&
d54e8570 95 GetTimeMs() - m_iLastCommandSent > 5000 &&
315ff809 96 !m_processor->IsMonitoring())
93729720 97 {
5e822b09 98 CStdString strLog;
62f5527d 99 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
5e822b09 100 AddLog(CEC_LOG_NOTICE, strLog);
d54e8570 101 m_iLastCommandSent = GetTimeMs();
93729720
LOK
102
103 cec_command command;
ab1469a0 104 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
93729720 105 if (m_processor->Transmit(command))
81a1e39d 106 m_condition.Wait(&m_transmitMutex, 1000);
93729720
LOK
107 }
108}
109
110bool CCECBusDevice::PowerOn(void)
111{
f437e4be
LOK
112 cec_power_status current = GetPowerStatus();
113 if (current != CEC_POWER_STATUS_ON &&
114 current != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)
115 {
116 CStdString strLog;
117 strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
118 AddLog(CEC_LOG_DEBUG, strLog.c_str());
93729720 119
f437e4be 120 SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
93729720 121
f437e4be 122 cec_command command;
ab1469a0 123 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
f437e4be
LOK
124
125 return m_processor->Transmit(command);
126 }
127
128 return true;
93729720
LOK
129}
130
131bool CCECBusDevice::Standby(void)
132{
133 CStdString strLog;
62f5527d 134 strLog.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress);
93729720
LOK
135 AddLog(CEC_LOG_DEBUG, strLog.c_str());
136
137 cec_command command;
ab1469a0 138 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY);
93729720
LOK
139
140 return m_processor->Transmit(command);
141}
142
143/** @name Getters */
144//@{
d7be392a 145cec_version CCECBusDevice::GetCecVersion(void)
93729720 146{
81a1e39d 147 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 148 {
81a1e39d
LOK
149 CStdString strLog;
150 strLog.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
151 AddLog(CEC_LOG_NOTICE, strLog);
152 cec_command command;
153 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION);
154 CLockObject lock(&m_transmitMutex);
155 if (m_processor->Transmit(command))
156 m_condition.Wait(&m_transmitMutex, 1000);
93729720
LOK
157 }
158
81a1e39d 159 CLockObject lock(&m_mutex);
93729720
LOK
160 return m_cecVersion;
161}
162
62f5527d
LOK
163const char* CCECBusDevice::GetLogicalAddressName(void) const
164{
c4098482 165 return ToString(m_iLogicalAddress);
62f5527d
LOK
166}
167
d7be392a 168cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
93729720 169{
81a1e39d 170 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 171 {
81a1e39d
LOK
172 CStdString strLog;
173 strLog.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
174 AddLog(CEC_LOG_NOTICE, strLog);
175 cec_command command;
176 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE);
177 CLockObject lock(&m_transmitMutex);
178 if (m_processor->Transmit(command))
179 m_condition.Wait(&m_transmitMutex, 1000);
93729720
LOK
180 }
181
81a1e39d 182 CLockObject lock(&m_mutex);
93729720
LOK
183 return m_menuLanguage;
184}
185
186cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const
187{
188 return m_processor->GetLogicalAddress();
f8513317
LOK
189}
190
e9de9629
LOK
191uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
192{
193 return m_processor->GetPhysicalAddress();
194}
195
d7be392a 196cec_power_status CCECBusDevice::GetPowerStatus(void)
e9de9629 197{
81a1e39d 198 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 199 {
81a1e39d
LOK
200 CStdString strLog;
201 strLog.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
202 AddLog(CEC_LOG_NOTICE, strLog);
203 cec_command command;
204 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
205 CLockObject lock(&m_transmitMutex);
206 if (m_processor->Transmit(command))
207 m_condition.Wait(&m_transmitMutex, 1000);
93729720
LOK
208 }
209
81a1e39d 210 CLockObject lock(&m_mutex);
93729720 211 return m_powerStatus;
e9de9629
LOK
212}
213
7856411b 214cec_vendor_id CCECBusDevice::GetVendorId(void)
a3269a0a 215{
81a1e39d 216 if (!MyLogicalAddressContains(m_iLogicalAddress))
a3269a0a 217 {
81a1e39d
LOK
218 CStdString strLog;
219 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
220 AddLog(CEC_LOG_NOTICE, strLog);
221 cec_command command;
222 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
223 CLockObject lock(&m_transmitMutex);
224
225 if (m_processor->Transmit(command))
226 m_condition.Wait(&m_transmitMutex, 1000);
a3269a0a 227 }
93729720 228
81a1e39d 229 CLockObject lock(&m_mutex);
93729720
LOK
230 return m_vendor;
231}
232
c4098482
LOK
233const char *CCECBusDevice::GetVendorName(void)
234{
81a1e39d 235 CLockObject lock(&m_mutex);
c4098482
LOK
236 return ToString(m_vendor);
237}
238
93729720
LOK
239bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
240{
241 return m_processor->HasLogicalAddress(address);
a3269a0a
LOK
242}
243
f8ae3295
LOK
244cec_bus_device_status CCECBusDevice::GetStatus(void)
245{
246 CLockObject lock(&m_mutex);
247 if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN)
248 {
249 if (m_processor->PollDevice(m_iLogicalAddress))
250 m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
251 else
252 m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT;
253 }
254
255 return m_deviceStatus;
256}
257
93729720
LOK
258//@}
259
260/** @name Setters */
261//@{
e55f3f70 262void CCECBusDevice::SetCecVersion(const cec_version newVersion)
6a1c0009 263{
6a1c0009
LOK
264 m_cecVersion = newVersion;
265
c686413b 266 CStdString strLog;
c4098482 267 strLog.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
6a1c0009
LOK
268 AddLog(CEC_LOG_DEBUG, strLog);
269}
270
93729720
LOK
271void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
272{
81a1e39d 273 CLockObject lock(&m_mutex);
93729720
LOK
274 if (language.device == m_iLogicalAddress)
275 {
276 CStdString strLog;
62f5527d 277 strLog.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
93729720
LOK
278 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
279 m_menuLanguage = language;
280 }
281}
282
15d1a84c
LOK
283void CCECBusDevice::SetOSDName(CStdString strName)
284{
285 CLockObject lock(&m_mutex);
286 if (m_strDeviceName != strName)
287 {
288 CStdString strLog;
289 strLog.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName);
290 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
291 m_strDeviceName = strName;
292 }
293}
294
28fa6c97
LOK
295void CCECBusDevice::SetMenuState(const cec_menu_state state)
296{
81a1e39d 297 CLockObject lock(&m_mutex);
28fa6c97
LOK
298 if (m_menuState != state)
299 {
300 CStdString strLog;
301 strLog.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState));
302 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
303 m_menuState = state;
304 }
305}
306
7856411b
LOK
307void CCECBusDevice::SetInactiveDevice(void)
308{
309 CLockObject lock(&m_mutex);
310 m_bActiveSource = false;
311}
312
313void CCECBusDevice::SetActiveDevice(void)
314{
315 CLockObject lock(&m_mutex);
316
317 for (int iPtr = 0; iPtr < 16; iPtr++)
318 if (iPtr != m_iLogicalAddress)
319 m_processor->m_busDevices[iPtr]->SetInactiveDevice();
320
321 m_bActiveSource = true;
322 m_powerStatus = CEC_POWER_STATUS_ON;
323}
324
9dc04b07 325void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
93729720 326{
81a1e39d 327 CLockObject lock(&m_mutex);
93729720
LOK
328 if (iNewAddress > 0)
329 {
330 CStdString strLog;
62f5527d 331 strLog.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
93729720
LOK
332 AddLog(CEC_LOG_DEBUG, strLog.c_str());
333
334 m_iPhysicalAddress = iNewAddress;
335 }
336}
337
9dc04b07
LOK
338void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
339{
81a1e39d 340 CLockObject lock(&m_mutex);
9dc04b07
LOK
341 if (iNewAddress > 0)
342 {
343 CStdString strLog;
62f5527d 344 strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress, iNewAddress);
9dc04b07
LOK
345 AddLog(CEC_LOG_DEBUG, strLog.c_str());
346
347 m_iStreamPath = iNewAddress;
96274140
LOK
348
349 if (iNewAddress > 0)
81a1e39d
LOK
350 {
351 lock.Leave();
96274140 352 SetPowerStatus(CEC_POWER_STATUS_ON);
81a1e39d 353 }
9dc04b07
LOK
354 }
355}
356
e55f3f70
LOK
357void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
358{
81a1e39d 359 CLockObject lock(&m_mutex);
b0271d54
LOK
360 if (m_powerStatus != powerStatus)
361 {
362 CStdString strLog;
c4098482 363 strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
b0271d54
LOK
364 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
365 m_powerStatus = powerStatus;
366 }
e55f3f70
LOK
367}
368
c4098482 369void CCECBusDevice::SetVendorId(uint64_t iVendorId)
e9de9629 370{
e9de9629 371 {
81a1e39d
LOK
372 CLockObject lock(&m_mutex);
373 m_vendor = (cec_vendor_id)iVendorId;
374
375 switch (iVendorId)
0ab58650 376 {
81a1e39d
LOK
377 case CEC_VENDOR_SAMSUNG:
378 if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG)
379 {
380 delete m_handler;
381 m_handler = new CANCommandHandler(this);
382 }
383 break;
384 case CEC_VENDOR_LG:
385 if (m_handler->GetVendorId() != CEC_VENDOR_LG)
386 {
387 delete m_handler;
388 m_handler = new CSLCommandHandler(this);
389 }
390 break;
391 case CEC_VENDOR_PANASONIC:
392 if (m_handler->GetVendorId() != CEC_VENDOR_PANASONIC)
393 {
394 delete m_handler;
395 m_handler = new CVLCommandHandler(this);
396 }
397 break;
398 default:
399 if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN)
400 {
401 delete m_handler;
402 m_handler = new CCECCommandHandler(this);
403 }
404 break;
0ab58650 405 }
e9de9629
LOK
406 }
407
408 CStdString strLog;
81a1e39d 409 strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), m_vendor);
e9de9629
LOK
410 m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
411}
93729720 412//@}
e9de9629 413
93729720
LOK
414/** @name Transmit methods */
415//@{
416bool CCECBusDevice::TransmitActiveSource(void)
0f23c85c 417{
81a1e39d 418 CLockObject lock(&m_mutex);
58c1f6f5
LOK
419 if (m_powerStatus != CEC_POWER_STATUS_ON)
420 {
421 CStdString strLog;
422 strLog.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress);
423 AddLog(CEC_LOG_DEBUG, strLog);
424 }
425 else if (m_bActiveSource)
8747dd4f
LOK
426 {
427 CStdString strLog;
62f5527d 428 strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
8747dd4f 429 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c 430
8747dd4f 431 cec_command command;
ab1469a0
LOK
432 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
433 command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
434 command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF));
0f23c85c 435
81a1e39d 436 lock.Leave();
8747dd4f
LOK
437 return m_processor->Transmit(command);
438 }
439 else
440 {
441 CStdString strLog;
62f5527d 442 strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress);
8747dd4f
LOK
443 AddLog(CEC_LOG_DEBUG, strLog);
444 }
445
446 return false;
0f23c85c
LOK
447}
448
29912296 449bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
0f23c85c 450{
81a1e39d 451 CLockObject lock(&m_mutex);
d7be392a 452 CStdString strLog;
c4098482 453 strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion));
d7be392a 454 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
455
456 cec_command command;
ab1469a0
LOK
457 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_CEC_VERSION);
458 command.parameters.PushBack((uint8_t)m_cecVersion);
0f23c85c 459
81a1e39d 460 lock.Leave();
0f23c85c
LOK
461 return m_processor->Transmit(command);
462}
463
93729720
LOK
464bool CCECBusDevice::TransmitInactiveView(void)
465{
d7be392a 466 CStdString strLog;
62f5527d 467 strLog.Format("<< %s (%X) -> broadcast (F): inactive view", GetLogicalAddressName(), m_iLogicalAddress);
d7be392a 468 AddLog(CEC_LOG_NOTICE, strLog);
93729720
LOK
469
470 cec_command command;
ab1469a0
LOK
471 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE);
472 command.parameters.PushBack((m_iPhysicalAddress >> 8) & 0xFF);
473 command.parameters.PushBack(m_iPhysicalAddress & 0xFF);
93729720
LOK
474
475 return m_processor->Transmit(command);
476}
477
29912296 478bool CCECBusDevice::TransmitMenuState(cec_logical_address dest)
0f23c85c 479{
d7be392a 480 CStdString strLog;
28fa6c97 481 strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState));
d7be392a 482 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
483
484 cec_command command;
ab1469a0
LOK
485 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS);
486 command.parameters.PushBack((uint8_t)m_menuState);
0f23c85c
LOK
487
488 return m_processor->Transmit(command);
489}
490
29912296 491bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
0f23c85c 492{
81a1e39d 493 CLockObject lock(&m_mutex);
0f23c85c 494 CStdString strLog;
c4098482 495 strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str());
0f23c85c
LOK
496 AddLog(CEC_LOG_NOTICE, strLog.c_str());
497
498 cec_command command;
ab1469a0 499 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_NAME);
787a3cb8 500 for (unsigned int iPtr = 0; iPtr < m_strDeviceName.length(); iPtr++)
ab1469a0 501 command.parameters.PushBack(m_strDeviceName.at(iPtr));
0f23c85c 502
81a1e39d 503 lock.Leave();
0f23c85c
LOK
504 return m_processor->Transmit(command);
505}
506
38bdb943
LOK
507bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
508{
81a1e39d 509 CLockObject lock(&m_mutex);
38bdb943 510 CStdString strLog;
c4098482 511 strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage);
38bdb943
LOK
512 AddLog(CEC_LOG_NOTICE, strLog.c_str());
513
514 cec_command command;
ab1469a0
LOK
515 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_STRING);
516 command.parameters.PushBack((uint8_t)duration);
38bdb943
LOK
517
518 unsigned int iLen = strlen(strMessage);
519 if (iLen > 13) iLen = 13;
520
521 for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
ab1469a0 522 command.parameters.PushBack(strMessage[iPtr]);
38bdb943 523
81a1e39d 524 lock.Leave();
38bdb943
LOK
525 return m_processor->Transmit(command);
526}
527
29912296 528bool CCECBusDevice::TransmitPhysicalAddress(void)
0f23c85c 529{
81a1e39d 530 CLockObject lock(&m_mutex);
0f23c85c 531 CStdString strLog;
62f5527d 532 strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
0f23c85c
LOK
533 AddLog(CEC_LOG_NOTICE, strLog.c_str());
534
535 cec_command command;
ab1469a0
LOK
536 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
537 command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
538 command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF));
539 command.parameters.PushBack((uint8_t) (m_type));
0f23c85c 540
81a1e39d 541 lock.Leave();
0f23c85c
LOK
542 return m_processor->Transmit(command);
543}
544
93729720 545bool CCECBusDevice::TransmitPoll(cec_logical_address dest)
57f45e6c
LOK
546{
547 bool bReturn(false);
93729720
LOK
548 if (dest == CECDEVICE_UNKNOWN)
549 dest = m_iLogicalAddress;
f8513317 550
57f45e6c 551 CStdString strLog;
c4098482 552 strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
d7be392a 553 AddLog(CEC_LOG_NOTICE, strLog.c_str());
57f45e6c
LOK
554
555 cec_command command;
ab1469a0 556 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_NONE);
81a1e39d 557 CLockObject lock(&m_transmitMutex);
57f45e6c
LOK
558
559 bReturn = m_processor->Transmit(command);
560 AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
561 return bReturn;
562}
93729720
LOK
563
564bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
565{
81a1e39d 566 CLockObject lock(&m_mutex);
93729720 567 CStdString strLog;
c4098482 568 strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
d7be392a
LOK
569 AddLog(CEC_LOG_NOTICE, strLog.c_str());
570
93729720 571 cec_command command;
ab1469a0
LOK
572 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS);
573 command.parameters.PushBack((uint8_t) m_powerStatus);
93729720 574
81a1e39d 575 lock.Leave();
93729720
LOK
576 return m_processor->Transmit(command);
577}
578
579bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
580{
81a1e39d 581 CLockObject lock(&m_mutex);
c4098482
LOK
582 if (m_vendor == CEC_VENDOR_UNKNOWN)
583 {
584 CStdString strLog;
585 strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
586 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a 587
81a1e39d 588 lock.Leave();
c4098482
LOK
589 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
590 return false;
591 }
592 else
593 {
594 CStdString strLog;
595 strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_vendor), (uint64_t)m_vendor);
596 AddLog(CEC_LOG_NOTICE, strLog);
597
598 cec_command command;
5e9b399e 599 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID);
c4098482 600
ab1469a0
LOK
601 command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 16) & 0xFF));
602 command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 8) & 0xFF));
603 command.parameters.PushBack((uint8_t) ((uint64_t)m_vendor & 0xFF));
c4098482 604
81a1e39d 605 lock.Leave();
c4098482
LOK
606 return m_processor->Transmit(command);
607 }
93729720
LOK
608}
609//@}