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