cec: cosmetics in cec-client
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
CommitLineData
e9de9629
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
33#include "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"
e9de9629
LOK
38
39using namespace CEC;
8747dd4f 40using namespace std;
e9de9629
LOK
41
42CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice)
43{
44 m_busDevice = busDevice;
45}
46
47bool CCECCommandHandler::HandleCommand(const cec_command &command)
48{
49 bool bHandled(true);
50
5e822b09 51 CStdString strLog;
62f5527d 52 strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
5e822b09
LOK
53 m_busDevice->AddLog(CEC_LOG_NOTICE, strLog);
54
6b72afcd 55 switch(command.opcode)
e9de9629 56 {
6b72afcd
LOK
57 case CEC_OPCODE_REPORT_POWER_STATUS:
58 HandleReportPowerStatus(command);
59 break;
60 case CEC_OPCODE_CEC_VERSION:
61 HandleDeviceCecVersion(command);
62 break;
63 case CEC_OPCODE_SET_MENU_LANGUAGE:
64 HandleSetMenuLanguage(command);
65 break;
66 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
67 HandleGivePhysicalAddress(command);
68 break;
69 case CEC_OPCODE_GIVE_OSD_NAME:
70 HandleGiveOSDName(command);
71 break;
72 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
73 HandleGiveDeviceVendorId(command);
74 break;
75 case CEC_OPCODE_DEVICE_VENDOR_ID:
76 HandleDeviceVendorId(command);
77 break;
78 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
79 HandleDeviceVendorCommandWithId(command);
80 break;
81 case CEC_OPCODE_GIVE_DECK_STATUS:
82 HandleGiveDeckStatus(command);
83 break;
84 case CEC_OPCODE_DECK_CONTROL:
85 HandleDeckControl(command);
86 break;
87 case CEC_OPCODE_MENU_REQUEST:
88 HandleMenuRequest(command);
89 break;
90 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
91 HandleGiveDevicePowerStatus(command);
92 break;
93 case CEC_OPCODE_GET_CEC_VERSION:
94 HandleGetCecVersion(command);
95 break;
96 case CEC_OPCODE_USER_CONTROL_PRESSED:
97 HandleUserControlPressed(command);
98 break;
99 case CEC_OPCODE_USER_CONTROL_RELEASE:
100 HandleUserControlRelease(command);
101 break;
102 case CEC_OPCODE_GIVE_AUDIO_STATUS:
103 HandleGiveAudioStatus(command);
104 break;
105 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
106 HandleGiveSystemAudioModeStatus(command);
107 break;
108 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
109 HandleSetSystemAudioModeRequest(command);
110 break;
111 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
112 HandleRequestActiveSource(command);
113 break;
114 case CEC_OPCODE_SET_STREAM_PATH:
115 HandleSetStreamPath(command);
116 break;
117 case CEC_OPCODE_ROUTING_CHANGE:
118 HandleRoutingChange(command);
119 break;
907bd60f
LOK
120 case CEC_OPCODE_ROUTING_INFORMATION:
121 HandleRoutingInformation(command);
122 break;
6b72afcd
LOK
123 case CEC_OPCODE_STANDBY:
124 HandleStandby(command);
125 break;
126 case CEC_OPCODE_ACTIVE_SOURCE:
127 HandleActiveSource(command);
128 break;
907bd60f
LOK
129 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
130 HandleReportPhysicalAddress(command);
131 break;
15d1a84c
LOK
132 case CEC_OPCODE_REPORT_AUDIO_STATUS:
133 HandleReportAudioStatus(command);
134 break;
868dc71f
LOK
135 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
136 HandleSystemAudioStatus(command);
137 break;
15d1a84c
LOK
138 case CEC_OPCODE_SET_OSD_NAME:
139 HandleSetOSDName(command);
140 break;
1a6669b8
LOK
141 case CEC_OPCODE_IMAGE_VIEW_ON:
142 HandleImageViewOn(command);
143 break;
144 case CEC_OPCODE_TEXT_VIEW_ON:
145 HandleTextViewOn(command);
146 break;
6b72afcd
LOK
147 default:
148 UnhandledCommand(command);
e9de9629 149 bHandled = false;
6b72afcd 150 break;
e9de9629
LOK
151 }
152
15d1a84c
LOK
153 if (command.destination == CECDEVICE_BROADCAST || m_busDevice->MyLogicalAddressContains(command.destination))
154 m_busDevice->GetProcessor()->AddCommand(command);
155
e9de9629
LOK
156 return bHandled;
157}
158
be5b0e24
LOK
159bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
160{
161 if (command.parameters.size == 2)
162 {
163 uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
164 return m_busDevice->GetProcessor()->SetStreamPath(iAddress);
165 }
166
167 return true;
168}
169
a9232a79
LOK
170bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
171{
172 CCECBusDevice *device = GetDevice(command.destination);
88e5de6f 173 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0)
a9232a79
LOK
174 {
175 ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
176 return true;
177 }
178
179 return false;
180}
181
6a1c0009
LOK
182bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
183{
184 if (command.parameters.size == 1)
185 {
186 CCECBusDevice *device = GetDevice(command.initiator);
187 if (device)
188 device->SetCecVersion((cec_version) command.parameters[0]);
189 }
190
191 return true;
192}
193
e9de9629
LOK
194bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
195{
6b72afcd
LOK
196 if (m_busDevice->MyLogicalAddressContains(command.destination))
197 m_busDevice->GetProcessor()->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
198
6a1c0009 199 return true;
e9de9629
LOK
200}
201
202bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
203{
181b3475 204 SetVendorId(command);
6a1c0009 205 return true;
e9de9629
LOK
206}
207
208bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
209{
6b72afcd
LOK
210 if (m_busDevice->MyLogicalAddressContains(command.destination))
211 {
212 CCECBusDevice *device = GetDevice(command.destination);
213 if (device)
214 return device->TransmitCECVersion(command.initiator);
215 }
0f23c85c
LOK
216
217 return false;
e9de9629
LOK
218}
219
a1f8fb1b
LOK
220bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
221{
6b72afcd
LOK
222 if (m_busDevice->MyLogicalAddressContains(command.destination))
223 {
224 CCECBusDevice *device = GetDevice(command.destination);
225 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
226 return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator);
227 }
a1f8fb1b
LOK
228
229 return false;
230}
231
e9de9629
LOK
232bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
233{
6b72afcd
LOK
234 if (m_busDevice->MyLogicalAddressContains(command.destination))
235 {
236 CCECBusDevice *device = GetDevice(command.destination);
237 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
238 return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator);
239 }
0f23c85c
LOK
240
241 return false;
e9de9629
LOK
242}
243
244bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
245{
6b72afcd
LOK
246 if (m_busDevice->MyLogicalAddressContains(command.destination))
247 {
248 CCECBusDevice *device = GetDevice(command.destination);
249 if (device)
250 return device->TransmitPowerState(command.initiator);
251 }
0f23c85c
LOK
252
253 return false;
e9de9629
LOK
254}
255
256bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
257{
6b72afcd
LOK
258 if (m_busDevice->MyLogicalAddressContains(command.destination))
259 {
260 CCECBusDevice *device = GetDevice(command.destination);
261 if (device)
262 return device->TransmitVendorID(command.initiator);
263 }
0f23c85c
LOK
264
265 return false;
e9de9629
LOK
266}
267
268bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
269{
6b72afcd
LOK
270 if (m_busDevice->MyLogicalAddressContains(command.destination))
271 {
272 CCECBusDevice *device = GetDevice(command.destination);
273 if (device)
274 return device->TransmitOSDName(command.initiator);
275 }
0f23c85c
LOK
276
277 return false;
e9de9629
LOK
278}
279
280bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
281{
6b72afcd
LOK
282 if (m_busDevice->MyLogicalAddressContains(command.destination))
283 {
284 CCECBusDevice *device = GetDevice(command.destination);
285 if (device)
286 return device->TransmitPhysicalAddress();
287 }
09c10b66
LOK
288
289 return false;
e9de9629
LOK
290}
291
1a6669b8
LOK
292bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
293{
294 if (m_busDevice->MyLogicalAddressContains(command.destination))
295 {
296 CCECBusDevice *device = GetDevice(command.destination);
297 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
298 return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
299 }
300
301 return false;
302}
303
304bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
305{
306 m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
307 return true;
308}
309
e9de9629
LOK
310bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
311{
6b72afcd 312 if (m_busDevice->MyLogicalAddressContains(command.destination))
0f23c85c 313 {
6b72afcd
LOK
314 if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
315 {
316 CCECBusDevice *device = GetDevice(command.destination);
317 if (device)
318 return device->TransmitMenuState(command.initiator);
319 }
15d1a84c
LOK
320 }
321
322 return false;
323}
324
325bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command)
326{
327 if (command.parameters.size == 1)
328 {
329 CCECBusDevice *device = GetDevice(command.initiator);
330 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
6b72afcd 331 {
15d1a84c
LOK
332 ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]);
333 return true;
6b72afcd 334 }
0f23c85c
LOK
335 }
336 return false;
e9de9629
LOK
337}
338
907bd60f
LOK
339bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
340{
0bfce006 341 if (command.parameters.size == 3)
907bd60f
LOK
342 {
343 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
16b1e052 344 SetPhysicalAddress(command.initiator, iNewAddress);
907bd60f
LOK
345 }
346 return true;
347}
348
e55f3f70
LOK
349bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command)
350{
351 if (command.parameters.size == 1)
352 {
353 CCECBusDevice *device = GetDevice(command.initiator);
354 if (device)
355 device->SetPowerStatus((cec_power_status) command.parameters[0]);
356 }
357 return true;
358}
359
e9de9629
LOK
360bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
361{
362 CStdString strLog;
363 strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
364 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
8747dd4f
LOK
365
366 vector<CCECBusDevice *> devices;
367 for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
368 devices[iDevicePtr]->TransmitActiveSource();
c4098482 369
8747dd4f 370 return true;
e9de9629
LOK
371}
372
373bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
374{
375 if (command.parameters.size == 4)
376 {
377 uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
378 uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]);
e9de9629 379
0f23c85c
LOK
380 CCECBusDevice *device = GetDevice(command.initiator);
381 if (device)
9dc04b07 382 device->SetStreamPath(iNewAddress, iOldAddress);
e9de9629
LOK
383 }
384 return true;
385}
386
907bd60f
LOK
387bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command)
388{
389 if (command.parameters.size == 2)
390 {
391 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
16b1e052 392 m_busDevice->GetProcessor()->SetStreamPath(iNewAddress);
907bd60f 393 }
15d1a84c
LOK
394
395 return false;
907bd60f
LOK
396}
397
a3269a0a
LOK
398bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
399{
400 if (command.parameters.size == 3)
401 {
402 CCECBusDevice *device = GetDevice(command.initiator);
403 if (device)
404 {
405 cec_menu_language language;
406 language.device = command.initiator;
56701628 407 for (uint8_t iPtr = 0; iPtr < 4; iPtr++)
a3269a0a
LOK
408 language.language[iPtr] = command.parameters[iPtr];
409 language.language[3] = 0;
410 device->SetMenuLanguage(language);
15d1a84c
LOK
411 return true;
412 }
413 }
414 return false;
415}
416
417bool CCECCommandHandler::HandleSetOSDName(const cec_command &command)
418{
419 if (command.parameters.size > 0)
420 {
421 CCECBusDevice *device = GetDevice(command.initiator);
422 if (device)
423 {
424 char buf[1024];
425 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
426 buf[iPtr] = (char)command.parameters[iPtr];
427 buf[command.parameters.size] = 0;
428
429 CStdString strName(buf);
430 device->SetOSDName(strName);
6b72afcd 431
15d1a84c 432 return true;
a3269a0a
LOK
433 }
434 }
15d1a84c 435 return false;
a3269a0a
LOK
436}
437
e9de9629
LOK
438bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
439{
440 if (command.parameters.size >= 2)
441 {
b6c7bc94 442 uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
e9de9629 443 CStdString strLog;
b6c7bc94 444 strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
e9de9629 445 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
04437dcf 446
b6c7bc94
LOK
447 if (m_busDevice->GetProcessor()->SetStreamPath(iStreamAddress))
448 {
449 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress);
450 if (device)
451 {
452 return device->TransmitActiveSource() &&
453 device->TransmitMenuState(command.initiator);
454 }
455 }
e9de9629 456 }
15d1a84c 457 return false;
e9de9629
LOK
458}
459
e5e86c76
LOK
460bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
461{
6b72afcd 462 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1)
e5e86c76
LOK
463 {
464 CCECBusDevice *device = GetDevice(command.destination);
465 if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
466 return ((CCECAudioSystem *) device)->SetSystemAudioMode(command);
467 }
6b72afcd 468 return false;
e5e86c76
LOK
469}
470
4d6b4433
LOK
471bool CCECCommandHandler::HandleStandby(const cec_command &command)
472{
473 CCECBusDevice *device = GetDevice(command.initiator);
474 if (device)
475 device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
6b72afcd 476
4d6b4433
LOK
477 return true;
478}
479
868dc71f
LOK
480bool CCECCommandHandler::HandleSystemAudioStatus(const cec_command &command)
481{
482 CCECBusDevice *device = GetDevice(command.initiator);
483 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
484 {
485 ((CCECAudioSystem *)device)->SetSystemAudioMode(command);
486 return true;
487 }
488
489 return false;
490}
491
1a6669b8 492bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
cf0ecd85 493{
1a6669b8
LOK
494 m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
495 return true;
cf0ecd85
LOK
496}
497
e9de9629
LOK
498bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
499{
6b72afcd 500 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
e9de9629
LOK
501 {
502 m_busDevice->GetProcessor()->AddKey();
503
504 if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
505 {
506 CStdString strLog;
68391d4f 507 strLog.Format("key pressed: %x", command.parameters[0]);
e9de9629
LOK
508 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
509
68391d4f
LOK
510 if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
511 command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
512 {
513 CCECBusDevice *device = GetDevice(command.destination);
514 if (device)
515 device->SetPowerStatus(CEC_POWER_STATUS_ON);
516 }
517
e9de9629 518 m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]);
15d1a84c 519 return true;
e9de9629
LOK
520 }
521 }
15d1a84c 522 return false;
e9de9629
LOK
523}
524
525bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
526{
6b72afcd
LOK
527 if (m_busDevice->MyLogicalAddressContains(command.destination))
528 m_busDevice->GetProcessor()->AddKey();
529
e9de9629
LOK
530 return true;
531}
532
533void CCECCommandHandler::UnhandledCommand(const cec_command &command)
534{
b5b53c7d
LOK
535 CStdString strLog;
536 strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator);
537 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
0f23c85c
LOK
538}
539
8747dd4f
LOK
540unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
541{
542 unsigned int iReturn(0);
543
544 cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
f2198ab5 545 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
8747dd4f
LOK
546 {
547 if (addresses[iPtr])
548 {
549 devices.push_back(GetDevice((cec_logical_address) iPtr));
550 ++iReturn;
551 }
552 }
553
554 return iReturn;
555}
556
0f23c85c
LOK
557CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
558{
559 CCECBusDevice *device = NULL;
560
561 if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST)
562 device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress];
563
564 return device;
e9de9629 565}
6685ae07
LOK
566
567CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
568{
8ac9c610 569 return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
6685ae07 570}
181b3475 571
c4098482
LOK
572CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const
573{
574 return m_busDevice->GetProcessor()->GetDeviceByType(type);
575}
576
181b3475
LOK
577void CCECCommandHandler::SetVendorId(const cec_command &command)
578{
579 if (command.parameters.size < 3)
580 {
581 m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
582 return;
583 }
584
bae71306
LOK
585 uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) +
586 ((uint64_t)command.parameters[1] << 8) +
181b3475
LOK
587 (uint64_t)command.parameters[2];
588
589 CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator);
590 if (device)
c4098482 591 device->SetVendorId(iVendorId);
181b3475 592}
5e822b09 593
16b1e052
LOK
594void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress)
595{
596 if (!m_busDevice->MyLogicalAddressContains(iAddress))
597 {
598 bool bOurAddress(m_busDevice->GetProcessor()->GetPhysicalAddress() == iNewAddress);
599 GetDevice(iAddress)->SetPhysicalAddress(iNewAddress);
600 if (bOurAddress)
601 {
602 /* another device reported the same physical address as ours
603 * since we don't have physical address detection yet, we'll just use the
604 * given address, increased by 0x100 for now */
605 m_busDevice->GetProcessor()->SetPhysicalAddress(iNewAddress + 0x100);
606 }
607 }
608}
609
28fa6c97
LOK
610const char *CCECCommandHandler::ToString(const cec_menu_state state)
611{
612 switch (state)
613 {
614 case CEC_MENU_STATE_ACTIVATED:
615 return "activated";
616 case CEC_MENU_STATE_DEACTIVATED:
617 return "deactivated";
618 default:
619 return "unknown";
620 }
621}
622
c686413b
LOK
623const char *CCECCommandHandler::ToString(const cec_version version)
624{
625 switch (version)
626 {
627 case CEC_VERSION_1_2:
628 return "1.2";
629 case CEC_VERSION_1_2A:
630 return "1.2a";
631 case CEC_VERSION_1_3:
632 return "1.3";
633 case CEC_VERSION_1_3A:
634 return "1.3a";
c4098482
LOK
635 case CEC_VERSION_1_4:
636 return "1.4";
c686413b
LOK
637 default:
638 return "unknown";
639 }
640}
641
66c16b69
LOK
642const char *CCECCommandHandler::ToString(const cec_power_status status)
643{
644 switch (status)
645 {
646 case CEC_POWER_STATUS_ON:
647 return "on";
648 case CEC_POWER_STATUS_STANDBY:
649 return "standby";
650 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
651 return "in transition from on to standby";
652 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
653 return "in transition from standby to on";
654 default:
655 return "unknown";
656 }
657}
658
62f5527d
LOK
659const char *CCECCommandHandler::ToString(const cec_logical_address address)
660{
661 switch(address)
662 {
663 case CECDEVICE_AUDIOSYSTEM:
664 return "Audio";
665 case CECDEVICE_BROADCAST:
666 return "Broadcast";
667 case CECDEVICE_FREEUSE:
668 return "Free use";
669 case CECDEVICE_PLAYBACKDEVICE1:
670 return "Playback 1";
671 case CECDEVICE_PLAYBACKDEVICE2:
672 return "Playback 2";
673 case CECDEVICE_PLAYBACKDEVICE3:
674 return "Playback 3";
675 case CECDEVICE_RECORDINGDEVICE1:
676 return "Recorder 1";
677 case CECDEVICE_RECORDINGDEVICE2:
678 return "Recorder 2";
679 case CECDEVICE_RECORDINGDEVICE3:
680 return "Recorder 3";
681 case CECDEVICE_RESERVED1:
682 return "Reserved 1";
683 case CECDEVICE_RESERVED2:
684 return "Reserved 2";
685 case CECDEVICE_TUNER1:
686 return "Tuner 1";
687 case CECDEVICE_TUNER2:
688 return "Tuner 2";
689 case CECDEVICE_TUNER3:
690 return "Tuner 3";
691 case CECDEVICE_TUNER4:
692 return "Tuner 4";
693 case CECDEVICE_TV:
694 return "TV";
695 default:
696 return "unknown";
697 }
698}
699
a9232a79
LOK
700const char *CCECCommandHandler::ToString(const cec_deck_control_mode mode)
701{
702 switch (mode)
703 {
704 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
705 return "skip forward wind";
706 case CEC_DECK_CONTROL_MODE_EJECT:
707 return "eject";
708 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
709 return "reverse rewind";
710 case CEC_DECK_CONTROL_MODE_STOP:
711 return "stop";
712 default:
713 return "unknown";
714 }
715}
716
8ac9c610
LOK
717const char *CCECCommandHandler::ToString(const cec_deck_info status)
718{
719 switch (status)
720 {
721 case CEC_DECK_INFO_PLAY:
722 return "play";
723 case CEC_DECK_INFO_RECORD:
724 return "record";
725 case CEC_DECK_INFO_PLAY_REVERSE:
726 return "play reverse";
727 case CEC_DECK_INFO_STILL:
728 return "still";
729 case CEC_DECK_INFO_SLOW:
730 return "slow";
731 case CEC_DECK_INFO_SLOW_REVERSE:
732 return "slow reverse";
733 case CEC_DECK_INFO_FAST_FORWARD:
734 return "fast forward";
735 case CEC_DECK_INFO_FAST_REVERSE:
736 return "fast reverse";
737 case CEC_DECK_INFO_NO_MEDIA:
738 return "no media";
739 case CEC_DECK_INFO_STOP:
740 return "stop";
741 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
742 return "info skip forward wind";
743 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
744 return "info skip reverse rewind";
745 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
746 return "info index search forward";
747 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
748 return "info index search reverse";
749 case CEC_DECK_INFO_OTHER_STATUS:
750 return "other";
751 default:
752 return "unknown";
753 }
754}
755
5e822b09
LOK
756const char *CCECCommandHandler::ToString(const cec_opcode opcode)
757{
758 switch (opcode)
759 {
760 case CEC_OPCODE_ACTIVE_SOURCE:
761 return "active source";
762 case CEC_OPCODE_IMAGE_VIEW_ON:
763 return "image view on";
764 case CEC_OPCODE_TEXT_VIEW_ON:
765 return "text view on";
766 case CEC_OPCODE_INACTIVE_SOURCE:
767 return "inactive source";
768 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
769 return "request active source";
770 case CEC_OPCODE_ROUTING_CHANGE:
771 return "routing change";
772 case CEC_OPCODE_ROUTING_INFORMATION:
773 return "routing information";
774 case CEC_OPCODE_SET_STREAM_PATH:
775 return "set stream path";
776 case CEC_OPCODE_STANDBY:
777 return "standby";
778 case CEC_OPCODE_RECORD_OFF:
779 return "record off";
780 case CEC_OPCODE_RECORD_ON:
781 return "record on";
782 case CEC_OPCODE_RECORD_STATUS:
783 return "record status";
784 case CEC_OPCODE_RECORD_TV_SCREEN:
785 return "record tv screen";
786 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
787 return "clear analogue timer";
788 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
789 return "clear digital timer";
790 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
791 return "clear external timer";
792 case CEC_OPCODE_SET_ANALOGUE_TIMER:
793 return "set analogue timer";
794 case CEC_OPCODE_SET_DIGITAL_TIMER:
795 return "set digital timer";
796 case CEC_OPCODE_SET_EXTERNAL_TIMER:
797 return "set external timer";
798 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
799 return "set timer program title";
800 case CEC_OPCODE_TIMER_CLEARED_STATUS:
801 return "timer cleared status";
802 case CEC_OPCODE_TIMER_STATUS:
803 return "timer status";
804 case CEC_OPCODE_CEC_VERSION:
805 return "cec version";
806 case CEC_OPCODE_GET_CEC_VERSION:
807 return "get cec version";
808 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
809 return "give physical address";
810 case CEC_OPCODE_GET_MENU_LANGUAGE:
811 return "get menu language";
812 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
813 return "report physical address";
814 case CEC_OPCODE_SET_MENU_LANGUAGE:
815 return "set menu language";
816 case CEC_OPCODE_DECK_CONTROL:
817 return "deck control";
818 case CEC_OPCODE_DECK_STATUS:
819 return "deck status";
820 case CEC_OPCODE_GIVE_DECK_STATUS:
821 return "give deck status";
822 case CEC_OPCODE_PLAY:
823 return "play";
824 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
825 return "give tuner status";
826 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
827 return "select analogue service";
828 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
829 return "set digital service";
830 case CEC_OPCODE_TUNER_DEVICE_STATUS:
831 return "tuner device status";
832 case CEC_OPCODE_TUNER_STEP_DECREMENT:
833 return "tuner step decrement";
834 case CEC_OPCODE_TUNER_STEP_INCREMENT:
835 return "tuner step increment";
836 case CEC_OPCODE_DEVICE_VENDOR_ID:
837 return "device vendor id";
838 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
839 return "give device vendor id";
840 case CEC_OPCODE_VENDOR_COMMAND:
841 return "vendor command";
842 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
843 return "vendor command with id";
844 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
845 return "vendor remote button down";
846 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
847 return "vendor remote button up";
848 case CEC_OPCODE_SET_OSD_STRING:
849 return "set osd string";
850 case CEC_OPCODE_GIVE_OSD_NAME:
851 return "give osd name";
852 case CEC_OPCODE_SET_OSD_NAME:
853 return "set osd name";
854 case CEC_OPCODE_MENU_REQUEST:
855 return "menu request";
856 case CEC_OPCODE_MENU_STATUS:
857 return "menu status";
858 case CEC_OPCODE_USER_CONTROL_PRESSED:
859 return "user control pressed";
860 case CEC_OPCODE_USER_CONTROL_RELEASE:
861 return "user control release";
862 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
863 return "give device power status";
864 case CEC_OPCODE_REPORT_POWER_STATUS:
865 return "report power status";
866 case CEC_OPCODE_FEATURE_ABORT:
867 return "feature abort";
868 case CEC_OPCODE_ABORT:
869 return "abort";
870 case CEC_OPCODE_GIVE_AUDIO_STATUS:
871 return "give audio status";
872 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
873 return "give audio mode status";
874 case CEC_OPCODE_REPORT_AUDIO_STATUS:
875 return "report audio status";
876 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
877 return "set system audio mode";
878 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
879 return "system audio mode request";
880 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
881 return "system audio mode status";
882 case CEC_OPCODE_SET_AUDIO_RATE:
883 return "set audio rate";
884 default:
885 return "UNKNOWN";
886 }
887}
c4098482
LOK
888
889const char *CCECCommandHandler::ToString(const cec_system_audio_status mode)
890{
891 switch(mode)
892 {
893 case CEC_SYSTEM_AUDIO_STATUS_ON:
894 return "on";
895 case CEC_SYSTEM_AUDIO_STATUS_OFF:
896 return "off";
897 default:
898 return "unknown";
899 }
900}
901
902const char *CCECCommandHandler::ToString(const cec_audio_status status)
903{
904 // TODO this is a mask
905 return "TODO";
906}
907
908const char *CCECCommandHandler::ToString(const cec_vendor_id vendor)
909{
910 switch (vendor)
911 {
912 case CEC_VENDOR_SAMSUNG:
913 return "Samsung";
914 case CEC_VENDOR_LG:
915 return "LG";
916 case CEC_VENDOR_PANASONIC:
917 return "Panasonic";
918 case CEC_VENDOR_PIONEER:
919 return "Pioneer";
cd02e9b2
LOK
920 case CEC_VENDOR_ONKYO:
921 return "Onkyo";
c4098482
LOK
922 default:
923 return "Unknown";
924 }
925}