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