037825acb1d4078c6369efcf2c04295841be6471
[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_SET_OSD_NAME:
136 HandleSetOSDName(command);
137 break;
138 default:
139 UnhandledCommand(command);
140 bHandled = false;
141 break;
142 }
143
144 if (command.destination == CECDEVICE_BROADCAST || m_busDevice->MyLogicalAddressContains(command.destination))
145 m_busDevice->GetProcessor()->AddCommand(command);
146
147 return bHandled;
148 }
149
150 bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
151 {
152 if (command.parameters.size == 2)
153 {
154 uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
155 return m_busDevice->GetProcessor()->SetStreamPath(iAddress);
156 }
157
158 return true;
159 }
160
161 bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
162 {
163 CCECBusDevice *device = GetDevice(command.destination);
164 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0)
165 {
166 ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
167 return true;
168 }
169
170 return false;
171 }
172
173 bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
174 {
175 if (command.parameters.size == 1)
176 {
177 CCECBusDevice *device = GetDevice(command.initiator);
178 if (device)
179 device->SetCecVersion((cec_version) command.parameters[0]);
180 }
181
182 return true;
183 }
184
185 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
186 {
187 if (m_busDevice->MyLogicalAddressContains(command.destination))
188 m_busDevice->GetProcessor()->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
189
190 return true;
191 }
192
193 bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
194 {
195 SetVendorId(command);
196 return true;
197 }
198
199 bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
200 {
201 if (m_busDevice->MyLogicalAddressContains(command.destination))
202 {
203 CCECBusDevice *device = GetDevice(command.destination);
204 if (device)
205 return device->TransmitCECVersion(command.initiator);
206 }
207
208 return false;
209 }
210
211 bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
212 {
213 if (m_busDevice->MyLogicalAddressContains(command.destination))
214 {
215 CCECBusDevice *device = GetDevice(command.destination);
216 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
217 return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator);
218 }
219
220 return false;
221 }
222
223 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
224 {
225 if (m_busDevice->MyLogicalAddressContains(command.destination))
226 {
227 CCECBusDevice *device = GetDevice(command.destination);
228 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
229 return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator);
230 }
231
232 return false;
233 }
234
235 bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
236 {
237 if (m_busDevice->MyLogicalAddressContains(command.destination))
238 {
239 CCECBusDevice *device = GetDevice(command.destination);
240 if (device)
241 return device->TransmitPowerState(command.initiator);
242 }
243
244 return false;
245 }
246
247 bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
248 {
249 if (m_busDevice->MyLogicalAddressContains(command.destination))
250 {
251 CCECBusDevice *device = GetDevice(command.destination);
252 if (device)
253 return device->TransmitVendorID(command.initiator);
254 }
255
256 return false;
257 }
258
259 bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
260 {
261 if (m_busDevice->MyLogicalAddressContains(command.destination))
262 {
263 CCECBusDevice *device = GetDevice(command.destination);
264 if (device)
265 return device->TransmitOSDName(command.initiator);
266 }
267
268 return false;
269 }
270
271 bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
272 {
273 if (m_busDevice->MyLogicalAddressContains(command.destination))
274 {
275 CCECBusDevice *device = GetDevice(command.destination);
276 if (device)
277 return device->TransmitPhysicalAddress();
278 }
279
280 return false;
281 }
282
283 bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
284 {
285 if (m_busDevice->MyLogicalAddressContains(command.destination))
286 {
287 if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
288 {
289 CCECBusDevice *device = GetDevice(command.destination);
290 if (device)
291 return device->TransmitMenuState(command.initiator);
292 }
293 }
294
295 return false;
296 }
297
298 bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command)
299 {
300 if (command.parameters.size == 1)
301 {
302 CCECBusDevice *device = GetDevice(command.initiator);
303 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
304 {
305 ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]);
306 return true;
307 }
308 }
309 return false;
310 }
311
312 bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
313 {
314 if (command.parameters.size == 3)
315 {
316 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
317 cec_device_type type = (cec_device_type)command.parameters[2];
318
319 CCECBusDevice *device = GetDevice(command.initiator);
320 if (device && device->GetType() == type)
321 device->SetPhysicalAddress(iNewAddress);
322 }
323 return true;
324 }
325
326 bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command)
327 {
328 if (command.parameters.size == 1)
329 {
330 CCECBusDevice *device = GetDevice(command.initiator);
331 if (device)
332 device->SetPowerStatus((cec_power_status) command.parameters[0]);
333 }
334 return true;
335 }
336
337 bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
338 {
339 CStdString strLog;
340 strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
341 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
342
343 vector<CCECBusDevice *> devices;
344 for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
345 devices[iDevicePtr]->TransmitActiveSource();
346
347 return true;
348 }
349
350 bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
351 {
352 if (command.parameters.size == 4)
353 {
354 uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
355 uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]);
356
357 CCECBusDevice *device = GetDevice(command.initiator);
358 if (device)
359 device->SetStreamPath(iNewAddress, iOldAddress);
360 }
361 return true;
362 }
363
364 bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command)
365 {
366 if (command.parameters.size == 2)
367 {
368 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
369
370 CCECBusDevice *device = GetDevice(command.initiator);
371 if (device)
372 {
373 device->SetPhysicalAddress(iNewAddress);
374 return true;
375 }
376 }
377
378 return false;
379 }
380
381 bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
382 {
383 if (command.parameters.size == 3)
384 {
385 CCECBusDevice *device = GetDevice(command.initiator);
386 if (device)
387 {
388 cec_menu_language language;
389 language.device = command.initiator;
390 for (uint8_t iPtr = 0; iPtr < 4; iPtr++)
391 language.language[iPtr] = command.parameters[iPtr];
392 language.language[3] = 0;
393 device->SetMenuLanguage(language);
394 return true;
395 }
396 }
397 return false;
398 }
399
400 bool CCECCommandHandler::HandleSetOSDName(const cec_command &command)
401 {
402 if (command.parameters.size > 0)
403 {
404 CCECBusDevice *device = GetDevice(command.initiator);
405 if (device)
406 {
407 char buf[1024];
408 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
409 buf[iPtr] = (char)command.parameters[iPtr];
410 buf[command.parameters.size] = 0;
411
412 CStdString strName(buf);
413 device->SetOSDName(strName);
414
415 return true;
416 }
417 }
418 return false;
419 }
420
421 bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
422 {
423 if (command.parameters.size >= 2)
424 {
425 uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
426 CStdString strLog;
427 strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
428 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
429
430 if (m_busDevice->GetProcessor()->SetStreamPath(iStreamAddress))
431 {
432 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress);
433 if (device)
434 {
435 return device->TransmitActiveSource() &&
436 device->TransmitMenuState(command.initiator);
437 }
438 }
439 }
440 return false;
441 }
442
443 bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
444 {
445 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1)
446 {
447 CCECBusDevice *device = GetDevice(command.destination);
448 if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
449 return ((CCECAudioSystem *) device)->SetSystemAudioMode(command);
450 }
451 return false;
452 }
453
454 bool CCECCommandHandler::HandleStandby(const cec_command &command)
455 {
456 CCECBusDevice *device = GetDevice(command.initiator);
457 if (device)
458 device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
459
460 return true;
461 }
462
463 bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
464 {
465 if (m_busDevice->MyLogicalAddressContains(command.destination))
466 {
467 CCECBusDevice *device = GetDevice(command.destination);
468 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
469 return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
470 }
471
472 return false;
473 }
474
475 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
476 {
477 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
478 {
479 m_busDevice->GetProcessor()->AddKey();
480
481 if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
482 {
483 CStdString strLog;
484 strLog.Format("key pressed: %x", command.parameters[0]);
485 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
486
487 if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
488 command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
489 {
490 CCECBusDevice *device = GetDevice(command.destination);
491 if (device)
492 device->SetPowerStatus(CEC_POWER_STATUS_ON);
493 }
494
495 m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]);
496 return true;
497 }
498 }
499 return false;
500 }
501
502 bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
503 {
504 if (m_busDevice->MyLogicalAddressContains(command.destination))
505 m_busDevice->GetProcessor()->AddKey();
506
507 return true;
508 }
509
510 void CCECCommandHandler::UnhandledCommand(const cec_command &command)
511 {
512 CStdString strLog;
513 strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator);
514 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
515 }
516
517 unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
518 {
519 unsigned int iReturn(0);
520
521 cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
522 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
523 {
524 if (addresses[iPtr])
525 {
526 devices.push_back(GetDevice((cec_logical_address) iPtr));
527 ++iReturn;
528 }
529 }
530
531 return iReturn;
532 }
533
534 CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
535 {
536 CCECBusDevice *device = NULL;
537
538 if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST)
539 device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress];
540
541 return device;
542 }
543
544 CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
545 {
546 return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
547 }
548
549 CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const
550 {
551 return m_busDevice->GetProcessor()->GetDeviceByType(type);
552 }
553
554 void CCECCommandHandler::SetVendorId(const cec_command &command)
555 {
556 if (command.parameters.size < 3)
557 {
558 m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
559 return;
560 }
561
562 uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) +
563 ((uint64_t)command.parameters[1] << 8) +
564 (uint64_t)command.parameters[2];
565
566 CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator);
567 if (device)
568 device->SetVendorId(iVendorId);
569 }
570
571 const char *CCECCommandHandler::ToString(const cec_menu_state state)
572 {
573 switch (state)
574 {
575 case CEC_MENU_STATE_ACTIVATED:
576 return "activated";
577 case CEC_MENU_STATE_DEACTIVATED:
578 return "deactivated";
579 default:
580 return "unknown";
581 }
582 }
583
584 const char *CCECCommandHandler::ToString(const cec_version version)
585 {
586 switch (version)
587 {
588 case CEC_VERSION_1_2:
589 return "1.2";
590 case CEC_VERSION_1_2A:
591 return "1.2a";
592 case CEC_VERSION_1_3:
593 return "1.3";
594 case CEC_VERSION_1_3A:
595 return "1.3a";
596 case CEC_VERSION_1_4:
597 return "1.4";
598 default:
599 return "unknown";
600 }
601 }
602
603 const char *CCECCommandHandler::ToString(const cec_power_status status)
604 {
605 switch (status)
606 {
607 case CEC_POWER_STATUS_ON:
608 return "on";
609 case CEC_POWER_STATUS_STANDBY:
610 return "standby";
611 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
612 return "in transition from on to standby";
613 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
614 return "in transition from standby to on";
615 default:
616 return "unknown";
617 }
618 }
619
620 const char *CCECCommandHandler::ToString(const cec_logical_address address)
621 {
622 switch(address)
623 {
624 case CECDEVICE_AUDIOSYSTEM:
625 return "Audio";
626 case CECDEVICE_BROADCAST:
627 return "Broadcast";
628 case CECDEVICE_FREEUSE:
629 return "Free use";
630 case CECDEVICE_PLAYBACKDEVICE1:
631 return "Playback 1";
632 case CECDEVICE_PLAYBACKDEVICE2:
633 return "Playback 2";
634 case CECDEVICE_PLAYBACKDEVICE3:
635 return "Playback 3";
636 case CECDEVICE_RECORDINGDEVICE1:
637 return "Recorder 1";
638 case CECDEVICE_RECORDINGDEVICE2:
639 return "Recorder 2";
640 case CECDEVICE_RECORDINGDEVICE3:
641 return "Recorder 3";
642 case CECDEVICE_RESERVED1:
643 return "Reserved 1";
644 case CECDEVICE_RESERVED2:
645 return "Reserved 2";
646 case CECDEVICE_TUNER1:
647 return "Tuner 1";
648 case CECDEVICE_TUNER2:
649 return "Tuner 2";
650 case CECDEVICE_TUNER3:
651 return "Tuner 3";
652 case CECDEVICE_TUNER4:
653 return "Tuner 4";
654 case CECDEVICE_TV:
655 return "TV";
656 default:
657 return "unknown";
658 }
659 }
660
661 const char *CCECCommandHandler::ToString(const cec_deck_control_mode mode)
662 {
663 switch (mode)
664 {
665 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
666 return "skip forward wind";
667 case CEC_DECK_CONTROL_MODE_EJECT:
668 return "eject";
669 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
670 return "reverse rewind";
671 case CEC_DECK_CONTROL_MODE_STOP:
672 return "stop";
673 default:
674 return "unknown";
675 }
676 }
677
678 const char *CCECCommandHandler::ToString(const cec_deck_info status)
679 {
680 switch (status)
681 {
682 case CEC_DECK_INFO_PLAY:
683 return "play";
684 case CEC_DECK_INFO_RECORD:
685 return "record";
686 case CEC_DECK_INFO_PLAY_REVERSE:
687 return "play reverse";
688 case CEC_DECK_INFO_STILL:
689 return "still";
690 case CEC_DECK_INFO_SLOW:
691 return "slow";
692 case CEC_DECK_INFO_SLOW_REVERSE:
693 return "slow reverse";
694 case CEC_DECK_INFO_FAST_FORWARD:
695 return "fast forward";
696 case CEC_DECK_INFO_FAST_REVERSE:
697 return "fast reverse";
698 case CEC_DECK_INFO_NO_MEDIA:
699 return "no media";
700 case CEC_DECK_INFO_STOP:
701 return "stop";
702 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
703 return "info skip forward wind";
704 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
705 return "info skip reverse rewind";
706 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
707 return "info index search forward";
708 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
709 return "info index search reverse";
710 case CEC_DECK_INFO_OTHER_STATUS:
711 return "other";
712 default:
713 return "unknown";
714 }
715 }
716
717 const char *CCECCommandHandler::ToString(const cec_opcode opcode)
718 {
719 switch (opcode)
720 {
721 case CEC_OPCODE_ACTIVE_SOURCE:
722 return "active source";
723 case CEC_OPCODE_IMAGE_VIEW_ON:
724 return "image view on";
725 case CEC_OPCODE_TEXT_VIEW_ON:
726 return "text view on";
727 case CEC_OPCODE_INACTIVE_SOURCE:
728 return "inactive source";
729 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
730 return "request active source";
731 case CEC_OPCODE_ROUTING_CHANGE:
732 return "routing change";
733 case CEC_OPCODE_ROUTING_INFORMATION:
734 return "routing information";
735 case CEC_OPCODE_SET_STREAM_PATH:
736 return "set stream path";
737 case CEC_OPCODE_STANDBY:
738 return "standby";
739 case CEC_OPCODE_RECORD_OFF:
740 return "record off";
741 case CEC_OPCODE_RECORD_ON:
742 return "record on";
743 case CEC_OPCODE_RECORD_STATUS:
744 return "record status";
745 case CEC_OPCODE_RECORD_TV_SCREEN:
746 return "record tv screen";
747 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
748 return "clear analogue timer";
749 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
750 return "clear digital timer";
751 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
752 return "clear external timer";
753 case CEC_OPCODE_SET_ANALOGUE_TIMER:
754 return "set analogue timer";
755 case CEC_OPCODE_SET_DIGITAL_TIMER:
756 return "set digital timer";
757 case CEC_OPCODE_SET_EXTERNAL_TIMER:
758 return "set external timer";
759 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
760 return "set timer program title";
761 case CEC_OPCODE_TIMER_CLEARED_STATUS:
762 return "timer cleared status";
763 case CEC_OPCODE_TIMER_STATUS:
764 return "timer status";
765 case CEC_OPCODE_CEC_VERSION:
766 return "cec version";
767 case CEC_OPCODE_GET_CEC_VERSION:
768 return "get cec version";
769 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
770 return "give physical address";
771 case CEC_OPCODE_GET_MENU_LANGUAGE:
772 return "get menu language";
773 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
774 return "report physical address";
775 case CEC_OPCODE_SET_MENU_LANGUAGE:
776 return "set menu language";
777 case CEC_OPCODE_DECK_CONTROL:
778 return "deck control";
779 case CEC_OPCODE_DECK_STATUS:
780 return "deck status";
781 case CEC_OPCODE_GIVE_DECK_STATUS:
782 return "give deck status";
783 case CEC_OPCODE_PLAY:
784 return "play";
785 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
786 return "give tuner status";
787 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
788 return "select analogue service";
789 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
790 return "set digital service";
791 case CEC_OPCODE_TUNER_DEVICE_STATUS:
792 return "tuner device status";
793 case CEC_OPCODE_TUNER_STEP_DECREMENT:
794 return "tuner step decrement";
795 case CEC_OPCODE_TUNER_STEP_INCREMENT:
796 return "tuner step increment";
797 case CEC_OPCODE_DEVICE_VENDOR_ID:
798 return "device vendor id";
799 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
800 return "give device vendor id";
801 case CEC_OPCODE_VENDOR_COMMAND:
802 return "vendor command";
803 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
804 return "vendor command with id";
805 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
806 return "vendor remote button down";
807 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
808 return "vendor remote button up";
809 case CEC_OPCODE_SET_OSD_STRING:
810 return "set osd string";
811 case CEC_OPCODE_GIVE_OSD_NAME:
812 return "give osd name";
813 case CEC_OPCODE_SET_OSD_NAME:
814 return "set osd name";
815 case CEC_OPCODE_MENU_REQUEST:
816 return "menu request";
817 case CEC_OPCODE_MENU_STATUS:
818 return "menu status";
819 case CEC_OPCODE_USER_CONTROL_PRESSED:
820 return "user control pressed";
821 case CEC_OPCODE_USER_CONTROL_RELEASE:
822 return "user control release";
823 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
824 return "give device power status";
825 case CEC_OPCODE_REPORT_POWER_STATUS:
826 return "report power status";
827 case CEC_OPCODE_FEATURE_ABORT:
828 return "feature abort";
829 case CEC_OPCODE_ABORT:
830 return "abort";
831 case CEC_OPCODE_GIVE_AUDIO_STATUS:
832 return "give audio status";
833 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
834 return "give audio mode status";
835 case CEC_OPCODE_REPORT_AUDIO_STATUS:
836 return "report audio status";
837 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
838 return "set system audio mode";
839 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
840 return "system audio mode request";
841 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
842 return "system audio mode status";
843 case CEC_OPCODE_SET_AUDIO_RATE:
844 return "set audio rate";
845 default:
846 return "UNKNOWN";
847 }
848 }
849
850 const char *CCECCommandHandler::ToString(const cec_system_audio_status mode)
851 {
852 switch(mode)
853 {
854 case CEC_SYSTEM_AUDIO_STATUS_ON:
855 return "on";
856 case CEC_SYSTEM_AUDIO_STATUS_OFF:
857 return "off";
858 default:
859 return "unknown";
860 }
861 }
862
863 const char *CCECCommandHandler::ToString(const cec_audio_status status)
864 {
865 // TODO this is a mask
866 return "TODO";
867 }
868
869 const char *CCECCommandHandler::ToString(const cec_vendor_id vendor)
870 {
871 switch (vendor)
872 {
873 case CEC_VENDOR_SAMSUNG:
874 return "Samsung";
875 case CEC_VENDOR_LG:
876 return "LG";
877 case CEC_VENDOR_PANASONIC:
878 return "Panasonic";
879 case CEC_VENDOR_PIONEER:
880 return "Pioneer";
881 case CEC_VENDOR_ONKYO:
882 return "Onkyo";
883 default:
884 return "Unknown";
885 }
886 }