cec: added GetResponseOpcode(cec_opcode opcode) to cec_command
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
CommitLineData
e9de9629
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
b492c10e 4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
e9de9629
LOK
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 "CECCommandHandler.h"
eafa9d46 34#include "../devices/CECBusDevice.h"
a1f8fb1b 35#include "../devices/CECAudioSystem.h"
28089abc 36#include "../devices/CECPlaybackDevice.h"
387b6f6f 37#include "../CECProcessor.h"
5477a250 38#include "../LibCEC.h"
e9de9629
LOK
39
40using namespace CEC;
8747dd4f 41using namespace std;
f00ff009 42using namespace PLATFORM;
e9de9629 43
8fa35473
LOK
44CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
45 m_busDevice(busDevice),
46 m_processor(m_busDevice->GetProcessor()),
ae693aaa
LOK
47 m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT),
48 m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT),
89a726fa 49 m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES),
b64db02e 50 m_bHandlerInited(false),
d79b67d8 51 m_bOPTSendDeckStatusUpdateOnActiveSource(false),
960f33c6 52 m_vendorId(CEC_VENDOR_UNKNOWN),
24dd566c 53 m_waitForResponse(new CWaitForResponse)
e9de9629 54{
8fa35473
LOK
55}
56
57CCECCommandHandler::~CCECCommandHandler(void)
58{
24dd566c 59 delete m_waitForResponse;
e9de9629
LOK
60}
61
62bool CCECCommandHandler::HandleCommand(const cec_command &command)
63{
d297cbd4
LOK
64 if (command.opcode_set == 0)
65 return HandlePoll(command);
66
3e61b350 67 bool bHandled(true);
e9de9629 68
02e7043e 69 CLibCEC::AddCommand(command);
855a3a98 70
6b72afcd 71 switch(command.opcode)
e9de9629 72 {
6b72afcd
LOK
73 case CEC_OPCODE_REPORT_POWER_STATUS:
74 HandleReportPowerStatus(command);
75 break;
76 case CEC_OPCODE_CEC_VERSION:
77 HandleDeviceCecVersion(command);
78 break;
79 case CEC_OPCODE_SET_MENU_LANGUAGE:
80 HandleSetMenuLanguage(command);
81 break;
82 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
3e61b350
LOK
83 if (m_processor->IsInitialised())
84 HandleGivePhysicalAddress(command);
6b72afcd 85 break;
fbdea54c
MK
86 case CEC_OPCODE_GET_MENU_LANGUAGE:
87 if (m_processor->IsInitialised())
88 HandleGiveMenuLanguage(command);
89 break;
6b72afcd 90 case CEC_OPCODE_GIVE_OSD_NAME:
3e61b350
LOK
91 if (m_processor->IsInitialised())
92 HandleGiveOSDName(command);
6b72afcd
LOK
93 break;
94 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
3e61b350
LOK
95 if (m_processor->IsInitialised())
96 HandleGiveDeviceVendorId(command);
6b72afcd
LOK
97 break;
98 case CEC_OPCODE_DEVICE_VENDOR_ID:
3e61b350 99 HandleDeviceVendorId(command);
6b72afcd
LOK
100 break;
101 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
102 HandleDeviceVendorCommandWithId(command);
103 break;
104 case CEC_OPCODE_GIVE_DECK_STATUS:
3e61b350
LOK
105 if (m_processor->IsInitialised())
106 HandleGiveDeckStatus(command);
6b72afcd
LOK
107 break;
108 case CEC_OPCODE_DECK_CONTROL:
109 HandleDeckControl(command);
110 break;
111 case CEC_OPCODE_MENU_REQUEST:
3e61b350
LOK
112 if (m_processor->IsInitialised())
113 HandleMenuRequest(command);
6b72afcd
LOK
114 break;
115 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
3e61b350
LOK
116 if (m_processor->IsInitialised())
117 HandleGiveDevicePowerStatus(command);
6b72afcd
LOK
118 break;
119 case CEC_OPCODE_GET_CEC_VERSION:
3e61b350
LOK
120 if (m_processor->IsInitialised())
121 HandleGetCecVersion(command);
6b72afcd
LOK
122 break;
123 case CEC_OPCODE_USER_CONTROL_PRESSED:
3e61b350
LOK
124 if (m_processor->IsInitialised())
125 HandleUserControlPressed(command);
6b72afcd
LOK
126 break;
127 case CEC_OPCODE_USER_CONTROL_RELEASE:
3e61b350
LOK
128 if (m_processor->IsInitialised())
129 HandleUserControlRelease(command);
6b72afcd
LOK
130 break;
131 case CEC_OPCODE_GIVE_AUDIO_STATUS:
3e61b350
LOK
132 if (m_processor->IsInitialised())
133 HandleGiveAudioStatus(command);
6b72afcd
LOK
134 break;
135 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
3e61b350
LOK
136 if (m_processor->IsInitialised())
137 HandleGiveSystemAudioModeStatus(command);
6b72afcd
LOK
138 break;
139 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
3e61b350
LOK
140 if (m_processor->IsInitialised())
141 HandleSystemAudioModeRequest(command);
aa517a0d
LOK
142 break;
143 case CEC_OPCODE_REPORT_AUDIO_STATUS:
855a3a98 144 HandleReportAudioStatus(command);
aa517a0d
LOK
145 break;
146 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
855a3a98 147 HandleSystemAudioModeStatus(command);
aa517a0d
LOK
148 break;
149 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
855a3a98 150 HandleSetSystemAudioMode(command);
6b72afcd
LOK
151 break;
152 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
3e61b350
LOK
153 if (m_processor->IsInitialised())
154 HandleRequestActiveSource(command);
6b72afcd
LOK
155 break;
156 case CEC_OPCODE_SET_STREAM_PATH:
157 HandleSetStreamPath(command);
158 break;
159 case CEC_OPCODE_ROUTING_CHANGE:
160 HandleRoutingChange(command);
161 break;
907bd60f
LOK
162 case CEC_OPCODE_ROUTING_INFORMATION:
163 HandleRoutingInformation(command);
164 break;
6b72afcd 165 case CEC_OPCODE_STANDBY:
3e61b350
LOK
166 if (m_processor->IsInitialised())
167 HandleStandby(command);
6b72afcd
LOK
168 break;
169 case CEC_OPCODE_ACTIVE_SOURCE:
170 HandleActiveSource(command);
171 break;
907bd60f
LOK
172 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
173 HandleReportPhysicalAddress(command);
174 break;
15d1a84c
LOK
175 case CEC_OPCODE_SET_OSD_NAME:
176 HandleSetOSDName(command);
177 break;
1a6669b8
LOK
178 case CEC_OPCODE_IMAGE_VIEW_ON:
179 HandleImageViewOn(command);
180 break;
181 case CEC_OPCODE_TEXT_VIEW_ON:
182 HandleTextViewOn(command);
183 break;
4d738fe3
LOK
184 case CEC_OPCODE_FEATURE_ABORT:
185 HandleFeatureAbort(command);
186 break;
468a1414
LOK
187 case CEC_OPCODE_VENDOR_COMMAND:
188 HandleVendorCommand(command);
189 break;
6b72afcd
LOK
190 default:
191 UnhandledCommand(command);
e9de9629 192 bHandled = false;
6b72afcd 193 break;
e9de9629
LOK
194 }
195
3e61b350 196 if (bHandled)
24dd566c 197 m_waitForResponse->Received((command.opcode == CEC_OPCODE_FEATURE_ABORT && command.parameters.size > 0) ? (cec_opcode)command.parameters[0] : command.opcode);
8fa35473 198
e9de9629
LOK
199 return bHandled;
200}
201
be5b0e24
LOK
202bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
203{
204 if (command.parameters.size == 2)
205 {
206 uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
37b0c572 207 return m_processor->SetActiveSource(iAddress);
be5b0e24
LOK
208 }
209
210 return true;
211}
212
a9232a79
LOK
213bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
214{
215 CCECBusDevice *device = GetDevice(command.destination);
88e5de6f 216 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0)
a9232a79
LOK
217 {
218 ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
219 return true;
220 }
221
222 return false;
223}
224
6a1c0009
LOK
225bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
226{
227 if (command.parameters.size == 1)
228 {
229 CCECBusDevice *device = GetDevice(command.initiator);
230 if (device)
231 device->SetCecVersion((cec_version) command.parameters[0]);
232 }
233
234 return true;
235}
236
e9de9629
LOK
237bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
238{
8e57f83c 239 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
fcf10e27 240 m_processor->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
6b72afcd 241
6a1c0009 242 return true;
e9de9629
LOK
243}
244
245bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
246{
8fa35473 247 return SetVendorId(command);
e9de9629
LOK
248}
249
4d738fe3
LOK
250bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command)
251{
69a1a673
LOK
252 if (command.parameters.size == 2 &&
253 (command.parameters[1] == CEC_ABORT_REASON_UNRECOGNIZED_OPCODE ||
254 command.parameters[1] == CEC_ABORT_REASON_REFUSED))
4d738fe3 255 m_processor->m_busDevices[command.initiator]->SetUnsupportedFeature((cec_opcode)command.parameters[0]);
7de6ad36 256 return true;
4d738fe3
LOK
257}
258
e9de9629
LOK
259bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
260{
8e57f83c 261 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
262 {
263 CCECBusDevice *device = GetDevice(command.destination);
264 if (device)
265 return device->TransmitCECVersion(command.initiator);
266 }
0f23c85c
LOK
267
268 return false;
e9de9629
LOK
269}
270
a1f8fb1b
LOK
271bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
272{
8e57f83c 273 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
274 {
275 CCECBusDevice *device = GetDevice(command.destination);
276 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
277 return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator);
278 }
a1f8fb1b
LOK
279
280 return false;
281}
282
e9de9629
LOK
283bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
284{
8e57f83c 285 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
286 {
287 CCECBusDevice *device = GetDevice(command.destination);
288 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
289 return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator);
290 }
0f23c85c
LOK
291
292 return false;
e9de9629
LOK
293}
294
295bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
296{
8e57f83c 297 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
298 {
299 CCECBusDevice *device = GetDevice(command.destination);
300 if (device)
301 return device->TransmitPowerState(command.initiator);
302 }
0f23c85c
LOK
303
304 return false;
e9de9629
LOK
305}
306
307bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
308{
8e57f83c 309 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
310 {
311 CCECBusDevice *device = GetDevice(command.destination);
312 if (device)
313 return device->TransmitVendorID(command.initiator);
314 }
0f23c85c
LOK
315
316 return false;
e9de9629
LOK
317}
318
319bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
320{
8e57f83c 321 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
322 {
323 CCECBusDevice *device = GetDevice(command.destination);
324 if (device)
325 return device->TransmitOSDName(command.initiator);
326 }
0f23c85c
LOK
327
328 return false;
e9de9629
LOK
329}
330
331bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
332{
8e57f83c 333 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
6b72afcd
LOK
334 {
335 CCECBusDevice *device = GetDevice(command.destination);
336 if (device)
7656096e 337 return device->TransmitPhysicalAddress();
6b72afcd 338 }
09c10b66
LOK
339
340 return false;
e9de9629
LOK
341}
342
fbdea54c
MK
343bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command)
344{
345 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
346 {
347 CCECBusDevice *device = GetDevice(command.destination);
348 if (device)
349 return device->TransmitSetMenuLanguage(command.initiator);
350 }
351
352 return false;
353}
354
1a6669b8
LOK
355bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
356{
8e57f83c 357 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
1a6669b8
LOK
358 {
359 CCECBusDevice *device = GetDevice(command.destination);
360 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
361 return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
362 }
363
364 return false;
365}
366
367bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
368{
37b0c572 369 m_processor->m_busDevices[command.initiator]->SetActiveSource();
1a6669b8
LOK
370 return true;
371}
372
e9de9629
LOK
373bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
374{
8e57f83c 375 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
0f23c85c 376 {
e1804a4e
LOK
377 CCECBusDevice *device = GetDevice(command.destination);
378 if (device)
6b72afcd 379 {
e1804a4e
LOK
380 if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_ACTIVATE)
381 {
382 if (CLibCEC::MenuStateChanged(CEC_MENU_STATE_ACTIVATED) == 1)
383 device->SetMenuState(CEC_MENU_STATE_ACTIVATED);
384 }
385 else if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_DEACTIVATE)
386 {
387 if (CLibCEC::MenuStateChanged(CEC_MENU_STATE_DEACTIVATED) == 1)
388 device->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
389 }
390 return device->TransmitMenuState(command.initiator);
6b72afcd 391 }
15d1a84c
LOK
392 }
393
394 return false;
395}
396
d297cbd4
LOK
397bool CCECCommandHandler::HandlePoll(const cec_command &command)
398{
a75e3a5a 399 m_busDevice->HandlePoll(command.destination);
d297cbd4
LOK
400 return true;
401}
402
15d1a84c
LOK
403bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command)
404{
405 if (command.parameters.size == 1)
406 {
407 CCECBusDevice *device = GetDevice(command.initiator);
408 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
6b72afcd 409 {
15d1a84c
LOK
410 ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]);
411 return true;
6b72afcd 412 }
0f23c85c
LOK
413 }
414 return false;
e9de9629
LOK
415}
416
907bd60f
LOK
417bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
418{
0bfce006 419 if (command.parameters.size == 3)
907bd60f
LOK
420 {
421 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
16b1e052 422 SetPhysicalAddress(command.initiator, iNewAddress);
907bd60f
LOK
423 }
424 return true;
425}
426
e55f3f70
LOK
427bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command)
428{
429 if (command.parameters.size == 1)
430 {
431 CCECBusDevice *device = GetDevice(command.initiator);
432 if (device)
433 device->SetPowerStatus((cec_power_status) command.parameters[0]);
434 }
435 return true;
436}
437
e9de9629
LOK
438bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
439{
8e57f83c 440 if (m_processor->IsRunning())
5f316715 441 {
5477a250 442 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator);
8747dd4f 443
5f316715 444 vector<CCECBusDevice *> devices;
f00ff009 445 for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++)
5f316715 446 devices[iDevicePtr]->TransmitActiveSource();
c4098482 447
5f316715
LOK
448 return true;
449 }
450 return false;
e9de9629
LOK
451}
452
453bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
454{
455 if (command.parameters.size == 4)
456 {
457 uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
458 uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]);
e9de9629 459
0f23c85c
LOK
460 CCECBusDevice *device = GetDevice(command.initiator);
461 if (device)
9dc04b07 462 device->SetStreamPath(iNewAddress, iOldAddress);
e9de9629
LOK
463 }
464 return true;
465}
466
907bd60f
LOK
467bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command)
468{
469 if (command.parameters.size == 2)
470 {
471 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
37b0c572 472 m_processor->SetActiveSource(iNewAddress);
907bd60f 473 }
15d1a84c
LOK
474
475 return false;
907bd60f
LOK
476}
477
a3269a0a
LOK
478bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
479{
480 if (command.parameters.size == 3)
481 {
482 CCECBusDevice *device = GetDevice(command.initiator);
483 if (device)
484 {
485 cec_menu_language language;
486 language.device = command.initiator;
56701628 487 for (uint8_t iPtr = 0; iPtr < 4; iPtr++)
a3269a0a
LOK
488 language.language[iPtr] = command.parameters[iPtr];
489 language.language[3] = 0;
490 device->SetMenuLanguage(language);
15d1a84c
LOK
491 return true;
492 }
493 }
494 return false;
495}
496
497bool CCECCommandHandler::HandleSetOSDName(const cec_command &command)
498{
499 if (command.parameters.size > 0)
500 {
501 CCECBusDevice *device = GetDevice(command.initiator);
502 if (device)
503 {
504 char buf[1024];
505 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
506 buf[iPtr] = (char)command.parameters[iPtr];
507 buf[command.parameters.size] = 0;
508
509 CStdString strName(buf);
510 device->SetOSDName(strName);
6b72afcd 511
15d1a84c 512 return true;
a3269a0a
LOK
513 }
514 }
15d1a84c 515 return false;
a3269a0a
LOK
516}
517
e9de9629
LOK
518bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
519{
8e57f83c 520 if (m_processor->IsRunning() && command.parameters.size >= 2)
e9de9629 521 {
b6c7bc94 522 uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
5477a250 523 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
72689600
LOK
524
525 /* one of the device handled by libCEC has been made active */
526 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress);
527 if (device && m_busDevice->MyLogicalAddressContains(device->GetLogicalAddress()))
528 {
529 device->SetActiveSource();
49c8f2e4 530 device->TransmitImageViewOn();
72689600 531 device->TransmitActiveSource();
538d8471
LOK
532
533 device->SetMenuState(CEC_MENU_STATE_ACTIVATED);
534 device->TransmitMenuState(command.initiator);
72689600 535 }
e9de9629 536 }
15d1a84c 537 return false;
e9de9629
LOK
538}
539
aa517a0d 540bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command)
e5e86c76 541{
8e57f83c 542 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
e5e86c76
LOK
543 {
544 CCECBusDevice *device = GetDevice(command.destination);
aa517a0d
LOK
545 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
546 {
547 if (command.parameters.size >= 2)
548 {
549 device->SetPowerStatus(CEC_POWER_STATUS_ON);
550 ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON);
551 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
552 CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress);
553 if (newActiveDevice)
37b0c572 554 newActiveDevice->SetActiveSource();
aa517a0d
LOK
555 return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator);
556 }
557 else
558 {
559 ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF);
560 return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator);
561 }
562 }
e5e86c76 563 }
6b72afcd 564 return false;
e5e86c76
LOK
565}
566
4d6b4433
LOK
567bool CCECCommandHandler::HandleStandby(const cec_command &command)
568{
569 CCECBusDevice *device = GetDevice(command.initiator);
570 if (device)
571 device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
6b72afcd 572
4d6b4433
LOK
573 return true;
574}
575
aa517a0d 576bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command)
868dc71f 577{
aa517a0d 578 if (command.parameters.size == 1)
868dc71f 579 {
aa517a0d
LOK
580 CCECBusDevice *device = GetDevice(command.initiator);
581 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
582 {
583 ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]);
584 return true;
585 }
586 }
587
588 return false;
589}
590
591bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command)
592{
593 if (command.parameters.size == 1)
594 {
595 CCECBusDevice *device = GetDevice(command.initiator);
596 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
597 {
598 ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]);
599 return true;
600 }
868dc71f
LOK
601 }
602
603 return false;
604}
605
1a6669b8 606bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
cf0ecd85 607{
37b0c572 608 m_processor->m_busDevices[command.initiator]->SetActiveSource();
1a6669b8 609 return true;
cf0ecd85
LOK
610}
611
e9de9629
LOK
612bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
613{
e33e0d75
MK
614 if (m_processor->IsRunning() &&
615 m_busDevice->MyLogicalAddressContains(command.destination) &&
616 command.parameters.size > 0)
e9de9629 617 {
02e7043e 618 CLibCEC::AddKey();
e9de9629 619 if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
e33e0d75
MK
620 CLibCEC::SetCurrentButton((cec_user_control_code) command.parameters[0]);
621
622 if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
623 command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
e9de9629 624 {
e33e0d75
MK
625 bool bPowerOn(true);
626 CCECBusDevice *device = GetDevice(command.destination);
627 if (!device)
628 return true;
629
630 // CEC_USER_CONTROL_CODE_POWER operates as a toggle
631 // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not
632 if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER)
68391d4f 633 {
e33e0d75
MK
634 cec_power_status status = device->GetPowerStatus();
635 bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
636 }
637
638 if (bPowerOn)
639 {
640 device->SetActiveSource();
641 device->TransmitImageViewOn();
642 device->TransmitActiveSource();
643
644 if (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
645 device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
646 ((CCECPlaybackDevice *)device)->TransmitDeckStatus(command.initiator);
68391d4f 647 }
d1ab114f
LOK
648 else
649 {
e33e0d75
MK
650 device->SetInactiveSource();
651 device->TransmitInactiveSource();
652 device->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
d1ab114f 653 }
e9de9629 654 }
e33e0d75
MK
655
656 return true;
e9de9629 657 }
15d1a84c 658 return false;
e9de9629
LOK
659}
660
661bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
662{
8e57f83c 663 if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
02e7043e 664 CLibCEC::AddKey();
6b72afcd 665
e9de9629
LOK
666 return true;
667}
668
1de6617c
LOK
669bool CCECCommandHandler::HandleVendorCommand(const cec_command & UNUSED(command))
670{
671 return true;
672}
673
e9de9629
LOK
674void CCECCommandHandler::UnhandledCommand(const cec_command &command)
675{
5477a250 676 CLibCEC::AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator);
0f23c85c
LOK
677}
678
6f14b512 679size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
8747dd4f 680{
6f14b512 681 size_t iReturn(0);
8747dd4f 682
fcf10e27 683 cec_logical_addresses addresses = m_processor->GetLogicalAddresses();
f2198ab5 684 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
8747dd4f
LOK
685 {
686 if (addresses[iPtr])
687 {
688 devices.push_back(GetDevice((cec_logical_address) iPtr));
689 ++iReturn;
690 }
691 }
692
693 return iReturn;
694}
695
0f23c85c
LOK
696CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
697{
698 CCECBusDevice *device = NULL;
699
700 if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST)
fcf10e27 701 device = m_processor->m_busDevices[iLogicalAddress];
0f23c85c
LOK
702
703 return device;
e9de9629 704}
6685ae07
LOK
705
706CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
707{
fcf10e27 708 return m_processor->GetDeviceByPhysicalAddress(iPhysicalAddress);
6685ae07 709}
181b3475 710
c4098482
LOK
711CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const
712{
fcf10e27 713 return m_processor->GetDeviceByType(type);
c4098482
LOK
714}
715
8fa35473 716bool CCECCommandHandler::SetVendorId(const cec_command &command)
181b3475 717{
8fa35473 718 bool bChanged(false);
181b3475
LOK
719 if (command.parameters.size < 3)
720 {
5477a250 721 CLibCEC::AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
8fa35473 722 return bChanged;
181b3475
LOK
723 }
724
bae71306
LOK
725 uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) +
726 ((uint64_t)command.parameters[1] << 8) +
181b3475
LOK
727 (uint64_t)command.parameters[2];
728
729 CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator);
730 if (device)
8fa35473
LOK
731 bChanged = device->SetVendorId(iVendorId);
732 return bChanged;
181b3475 733}
5e822b09 734
16b1e052
LOK
735void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress)
736{
737 if (!m_busDevice->MyLogicalAddressContains(iAddress))
738 {
fcf10e27 739 bool bOurAddress(m_processor->GetPhysicalAddress() == iNewAddress);
16b1e052
LOK
740 GetDevice(iAddress)->SetPhysicalAddress(iNewAddress);
741 if (bOurAddress)
742 {
743 /* another device reported the same physical address as ours
744 * since we don't have physical address detection yet, we'll just use the
745 * given address, increased by 0x100 for now */
fcf10e27 746 m_processor->SetPhysicalAddress(iNewAddress + 0x100);
16b1e052
LOK
747 }
748 }
749}
855a3a98 750
f4698390
LOK
751bool CCECCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
752{
753 if (iDestination == CECDEVICE_TV)
754 return TransmitImageViewOn(iInitiator, iDestination);
755
756 return TransmitKeypress(iInitiator, iDestination, CEC_USER_CONTROL_CODE_POWER) &&
757 TransmitKeyRelease(iInitiator, iDestination);
758}
759
b64db02e 760bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
8fa35473
LOK
761{
762 cec_command command;
ae693aaa 763 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON);
8fa35473 764
19cbfa8f 765 return Transmit(command, false);
8fa35473
LOK
766}
767
768bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination)
769{
770 cec_command command;
ae693aaa 771 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_STANDBY);
8fa35473 772
19cbfa8f 773 return Transmit(command, false);
8fa35473
LOK
774}
775
a75e3a5a 776bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
8fa35473
LOK
777{
778 cec_command command;
ae693aaa 779 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION);
8fa35473 780
a75e3a5a 781 return Transmit(command, bWaitForResponse, CEC_OPCODE_CEC_VERSION);
8fa35473
LOK
782}
783
a75e3a5a 784bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
8fa35473
LOK
785{
786 cec_command command;
ae693aaa 787 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE);
8fa35473 788
a75e3a5a 789 return Transmit(command, bWaitForResponse, CEC_OPCODE_SET_MENU_LANGUAGE);
8fa35473
LOK
790}
791
a75e3a5a 792bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
8fa35473
LOK
793{
794 cec_command command;
ae693aaa 795 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME);
8fa35473 796
a75e3a5a 797 return Transmit(command, bWaitForResponse, CEC_OPCODE_SET_OSD_NAME);
8fa35473
LOK
798}
799
a75e3a5a 800bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
8fa35473
LOK
801{
802 cec_command command;
ae693aaa 803 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS);
8fa35473 804
a75e3a5a 805 return Transmit(command, bWaitForResponse, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
8fa35473
LOK
806}
807
a75e3a5a 808bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
8fa35473
LOK
809{
810 cec_command command;
ae693aaa 811 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
8fa35473 812
a75e3a5a 813 return Transmit(command, bWaitForResponse, CEC_OPCODE_REPORT_POWER_STATUS);
8fa35473
LOK
814}
815
a75e3a5a 816bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
8fa35473
LOK
817{
818 cec_command command;
ae693aaa 819 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
8fa35473 820
a75e3a5a 821 return Transmit(command, bWaitForResponse, CEC_OPCODE_DEVICE_VENDOR_ID);
8fa35473
LOK
822}
823
824bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
825{
826 cec_command command;
ae693aaa 827 cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
8fa35473
LOK
828 command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF));
829 command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF));
830
19cbfa8f 831 return Transmit(command, false);
8fa35473
LOK
832}
833
834bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion)
835{
836 cec_command command;
ae693aaa 837 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_CEC_VERSION);
8fa35473
LOK
838 command.parameters.PushBack((uint8_t)cecVersion);
839
19cbfa8f 840 return Transmit(command, false);
8fa35473
LOK
841}
842
843bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
844{
845 cec_command command;
ae693aaa 846 cec_command::Format(command, iInitiator, CECDEVICE_TV, CEC_OPCODE_INACTIVE_SOURCE);
8fa35473
LOK
847 command.parameters.PushBack((iPhysicalAddress >> 8) & 0xFF);
848 command.parameters.PushBack(iPhysicalAddress & 0xFF);
849
19cbfa8f 850 return Transmit(command, false);
8fa35473
LOK
851}
852
853bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_menu_state menuState)
854{
855 cec_command command;
ae693aaa 856 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_MENU_STATUS);
8fa35473
LOK
857 command.parameters.PushBack((uint8_t)menuState);
858
19cbfa8f 859 return Transmit(command, false);
8fa35473
LOK
860}
861
862bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, CStdString strDeviceName)
863{
864 cec_command command;
ae693aaa 865 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME);
6f14b512 866 for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
8fa35473
LOK
867 command.parameters.PushBack(strDeviceName.at(iPtr));
868
19cbfa8f 869 return Transmit(command, false);
8fa35473
LOK
870}
871
872bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_display_control duration, const char *strMessage)
873{
874 cec_command command;
ae693aaa 875 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING);
8fa35473
LOK
876 command.parameters.PushBack((uint8_t)duration);
877
6f14b512 878 size_t iLen = strlen(strMessage);
8fa35473
LOK
879 if (iLen > 13) iLen = 13;
880
6f14b512 881 for (size_t iPtr = 0; iPtr < iLen; iPtr++)
8fa35473
LOK
882 command.parameters.PushBack(strMessage[iPtr]);
883
19cbfa8f 884 return Transmit(command, false);
8fa35473
LOK
885}
886
887bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, cec_device_type type)
888{
889 cec_command command;
ae693aaa 890 cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
8fa35473
LOK
891 command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF));
892 command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF));
893 command.parameters.PushBack((uint8_t) (type));
894
fbdea54c
MK
895 return Transmit(command, false);
896}
897
898bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInitiator, const char lang[3])
899{
900 cec_command command;
901 command.Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_SET_MENU_LANGUAGE);
902 command.parameters.PushBack((uint8_t) lang[0]);
903 command.parameters.PushBack((uint8_t) lang[1]);
904 command.parameters.PushBack((uint8_t) lang[2]);
905
19cbfa8f 906 return Transmit(command, false);
8fa35473
LOK
907}
908
909bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, const cec_logical_address iDestination)
910{
911 cec_command command;
ae693aaa 912 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_NONE);
8fa35473 913
ae693aaa 914 return Transmit(command, false);
8fa35473
LOK
915}
916
917bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_power_status state)
918{
919 cec_command command;
ae693aaa 920 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_POWER_STATUS);
8fa35473
LOK
921 command.parameters.PushBack((uint8_t) state);
922
19cbfa8f 923 return Transmit(command, false);
8fa35473
LOK
924}
925
926bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator, uint64_t iVendorId)
927{
928 cec_command command;
ae693aaa 929 cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID);
8fa35473
LOK
930
931 command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 16) & 0xFF));
932 command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 8) & 0xFF));
933 command.parameters.PushBack((uint8_t) ((uint64_t)iVendorId & 0xFF));
934
19cbfa8f 935 return Transmit(command, false);
8fa35473
LOK
936}
937
938bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, uint8_t state)
939{
940 cec_command command;
ae693aaa 941 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_AUDIO_STATUS);
8fa35473
LOK
942 command.parameters.PushBack(state);
943
19cbfa8f 944 return Transmit(command, false);
8fa35473
LOK
945}
946
947bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state)
948{
949 cec_command command;
ae693aaa 950 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE);
8fa35473
LOK
951 command.parameters.PushBack((uint8_t)state);
952
19cbfa8f 953 return Transmit(command, false);
8fa35473
LOK
954}
955
f42d3e0f
LOK
956bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath)
957{
958 cec_command command;
959 cec_command::Format(command, m_busDevice->GetLogicalAddress(), CECDEVICE_BROADCAST, CEC_OPCODE_SET_STREAM_PATH);
960 command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF));
961 command.parameters.PushBack((uint8_t) (iStreamPath & 0xFF));
962
963 return Transmit(command, false);
964}
965
8fa35473
LOK
966bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state)
967{
968 cec_command command;
ae693aaa 969 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS);
8fa35473
LOK
970 command.parameters.PushBack((uint8_t)state);
971
19cbfa8f 972 return Transmit(command, false);
8fa35473
LOK
973}
974
975bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state)
976{
977 cec_command command;
ae693aaa 978 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_DECK_STATUS);
8fa35473
LOK
979 command.PushBack((uint8_t)state);
980
19cbfa8f 981 return Transmit(command, false);
8fa35473
LOK
982}
983
4bec9d79 984bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
8fa35473
LOK
985{
986 cec_command command;
ae693aaa 987 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED);
8fa35473
LOK
988 command.parameters.PushBack((uint8_t)key);
989
4bec9d79 990 return Transmit(command, bWait);
8fa35473
LOK
991}
992
4bec9d79 993bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait /* = true */)
8fa35473
LOK
994{
995 cec_command command;
ae693aaa 996 cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE);
8fa35473 997
4bec9d79 998 return Transmit(command, bWait);
8fa35473
LOK
999}
1000
446c0cfc 1001bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* = true */, cec_opcode expectedResponse /* = CEC_OPCODE_NONE */)
8fa35473 1002{
b64db02e 1003 bool bReturn(false);
ae693aaa 1004 command.transmit_timeout = m_iTransmitTimeout;
ae693aaa 1005
7e4558f1
LOK
1006 if (command.initiator == CECDEVICE_UNKNOWN)
1007 {
1008 CLibCEC::AddLog(CEC_LOG_ERROR, "not transmitting a command without a valid initiator");
1009 return bReturn;
1010 }
1011
ae693aaa 1012 {
6c0ccaa5 1013 uint8_t iTries(0), iMaxTries(!command.opcode_set ? 1 : m_iTransmitRetries + 1);
ec15344c 1014 while (!bReturn && ++iTries <= iMaxTries && !m_busDevice->IsUnsupportedFeature(command.opcode))
b64db02e 1015 {
99666519 1016 if ((bReturn = m_processor->Transmit(command)) == true)
19cbfa8f 1017 {
5477a250 1018 CLibCEC::AddLog(CEC_LOG_DEBUG, "command transmitted");
4478bc79 1019 if (bExpectResponse)
24dd566c
LOK
1020 {
1021 bReturn = m_waitForResponse->Wait(expectedResponse);
1022 CLibCEC::AddLog(CEC_LOG_DEBUG, bReturn ? "expected response received (%X: %s)" : "expected response not received (%X: %s)", (int)expectedResponse, m_processor->ToString(expectedResponse));
1023 }
19cbfa8f 1024 }
b64db02e 1025 }
ae693aaa 1026 }
8fa35473 1027
b64db02e 1028 return bReturn;
8fa35473 1029}
83be0701 1030
3e61b350 1031bool CCECCommandHandler::ActivateSource(void)
83be0701 1032{
c4287bcd
LOK
1033 if (m_busDevice->IsActiveSource() &&
1034 m_busDevice->GetStatus(false) == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
1035 {
1036 m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON);
1037 m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED);
1038
1039 m_busDevice->TransmitImageViewOn();
1040 m_busDevice->TransmitActiveSource();
1041 m_busDevice->TransmitMenuState(CECDEVICE_TV);
1042 if ((m_busDevice->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
1043 m_busDevice->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
1044 SendDeckStatusUpdateOnActiveSource())
1045 ((CCECPlaybackDevice *)m_busDevice)->TransmitDeckStatus(CECDEVICE_TV);
1046 m_bHandlerInited = true;
83be0701 1047 }
7dc58c9f 1048 return true;
83be0701 1049}