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