cec: added SetHDMIPort()/cec_set_hdmi_port(). devices are now detected on load and...
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
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"
34 #include "../devices/CECBusDevice.h"
35 #include "../devices/CECAudioSystem.h"
36 #include "../devices/CECPlaybackDevice.h"
37 #include "../CECProcessor.h"
38
39 using namespace CEC;
40 using namespace std;
41
42 CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice)
43 {
44 m_busDevice = busDevice;
45 }
46
47 bool CCECCommandHandler::HandleCommand(const cec_command &command)
48 {
49 bool bHandled(true);
50
51 CStdString strLog;
52 strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
53 m_busDevice->AddLog(CEC_LOG_NOTICE, strLog);
54
55 switch(command.opcode)
56 {
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;
120 case CEC_OPCODE_ROUTING_INFORMATION:
121 HandleRoutingInformation(command);
122 break;
123 case CEC_OPCODE_STANDBY:
124 HandleStandby(command);
125 break;
126 case CEC_OPCODE_ACTIVE_SOURCE:
127 HandleActiveSource(command);
128 break;
129 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
130 HandleReportPhysicalAddress(command);
131 break;
132 case CEC_OPCODE_REPORT_AUDIO_STATUS:
133 HandleReportAudioStatus(command);
134 break;
135 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
136 HandleSystemAudioStatus(command);
137 break;
138 case CEC_OPCODE_SET_OSD_NAME:
139 HandleSetOSDName(command);
140 break;
141 case CEC_OPCODE_IMAGE_VIEW_ON:
142 HandleImageViewOn(command);
143 break;
144 case CEC_OPCODE_TEXT_VIEW_ON:
145 HandleTextViewOn(command);
146 break;
147 default:
148 UnhandledCommand(command);
149 bHandled = false;
150 break;
151 }
152
153 if (command.destination == CECDEVICE_BROADCAST || m_busDevice->MyLogicalAddressContains(command.destination))
154 m_busDevice->GetProcessor()->AddCommand(command);
155
156 return bHandled;
157 }
158
159 bool 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
170 bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
171 {
172 CCECBusDevice *device = GetDevice(command.destination);
173 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0)
174 {
175 ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
176 return true;
177 }
178
179 return false;
180 }
181
182 bool 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
194 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
195 {
196 if (m_busDevice->MyLogicalAddressContains(command.destination))
197 m_busDevice->GetProcessor()->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
198
199 return true;
200 }
201
202 bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
203 {
204 SetVendorId(command);
205 return true;
206 }
207
208 bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
209 {
210 if (m_busDevice->MyLogicalAddressContains(command.destination))
211 {
212 CCECBusDevice *device = GetDevice(command.destination);
213 if (device)
214 return device->TransmitCECVersion(command.initiator);
215 }
216
217 return false;
218 }
219
220 bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
221 {
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 }
228
229 return false;
230 }
231
232 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
233 {
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 }
240
241 return false;
242 }
243
244 bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
245 {
246 if (m_busDevice->MyLogicalAddressContains(command.destination))
247 {
248 CCECBusDevice *device = GetDevice(command.destination);
249 if (device)
250 return device->TransmitPowerState(command.initiator);
251 }
252
253 return false;
254 }
255
256 bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
257 {
258 if (m_busDevice->MyLogicalAddressContains(command.destination))
259 {
260 CCECBusDevice *device = GetDevice(command.destination);
261 if (device)
262 return device->TransmitVendorID(command.initiator);
263 }
264
265 return false;
266 }
267
268 bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
269 {
270 if (m_busDevice->MyLogicalAddressContains(command.destination))
271 {
272 CCECBusDevice *device = GetDevice(command.destination);
273 if (device)
274 return device->TransmitOSDName(command.initiator);
275 }
276
277 return false;
278 }
279
280 bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
281 {
282 if (m_busDevice->MyLogicalAddressContains(command.destination))
283 {
284 CCECBusDevice *device = GetDevice(command.destination);
285 if (device)
286 return device->TransmitPhysicalAddress();
287 }
288
289 return false;
290 }
291
292 bool 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
304 bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
305 {
306 m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
307 return true;
308 }
309
310 bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
311 {
312 if (m_busDevice->MyLogicalAddressContains(command.destination))
313 {
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 }
320 }
321
322 return false;
323 }
324
325 bool 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)
331 {
332 ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]);
333 return true;
334 }
335 }
336 return false;
337 }
338
339 bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
340 {
341 if (command.parameters.size == 3)
342 {
343 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
344 SetPhysicalAddress(command.initiator, iNewAddress);
345 }
346 return true;
347 }
348
349 bool 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
360 bool 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());
365
366 vector<CCECBusDevice *> devices;
367 for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
368 devices[iDevicePtr]->TransmitActiveSource();
369
370 return true;
371 }
372
373 bool 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]);
379
380 CCECBusDevice *device = GetDevice(command.initiator);
381 if (device)
382 device->SetStreamPath(iNewAddress, iOldAddress);
383 }
384 return true;
385 }
386
387 bool 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]);
392 m_busDevice->GetProcessor()->SetStreamPath(iNewAddress);
393 }
394
395 return false;
396 }
397
398 bool 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;
407 for (uint8_t iPtr = 0; iPtr < 4; iPtr++)
408 language.language[iPtr] = command.parameters[iPtr];
409 language.language[3] = 0;
410 device->SetMenuLanguage(language);
411 return true;
412 }
413 }
414 return false;
415 }
416
417 bool 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);
431
432 return true;
433 }
434 }
435 return false;
436 }
437
438 bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
439 {
440 if (command.parameters.size >= 2)
441 {
442 uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
443 CStdString strLog;
444 strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
445 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
446
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 }
456 }
457 return false;
458 }
459
460 bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
461 {
462 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1)
463 {
464 CCECBusDevice *device = GetDevice(command.destination);
465 if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
466 return ((CCECAudioSystem *) device)->SetSystemAudioMode(command);
467 }
468 return false;
469 }
470
471 bool CCECCommandHandler::HandleStandby(const cec_command &command)
472 {
473 CCECBusDevice *device = GetDevice(command.initiator);
474 if (device)
475 device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
476
477 return true;
478 }
479
480 bool 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
492 bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
493 {
494 m_busDevice->GetProcessor()->SetActiveSource(command.initiator);
495 return true;
496 }
497
498 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
499 {
500 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
501 {
502 m_busDevice->GetProcessor()->AddKey();
503
504 if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
505 {
506 CStdString strLog;
507 strLog.Format("key pressed: %x", command.parameters[0]);
508 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
509
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
518 m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]);
519 return true;
520 }
521 }
522 return false;
523 }
524
525 bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
526 {
527 if (m_busDevice->MyLogicalAddressContains(command.destination))
528 m_busDevice->GetProcessor()->AddKey();
529
530 return true;
531 }
532
533 void CCECCommandHandler::UnhandledCommand(const cec_command &command)
534 {
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);
538 }
539
540 unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
541 {
542 unsigned int iReturn(0);
543
544 cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
545 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
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
557 CCECBusDevice *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;
565 }
566
567 CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
568 {
569 return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
570 }
571
572 CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const
573 {
574 return m_busDevice->GetProcessor()->GetDeviceByType(type);
575 }
576
577 void 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
585 uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) +
586 ((uint64_t)command.parameters[1] << 8) +
587 (uint64_t)command.parameters[2];
588
589 CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator);
590 if (device)
591 device->SetVendorId(iVendorId);
592 }
593
594 void 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
610 const 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
623 const 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";
635 case CEC_VERSION_1_4:
636 return "1.4";
637 default:
638 return "unknown";
639 }
640 }
641
642 const 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
659 const 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
700 const 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
717 const 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
756 const 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 }
888
889 const 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
902 const char *CCECCommandHandler::ToString(const cec_audio_status status)
903 {
904 // TODO this is a mask
905 return "TODO";
906 }
907
908 const 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";
920 case CEC_VENDOR_ONKYO:
921 return "Onkyo";
922 default:
923 return "Unknown";
924 }
925 }