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(1000)
49 CCECCommandHandler::~CCECCommandHandler(void)
51 m_condition
.Broadcast();
54 bool CCECCommandHandler::HandleCommand(const cec_command
&command
)
56 bool bHandled(true), bHandlerChanged(false);
59 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
);
60 m_busDevice
->AddLog(CEC_LOG_NOTICE
, strLog
);
62 m_processor
->AddCommand(command
);
64 switch(command
.opcode
)
66 case CEC_OPCODE_REPORT_POWER_STATUS
:
67 HandleReportPowerStatus(command
);
69 case CEC_OPCODE_CEC_VERSION
:
70 HandleDeviceCecVersion(command
);
72 case CEC_OPCODE_SET_MENU_LANGUAGE
:
73 HandleSetMenuLanguage(command
);
75 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
76 HandleGivePhysicalAddress(command
);
78 case CEC_OPCODE_GIVE_OSD_NAME
:
79 HandleGiveOSDName(command
);
81 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
82 HandleGiveDeviceVendorId(command
);
84 case CEC_OPCODE_DEVICE_VENDOR_ID
:
85 bHandlerChanged
= HandleDeviceVendorId(command
);
87 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
88 HandleDeviceVendorCommandWithId(command
);
90 case CEC_OPCODE_GIVE_DECK_STATUS
:
91 HandleGiveDeckStatus(command
);
93 case CEC_OPCODE_DECK_CONTROL
:
94 HandleDeckControl(command
);
96 case CEC_OPCODE_MENU_REQUEST
:
97 HandleMenuRequest(command
);
99 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
100 HandleGiveDevicePowerStatus(command
);
102 case CEC_OPCODE_GET_CEC_VERSION
:
103 HandleGetCecVersion(command
);
105 case CEC_OPCODE_USER_CONTROL_PRESSED
:
106 HandleUserControlPressed(command
);
108 case CEC_OPCODE_USER_CONTROL_RELEASE
:
109 HandleUserControlRelease(command
);
111 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
112 HandleGiveAudioStatus(command
);
114 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
115 HandleGiveSystemAudioModeStatus(command
);
117 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
118 HandleSystemAudioModeRequest(command
);
120 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
121 HandleReportAudioStatus(command
);
123 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
124 HandleSystemAudioModeStatus(command
);
126 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
127 HandleSetSystemAudioMode(command
);
129 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
130 HandleRequestActiveSource(command
);
132 case CEC_OPCODE_SET_STREAM_PATH
:
133 HandleSetStreamPath(command
);
135 case CEC_OPCODE_ROUTING_CHANGE
:
136 HandleRoutingChange(command
);
138 case CEC_OPCODE_ROUTING_INFORMATION
:
139 HandleRoutingInformation(command
);
141 case CEC_OPCODE_STANDBY
:
142 HandleStandby(command
);
144 case CEC_OPCODE_ACTIVE_SOURCE
:
145 HandleActiveSource(command
);
147 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
148 HandleReportPhysicalAddress(command
);
150 case CEC_OPCODE_SET_OSD_NAME
:
151 HandleSetOSDName(command
);
153 case CEC_OPCODE_IMAGE_VIEW_ON
:
154 HandleImageViewOn(command
);
156 case CEC_OPCODE_TEXT_VIEW_ON
:
157 HandleTextViewOn(command
);
160 UnhandledCommand(command
);
165 if (bHandled
&& !bHandlerChanged
)
167 CLockObject
lock(&m_processor
->m_transmitMutex
);
168 m_condition
.Signal();
174 bool CCECCommandHandler::HandleActiveSource(const cec_command
&command
)
176 if (command
.parameters
.size
== 2)
178 uint16_t iAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
179 return m_processor
->SetStreamPath(iAddress
);
185 bool CCECCommandHandler::HandleDeckControl(const cec_command
&command
)
187 CCECBusDevice
*device
= GetDevice(command
.destination
);
188 if (device
&& (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
) && command
.parameters
.size
> 0)
190 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode((cec_deck_control_mode
) command
.parameters
[0]);
197 bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command
&command
)
199 if (command
.parameters
.size
== 1)
201 CCECBusDevice
*device
= GetDevice(command
.initiator
);
203 device
->SetCecVersion((cec_version
) command
.parameters
[0]);
209 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command
&command
)
211 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
212 m_processor
->TransmitAbort(command
.initiator
, command
.opcode
, CEC_ABORT_REASON_REFUSED
);
217 bool CCECCommandHandler::HandleDeviceVendorId(const cec_command
&command
)
219 return SetVendorId(command
);
222 bool CCECCommandHandler::HandleGetCecVersion(const cec_command
&command
)
224 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
226 CCECBusDevice
*device
= GetDevice(command
.destination
);
228 return device
->TransmitCECVersion(command
.initiator
);
234 bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command
&command
)
236 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
238 CCECBusDevice
*device
= GetDevice(command
.destination
);
239 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
240 return ((CCECAudioSystem
*) device
)->TransmitAudioStatus(command
.initiator
);
246 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command
&command
)
248 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
250 CCECBusDevice
*device
= GetDevice(command
.destination
);
251 if (device
&& (device
->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| device
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
))
252 return ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(command
.initiator
);
258 bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command
&command
)
260 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
262 CCECBusDevice
*device
= GetDevice(command
.destination
);
264 return device
->TransmitPowerState(command
.initiator
);
270 bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command
&command
)
272 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
274 CCECBusDevice
*device
= GetDevice(command
.destination
);
276 return device
->TransmitVendorID(command
.initiator
);
282 bool CCECCommandHandler::HandleGiveOSDName(const cec_command
&command
)
284 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
286 CCECBusDevice
*device
= GetDevice(command
.destination
);
288 return device
->TransmitOSDName(command
.initiator
);
294 bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command
&command
)
296 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
298 CCECBusDevice
*device
= GetDevice(command
.destination
);
300 return device
->TransmitPhysicalAddress();
306 bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command
&command
)
308 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
310 CCECBusDevice
*device
= GetDevice(command
.destination
);
311 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
312 return ((CCECAudioSystem
*) device
)->TransmitSystemAudioModeStatus(command
.initiator
);
318 bool CCECCommandHandler::HandleImageViewOn(const cec_command
&command
)
320 m_processor
->SetActiveSource(command
.initiator
);
324 bool CCECCommandHandler::HandleMenuRequest(const cec_command
&command
)
326 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
328 if (command
.parameters
[0] == CEC_MENU_REQUEST_TYPE_QUERY
)
330 CCECBusDevice
*device
= GetDevice(command
.destination
);
332 return device
->TransmitMenuState(command
.initiator
);
339 bool CCECCommandHandler::HandleReportAudioStatus(const cec_command
&command
)
341 if (command
.parameters
.size
== 1)
343 CCECBusDevice
*device
= GetDevice(command
.initiator
);
344 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
346 ((CCECAudioSystem
*)device
)->SetAudioStatus(command
.parameters
[0]);
353 bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command
&command
)
355 if (command
.parameters
.size
== 3)
357 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
358 SetPhysicalAddress(command
.initiator
, iNewAddress
);
363 bool CCECCommandHandler::HandleReportPowerStatus(const cec_command
&command
)
365 if (command
.parameters
.size
== 1)
367 CCECBusDevice
*device
= GetDevice(command
.initiator
);
369 device
->SetPowerStatus((cec_power_status
) command
.parameters
[0]);
374 bool CCECCommandHandler::HandleRequestActiveSource(const cec_command
&command
)
377 strLog
.Format(">> %i requests active source", (uint8_t) command
.initiator
);
378 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
380 vector
<CCECBusDevice
*> devices
;
381 for (int iDevicePtr
= (int)GetMyDevices(devices
)-1; iDevicePtr
>=0; iDevicePtr
--)
382 devices
[iDevicePtr
]->TransmitActiveSource();
387 bool CCECCommandHandler::HandleRoutingChange(const cec_command
&command
)
389 if (command
.parameters
.size
== 4)
391 uint16_t iOldAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
392 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[2] << 8) | ((uint16_t)command
.parameters
[3]);
394 CCECBusDevice
*device
= GetDevice(command
.initiator
);
396 device
->SetStreamPath(iNewAddress
, iOldAddress
);
401 bool CCECCommandHandler::HandleRoutingInformation(const cec_command
&command
)
403 if (command
.parameters
.size
== 2)
405 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
406 m_processor
->SetStreamPath(iNewAddress
);
412 bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command
&command
)
414 if (command
.parameters
.size
== 3)
416 CCECBusDevice
*device
= GetDevice(command
.initiator
);
419 cec_menu_language language
;
420 language
.device
= command
.initiator
;
421 for (uint8_t iPtr
= 0; iPtr
< 4; iPtr
++)
422 language
.language
[iPtr
] = command
.parameters
[iPtr
];
423 language
.language
[3] = 0;
424 device
->SetMenuLanguage(language
);
431 bool CCECCommandHandler::HandleSetOSDName(const cec_command
&command
)
433 if (command
.parameters
.size
> 0)
435 CCECBusDevice
*device
= GetDevice(command
.initiator
);
439 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
440 buf
[iPtr
] = (char)command
.parameters
[iPtr
];
441 buf
[command
.parameters
.size
] = 0;
443 CStdString
strName(buf
);
444 device
->SetOSDName(strName
);
452 bool CCECCommandHandler::HandleSetStreamPath(const cec_command
&command
)
454 if (command
.parameters
.size
>= 2)
456 uint16_t iStreamAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
458 strLog
.Format(">> %i sets stream path to physical address %04x", command
.initiator
, iStreamAddress
);
459 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
461 if (m_processor
->SetStreamPath(iStreamAddress
))
463 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamAddress
);
466 return device
->TransmitActiveSource() &&
467 device
->TransmitMenuState(command
.initiator
);
474 bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command
&command
)
476 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
478 CCECBusDevice
*device
= GetDevice(command
.destination
);
479 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
481 if (command
.parameters
.size
>= 2)
483 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
484 ((CCECAudioSystem
*) device
)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON
);
485 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
486 CCECBusDevice
*newActiveDevice
= GetDeviceByPhysicalAddress(iNewAddress
);
488 m_processor
->SetActiveSource(newActiveDevice
->GetLogicalAddress());
489 return ((CCECAudioSystem
*) device
)->TransmitSetSystemAudioMode(command
.initiator
);
493 ((CCECAudioSystem
*) device
)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF
);
494 return ((CCECAudioSystem
*) device
)->TransmitSetSystemAudioMode(command
.initiator
);
501 bool CCECCommandHandler::HandleStandby(const cec_command
&command
)
503 CCECBusDevice
*device
= GetDevice(command
.initiator
);
505 device
->SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
510 bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command
&command
)
512 if (command
.parameters
.size
== 1)
514 CCECBusDevice
*device
= GetDevice(command
.initiator
);
515 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
517 ((CCECAudioSystem
*)device
)->SetSystemAudioModeStatus((cec_system_audio_status
)command
.parameters
[0]);
525 bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command
&command
)
527 if (command
.parameters
.size
== 1)
529 CCECBusDevice
*device
= GetDevice(command
.initiator
);
530 if (device
&& device
->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
532 ((CCECAudioSystem
*)device
)->SetSystemAudioModeStatus((cec_system_audio_status
)command
.parameters
[0]);
540 bool CCECCommandHandler::HandleTextViewOn(const cec_command
&command
)
542 m_processor
->SetActiveSource(command
.initiator
);
546 bool CCECCommandHandler::HandleUserControlPressed(const cec_command
&command
)
548 if (m_busDevice
->MyLogicalAddressContains(command
.destination
) && command
.parameters
.size
> 0)
550 m_processor
->AddKey();
552 if (command
.parameters
[0] <= CEC_USER_CONTROL_CODE_MAX
)
555 strLog
.Format("key pressed: %x", command
.parameters
[0]);
556 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
558 if (command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER
||
559 command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION
)
561 CCECBusDevice
*device
= GetDevice(command
.destination
);
563 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
566 m_processor
->SetCurrentButton((cec_user_control_code
) command
.parameters
[0]);
573 bool CCECCommandHandler::HandleUserControlRelease(const cec_command
&command
)
575 if (m_busDevice
->MyLogicalAddressContains(command
.destination
))
576 m_processor
->AddKey();
581 void CCECCommandHandler::UnhandledCommand(const cec_command
&command
)
584 strLog
.Format("unhandled command with opcode %02x from address %d", command
.opcode
, command
.initiator
);
585 m_busDevice
->AddLog(CEC_LOG_DEBUG
, strLog
);
588 unsigned int CCECCommandHandler::GetMyDevices(vector
<CCECBusDevice
*> &devices
) const
590 unsigned int iReturn(0);
592 cec_logical_addresses addresses
= m_processor
->GetLogicalAddresses();
593 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
597 devices
.push_back(GetDevice((cec_logical_address
) iPtr
));
605 CCECBusDevice
*CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress
) const
607 CCECBusDevice
*device
= NULL
;
609 if (iLogicalAddress
>= CECDEVICE_TV
&& iLogicalAddress
<= CECDEVICE_BROADCAST
)
610 device
= m_processor
->m_busDevices
[iLogicalAddress
];
615 CCECBusDevice
*CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
) const
617 return m_processor
->GetDeviceByPhysicalAddress(iPhysicalAddress
);
620 CCECBusDevice
*CCECCommandHandler::GetDeviceByType(cec_device_type type
) const
622 return m_processor
->GetDeviceByType(type
);
625 bool CCECCommandHandler::SetVendorId(const cec_command
&command
)
627 bool bChanged(false);
628 if (command
.parameters
.size
< 3)
630 m_busDevice
->AddLog(CEC_LOG_WARNING
, "invalid vendor ID received");
634 uint64_t iVendorId
= ((uint64_t)command
.parameters
[0] << 16) +
635 ((uint64_t)command
.parameters
[1] << 8) +
636 (uint64_t)command
.parameters
[2];
638 CCECBusDevice
*device
= GetDevice((cec_logical_address
) command
.initiator
);
640 bChanged
= device
->SetVendorId(iVendorId
);
644 void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress
, uint16_t iNewAddress
)
646 if (!m_busDevice
->MyLogicalAddressContains(iAddress
))
648 bool bOurAddress(m_processor
->GetPhysicalAddress() == iNewAddress
);
649 GetDevice(iAddress
)->SetPhysicalAddress(iNewAddress
);
652 /* another device reported the same physical address as ours
653 * since we don't have physical address detection yet, we'll just use the
654 * given address, increased by 0x100 for now */
655 m_processor
->SetPhysicalAddress(iNewAddress
+ 0x100);
660 void CCECCommandHandler::HandlePoll(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
663 strLog
.Format("<< POLL: %s (%x) -> %s (%x)", m_processor
->ToString(iInitiator
), iInitiator
, m_processor
->ToString(iDestination
), iDestination
);
664 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
667 bool CCECCommandHandler::HandleReceiveFailed(void)
669 /* default = error */
673 bool CCECCommandHandler::TransmitPowerOn(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
676 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_IMAGE_VIEW_ON
, m_iTransmitTimeout
);
678 return Transmit(command
);
681 bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
684 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_STANDBY
, m_iTransmitTimeout
);
686 return Transmit(command
);
689 bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
692 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GET_CEC_VERSION
, m_iTransmitTimeout
);
694 return Transmit(command
);
697 bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
700 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GET_MENU_LANGUAGE
, m_iTransmitTimeout
);
702 return Transmit(command
);
705 bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
708 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_OSD_NAME
, m_iTransmitTimeout
);
710 return Transmit(command
);
713 bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
716 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
, m_iTransmitTimeout
);
718 return Transmit(command
);
721 bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
724 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
, m_iTransmitTimeout
);
726 return Transmit(command
);
729 bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
732 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
, m_iTransmitTimeout
);
734 return Transmit(command
);
737 bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
740 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_ACTIVE_SOURCE
, m_iTransmitTimeout
);
741 command
.parameters
.PushBack((uint8_t) ((iPhysicalAddress
>> 8) & 0xFF));
742 command
.parameters
.PushBack((uint8_t) (iPhysicalAddress
& 0xFF));
744 return Transmit(command
);
747 bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_version cecVersion
)
750 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_CEC_VERSION
, m_iTransmitTimeout
);
751 command
.parameters
.PushBack((uint8_t)cecVersion
);
753 return Transmit(command
);
756 bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
759 cec_command::Format(command
, iInitiator
, CECDEVICE_TV
, CEC_OPCODE_INACTIVE_SOURCE
, m_iTransmitTimeout
);
760 command
.parameters
.PushBack((iPhysicalAddress
>> 8) & 0xFF);
761 command
.parameters
.PushBack(iPhysicalAddress
& 0xFF);
763 return Transmit(command
);
766 bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_menu_state menuState
)
769 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_MENU_STATUS
, m_iTransmitTimeout
);
770 command
.parameters
.PushBack((uint8_t)menuState
);
772 return Transmit(command
);
775 bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, CStdString strDeviceName
)
778 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_OSD_NAME
, m_iTransmitTimeout
);
779 for (unsigned int iPtr
= 0; iPtr
< strDeviceName
.length(); iPtr
++)
780 command
.parameters
.PushBack(strDeviceName
.at(iPtr
));
782 return Transmit(command
);
785 bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_display_control duration
, const char *strMessage
)
788 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_OSD_STRING
, m_iTransmitTimeout
);
789 command
.parameters
.PushBack((uint8_t)duration
);
791 unsigned int iLen
= strlen(strMessage
);
792 if (iLen
> 13) iLen
= 13;
794 for (unsigned int iPtr
= 0; iPtr
< iLen
; iPtr
++)
795 command
.parameters
.PushBack(strMessage
[iPtr
]);
797 return Transmit(command
);
800 bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
, cec_device_type type
)
803 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
, m_iTransmitTimeout
);
804 command
.parameters
.PushBack((uint8_t) ((iPhysicalAddress
>> 8) & 0xFF));
805 command
.parameters
.PushBack((uint8_t) (iPhysicalAddress
& 0xFF));
806 command
.parameters
.PushBack((uint8_t) (type
));
808 return Transmit(command
);
811 bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
814 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_NONE
, m_iTransmitTimeout
);
817 return Transmit(command
);
820 bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_power_status state
)
823 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_REPORT_POWER_STATUS
, m_iTransmitTimeout
);
824 command
.parameters
.PushBack((uint8_t) state
);
826 return Transmit(command
);
829 bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator
, uint64_t iVendorId
)
832 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_DEVICE_VENDOR_ID
, m_iTransmitTimeout
);
834 command
.parameters
.PushBack((uint8_t) (((uint64_t)iVendorId
>> 16) & 0xFF));
835 command
.parameters
.PushBack((uint8_t) (((uint64_t)iVendorId
>> 8) & 0xFF));
836 command
.parameters
.PushBack((uint8_t) ((uint64_t)iVendorId
& 0xFF));
838 return Transmit(command
);
841 bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, uint8_t state
)
844 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_REPORT_AUDIO_STATUS
, m_iTransmitTimeout
);
845 command
.parameters
.PushBack(state
);
847 return Transmit(command
);
850 bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_system_audio_status state
)
853 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
, m_iTransmitTimeout
);
854 command
.parameters
.PushBack((uint8_t)state
);
856 return Transmit(command
);
859 bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_system_audio_status state
)
862 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
, m_iTransmitTimeout
);
863 command
.parameters
.PushBack((uint8_t)state
);
865 return Transmit(command
);
868 bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_deck_info state
)
871 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_DECK_STATUS
, m_iTransmitTimeout
);
872 command
.PushBack((uint8_t)state
);
874 return Transmit(command
);
877 bool CCECCommandHandler::SendKeypress(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_user_control_code key
)
880 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_USER_CONTROL_PRESSED
, m_iTransmitTimeout
);
881 command
.parameters
.PushBack((uint8_t)key
);
883 return Transmit(command
);
886 bool CCECCommandHandler::SendKeyRelease(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
889 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_USER_CONTROL_RELEASE
, m_iTransmitTimeout
);
891 return Transmit(command
);
894 bool CCECCommandHandler::Transmit(cec_command
&command
)
896 CLockObject
writeLock(&m_processor
->m_transmitMutex
);
897 if (m_processor
->Transmit(command
))
898 return m_condition
.Wait(&m_processor
->m_transmitMutex
, m_iTransmitTimeout
);