cec: always send a power on command in CCECBusDevice::PowerOn()
[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{
00762a71
LOK
112 CStdString strLog;
113 strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
114 AddLog(CEC_LOG_DEBUG, strLog.c_str());
115
116 cec_command command;
117 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
118 if (m_processor->Transmit(command))
119 {
120 GetPowerStatus();
121 return true;
f437e4be
LOK
122 }
123
00762a71 124 return false;
93729720
LOK
125}
126
127bool CCECBusDevice::Standby(void)
128{
129 CStdString strLog;
62f5527d 130 strLog.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress);
93729720
LOK
131 AddLog(CEC_LOG_DEBUG, strLog.c_str());
132
133 cec_command command;
ab1469a0 134 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY);
93729720
LOK
135
136 return m_processor->Transmit(command);
137}
138
139/** @name Getters */
140//@{
d7be392a 141cec_version CCECBusDevice::GetCecVersion(void)
93729720 142{
f294b22f
LOK
143 CLockObject lock(&m_mutex);
144 if (m_cecVersion == CEC_VERSION_UNKNOWN)
145 {
146 lock.Leave();
147 RequestCecVersion();
148 lock.Lock();
149 }
150
151 return m_cecVersion;
152}
153
154bool CCECBusDevice::RequestCecVersion(void)
155{
156 bool bReturn(false);
81a1e39d 157 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 158 {
81a1e39d
LOK
159 CStdString strLog;
160 strLog.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
161 AddLog(CEC_LOG_NOTICE, strLog);
162 cec_command command;
163 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION);
164 CLockObject lock(&m_transmitMutex);
165 if (m_processor->Transmit(command))
f294b22f 166 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
93729720 167 }
f294b22f 168 return bReturn;
93729720
LOK
169}
170
62f5527d
LOK
171const char* CCECBusDevice::GetLogicalAddressName(void) const
172{
c4098482 173 return ToString(m_iLogicalAddress);
62f5527d
LOK
174}
175
d7be392a 176cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
93729720 177{
f294b22f
LOK
178 CLockObject lock(&m_mutex);
179 if (!strcmp(m_menuLanguage.language, "???"))
180 {
181 lock.Leave();
182 RequestMenuLanguage();
183 lock.Lock();
184 }
185 return m_menuLanguage;
186}
187
188bool CCECBusDevice::RequestMenuLanguage(void)
189{
190 bool bReturn(false);
81a1e39d 191 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 192 {
81a1e39d
LOK
193 CStdString strLog;
194 strLog.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
195 AddLog(CEC_LOG_NOTICE, strLog);
196 cec_command command;
197 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE);
198 CLockObject lock(&m_transmitMutex);
199 if (m_processor->Transmit(command))
f294b22f 200 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
93729720 201 }
f294b22f 202 return bReturn;
93729720
LOK
203}
204
205cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const
206{
207 return m_processor->GetLogicalAddress();
f8513317
LOK
208}
209
e9de9629
LOK
210uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
211{
212 return m_processor->GetPhysicalAddress();
213}
214
d7be392a 215cec_power_status CCECBusDevice::GetPowerStatus(void)
e9de9629 216{
f294b22f
LOK
217 CLockObject lock(&m_mutex);
218 if (m_powerStatus == CEC_POWER_STATUS_UNKNOWN)
219 {
220 lock.Leave();
221 RequestPowerStatus();
222 lock.Lock();
223 }
224 return m_powerStatus;
225}
226
227bool CCECBusDevice::RequestPowerStatus(void)
228{
229 bool bReturn(false);
81a1e39d 230 if (!MyLogicalAddressContains(m_iLogicalAddress))
93729720 231 {
81a1e39d
LOK
232 CStdString strLog;
233 strLog.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
234 AddLog(CEC_LOG_NOTICE, strLog);
235 cec_command command;
236 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
237 CLockObject lock(&m_transmitMutex);
238 if (m_processor->Transmit(command))
f294b22f 239 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
93729720 240 }
f294b22f
LOK
241 return bReturn;
242}
93729720 243
f294b22f
LOK
244cec_vendor_id CCECBusDevice::GetVendorId(void)
245{
81a1e39d 246 CLockObject lock(&m_mutex);
f294b22f
LOK
247 if (m_vendor == CEC_VENDOR_UNKNOWN)
248 {
249 lock.Leave();
250 RequestVendorId();
251 lock.Lock();
252 }
253 return m_vendor;
e9de9629
LOK
254}
255
f294b22f 256bool CCECBusDevice::RequestVendorId(void)
a3269a0a 257{
f294b22f 258 bool bReturn(false);
81a1e39d 259 if (!MyLogicalAddressContains(m_iLogicalAddress))
a3269a0a 260 {
81a1e39d
LOK
261 CStdString strLog;
262 strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
263 AddLog(CEC_LOG_NOTICE, strLog);
264 cec_command command;
265 cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
81a1e39d 266
f294b22f 267 CLockObject lock(&m_transmitMutex);
81a1e39d 268 if (m_processor->Transmit(command))
f294b22f 269 bReturn = m_condition.Wait(&m_transmitMutex, 1000);
a3269a0a 270 }
f294b22f 271 return bReturn;
93729720
LOK
272}
273
c4098482
LOK
274const char *CCECBusDevice::GetVendorName(void)
275{
f294b22f 276 return ToString(GetVendorId());
c4098482
LOK
277}
278
93729720
LOK
279bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
280{
281 return m_processor->HasLogicalAddress(address);
a3269a0a
LOK
282}
283
f8ae3295
LOK
284cec_bus_device_status CCECBusDevice::GetStatus(void)
285{
286 CLockObject lock(&m_mutex);
287 if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN)
288 {
289 if (m_processor->PollDevice(m_iLogicalAddress))
290 m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
291 else
292 m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT;
293 }
294
295 return m_deviceStatus;
296}
297
93729720
LOK
298//@}
299
300/** @name Setters */
301//@{
e55f3f70 302void CCECBusDevice::SetCecVersion(const cec_version newVersion)
6a1c0009 303{
6a1c0009
LOK
304 m_cecVersion = newVersion;
305
c686413b 306 CStdString strLog;
c4098482 307 strLog.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
6a1c0009
LOK
308 AddLog(CEC_LOG_DEBUG, strLog);
309}
310
93729720
LOK
311void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
312{
81a1e39d 313 CLockObject lock(&m_mutex);
93729720
LOK
314 if (language.device == m_iLogicalAddress)
315 {
316 CStdString strLog;
62f5527d 317 strLog.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
93729720
LOK
318 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
319 m_menuLanguage = language;
320 }
321}
322
15d1a84c
LOK
323void CCECBusDevice::SetOSDName(CStdString strName)
324{
325 CLockObject lock(&m_mutex);
326 if (m_strDeviceName != strName)
327 {
328 CStdString strLog;
329 strLog.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName);
330 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
331 m_strDeviceName = strName;
332 }
333}
334
28fa6c97
LOK
335void CCECBusDevice::SetMenuState(const cec_menu_state state)
336{
81a1e39d 337 CLockObject lock(&m_mutex);
28fa6c97
LOK
338 if (m_menuState != state)
339 {
340 CStdString strLog;
341 strLog.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState));
342 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
343 m_menuState = state;
344 }
345}
346
7856411b
LOK
347void CCECBusDevice::SetInactiveDevice(void)
348{
349 CLockObject lock(&m_mutex);
350 m_bActiveSource = false;
351}
352
353void CCECBusDevice::SetActiveDevice(void)
354{
355 CLockObject lock(&m_mutex);
356
357 for (int iPtr = 0; iPtr < 16; iPtr++)
358 if (iPtr != m_iLogicalAddress)
359 m_processor->m_busDevices[iPtr]->SetInactiveDevice();
360
361 m_bActiveSource = true;
362 m_powerStatus = CEC_POWER_STATUS_ON;
363}
364
93fff5c1
LOK
365bool CCECBusDevice::TryLogicalAddress(void)
366{
367 CStdString strLog;
368 strLog.Format("trying logical address '%s'", GetLogicalAddressName());
369 AddLog(CEC_LOG_DEBUG, strLog);
370
371 m_processor->SetAckMask(0x1 << m_iLogicalAddress);
372 if (!TransmitPoll(m_iLogicalAddress))
373 {
374 strLog.Format("using logical address '%s'", GetLogicalAddressName());
375 AddLog(CEC_LOG_NOTICE, strLog);
376 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
377
378 return true;
379 }
380
381 strLog.Format("logical address '%s' already taken", GetLogicalAddressName());
382 AddLog(CEC_LOG_DEBUG, strLog);
383 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT);
384 return false;
385}
386
387void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
388{
389 CLockObject lock(&m_mutex);
390 switch (newStatus)
391 {
392 case CEC_DEVICE_STATUS_UNKNOWN:
393 m_iStreamPath = 0;
394 m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
395 m_vendor = CEC_VENDOR_UNKNOWN;
396 m_menuState = CEC_MENU_STATE_ACTIVATED;
397 m_bActiveSource = false;
398 m_iLastCommandSent = 0;
399 m_iLastActive = 0;
400 m_cecVersion = CEC_VERSION_UNKNOWN;
401 m_deviceStatus = newStatus;
402 break;
403 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC:
404 m_iStreamPath = 0;
405 m_powerStatus = CEC_POWER_STATUS_ON;
406 m_vendor = CEC_VENDOR_UNKNOWN;
407 m_menuState = CEC_MENU_STATE_ACTIVATED;
408 m_bActiveSource = false;
409 m_iLastCommandSent = 0;
410 m_iLastActive = 0;
411 m_cecVersion = CEC_VERSION_1_3A;
412 m_deviceStatus = newStatus;
413 break;
414 case CEC_DEVICE_STATUS_PRESENT:
415 case CEC_DEVICE_STATUS_NOT_PRESENT:
416 m_deviceStatus = newStatus;
417 break;
418 }
419}
420
9dc04b07 421void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
93729720 422{
81a1e39d 423 CLockObject lock(&m_mutex);
93729720
LOK
424 if (iNewAddress > 0)
425 {
426 CStdString strLog;
62f5527d 427 strLog.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
93729720
LOK
428 AddLog(CEC_LOG_DEBUG, strLog.c_str());
429
430 m_iPhysicalAddress = iNewAddress;
431 }
432}
433
9dc04b07
LOK
434void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
435{
81a1e39d 436 CLockObject lock(&m_mutex);
9dc04b07
LOK
437 if (iNewAddress > 0)
438 {
439 CStdString strLog;
62f5527d 440 strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress, iNewAddress);
9dc04b07
LOK
441 AddLog(CEC_LOG_DEBUG, strLog.c_str());
442
443 m_iStreamPath = iNewAddress;
96274140
LOK
444
445 if (iNewAddress > 0)
81a1e39d
LOK
446 {
447 lock.Leave();
96274140 448 SetPowerStatus(CEC_POWER_STATUS_ON);
81a1e39d 449 }
9dc04b07
LOK
450 }
451}
452
e55f3f70
LOK
453void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
454{
81a1e39d 455 CLockObject lock(&m_mutex);
b0271d54
LOK
456 if (m_powerStatus != powerStatus)
457 {
458 CStdString strLog;
c4098482 459 strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
b0271d54
LOK
460 m_processor->AddLog(CEC_LOG_DEBUG, strLog);
461 m_powerStatus = powerStatus;
462 }
e55f3f70
LOK
463}
464
c4098482 465void CCECBusDevice::SetVendorId(uint64_t iVendorId)
e9de9629 466{
e9de9629 467 {
81a1e39d
LOK
468 CLockObject lock(&m_mutex);
469 m_vendor = (cec_vendor_id)iVendorId;
470
471 switch (iVendorId)
0ab58650 472 {
81a1e39d
LOK
473 case CEC_VENDOR_SAMSUNG:
474 if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG)
475 {
476 delete m_handler;
477 m_handler = new CANCommandHandler(this);
478 }
479 break;
480 case CEC_VENDOR_LG:
481 if (m_handler->GetVendorId() != CEC_VENDOR_LG)
482 {
483 delete m_handler;
484 m_handler = new CSLCommandHandler(this);
485 }
486 break;
487 case CEC_VENDOR_PANASONIC:
488 if (m_handler->GetVendorId() != CEC_VENDOR_PANASONIC)
489 {
490 delete m_handler;
491 m_handler = new CVLCommandHandler(this);
492 }
493 break;
494 default:
495 if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN)
496 {
497 delete m_handler;
498 m_handler = new CCECCommandHandler(this);
499 }
500 break;
0ab58650 501 }
e9de9629
LOK
502 }
503
504 CStdString strLog;
81a1e39d 505 strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), m_vendor);
e9de9629
LOK
506 m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
507}
93729720 508//@}
e9de9629 509
93729720
LOK
510/** @name Transmit methods */
511//@{
512bool CCECBusDevice::TransmitActiveSource(void)
0f23c85c 513{
81a1e39d 514 CLockObject lock(&m_mutex);
58c1f6f5
LOK
515 if (m_powerStatus != CEC_POWER_STATUS_ON)
516 {
517 CStdString strLog;
518 strLog.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress);
519 AddLog(CEC_LOG_DEBUG, strLog);
520 }
521 else if (m_bActiveSource)
8747dd4f
LOK
522 {
523 CStdString strLog;
62f5527d 524 strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
8747dd4f 525 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c 526
8747dd4f 527 cec_command command;
ab1469a0
LOK
528 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
529 command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
530 command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF));
0f23c85c 531
81a1e39d 532 lock.Leave();
8747dd4f
LOK
533 return m_processor->Transmit(command);
534 }
535 else
536 {
537 CStdString strLog;
62f5527d 538 strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress);
8747dd4f
LOK
539 AddLog(CEC_LOG_DEBUG, strLog);
540 }
541
542 return false;
0f23c85c
LOK
543}
544
29912296 545bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
0f23c85c 546{
81a1e39d 547 CLockObject lock(&m_mutex);
d7be392a 548 CStdString strLog;
c4098482 549 strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion));
d7be392a 550 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
551
552 cec_command command;
ab1469a0
LOK
553 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_CEC_VERSION);
554 command.parameters.PushBack((uint8_t)m_cecVersion);
0f23c85c 555
81a1e39d 556 lock.Leave();
0f23c85c
LOK
557 return m_processor->Transmit(command);
558}
559
93729720
LOK
560bool CCECBusDevice::TransmitInactiveView(void)
561{
d7be392a 562 CStdString strLog;
62f5527d 563 strLog.Format("<< %s (%X) -> broadcast (F): inactive view", GetLogicalAddressName(), m_iLogicalAddress);
d7be392a 564 AddLog(CEC_LOG_NOTICE, strLog);
93729720
LOK
565
566 cec_command command;
ab1469a0
LOK
567 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE);
568 command.parameters.PushBack((m_iPhysicalAddress >> 8) & 0xFF);
569 command.parameters.PushBack(m_iPhysicalAddress & 0xFF);
93729720
LOK
570
571 return m_processor->Transmit(command);
572}
573
29912296 574bool CCECBusDevice::TransmitMenuState(cec_logical_address dest)
0f23c85c 575{
d7be392a 576 CStdString strLog;
28fa6c97 577 strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState));
d7be392a 578 AddLog(CEC_LOG_NOTICE, strLog);
0f23c85c
LOK
579
580 cec_command command;
ab1469a0
LOK
581 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS);
582 command.parameters.PushBack((uint8_t)m_menuState);
0f23c85c
LOK
583
584 return m_processor->Transmit(command);
585}
586
29912296 587bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
0f23c85c 588{
81a1e39d 589 CLockObject lock(&m_mutex);
0f23c85c 590 CStdString strLog;
c4098482 591 strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str());
0f23c85c
LOK
592 AddLog(CEC_LOG_NOTICE, strLog.c_str());
593
594 cec_command command;
ab1469a0 595 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_NAME);
787a3cb8 596 for (unsigned int iPtr = 0; iPtr < m_strDeviceName.length(); iPtr++)
ab1469a0 597 command.parameters.PushBack(m_strDeviceName.at(iPtr));
0f23c85c 598
81a1e39d 599 lock.Leave();
0f23c85c
LOK
600 return m_processor->Transmit(command);
601}
602
38bdb943
LOK
603bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
604{
81a1e39d 605 CLockObject lock(&m_mutex);
38bdb943 606 CStdString strLog;
c4098482 607 strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage);
38bdb943
LOK
608 AddLog(CEC_LOG_NOTICE, strLog.c_str());
609
610 cec_command command;
ab1469a0
LOK
611 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_STRING);
612 command.parameters.PushBack((uint8_t)duration);
38bdb943
LOK
613
614 unsigned int iLen = strlen(strMessage);
615 if (iLen > 13) iLen = 13;
616
617 for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
ab1469a0 618 command.parameters.PushBack(strMessage[iPtr]);
38bdb943 619
81a1e39d 620 lock.Leave();
38bdb943
LOK
621 return m_processor->Transmit(command);
622}
623
29912296 624bool CCECBusDevice::TransmitPhysicalAddress(void)
0f23c85c 625{
81a1e39d 626 CLockObject lock(&m_mutex);
0f23c85c 627 CStdString strLog;
62f5527d 628 strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
0f23c85c
LOK
629 AddLog(CEC_LOG_NOTICE, strLog.c_str());
630
631 cec_command command;
ab1469a0
LOK
632 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
633 command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
634 command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF));
635 command.parameters.PushBack((uint8_t) (m_type));
0f23c85c 636
81a1e39d 637 lock.Leave();
0f23c85c
LOK
638 return m_processor->Transmit(command);
639}
640
93729720 641bool CCECBusDevice::TransmitPoll(cec_logical_address dest)
57f45e6c
LOK
642{
643 bool bReturn(false);
93729720
LOK
644 if (dest == CECDEVICE_UNKNOWN)
645 dest = m_iLogicalAddress;
f8513317 646
57f45e6c 647 CStdString strLog;
c4098482 648 strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
d7be392a 649 AddLog(CEC_LOG_NOTICE, strLog.c_str());
57f45e6c
LOK
650
651 cec_command command;
ab1469a0 652 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_NONE);
81a1e39d 653 CLockObject lock(&m_transmitMutex);
57f45e6c
LOK
654
655 bReturn = m_processor->Transmit(command);
656 AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
657 return bReturn;
658}
93729720
LOK
659
660bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
661{
81a1e39d 662 CLockObject lock(&m_mutex);
93729720 663 CStdString strLog;
c4098482 664 strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
d7be392a
LOK
665 AddLog(CEC_LOG_NOTICE, strLog.c_str());
666
93729720 667 cec_command command;
ab1469a0
LOK
668 cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS);
669 command.parameters.PushBack((uint8_t) m_powerStatus);
93729720 670
81a1e39d 671 lock.Leave();
93729720
LOK
672 return m_processor->Transmit(command);
673}
674
675bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
676{
81a1e39d 677 CLockObject lock(&m_mutex);
c4098482
LOK
678 if (m_vendor == CEC_VENDOR_UNKNOWN)
679 {
680 CStdString strLog;
681 strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
682 AddLog(CEC_LOG_NOTICE, strLog);
d7be392a 683
81a1e39d 684 lock.Leave();
c4098482
LOK
685 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
686 return false;
687 }
688 else
689 {
690 CStdString strLog;
691 strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_vendor), (uint64_t)m_vendor);
692 AddLog(CEC_LOG_NOTICE, strLog);
693
694 cec_command command;
5e9b399e 695 cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID);
c4098482 696
ab1469a0
LOK
697 command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 16) & 0xFF));
698 command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 8) & 0xFF));
699 command.parameters.PushBack((uint8_t) ((uint64_t)m_vendor & 0xFF));
c4098482 700
81a1e39d 701 lock.Leave();
c4098482
LOK
702 return m_processor->Transmit(command);
703 }
93729720
LOK
704}
705//@}