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