2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
33 #include "CECCommandHandler.h"
34 #include "../devices/CECBusDevice.h"
35 #include "../devices/CECAudioSystem.h"
36 #include "../devices/CECPlaybackDevice.h"
37 #include "../CECProcessor.h"
42 CCECCommandHandler::CCECCommandHandler(CCECBusDevice
*busDevice
) :
43 m_busDevice(busDevice
),
44 m_processor(m_busDevice
->GetProcessor()),
45 m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT
),
46 m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT
),
47 m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES
)
51 CCECCommandHandler::~CCECCommandHandler(void)
53 m_condition
.Broadcast();
56 bool CCECCommandHandler::HandleCommand(const cec_command
&command
)
58 bool bHandled(true), bHandlerChanged(false);
61 strLog
.Format(">> %s (%X) -> %s (%X): %s (%2X)", m_processor
->ToString(command
.initiator
), command
.initiator
, m_processor
->ToString(command
.destination
), command
.destination
, m_processor
->ToString(command
.opcode
), command
.opcode
);
62 m_busDevice
->AddLog(CEC_LOG_NOTICE
, strLog
);
64 m_processor
->AddCommand(command
);
66 switch(command
.opcode
)
68 case CEC_OPCODE_REPORT_POWER_STATUS
:
69 HandleReportPowerStatus(command
);
71 case CEC_OPCODE_CEC_VERSION
:
72 HandleDeviceCecVersion(command
);
74 case CEC_OPCODE_SET_MENU_LANGUAGE
:
75 HandleSetMenuLanguage(command
);
77 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
78 HandleGivePhysicalAddress(command
);
80 case CEC_OPCODE_GIVE_OSD_NAME
:
81 HandleGiveOSDName(command
);
83 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
84 HandleGiveDeviceVendorId(command
);
86 case CEC_OPCODE_DEVICE_VENDOR_ID
:
87 bHandlerChanged
= HandleDeviceVendorId(command
);
89 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
90 HandleDeviceVendorCommandWithId(command
);
92 case CEC_OPCODE_GIVE_DECK_STATUS
:
93 HandleGiveDeckStatus(command
);
95 case CEC_OPCODE_DECK_CONTROL
:
96 HandleDeckControl(command
);
98 case CEC_OPCODE_MENU_REQUEST
:
99 HandleMenuRequest(command
);
101 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
102 HandleGiveDevicePowerStatus(command
);
104 case CEC_OPCODE_GET_CEC_VERSION
:
105 HandleGetCecVersion(command
);
107 case CEC_OPCODE_USER_CONTROL_PRESSED
:
108 HandleUserControlPressed(command
);
110 case CEC_OPCODE_USER_CONTROL_RELEASE
:
111 HandleUserControlRelease(command
);
113 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
114 HandleGiveAudioStatus(command
);
116 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
117 HandleGiveSystemAudioModeStatus(command
);
119 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
120 HandleSystemAudioModeRequest(command
);
122 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
123 HandleReportAudioStatus(command
);
125 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
126 HandleSystemAudioModeStatus(command
);
128 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
129 HandleSetSystemAudioMode(command
);
131 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
132 HandleRequestActiveSource(command
);
134 case CEC_OPCODE_SET_STREAM_PATH
:
135 HandleSetStreamPath(command
);
137 case CEC_OPCODE_ROUTING_CHANGE
:
138 HandleRoutingChange(command
);
140 case CEC_OPCODE_ROUTING_INFORMATION
:
141 HandleRoutingInformation(command
);
143 case CEC_OPCODE_STANDBY
:
144 HandleStandby(command
);
146 case CEC_OPCODE_ACTIVE_SOURCE
:
147 HandleActiveSource(command
);
149 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
150 HandleReportPhysicalAddress(command
);
152 case CEC_OPCODE_SET_OSD_NAME
:
153 HandleSetOSDName(command
);
155 case CEC_OPCODE_IMAGE_VIEW_ON
:
156 HandleImageViewOn(command
);
158 case CEC_OPCODE_TEXT_VIEW_ON
:
159 HandleTextViewOn(command
);
162 UnhandledCommand(command
);
167 if (bHandled
&& !bHandlerChanged
)
169 CLockObject
lock(&m_receiveMutex
);
170 m_condition
.Signal();
176 bool CCECCommandHandler::HandleActiveSource(const cec_command
&command
)
178 if (command
.parameters
.size
== 2)
180 uint16_t iAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
181 return m_processor
->SetStreamPath(iAddress
);
187 bool CCECCommandHandler::HandleDeckControl(const cec_command
&command
)
189 CCECBusDevice
*device
= GetDevice(command
.destination
);
190 if (device
&& (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
) && command
.parameters
.size
> 0)
192 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode((cec_deck_control_mode
) command
.parameters
[0]);
199 bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command
&command
)
201 if (command
.parameters
.size
== 1)
203 CCECBusDevice
*device
= GetDevice(command
.initiator
);
205 device
->SetCecVersion((cec_version
) command
.parameters
[0]);
211 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command
&command
)
213 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
214 m_processor
->TransmitAbort(command
.initiator
, command
.opcode
, CEC_ABORT_REASON_REFUSED
);
219 bool CCECCommandHandler::HandleDeviceVendorId(const cec_command
&command
)
221 return SetVendorId(command
);
224 bool CCECCommandHandler::HandleGetCecVersion(const cec_command
&command
)
226 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
228 CCECBusDevice
*device
= GetDevice(command
.destination
);
230 return device
->TransmitCECVersion(command
.initiator
);
236 bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command
&command
)
238 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
240 CCECBusDevice
*device
= GetDevice(command
.destination
);
241 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
242 return ((CCECAudioSystem
*) device
)->TransmitAudioStatus(command
.initiator
);
248 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command
&command
)
250 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
252 CCECBusDevice
*device
= GetDevice(command
.destination
);
253 if (device
&& (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
254 return ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(command
.initiator
);
260 bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command
&command
)
262 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
264 CCECBusDevice
*device
= GetDevice(command
.destination
);
266 return device
->TransmitPowerState(command
.initiator
);
272 bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command
&command
)
274 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
276 CCECBusDevice
*device
= GetDevice(command
.destination
);
278 return device
->TransmitVendorID(command
.initiator
);
284 bool CCECCommandHandler::HandleGiveOSDName(const cec_command
&command
)
286 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
288 CCECBusDevice
*device
= GetDevice(command
.destination
);
290 return device
->TransmitOSDName(command
.initiator
);
296 bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command
&command
)
298 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
300 CCECBusDevice
*device
= GetDevice(command
.destination
);
302 return device
->TransmitPhysicalAddress();
308 bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command
&command
)
310 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
312 CCECBusDevice
*device
= GetDevice(command
.destination
);
313 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
314 return ((CCECAudioSystem
*) device
)->TransmitSystemAudioModeStatus(command
.initiator
);
320 bool CCECCommandHandler::HandleImageViewOn(const cec_command
&command
)
322 m_processor
->SetStreamPath(m_processor
->m_busDevices
[command
.initiator
]->GetPhysicalAddress(false));
326 bool CCECCommandHandler::HandleMenuRequest(const cec_command
&command
)
328 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
330 if (command
.parameters
[0] == CEC_MENU_REQUEST_TYPE_QUERY
)
332 CCECBusDevice
*device
= GetDevice(command
.destination
);
334 return device
->TransmitMenuState(command
.initiator
);
341 bool CCECCommandHandler::HandleReportAudioStatus(const cec_command
&command
)
343 if (command
.parameters
.size
== 1)
345 CCECBusDevice
*device
= GetDevice(command
.initiator
);
346 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
348 ((CCECAudioSystem
*)device
)->SetAudioStatus(command
.parameters
[0]);
355 bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command
&command
)
357 if (command
.parameters
.size
== 3)
359 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
360 SetPhysicalAddress(command
.initiator
, iNewAddress
);
365 bool CCECCommandHandler::HandleReportPowerStatus(const cec_command
&command
)
367 if (command
.parameters
.size
== 1)
369 CCECBusDevice
*device
= GetDevice(command
.initiator
);
371 device
->SetPowerStatus((cec_power_status
) command
.parameters
[0]);
376 bool CCECCommandHandler::HandleRequestActiveSource(const cec_command
&command
)
378 if (m_processor
->IsStarted())
381 strLog
.Format(">> %i requests active source", (uint8_t) command
.initiator
);
382 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
384 vector
<CCECBusDevice
*> devices
;
385 for (int iDevicePtr
= (int)GetMyDevices(devices
)-1; iDevicePtr
>=0; iDevicePtr
--)
386 devices
[iDevicePtr
]->TransmitActiveSource();
393 bool CCECCommandHandler::HandleRoutingChange(const cec_command
&command
)
395 if (command
.parameters
.size
== 4)
397 uint16_t iOldAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
398 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[2] << 8) | ((uint16_t)command
.parameters
[3]);
400 CCECBusDevice
*device
= GetDevice(command
.initiator
);
402 device
->SetStreamPath(iNewAddress
, iOldAddress
);
407 bool CCECCommandHandler::HandleRoutingInformation(const cec_command
&command
)
409 if (command
.parameters
.size
== 2)
411 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
412 m_processor
->SetStreamPath(iNewAddress
);
418 bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command
&command
)
420 if (command
.parameters
.size
== 3)
422 CCECBusDevice
*device
= GetDevice(command
.initiator
);
425 cec_menu_language language
;
426 language
.device
= command
.initiator
;
427 for (uint8_t iPtr
= 0; iPtr
< 4; iPtr
++)
428 language
.language
[iPtr
] = command
.parameters
[iPtr
];
429 language
.language
[3] = 0;
430 device
->SetMenuLanguage(language
);
437 bool CCECCommandHandler::HandleSetOSDName(const cec_command
&command
)
439 if (command
.parameters
.size
> 0)
441 CCECBusDevice
*device
= GetDevice(command
.initiator
);
445 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
446 buf
[iPtr
] = (char)command
.parameters
[iPtr
];
447 buf
[command
.parameters
.size
] = 0;
449 CStdString
strName(buf
);
450 device
->SetOSDName(strName
);
458 bool CCECCommandHandler::HandleSetStreamPath(const cec_command
&command
)
460 if (m_processor
->IsStarted() && command
.parameters
.size
>= 2)
462 uint16_t iStreamAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
464 strLog
.Format(">> %i sets stream path to physical address %04x", command
.initiator
, iStreamAddress
);
465 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
467 if (m_processor
->SetStreamPath(iStreamAddress
))
469 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamAddress
);
472 return device
->TransmitActiveSource() &&
473 device
->TransmitMenuState(command
.initiator
);
480 bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command
&command
)
482 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
484 CCECBusDevice
*device
= GetDevice(command
.destination
);
485 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
487 if (command
.parameters
.size
>= 2)
489 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
490 ((CCECAudioSystem
*) device
)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON
);
491 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
492 CCECBusDevice
*newActiveDevice
= GetDeviceByPhysicalAddress(iNewAddress
);
494 m_processor
->SetStreamPath(newActiveDevice
->GetPhysicalAddress(false));
495 return ((CCECAudioSystem
*) device
)->TransmitSetSystemAudioMode(command
.initiator
);
499 ((CCECAudioSystem
*) device
)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF
);
500 return ((CCECAudioSystem
*) device
)->TransmitSetSystemAudioMode(command
.initiator
);
507 bool CCECCommandHandler::HandleStandby(const cec_command
&command
)
509 CCECBusDevice
*device
= GetDevice(command
.initiator
);
511 device
->SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
516 bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command
&command
)
518 if (command
.parameters
.size
== 1)
520 CCECBusDevice
*device
= GetDevice(command
.initiator
);
521 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
523 ((CCECAudioSystem
*)device
)->SetSystemAudioModeStatus((cec_system_audio_status
)command
.parameters
[0]);
531 bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command
&command
)
533 if (command
.parameters
.size
== 1)
535 CCECBusDevice
*device
= GetDevice(command
.initiator
);
536 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
538 ((CCECAudioSystem
*)device
)->SetSystemAudioModeStatus((cec_system_audio_status
)command
.parameters
[0]);
546 bool CCECCommandHandler::HandleTextViewOn(const cec_command
&command
)
548 m_processor
->SetStreamPath(m_processor
->m_busDevices
[command
.initiator
]->GetPhysicalAddress(false));
552 bool CCECCommandHandler::HandleUserControlPressed(const cec_command
&command
)
554 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
) && command
.parameters
.size
> 0)
556 m_processor
->AddKey();
558 if (command
.parameters
[0] <= CEC_USER_CONTROL_CODE_MAX
)
561 strLog
.Format("key pressed: %x", command
.parameters
[0]);
562 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
564 if (command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER
||
565 command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION
)
567 CCECBusDevice
*device
= GetDevice(command
.destination
);
569 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
572 m_processor
->SetCurrentButton((cec_user_control_code
) command
.parameters
[0]);
579 bool CCECCommandHandler::HandleUserControlRelease(const cec_command
&command
)
581 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
582 m_processor
->AddKey();
587 void CCECCommandHandler::UnhandledCommand(const cec_command
&command
)
590 strLog
.Format("unhandled command with opcode %02x from address %d", command
.opcode
, command
.initiator
);
591 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
);
594 unsigned int CCECCommandHandler::GetMyDevices(vector
<CCECBusDevice
*> &devices
) const
596 unsigned int iReturn(0);
598 cec_logical_addresses addresses
= m_processor
->GetLogicalAddresses();
599 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
603 devices
.push_back(GetDevice((cec_logical_address
) iPtr
));
611 CCECBusDevice
*CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress
) const
613 CCECBusDevice
*device
= NULL
;
615 if (iLogicalAddress
>= CECDEVICE_TV
&& iLogicalAddress
<= CECDEVICE_BROADCAST
)
616 device
= m_processor
->m_busDevices
[iLogicalAddress
];
621 CCECBusDevice
*CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
) const
623 return m_processor
->GetDeviceByPhysicalAddress(iPhysicalAddress
);
626 CCECBusDevice
*CCECCommandHandler::GetDeviceByType(cec_device_type type
) const
628 return m_processor
->GetDeviceByType(type
);
631 bool CCECCommandHandler::SetVendorId(const cec_command
&command
)
633 bool bChanged(false);
634 if (command
.parameters
.size
< 3)
636 m_busDevice
->AddLog(CEC_LOG_WARNING
, "invalid vendor ID received");
640 uint64_t iVendorId
= ((uint64_t)command
.parameters
[0] << 16) +
641 ((uint64_t)command
.parameters
[1] << 8) +
642 (uint64_t)command
.parameters
[2];
644 CCECBusDevice
*device
= GetDevice((cec_logical_address
) command
.initiator
);
646 bChanged
= device
->SetVendorId(iVendorId
);
650 void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress
, uint16_t iNewAddress
)
652 if (!m_busDevice
->MyLogicalAddressContains(iAddress
))
654 bool bOurAddress(m_processor
->GetPhysicalAddress() == iNewAddress
);
655 GetDevice(iAddress
)->SetPhysicalAddress(iNewAddress
);
658 /* another device reported the same physical address as ours
659 * since we don't have physical address detection yet, we'll just use the
660 * given address, increased by 0x100 for now */
661 m_processor
->SetPhysicalAddress(iNewAddress
+ 0x100);
666 void CCECCommandHandler::HandlePoll(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
669 strLog
.Format("<< POLL: %s (%x) -> %s (%x)", m_processor
->ToString(iInitiator
), iInitiator
, m_processor
->ToString(iDestination
), iDestination
);
670 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
673 bool CCECCommandHandler::HandleReceiveFailed(void)
675 /* default = error */
679 bool CCECCommandHandler::TransmitPowerOn(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
682 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_IMAGE_VIEW_ON
);
684 return Transmit(command
);
687 bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
690 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_STANDBY
);
692 return Transmit(command
);
695 bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
698 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GET_CEC_VERSION
);
700 return Transmit(command
);
703 bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
706 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GET_MENU_LANGUAGE
);
708 return Transmit(command
);
711 bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
714 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_OSD_NAME
);
716 return Transmit(command
);
719 bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
722 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
);
724 return Transmit(command
);
727 bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
730 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
);
732 return Transmit(command
);
735 bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
738 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
740 return Transmit(command
);
743 bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
746 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_ACTIVE_SOURCE
);
747 command
.parameters
.PushBack((uint8_t) ((iPhysicalAddress
>> 8) & 0xFF));
748 command
.parameters
.PushBack((uint8_t) (iPhysicalAddress
& 0xFF));
750 return Transmit(command
);
753 bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_version cecVersion
)
756 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_CEC_VERSION
);
757 command
.parameters
.PushBack((uint8_t)cecVersion
);
759 return Transmit(command
);
762 bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
765 cec_command::Format(command
, iInitiator
, CECDEVICE_TV
, CEC_OPCODE_INACTIVE_SOURCE
);
766 command
.parameters
.PushBack((iPhysicalAddress
>> 8) & 0xFF);
767 command
.parameters
.PushBack(iPhysicalAddress
& 0xFF);
769 return Transmit(command
);
772 bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_menu_state menuState
)
775 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_MENU_STATUS
);
776 command
.parameters
.PushBack((uint8_t)menuState
);
778 return Transmit(command
);
781 bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, CStdString strDeviceName
)
784 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_OSD_NAME
);
785 for (unsigned int iPtr
= 0; iPtr
< strDeviceName
.length(); iPtr
++)
786 command
.parameters
.PushBack(strDeviceName
.at(iPtr
));
788 return Transmit(command
);
791 bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_display_control duration
, const char *strMessage
)
794 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_OSD_STRING
);
795 command
.parameters
.PushBack((uint8_t)duration
);
797 unsigned int iLen
= strlen(strMessage
);
798 if (iLen
> 13) iLen
= 13;
800 for (unsigned int iPtr
= 0; iPtr
< iLen
; iPtr
++)
801 command
.parameters
.PushBack(strMessage
[iPtr
]);
803 return Transmit(command
);
806 bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
, cec_device_type type
)
809 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
);
810 command
.parameters
.PushBack((uint8_t) ((iPhysicalAddress
>> 8) & 0xFF));
811 command
.parameters
.PushBack((uint8_t) (iPhysicalAddress
& 0xFF));
812 command
.parameters
.PushBack((uint8_t) (type
));
814 return Transmit(command
);
817 bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
820 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_NONE
);
822 return Transmit(command
, false);
825 bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_power_status state
)
828 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_REPORT_POWER_STATUS
);
829 command
.parameters
.PushBack((uint8_t) state
);
831 return Transmit(command
);
834 bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator
, uint64_t iVendorId
)
837 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_DEVICE_VENDOR_ID
);
839 command
.parameters
.PushBack((uint8_t) (((uint64_t)iVendorId
>> 16) & 0xFF));
840 command
.parameters
.PushBack((uint8_t) (((uint64_t)iVendorId
>> 8) & 0xFF));
841 command
.parameters
.PushBack((uint8_t) ((uint64_t)iVendorId
& 0xFF));
843 return Transmit(command
);
846 bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, uint8_t state
)
849 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_REPORT_AUDIO_STATUS
);
850 command
.parameters
.PushBack(state
);
852 return Transmit(command
);
855 bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_system_audio_status state
)
858 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
);
859 command
.parameters
.PushBack((uint8_t)state
);
861 return Transmit(command
);
864 bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_system_audio_status state
)
867 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
);
868 command
.parameters
.PushBack((uint8_t)state
);
870 return Transmit(command
);
873 bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_deck_info state
)
876 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_DECK_STATUS
);
877 command
.PushBack((uint8_t)state
);
879 return Transmit(command
);
882 bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_user_control_code key
)
885 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_USER_CONTROL_PRESSED
);
886 command
.parameters
.PushBack((uint8_t)key
);
888 return Transmit(command
);
891 bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
894 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_USER_CONTROL_RELEASE
);
896 return Transmit(command
);
899 bool CCECCommandHandler::Transmit(cec_command
&command
, bool bExpectResponse
/* = true */)
901 command
.transmit_timeout
= m_iTransmitTimeout
;
902 if (command
.retries
== CEC_DEFAULT_TRANSMIT_RETRIES
)
903 command
.retries
= m_iTransmitRetries
;
905 CLockObject
writeLock(&m_processor
->m_transmitMutex
);
906 CLockObject
receiveLock(&m_receiveMutex
);
907 if (m_processor
->Transmit(command
))
910 return m_condition
.Wait(&m_receiveMutex
, m_iTransmitWait
);